2014-02-08 20:57:42 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Responsive navigation tabs.
|
|
|
|
* Utilizes jquery.intrinsic.js to calculate if the tabs are larger than their
|
|
|
|
* container and toggles the 'is-horizontal' class.
|
|
|
|
*
|
2014-09-18 14:27:00 +00:00
|
|
|
* This also supports collapsible navigable is the 'is-collapsible' class is
|
2014-02-08 20:57:42 +00:00
|
|
|
* added to the main element, and a target element is included.
|
|
|
|
*/
|
|
|
|
(function ($, Drupal) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2014-07-02 18:48:06 +00:00
|
|
|
function init(i, tab) {
|
2014-02-08 20:57:42 +00:00
|
|
|
var $tab = $(tab);
|
|
|
|
var $target = $tab.find('[data-drupal-nav-tabs-target]');
|
|
|
|
var isCollapsible = $tab.hasClass('is-collapsible');
|
|
|
|
|
2014-07-02 18:48:06 +00:00
|
|
|
function openMenu(e) {
|
2014-02-08 20:57:42 +00:00
|
|
|
$target.toggleClass('is-open');
|
|
|
|
}
|
|
|
|
|
2014-07-02 18:48:06 +00:00
|
|
|
function handleResize(e) {
|
2014-02-08 20:57:42 +00:00
|
|
|
$tab.addClass('is-horizontal');
|
|
|
|
var isHorizontal = $tab.parent().width() > $tab.intrinsic('width');
|
|
|
|
$tab.toggleClass('is-horizontal', isHorizontal);
|
2014-07-02 18:48:06 +00:00
|
|
|
if (isCollapsible) {
|
2014-02-08 20:57:42 +00:00
|
|
|
$tab.toggleClass('is-collapse-enabled', !isHorizontal);
|
|
|
|
}
|
|
|
|
if (isHorizontal) {
|
|
|
|
$target.removeClass('is-open');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$tab.addClass('position-container is-horizontal-enabled');
|
|
|
|
|
|
|
|
$tab.on('click.tabs', '[data-drupal-nav-tabs-trigger]', openMenu);
|
|
|
|
$(window).on('resize.tabs', Drupal.debounce(handleResize)).trigger('resize.tabs');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise the tabs JS.
|
|
|
|
*/
|
|
|
|
Drupal.behaviors.navTabs = {
|
|
|
|
attach: function (context, settings) {
|
|
|
|
var $tabs = $(context).find('[data-drupal-nav-tabs]');
|
|
|
|
if ($tabs.length) {
|
|
|
|
var notSmartPhone = window.matchMedia('(min-width: 300px)');
|
|
|
|
if (notSmartPhone.matches) {
|
|
|
|
$tabs.once('nav-tabs').each(init);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})(jQuery, Drupal);
|