Skip to content

Commit

Permalink
Cleanup app menu registration
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Nov 2, 2018
1 parent 76fdc21 commit 90bc047
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 36 deletions.
35 changes: 6 additions & 29 deletions core/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -1447,23 +1447,18 @@ function initCore() {
*/
function setupMainMenu() {

// init the more-apps menu
OC.registerMenu($('#more-apps > a'), $('#navigation'));

// toggle the navigation
var $toggle = $('#header .header-appname-container');
var $toggle = $('#more-apps > a');
var $navigation = $('#navigation');
var $appmenu = $('#appmenu');

// init the menu
// init the more-apps menu
OC.registerMenu($toggle, $navigation);
$toggle.data('oldhref', $toggle.attr('href'));
$toggle.attr('href', '#');
$navigation.hide();

// show loading feedback
$navigation.delegate('a', 'click', function(event) {
var $app = $(event.target);

if(!$app.is('a')) {
$app = $app.closest('a');
}
Expand All @@ -1486,6 +1481,9 @@ function initCore() {

$appmenu.delegate('a', 'click', function(event) {
var $app = $(event.target);
if ($app.parent().hasClass('menutoggle')) {
return;
}
if(!$app.is('a')) {
$app = $app.closest('a');
}
Expand Down Expand Up @@ -1539,27 +1537,6 @@ function initCore() {
setupUserMenu();
setupContactsMenu();

// move triangle of apps dropdown to align with app name triangle
// 2 is the additional offset between the triangles
if($('#navigation').length) {
$('#header #nextcloud + .menutoggle').on('click', function(){
$('#menu-css-helper').remove();
var caretPosition = $('.header-appname + .icon-caret').offset().left - 2;
if(caretPosition > 255) {
// if the app name is longer than the menu, just put the triangle in the middle
return;
} else {
$('head').append('<style id="menu-css-helper">#navigation:after { left: '+ caretPosition +'px; }</style>');
}
});
$('#header #appmenu .menutoggle').on('click', function() {
$('#appmenu').toggleClass('menu-open');
if($('#appmenu').is(':visible')) {
$('#menu-css-helper').remove();
}
});
}

var resizeMenu = function() {
var appList = $('#appmenu li');
var rightHeaderWidth = $('.header-right').outerWidth();
Expand Down
21 changes: 14 additions & 7 deletions core/js/tests/specs/coreSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,17 @@ describe('Core base tests', function() {
beforeEach(function() {
jQuery.fx.off = true;
clock = sinon.useFakeTimers();
$('#testArea').append('<div id="header">' +
'<a class="menutoggle header-appname-container" href="#">' +
'<h1 class="header-appname"></h1>' +
'<div class="icon-caret"></div>' +
'</a>' +
$('#testArea').append('<header id="header">' +
'<div class="header-left">' +
'<a href="#" id="#nextcloud"></a>' +
'<ul id="appmenu">' +
'<li id="more-apps" class="menutoggle"><a>foo</a></li>' +
'</ul>' +
'<nav role="navigation"><div id="navigation" style="display: none;">Content</div></nav>' +
'</div>' +
'<div id="navigation"></div>');
$toggle = $('#header').find('.menutoggle');
'<div class="header-right"></div>' +
'</header>');
$toggle = $('#header').find('#more-apps > a');
$navigation = $('#navigation');
});
afterEach(function() {
Expand All @@ -573,6 +576,10 @@ describe('Core base tests', function() {
});
it('Clicking menu toggle toggles navigation in', function() {
window.initCore();
// fore show more apps icon since otherwise it would be hidden since no icons are available
clock.tick(1 * 1000);
$('#more-apps').show();

expect($navigation.is(':visible')).toEqual(false);
$toggle.click();
clock.tick(1 * 1000);
Expand Down

0 comments on commit 90bc047

Please sign in to comment.