Security update for Core, with self-updated composer
[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 = $tabs.outerHeight() <= $tabs.find('.tabs__tab').outerHeight();
22       $tab.toggleClass('is-horizontal', isHorizontal);
23       if (isCollapsible) {
24         $tab.toggleClass('is-collapse-enabled', !isHorizontal);
25       }
26       if (isHorizontal) {
27         $target.removeClass('is-open');
28       }
29     }
30
31     $tab.addClass('position-container is-horizontal-enabled');
32
33     $tab.on('click.tabs', '[data-drupal-nav-tabs-trigger]', openMenu);
34     $(window).on('resize.tabs', Drupal.debounce(handleResize, 150)).trigger('resize.tabs');
35   }
36
37   /**
38    * Initialise the tabs JS.
39    */
40   Drupal.behaviors.navTabs = {
41     attach(context, settings) {
42       const $tabs = $(context).find('[data-drupal-nav-tabs]');
43       if ($tabs.length) {
44         const notSmartPhone = window.matchMedia('(min-width: 300px)');
45         if (notSmartPhone.matches) {
46           $tabs.once('nav-tabs').each(init);
47         }
48       }
49     },
50   };
51 }(jQuery, Drupal));