diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-04-25 19:42:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-25 19:42:01 +0200 |
commit | db94b5d4af711f6e18aac0c9d4b0357a3b9123d1 (patch) | |
tree | 94765548709d2ee9612c715d0f1e775e56bf773a /core/js/js.js | |
parent | 51da0442d9604f9285d02b56f2b1f669701da90b (diff) | |
parent | 27b19aaba1c9a710bb2b1d3338a74ba05ea0678e (diff) | |
download | nextcloud-server-db94b5d4af711f6e18aac0c9d4b0357a3b9123d1.tar.gz nextcloud-server-db94b5d4af711f6e18aac0c9d4b0357a3b9123d1.zip |
Merge pull request #4439 from nextcloud/appmenu-responsive
Responsive app menu
Diffstat (limited to 'core/js/js.js')
-rw-r--r-- | core/js/js.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/core/js/js.js b/core/js/js.js index 883431b2b02..95c00dd6448 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1398,6 +1398,7 @@ function initCore() { // toggle the navigation var $toggle = $('#header .header-appname-container'); var $navigation = $('#navigation'); + var $appmenu = $('#appmenu'); // init the menu OC.registerMenu($toggle, $navigation); @@ -1427,6 +1428,20 @@ function initCore() { OC.hideMenus(function(){return false}); } }); + + $appmenu.delegate('a', 'click', function(event) { + var $app = $(event.target); + if(!$app.is('a')) { + $app = $app.closest('a'); + } + if(event.which === 1 && !event.ctrlKey && !event.metaKey) { + $app.addClass('app-loading'); + } else { + // Close navigation when opening app in + // a new tab + OC.hideMenus(function(){return false}); + } + }); } function setupUserMenu() { @@ -1482,6 +1497,53 @@ function initCore() { }); } + var resizeMenu = function() { + var maxApps = 8; + var appList = $('#appmenu li'); + var availableWidth = $('#header-left').width() - $('#nextcloud').width() - 44; + var appCount = Math.floor((availableWidth)/44); + console.log(appCount); + // show a maximum of 8 apps + if(appCount >= maxApps) { + appCount = maxApps; + } + // show at least 2 apps in the popover + if(appList.length-1-appCount >= 1) { + appCount--; + } + + $('#more-apps a').removeClass('active'); + var lastShownApp; + for (var k = 0; k < appList.length-1; k++) { + var name = $(appList[k]).data('id'); + if(k < appCount) { + $(appList[k]).removeClass('hidden'); + $('#apps li[data-id=' + name + ']').addClass('in-header'); + lastShownApp = appList[k]; + } else { + $(appList[k]).addClass('hidden'); + $('#apps li[data-id=' + name + ']').removeClass('in-header'); + // move active app to last position if it is active + if(appCount > 0 && $(appList[k]).children('a').hasClass('active')) { + $(lastShownApp).addClass('hidden'); + $('#apps li[data-id=' + $(lastShownApp).data('id') + ']').removeClass('in-header'); + $(appList[k]).removeClass('hidden'); + $('#apps li[data-id=' + name + ']').addClass('in-header'); + } + } + } + + // show/hide more apps icon + if($('#apps li:not(.in-header)').length === 0) { + $('#more-apps').hide(); + $('#navigation').hide(); + } else { + $('#more-apps').show(); + } + }; + $(window).resize(resizeMenu); + resizeMenu(); + // just add snapper for logged in users if($('#app-navigation').length && !$('html').hasClass('lte9')) { |