2020-08-04 09:15:16 +02:00
|
|
|
var menuCache = null
|
|
|
|
|
|
|
|
var updateTopMenu = function() {
|
|
|
|
var breakpointMobileWidth = 1024
|
2020-09-03 09:49:30 +02:00
|
|
|
var menu = jQuery('#appmenu')
|
2020-08-04 09:15:16 +02:00
|
|
|
var apps = menu.find('li')
|
|
|
|
var minAppsDesktop = 8
|
2020-08-19 11:29:21 +02:00
|
|
|
var usePercentualAppMenuLimit = 0.8
|
2020-09-03 09:49:30 +02:00
|
|
|
var isMobile = jQuery(window).width() < breakpointMobileWidth
|
2020-08-04 09:15:16 +02:00
|
|
|
var lastShownApp = null
|
|
|
|
var appShown = []
|
2020-09-03 09:49:30 +02:00
|
|
|
var moreApps = jQuery('#more-apps')
|
|
|
|
var navigation = jQuery('#navigation')
|
|
|
|
var navigationApps = jQuery('#apps ul')
|
2020-08-04 09:15:16 +02:00
|
|
|
var appCount = null
|
|
|
|
|
|
|
|
var currentMenuCache = menu.html() + menu.next().html()
|
|
|
|
|
|
|
|
if (currentMenuCache === menuCache) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
navigationApps.html('')
|
|
|
|
|
|
|
|
apps.each(function(i, app) {
|
|
|
|
var dataId = app.getAttribute('data-id')
|
|
|
|
|
|
|
|
if (dataId === null) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-12 10:51:49 +02:00
|
|
|
if (topMenuApps.indexOf(dataId) === -1) {
|
2020-08-04 09:15:16 +02:00
|
|
|
app.classList.add('hidden')
|
|
|
|
app.classList.add('app-hidden')
|
|
|
|
} else {
|
|
|
|
app.classList.remove('hidden')
|
|
|
|
app.classList.add('app-external-site')
|
|
|
|
appShown.push(app)
|
|
|
|
navigationApps.append(app.outerHTML)
|
|
|
|
}
|
2020-09-12 16:32:10 +02:00
|
|
|
|
|
|
|
if (targetBlankApps.indexOf(dataId) !== -1) {
|
|
|
|
jQuery(app).children('a').attr('target', '_blank');
|
|
|
|
}
|
2020-08-04 09:15:16 +02:00
|
|
|
})
|
|
|
|
|
2020-09-03 09:49:30 +02:00
|
|
|
var rightHeaderWidth = jQuery('.header-right').outerWidth()
|
|
|
|
var headerWidth = jQuery('header').outerWidth()
|
|
|
|
var availableWidth = headerWidth - jQuery('#nextcloud').outerWidth()
|
|
|
|
- jQuery('#header .side-menu-opener').outerWidth()
|
2020-08-19 11:29:21 +02:00
|
|
|
- (rightHeaderWidth > 230 ? rightHeaderWidth : 230)
|
2020-08-04 09:15:16 +02:00
|
|
|
|
|
|
|
if (!isMobile) {
|
|
|
|
availableWidth = availableWidth * usePercentualAppMenuLimit
|
|
|
|
}
|
|
|
|
|
2020-09-03 09:49:30 +02:00
|
|
|
appCount = Math.floor(availableWidth / jQuery('#appmenu li').width())
|
2020-08-19 11:29:21 +02:00
|
|
|
|
2020-08-04 09:15:16 +02:00
|
|
|
if (isMobile && appCount > minAppsDesktop) {
|
|
|
|
appCount = minAppsDesktop
|
|
|
|
} else if (!isMobile && appCount < minAppsDesktop) {
|
|
|
|
appCount = minAppsDesktop
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appCount === 0) {
|
|
|
|
menu.addClass('hidden')
|
|
|
|
}
|
|
|
|
|
|
|
|
menu.removeClass('hidden')
|
|
|
|
menu.css('opacity', 1)
|
|
|
|
|
|
|
|
if (appShown.length - 1 - appCount >= 1) {
|
|
|
|
appCount--
|
|
|
|
}
|
|
|
|
|
|
|
|
moreApps.find('a').removeClass('active')
|
|
|
|
|
|
|
|
var k = 0
|
|
|
|
var notInHeader = 0
|
|
|
|
var name
|
|
|
|
|
2020-09-03 09:49:30 +02:00
|
|
|
jQuery(appShown).each(function(i, app) {
|
|
|
|
app = jQuery(app)
|
2020-08-04 09:15:16 +02:00
|
|
|
name = app.data('id')
|
|
|
|
|
|
|
|
if (k < appCount && appCount > 0) {
|
|
|
|
app.removeClass('hidden')
|
|
|
|
lastShownApp = app
|
|
|
|
|
2020-09-03 09:49:30 +02:00
|
|
|
jQuery('#apps li[data-id=' + name + '].app-external-site').addClass('in-header')
|
2020-08-04 09:15:16 +02:00
|
|
|
} else {
|
|
|
|
app.addClass('hidden')
|
|
|
|
notInHeader++
|
|
|
|
|
2020-09-03 09:49:30 +02:00
|
|
|
jQuery('#apps li[data-id=' + name + '].app-external-site').removeClass('in-header')
|
2020-08-04 09:15:16 +02:00
|
|
|
|
|
|
|
if (appCount > 0 && app.children('a').hasClass('active')) {
|
|
|
|
lastShownApp.addClass('hidden')
|
|
|
|
app.removeClass('hidden')
|
|
|
|
notInHeader++
|
|
|
|
|
2020-09-03 09:49:30 +02:00
|
|
|
jQuery('#apps li[data-id=' + name + '].app-external-site')
|
2020-08-04 09:15:16 +02:00
|
|
|
.removeClass('in-header')
|
|
|
|
.addClass('in-header')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
k++
|
|
|
|
})
|
|
|
|
|
2020-10-13 14:32:15 +02:00
|
|
|
// Hack for https://github.com/nextcloud/server/blob/23b0b63c213f5b31eecae817ffd4a9e26f6624d0/core/src/components/MainMenu.js#L74-L96
|
|
|
|
menu.undelegate('li:not(#more-apps) > a', 'click')
|
|
|
|
menu.delegate('li:not(#more-apps) > a', 'click', function(e) {
|
|
|
|
var a = $(e.target)
|
|
|
|
|
|
|
|
if (!a.is('a')) {
|
|
|
|
a = a.closest('a')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a.attr('target') !== '_blank' && e.which === 1 && !e.ctrlKey && !e.metaKey && a.parent('#more-apps').length === 0) {
|
|
|
|
a.find('svg').remove()
|
|
|
|
a.find('div').remove()
|
|
|
|
a.prepend(jQuery('<div/>').addClass(
|
|
|
|
OCA.Theming && OCA.Theming.inverted
|
|
|
|
? 'icon-loading-small'
|
|
|
|
: 'icon-loading-small-dark'
|
|
|
|
))
|
|
|
|
|
|
|
|
window.location.href = a.attr('href')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-09-03 09:49:30 +02:00
|
|
|
jQuery('#apps li.app-external-site').each(function(i, app) {
|
|
|
|
app = jQuery(app)
|
2020-08-19 11:29:21 +02:00
|
|
|
var appId = app.attr('data-id')
|
|
|
|
|
|
|
|
if (app.hasClass('in-header')) {
|
|
|
|
app.find('svg').find('defs').remove()
|
|
|
|
} else {
|
|
|
|
var svg = app.find('svg');
|
|
|
|
|
|
|
|
if (svg.find('defs').length > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var defs = `
|
|
|
|
<defs>
|
|
|
|
<filter id="invertMenuMore-${appId}">
|
|
|
|
<feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"></feColorMatrix>
|
|
|
|
</filter>
|
|
|
|
</defs>`
|
|
|
|
|
|
|
|
svg.prepend(defs)
|
|
|
|
svg.find('image').attr('filter', `url(#invertMenuMore-${appId})`)
|
|
|
|
|
|
|
|
var html = svg.get(0).innerHTML.replace(/fecolormatrix/g, 'feColorMatrix');
|
|
|
|
|
|
|
|
svg.html(html)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-08-04 09:15:16 +02:00
|
|
|
if (notInHeader === 0) {
|
|
|
|
moreApps.hide()
|
|
|
|
navigation.hide()
|
|
|
|
} else {
|
|
|
|
moreApps.show()
|
|
|
|
}
|
|
|
|
|
|
|
|
menuCache = menu.html() + menu.next().html()
|
|
|
|
}
|
|
|
|
|
|
|
|
setInterval(updateTopMenu, 50)
|