From ec3551ede05d9f0ad6d29a6c10660eb6f7ca2f06 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 18 Jul 2019 08:41:48 -0400 Subject: [PATCH] PCHR-4473: Menubar height fixes Included in CiviCRM 5.16.0 Core PR: https://github.com/civicrm/civicrm-core/pull/14839 Gitlab Issue: https://lab.civicrm.org/dev/core/issues/1127 --- css/crm-menubar.css | 2 +- js/crm.menubar.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/css/crm-menubar.css b/css/crm-menubar.css index c3d0ffd22f12..42e316bbf968 100644 --- a/css/crm-menubar.css +++ b/css/crm-menubar.css @@ -203,7 +203,7 @@ body.crm-menubar-over-cms-menu #crm-menubar-toggle-position a i { /* hide the button in desktop view */ #civicrm-menu-nav .crm-menubar-toggle-btn { position: absolute; - top: -99999px; + top: -99999px; /* do not edit this without updating the isMobile() function in crm.menubar.js */ } #civicrm-menu { diff --git a/js/crm.menubar.js b/js/crm.menubar.js index ed5eb920ee60..bd42b8992f38 100644 --- a/js/crm.menubar.js +++ b/js/crm.menubar.js @@ -27,13 +27,13 @@ // Wait for crm-container present on the page as it's faster than document.ready function insert(markup) { - if ($('#crm-container').length) { + if ($('.crm-container').length) { render(markup); } else { new MutationObserver(function(mutations, observer) { _.each(mutations, function(mutant) { _.each(mutant.addedNodes, function(node) { - if ($(node).is('#crm-container')) { + if ($(node).is('.crm-container')) { render(markup); observer.disconnect(); } @@ -244,7 +244,7 @@ } }) .on('resize', function() { - if ($(window).width() >= 768 && $mainMenuState[0].checked) { + if (!isMobile() && $mainMenuState[0].checked) { $mainMenuState[0].click(); } handleResize(); @@ -438,13 +438,18 @@ } function handleResize() { - if ($(window).width() >= 768 && $('#civicrm-menu').height() > 50) { + if (!isMobile() && ($('#civicrm-menu').height() >= (2 * $('#civicrm-menu > li').height()))) { $('body').addClass('crm-menubar-wrapped'); } else { $('body').removeClass('crm-menubar-wrapped'); } } + // Figure out if we've hit the mobile breakpoint, based on the rule in crm-menubar.css + function isMobile() { + return $('.crm-menubar-toggle-btn', '#civicrm-menu-nav').css('top') !== '-99999px'; + } + function traverse(items, itemName, op) { var found; _.each(items, function(item, index) {