Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally use Drupal's jQuery only if available #14442

Merged
merged 1 commit into from
Jun 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.$);