2021-03-31 13:15:40 +03:00
|
|
|
/**
|
2019-05-10 14:38:11 +03:00
|
|
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
*
|
2021-03-31 13:15:40 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2019-05-10 14:38:11 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2021-03-31 13:15:40 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2019-05-10 14:38:11 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
import $ from 'jquery'
|
|
|
|
|
|
|
|
import OC from '../OC'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up the main menu toggle to react to media query changes.
|
|
|
|
* If the screen is small enough, the main menu becomes a toggle.
|
|
|
|
* If the screen is bigger, the main menu is not a toggle any more.
|
|
|
|
*/
|
|
|
|
export const setUp = () => {
|
|
|
|
// init the more-apps menu
|
|
|
|
OC.registerMenu($('#more-apps > a'), $('#navigation'))
|
|
|
|
|
|
|
|
// toggle the navigation
|
|
|
|
const $toggle = $('#header .header-appname-container')
|
|
|
|
const $navigation = $('#navigation')
|
|
|
|
const $appmenu = $('#appmenu')
|
|
|
|
|
|
|
|
// init the menu
|
|
|
|
OC.registerMenu($toggle, $navigation)
|
|
|
|
$toggle.data('oldhref', $toggle.attr('href'))
|
|
|
|
$toggle.attr('href', '#')
|
|
|
|
$navigation.hide()
|
|
|
|
|
|
|
|
// show loading feedback on more apps list
|
|
|
|
$navigation.delegate('a', 'click', event => {
|
|
|
|
let $app = $(event.target)
|
|
|
|
if (!$app.is('a')) {
|
|
|
|
$app = $app.closest('a')
|
|
|
|
}
|
|
|
|
if (event.which === 1 && !event.ctrlKey && !event.metaKey) {
|
|
|
|
$app.find('svg').remove()
|
|
|
|
$app.find('div').remove() // prevent odd double-clicks
|
|
|
|
// no need for theming, loader is already inverted on dark mode
|
|
|
|
// but we need it over the primary colour
|
|
|
|
$app.prepend($('<div/>').addClass('icon-loading-small'))
|
|
|
|
} else {
|
|
|
|
// Close navigation when opening app in
|
|
|
|
// a new tab
|
|
|
|
OC.hideMenus(() => false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
$navigation.delegate('a', 'mouseup', event => {
|
|
|
|
if (event.which === 2) {
|
|
|
|
// Close navigation when opening app in
|
|
|
|
// a new tab via middle click
|
|
|
|
OC.hideMenus(() => false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// show loading feedback on visible apps list
|
|
|
|
$appmenu.delegate('li:not(#more-apps) > a', 'click', event => {
|
|
|
|
let $app = $(event.target)
|
|
|
|
if (!$app.is('a')) {
|
|
|
|
$app = $app.closest('a')
|
|
|
|
}
|
2019-08-06 15:37:03 +03:00
|
|
|
|
2019-05-10 14:38:11 +03:00
|
|
|
if (event.which === 1 && !event.ctrlKey && !event.metaKey && $app.parent('#more-apps').length === 0) {
|
|
|
|
$app.find('svg').remove()
|
|
|
|
$app.find('div').remove() // prevent odd double-clicks
|
|
|
|
$app.prepend($('<div/>').addClass(
|
|
|
|
OCA.Theming && OCA.Theming.inverted
|
|
|
|
? 'icon-loading-small'
|
|
|
|
: 'icon-loading-small-dark'
|
|
|
|
))
|
2019-09-10 13:09:32 +03:00
|
|
|
// trigger redirect
|
|
|
|
// needed for ie, but also works for every browser
|
|
|
|
window.location = $app.attr('href')
|
2019-05-10 14:38:11 +03:00
|
|
|
} else {
|
|
|
|
// Close navigation when opening app in
|
|
|
|
// a new tab
|
|
|
|
OC.hideMenus(() => false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|