Skip to content

Commit 90bc047

Browse files
committed
Cleanup app menu registration
Signed-off-by: Julius Härtl <[email protected]>
1 parent 76fdc21 commit 90bc047

File tree

2 files changed

+20
-36
lines changed

2 files changed

+20
-36
lines changed

core/js/js.js

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,23 +1447,18 @@ function initCore() {
14471447
*/
14481448
function setupMainMenu() {
14491449

1450-
// init the more-apps menu
1451-
OC.registerMenu($('#more-apps > a'), $('#navigation'));
1452-
14531450
// toggle the navigation
1454-
var $toggle = $('#header .header-appname-container');
1451+
var $toggle = $('#more-apps > a');
14551452
var $navigation = $('#navigation');
14561453
var $appmenu = $('#appmenu');
14571454

1458-
// init the menu
1455+
// init the more-apps menu
14591456
OC.registerMenu($toggle, $navigation);
1460-
$toggle.data('oldhref', $toggle.attr('href'));
1461-
$toggle.attr('href', '#');
1462-
$navigation.hide();
14631457

14641458
// show loading feedback
14651459
$navigation.delegate('a', 'click', function(event) {
14661460
var $app = $(event.target);
1461+
14671462
if(!$app.is('a')) {
14681463
$app = $app.closest('a');
14691464
}
@@ -1486,6 +1481,9 @@ function initCore() {
14861481

14871482
$appmenu.delegate('a', 'click', function(event) {
14881483
var $app = $(event.target);
1484+
if ($app.parent().hasClass('menutoggle')) {
1485+
return;
1486+
}
14891487
if(!$app.is('a')) {
14901488
$app = $app.closest('a');
14911489
}
@@ -1539,27 +1537,6 @@ function initCore() {
15391537
setupUserMenu();
15401538
setupContactsMenu();
15411539

1542-
// move triangle of apps dropdown to align with app name triangle
1543-
// 2 is the additional offset between the triangles
1544-
if($('#navigation').length) {
1545-
$('#header #nextcloud + .menutoggle').on('click', function(){
1546-
$('#menu-css-helper').remove();
1547-
var caretPosition = $('.header-appname + .icon-caret').offset().left - 2;
1548-
if(caretPosition > 255) {
1549-
// if the app name is longer than the menu, just put the triangle in the middle
1550-
return;
1551-
} else {
1552-
$('head').append('<style id="menu-css-helper">#navigation:after { left: '+ caretPosition +'px; }</style>');
1553-
}
1554-
});
1555-
$('#header #appmenu .menutoggle').on('click', function() {
1556-
$('#appmenu').toggleClass('menu-open');
1557-
if($('#appmenu').is(':visible')) {
1558-
$('#menu-css-helper').remove();
1559-
}
1560-
});
1561-
}
1562-
15631540
var resizeMenu = function() {
15641541
var appList = $('#appmenu li');
15651542
var rightHeaderWidth = $('.header-right').outerWidth();

core/js/tests/specs/coreSpec.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -552,14 +552,17 @@ describe('Core base tests', function() {
552552
beforeEach(function() {
553553
jQuery.fx.off = true;
554554
clock = sinon.useFakeTimers();
555-
$('#testArea').append('<div id="header">' +
556-
'<a class="menutoggle header-appname-container" href="#">' +
557-
'<h1 class="header-appname"></h1>' +
558-
'<div class="icon-caret"></div>' +
559-
'</a>' +
555+
$('#testArea').append('<header id="header">' +
556+
'<div class="header-left">' +
557+
'<a href="#" id="#nextcloud"></a>' +
558+
'<ul id="appmenu">' +
559+
'<li id="more-apps" class="menutoggle"><a>foo</a></li>' +
560+
'</ul>' +
561+
'<nav role="navigation"><div id="navigation" style="display: none;">Content</div></nav>' +
560562
'</div>' +
561-
'<div id="navigation"></div>');
562-
$toggle = $('#header').find('.menutoggle');
563+
'<div class="header-right"></div>' +
564+
'</header>');
565+
$toggle = $('#header').find('#more-apps > a');
563566
$navigation = $('#navigation');
564567
});
565568
afterEach(function() {
@@ -573,6 +576,10 @@ describe('Core base tests', function() {
573576
});
574577
it('Clicking menu toggle toggles navigation in', function() {
575578
window.initCore();
579+
// fore show more apps icon since otherwise it would be hidden since no icons are available
580+
clock.tick(1 * 1000);
581+
$('#more-apps').show();
582+
576583
expect($navigation.is(':visible')).toEqual(false);
577584
$toggle.click();
578585
clock.tick(1 * 1000);

0 commit comments

Comments
 (0)