mirror of
https://github.com/nextcloud/server.git
synced 2026-02-18 18:28:50 -05:00
chore!(core): remove global snapper.js handling
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
c89939fbd6
commit
fd5108b68b
1 changed files with 2 additions and 182 deletions
184
core/src/init.js
184
core/src/init.js
|
|
@ -3,22 +3,15 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { isRTL } from '@nextcloud/l10n'
|
||||
import $ from 'jquery'
|
||||
import { getLocale } from '@nextcloud/l10n'
|
||||
import moment from 'moment'
|
||||
/* globals Snap */
|
||||
import _ from 'underscore'
|
||||
import { setUp as setUpContactsMenu } from './components/ContactsMenu.js'
|
||||
import { setUp as setUpMainMenu } from './components/MainMenu.js'
|
||||
import { setUp as setUpUserMenu } from './components/UserMenu.js'
|
||||
import OC from './OC/index.js'
|
||||
import { initSessionHeartBeat } from './session-heartbeat.ts'
|
||||
import { initFallbackClipboardAPI } from './utils/ClipboardFallback.ts'
|
||||
import { interceptRequests } from './utils/xhr-request.js'
|
||||
|
||||
// keep in sync with core/css/variables.scss
|
||||
const breakpointMobileWidth = 1024
|
||||
|
||||
/**
|
||||
* Moment doesn't have aliases for every locale and doesn't parse some locale IDs correctly so we need to alias them
|
||||
*/
|
||||
|
|
@ -34,7 +27,7 @@ const localeAliases = {
|
|||
zh_Hant_MO: 'zh-mo',
|
||||
zh_Hant_TW: 'zh-tw',
|
||||
}
|
||||
let locale = OC.getLocale()
|
||||
let locale = getLocale()
|
||||
if (Object.hasOwn(localeAliases, locale)) {
|
||||
locale = localeAliases[locale]
|
||||
}
|
||||
|
|
@ -48,9 +41,6 @@ moment.locale(locale)
|
|||
* Initializes core
|
||||
*/
|
||||
export function initCore() {
|
||||
const SNAPPER_OPEN = isRTL() ? 'right' : 'left'
|
||||
const SNAPPER_CLOSE = isRTL() ? 'left' : 'right'
|
||||
|
||||
interceptRequests()
|
||||
initFallbackClipboardAPI()
|
||||
|
||||
|
|
@ -59,174 +49,4 @@ export function initCore() {
|
|||
setUpMainMenu()
|
||||
setUpUserMenu()
|
||||
setUpContactsMenu()
|
||||
|
||||
// just add snapper for logged in users
|
||||
// and if the app doesn't handle the nav slider itself
|
||||
if ($('#app-navigation').length && !$('html').hasClass('lte9')
|
||||
&& !$('#app-content').hasClass('no-snapper')) {
|
||||
// App sidebar on mobile
|
||||
const snapper = new Snap({
|
||||
element: document.getElementById('app-content'),
|
||||
disable: SNAPPER_CLOSE,
|
||||
maxPosition: 300, // $navigation-width
|
||||
minPosition: -300, // $navigation-width for RTL
|
||||
minDragDistance: 100,
|
||||
})
|
||||
|
||||
$('#app-content').prepend('<div id="app-navigation-toggle" class="icon-menu" style="display:none" tabindex="0"></div>')
|
||||
|
||||
// keep track whether snapper is currently animating, and
|
||||
// prevent to call open or close while that is the case
|
||||
// to avoid duplicating events (snap.js doesn't check this)
|
||||
let animating = false
|
||||
snapper.on('animating', () => {
|
||||
// we need this because the trigger button
|
||||
// is also implicitly wired to close by snapper
|
||||
animating = true
|
||||
})
|
||||
snapper.on('animated', () => {
|
||||
animating = false
|
||||
})
|
||||
snapper.on('start', () => {
|
||||
// we need this because dragging triggers that
|
||||
animating = true
|
||||
})
|
||||
snapper.on('end', () => {
|
||||
// we need this because dragging stop triggers that
|
||||
animating = false
|
||||
})
|
||||
snapper.on('open', () => {
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
$appNavigation.attr('aria-hidden', 'false')
|
||||
})
|
||||
snapper.on('close', () => {
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
$appNavigation.attr('aria-hidden', 'true')
|
||||
})
|
||||
|
||||
// These are necessary because calling open or close
|
||||
// on snapper during an animation makes it trigger an
|
||||
// unfinishable animation, which itself will continue
|
||||
// triggering animating events and cause high CPU load,
|
||||
//
|
||||
// Ref https://github.com/jakiestfu/Snap.js/issues/216
|
||||
const oldSnapperOpen = snapper.open
|
||||
const oldSnapperClose = snapper.close
|
||||
const _snapperOpen = () => {
|
||||
if (animating || snapper.state().state !== 'closed') {
|
||||
return
|
||||
}
|
||||
oldSnapperOpen(SNAPPER_OPEN)
|
||||
}
|
||||
|
||||
const _snapperClose = () => {
|
||||
if (animating || snapper.state().state === 'closed') {
|
||||
return
|
||||
}
|
||||
oldSnapperClose()
|
||||
}
|
||||
|
||||
// Needs to be deferred to properly catch in-between
|
||||
// events that snap.js is triggering after dragging.
|
||||
//
|
||||
// Skipped when running unit tests as we are not testing
|
||||
// the snap.js workarounds...
|
||||
if (!window.TESTING) {
|
||||
snapper.open = () => {
|
||||
_.defer(_snapperOpen)
|
||||
}
|
||||
snapper.close = () => {
|
||||
_.defer(_snapperClose)
|
||||
}
|
||||
}
|
||||
|
||||
$('#app-navigation-toggle').click(() => {
|
||||
// close is implicit in the button by snap.js
|
||||
if (snapper.state().state !== SNAPPER_OPEN) {
|
||||
snapper.open(SNAPPER_OPEN)
|
||||
}
|
||||
})
|
||||
$('#app-navigation-toggle').keypress(() => {
|
||||
if (snapper.state().state === SNAPPER_OPEN) {
|
||||
snapper.close()
|
||||
} else {
|
||||
snapper.open(SNAPPER_OPEN)
|
||||
}
|
||||
})
|
||||
|
||||
// close sidebar when switching navigation entry
|
||||
const $appNavigation = $('#app-navigation')
|
||||
$appNavigation.attr('aria-hidden', 'true')
|
||||
$appNavigation.delegate('a, :button', 'click', (event) => {
|
||||
const $target = $(event.target)
|
||||
// don't hide navigation when changing settings or adding things
|
||||
if ($target.is('.app-navigation-noclose')
|
||||
|| $target.closest('.app-navigation-noclose').length) {
|
||||
return
|
||||
}
|
||||
if ($target.is('.app-navigation-entry-utils-menu-button')
|
||||
|| $target.closest('.app-navigation-entry-utils-menu-button').length) {
|
||||
return
|
||||
}
|
||||
if ($target.is('.add-new')
|
||||
|| $target.closest('.add-new').length) {
|
||||
return
|
||||
}
|
||||
if ($target.is('#app-settings')
|
||||
|| $target.closest('#app-settings').length) {
|
||||
return
|
||||
}
|
||||
snapper.close()
|
||||
})
|
||||
|
||||
let navigationBarSlideGestureEnabled = false
|
||||
let navigationBarSlideGestureAllowed = true
|
||||
let navigationBarSlideGestureEnablePending = false
|
||||
|
||||
OC.allowNavigationBarSlideGesture = () => {
|
||||
navigationBarSlideGestureAllowed = true
|
||||
|
||||
if (navigationBarSlideGestureEnablePending) {
|
||||
snapper.enable()
|
||||
|
||||
navigationBarSlideGestureEnabled = true
|
||||
navigationBarSlideGestureEnablePending = false
|
||||
}
|
||||
}
|
||||
|
||||
OC.disallowNavigationBarSlideGesture = () => {
|
||||
navigationBarSlideGestureAllowed = false
|
||||
|
||||
if (navigationBarSlideGestureEnabled) {
|
||||
const endCurrentDrag = true
|
||||
snapper.disable(endCurrentDrag)
|
||||
|
||||
navigationBarSlideGestureEnabled = false
|
||||
navigationBarSlideGestureEnablePending = true
|
||||
}
|
||||
}
|
||||
|
||||
const toggleSnapperOnSize = () => {
|
||||
if ($(window).width() > breakpointMobileWidth) {
|
||||
$appNavigation.attr('aria-hidden', 'false')
|
||||
snapper.close()
|
||||
snapper.disable()
|
||||
|
||||
navigationBarSlideGestureEnabled = false
|
||||
navigationBarSlideGestureEnablePending = false
|
||||
} else if (navigationBarSlideGestureAllowed) {
|
||||
snapper.enable()
|
||||
|
||||
navigationBarSlideGestureEnabled = true
|
||||
navigationBarSlideGestureEnablePending = false
|
||||
} else {
|
||||
navigationBarSlideGestureEnablePending = true
|
||||
}
|
||||
}
|
||||
|
||||
$(window).resize(_.debounce(toggleSnapperOnSize, 250))
|
||||
|
||||
// initial call
|
||||
toggleSnapperOnSize()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue