Skip to content

Commit

Permalink
Merge pull request #14442 from colemanw/drupal8jquery
Browse files Browse the repository at this point in the history
Conditionally use Drupal's jQuery only if available
  • Loading branch information
eileenmcnaughton authored Jun 6, 2019
2 parents 64979de + 5d17546 commit 04656e8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions js/crm.drupal8.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ localStorage.setItem('Drupal.toolbar.activeTabID', JSON.stringify('toolbar-item-

// Wait for document.ready so Drupal's jQuery is available to this script
$(function($) {
// Need Drupal's jQuery to listen to this event
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]();
}
});
// 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.$);

0 comments on commit 04656e8

Please sign in to comment.