Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / themes / seven / js / nav-tabs.es6.js
1 /**
2  * @file
3  * Responsive navigation tabs.
4  *
5  * This also supports collapsible navigable is the 'is-collapsible' class is
6  * added to the main element, and a target element is included.
7  */
8 (function($, Drupal) {
9   function init(i, tab) {
10     const $tab = $(tab);
11     const $target = $tab.find('[data-drupal-nav-tabs-target]');
12     const isCollapsible = $tab.hasClass('is-collapsible');
13
14     function openMenu(e) {
15       $target.toggleClass('is-open');
16     }
17
18     function handleResize(e) {
19       $tab.addClass('is-horizontal');
20       const $tabs = $tab.find('.tabs');
21       const isHorizontal =
22         $tabs.outerHeight() <= $tabs.find('.tabs__tab').outerHeight();
23       $tab.toggleClass('is-horizontal', isHorizontal);
24       if (isCollapsible) {
25         $tab.toggleClass('is-collapse-enabled', !isHorizontal);
26       }
27       if (isHorizontal) {
28         $target.removeClass('is-open');
29       }
30     }
31
32     $tab.addClass('position-container is-horizontal-enabled');
33
34     $tab.on('click.tabs', '[data-drupal-nav-tabs-trigger]', openMenu);
35     $(window)
36       .on('resize.tabs', Drupal.debounce(handleResize, 150))
37       .trigger('resize.tabs');
38   }
39
40   /**
41    * Initialise the tabs JS.
42    */
43   Drupal.behaviors.navTabs = {
44     attach(context, settings) {
45       const $tabs = $(context).find('[data-drupal-nav-tabs]');
46       if ($tabs.length) {
47         const notSmartPhone = window.matchMedia('(min-width: 300px)');
48         if (notSmartPhone.matches) {
49           $tabs.once('nav-tabs').each(init);
50         }
51       }
52     },
53   };
54 })(jQuery, Drupal);