Merge pull request #1 from civicrm/master
[civicrm-core.git] / js / crm.drupal8.js
CommitLineData
7eed4524 1// http://civicrm.org/licensing
7eed4524 2
b30809e4
CW
3// When on a CiviCRM page the CiviCRM toolbar tab should be active
4localStorage.setItem('Drupal.toolbar.activeTabID', JSON.stringify('toolbar-item-civicrm'));
7eed4524 5
b30809e4
CW
6(function($) {
7 function adjustToggle() {
58152244 8 if ($(window).width() < 768 && $('#toolbar-item-civicrm').length) {
b30809e4
CW
9 $('#civicrm-menu-nav .crm-menubar-toggle-btn').css({
10 left: '' + $('#toolbar-item-civicrm').offset().left + 'px',
11 width: '' + $('#toolbar-item-civicrm').innerWidth() + 'px'
12 });
13 }
14 }
15 $(window).resize(adjustToggle);
16 $(document).on('crmLoad', adjustToggle);
17
18 // Wait for document.ready so Drupal's jQuery is available to this script
19 $(function($) {
5d175460
CW
20 // 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
21 if (window.jQuery) {
22 // This event is only triggered by Drupal's copy of jQuery. CRM.$ won't pick it up.
23 jQuery(document).on('drupalToolbarTabChange', function (event, tab) {
24 if (CRM.menubar && CRM.menubar.position === 'below-cms-menu') {
25 var action = jQuery(tab).is('#toolbar-item-civicrm') ? 'show' : 'hide';
26 CRM.menubar[action]();
27 }
28 });
29 }
b30809e4
CW
30 });
31
32})(CRM.$);