Merge pull request #13768 from eileenmcnaughton/activity_yay
[civicrm-core.git] / js / crm.drupal8.js
index 32c06a6bb43a1a1f3715c4be38f0507c637101c3..74e64cb779290f261b403dddcce74bd3f54a3afa 100644 (file)
@@ -1,17 +1,29 @@
 // http://civicrm.org/licensing
-CRM.$(function($) {
-   // d8 Hack to hide title when it should be (CRM-19960)
-   var pageTitle = $('.page-title');
-   if ('<span id="crm-remove-title" style="display:none">CiviCRM</span>' == 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'));
 
-   $('.crm-hidemenu').click(function(e) {
-     $('#toolbar-bar').slideDown();
-   });
-   $('#crm-notification-container').on('click', '#crm-restore-menu', function() {
-     $('#toolbar-bar').slideUp();
-   });
-});
+(function($) {
+  function adjustToggle() {
+    if ($(window).width() < 768) {
+      $('#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($) {
+    // 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]();
+      }
+    });
+  });
+
+})(CRM.$);