nav-tabs.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. /*eslint-disable */
  8. (function ($, Drupal) {
  9. function init(i, tab) {
  10. var $tab = $(tab);
  11. var $target = $tab.find('[data-drupal-nav-tabs-target]');
  12. var isCollapsible = $tab.hasClass('is-collapsible');
  13. function openMenu(e) {
  14. $target.toggleClass('is-open');
  15. }
  16. function handleResize(e) {
  17. $tab.addClass('is-horizontal');
  18. var $tabs = $tab.find('.tabs');
  19. var isHorizontal = $tabs.outerHeight() <= $tabs.find('.tabs__tab').outerHeight();
  20. $tab.toggleClass('is-horizontal', isHorizontal);
  21. if (isCollapsible) {
  22. $tab.toggleClass('is-collapse-enabled', !isHorizontal);
  23. }
  24. if (isHorizontal) {
  25. $target.removeClass('is-open');
  26. }
  27. }
  28. $tab.addClass('position-container is-horizontal-enabled');
  29. $tab.on('click.tabs', '[data-drupal-nav-tabs-trigger]', openMenu);
  30. $(window).on('resize.tabs', Drupal.debounce(handleResize, 150)).trigger('resize.tabs');
  31. }
  32. Drupal.behaviors.navTabs = {
  33. attach: function attach(context, settings) {
  34. var $tabs = $(context).find('[data-drupal-nav-tabs]');
  35. if ($tabs.length) {
  36. var notSmartPhone = window.matchMedia('(min-width: 300px)');
  37. if (notSmartPhone.matches) {
  38. $tabs.once('nav-tabs').each(init);
  39. }
  40. }
  41. }
  42. };
  43. })(jQuery, Drupal);