X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fcrm.drupal8.js;h=91c7080fbe293a5f50f466857b2e50ed230a911e;hb=6871137ee4dda24f7ae671d73d128e97ce8e0cfa;hp=d141841815eda0f1f94ae23c37106f8574a37463;hpb=c8115b6a584df05d3992d4ef86ac6fd5344a5e28;p=civicrm-core.git diff --git a/js/crm.drupal8.js b/js/crm.drupal8.js index d141841815..91c7080fbe 100644 --- a/js/crm.drupal8.js +++ b/js/crm.drupal8.js @@ -1,17 +1,32 @@ // http://civicrm.org/licensing -CRM.$(function($) { - // d8 Hack to hide title when it should be (CRM-19960) - var pageTitle = $('.page-title'); - if ('' == pageTitle.text()) { - pageTitle.hide(); - } - $('#toolbar-bar').hide(); +// When on a CiviCRM page the CiviCRM toolbar tab should be active +localStorage.setItem('Drupal.toolbar.activeTabID', JSON.stringify('toolbar-item-civicrm')); - $('body').on('click', '.crm-hidemenu', function() { - $('#toolbar-bar').slideDown(); - }); - $('#crm-notification-container').on('click', '#crm-restore-menu', function() { - $('#toolbar-bar').slideUp(); - }); -}); +(function($) { + function adjustToggle() { + if ($(window).width() < 768 && $('#toolbar-item-civicrm').length) { + $('#civicrm-menu-nav .crm-menubar-toggle-btn').css({ + left: '' + $('#toolbar-item-civicrm').offset().left + 'px', + width: '' + $('#toolbar-item-civicrm').innerWidth() + 'px' + }); + } + } + $(window).resize(adjustToggle); + $(document).on('crmLoad', adjustToggle); + + // Wait for document.ready so Drupal's jQuery is available to this script + $(function($) { + // If Drupal's jQuery isn't loaded (e.g. on a stripped-down front-end page), we don't need to worry about the toolbar + if (window.jQuery) { + // This event is only triggered by Drupal's copy of jQuery. CRM.$ won't pick it up. + jQuery(document).on('drupalToolbarTabChange', function (event, tab) { + if (CRM.menubar && CRM.menubar.position === 'below-cms-menu') { + var action = jQuery(tab).is('#toolbar-item-civicrm') ? 'show' : 'hide'; + CRM.menubar[action](); + } + }); + } + }); + +})(CRM.$);