Browse Source

fix issue #19: add a hack to show external sites in the top menu with navigation

tags/v1.6.1
Simon Vieille 1 week ago
parent
commit
03dbe8eeed
Signed by: deblan <simon@deblan.fr> GPG Key ID: 03383D15A1D31745
4 changed files with 128 additions and 35 deletions
  1. +10
    -2
      src/SideMenu.vue
  2. +0
    -1
      src/admin.js
  3. +8
    -8
      templates/css/stylesheet.php
  4. +110
    -24
      templates/js/script.php

+ 10
- 2
src/SideMenu.vue View File

@@ -54,9 +54,17 @@ export default {

for (let element of links) {
let href = element.getAttribute('href')
var parent = element.parentNode

if (this.ignoreExternalSites && element.parentNode.getAttribute('data-id').indexOf('external_index') !== -1) {
continue;
if (!parent) {
continue
}

var dataId = parent.getAttribute('data-id')
dataId = dataId !== null ? dataId : ''

if (this.ignoreExternalSites && dataId.indexOf('external_index') !== -1) {
continue
}

if (href !== '#') {


+ 0
- 1
src/admin.js View File

@@ -30,7 +30,6 @@ const appConfig = (name, value, callbacks) => {
OCP.AppConfig.setValue('side_menu', name, value, callbacks)
}


const saveSettings = (key) => {
const element = elements.get(key)
const name = $(element).attr('name')


+ 8
- 8
templates/css/stylesheet.php View File

@@ -12,11 +12,16 @@
#appmenu {
display: none;
}

#appmenu + nav {
display: none;
}
<?php else: ?>
.app-hidden {
opacity: 0;
}
<?php endif; ?>

#appmenu + nav {
display: none;
}

<?php if ($_['opener-only'] === true): ?>
#nextcloud {
@@ -42,11 +47,6 @@
visibility: hidden;
}

#side-menu.hide-opener .side-menu-apps-list {
/* height: calc(100vh);
top: 0; */
}

<?php if ($_['size-text'] === 'hidden'): ?>
#side-menu, .side-menu-apps-list {
<?php if ($_['size-icon'] === 'big'): ?>


+ 110
- 24
templates/js/script.php View File

@@ -9,30 +9,6 @@
sideMenuContainer.attr('data-forcelighticon', '1')
<?php endif; ?>

<?php if ($_['external-sites-in-top-menu']): ?>
sideMenuContainer.attr('data-externalsitesintopmenu', '1')

var externalSitesInTopMenu = function() {
var items = $('#appmenu').find('li')

items.each(function(i, item) {
var dataId = item.getAttribute('data-id')

if (dataId === null || dataId.indexOf('external_index') === -1) {
item.style.display = 'none'
item.classList.remove('hidden')
} else {
item.style.display = 'flex'
item.classList.add('hidden')
}
})
}

$(window).resize(externalSitesInTopMenu);

setInterval(externalSitesInTopMenu, 500);
<?php endif; ?>

body.on('side-menu.apps', function(e, apps) {
<?php if ($_['hide-when-no-apps']): ?>
sideMenu = $('#side-menu')
@@ -93,4 +69,114 @@
<?php else: ?>
sideMenuOpener.insertAfter('#nextcloud')
<?php endif; ?>

<?php if ($_['external-sites-in-top-menu']): ?>
sideMenuContainer.attr('data-externalsitesintopmenu', '1')

var updateTopMenu = function() {
var breakpointMobileWidth = 1024
var menu = $('#appmenu')
var apps = menu.find('li')
var minAppsDesktop = 8
var usePercentualAppMenuLimit = 0.9
var isMobile = $(window).width() < breakpointMobileWidth
var lastShownApp = null
var appShown = []
var moreApps = $('#more-apps')
var navigation = $('#navigation')
var navigationApps = $('#apps ul')
var appCount = null

navigationApps.html('')

apps.each(function(i, app) {
var dataId = app.getAttribute('data-id')

if (dataId === null) {
return
}

if (dataId.indexOf('external_index') === -1) {
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)
}
})

var rightHeaderWidth = $('.header-right').outerWidth()
var headerWidth = $('header').outerWidth()
var availableWidth = headerWidth - $('#nextcloud').outerWidth() - $('#header .side-menu-opener').outerWidth() - (rightHeaderWidth > 210 ? rightHeaderWidth : 210)

if (!isMobile) {
availableWidth = availableWidth * usePercentualAppMenuLimit
}

if (isMobile && appCount > minAppsDesktop) {
appCount = minAppsDesktop
} else if (!isMobile && appCount < minAppsDesktop) {
appCount = minAppsDesktop
} else {
appCount = Math.floor(availableWidth / $('#appmenu li').width())
}

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

$(appShown).each(function(i, app) {
app = $(app)
name = app.data('id')

if (k < appCount && appCount > 0) {
app.removeClass('hidden')
lastShownApp = app

$('#apps li[data-id=' + name + '].app-external-site').addClass('in-header')
} else {
app.addClass('hidden')
notInHeader++

$('#apps li[data-id=' + name + '].app-external-site').removeClass('in-header')

if (appCount > 0 && app.children('a').hasClass('active')) {
lastShownApp.addClass('hidden')
app.removeClass('hidden')
notInHeader++

$('#apps li[data-id=' + name + '].app-external-site')
.removeClass('in-header')
.addClass('in-header')
}
}

k++
})

if (notInHeader === 0) {
moreApps.hide()
navigation.hide()
} else {
moreApps.show()
}
}

setInterval(updateTopMenu, 50)
<?php endif; ?>
})();

Loading…
Cancel
Save