foundation.tabs.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("./foundation.core"), require("./foundation.util.imageLoader"), require("./foundation.util.keyboard"), require("jquery"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["./foundation.core", "./foundation.util.imageLoader", "./foundation.util.keyboard", "jquery"], factory);
  6. else if(typeof exports === 'object')
  7. exports["foundation.tabs"] = factory(require("./foundation.core"), require("./foundation.util.imageLoader"), require("./foundation.util.keyboard"), require("jquery"));
  8. else
  9. root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.tabs"] = factory(root["__FOUNDATION_EXTERNAL__"]["foundation.core"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.imageLoader"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.keyboard"], root["jQuery"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE__foundation_core__, __WEBPACK_EXTERNAL_MODULE__foundation_util_imageLoader__, __WEBPACK_EXTERNAL_MODULE__foundation_util_keyboard__, __WEBPACK_EXTERNAL_MODULE_jquery__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = 18);
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "./foundation.core":
  99. /*!****************************************************************************************************************************************************************!*\
  100. !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.core"],"amd":"./foundation.core","commonjs":"./foundation.core","commonjs2":"./foundation.core"} ***!
  101. \****************************************************************************************************************************************************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_core__;
  105. /***/ }),
  106. /***/ "./foundation.util.imageLoader":
  107. /*!****************************************************************************************************************************************************************************************************************!*\
  108. !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.util.imageLoader"],"amd":"./foundation.util.imageLoader","commonjs":"./foundation.util.imageLoader","commonjs2":"./foundation.util.imageLoader"} ***!
  109. \****************************************************************************************************************************************************************************************************************/
  110. /*! no static exports found */
  111. /***/ (function(module, exports) {
  112. module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_util_imageLoader__;
  113. /***/ }),
  114. /***/ "./foundation.util.keyboard":
  115. /*!****************************************************************************************************************************************************************************************************!*\
  116. !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.util.keyboard"],"amd":"./foundation.util.keyboard","commonjs":"./foundation.util.keyboard","commonjs2":"./foundation.util.keyboard"} ***!
  117. \****************************************************************************************************************************************************************************************************/
  118. /*! no static exports found */
  119. /***/ (function(module, exports) {
  120. module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_util_keyboard__;
  121. /***/ }),
  122. /***/ "./js/entries/plugins/foundation.tabs.js":
  123. /*!***********************************************!*\
  124. !*** ./js/entries/plugins/foundation.tabs.js ***!
  125. \***********************************************/
  126. /*! exports provided: Foundation, Tabs */
  127. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  128. "use strict";
  129. __webpack_require__.r(__webpack_exports__);
  130. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core");
  131. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_0__);
  132. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Foundation", function() { return _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"]; });
  133. /* harmony import */ var _foundation_tabs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.tabs */ "./js/foundation.tabs.js");
  134. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Tabs", function() { return _foundation_tabs__WEBPACK_IMPORTED_MODULE_1__["Tabs"]; });
  135. _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"].plugin(_foundation_tabs__WEBPACK_IMPORTED_MODULE_1__["Tabs"], 'Tabs');
  136. /***/ }),
  137. /***/ "./js/foundation.tabs.js":
  138. /*!*******************************!*\
  139. !*** ./js/foundation.tabs.js ***!
  140. \*******************************/
  141. /*! exports provided: Tabs */
  142. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  143. "use strict";
  144. __webpack_require__.r(__webpack_exports__);
  145. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Tabs", function() { return Tabs; });
  146. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
  147. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
  148. /* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.core.plugin */ "./foundation.core");
  149. /* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__);
  150. /* harmony import */ var _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.util.keyboard */ "./foundation.util.keyboard");
  151. /* harmony import */ var _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2__);
  152. /* harmony import */ var _foundation_util_imageLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./foundation.util.imageLoader */ "./foundation.util.imageLoader");
  153. /* harmony import */ var _foundation_util_imageLoader__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_imageLoader__WEBPACK_IMPORTED_MODULE_3__);
  154. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  155. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  156. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  157. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  158. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  159. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  160. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  161. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  162. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  163. /**
  164. * Tabs module.
  165. * @module foundation.tabs
  166. * @requires foundation.util.keyboard
  167. * @requires foundation.util.imageLoader if tabs contain images
  168. */
  169. var Tabs =
  170. /*#__PURE__*/
  171. function (_Plugin) {
  172. _inherits(Tabs, _Plugin);
  173. function Tabs() {
  174. _classCallCheck(this, Tabs);
  175. return _possibleConstructorReturn(this, _getPrototypeOf(Tabs).apply(this, arguments));
  176. }
  177. _createClass(Tabs, [{
  178. key: "_setup",
  179. /**
  180. * Creates a new instance of tabs.
  181. * @class
  182. * @name Tabs
  183. * @fires Tabs#init
  184. * @param {jQuery} element - jQuery object to make into tabs.
  185. * @param {Object} options - Overrides to the default plugin settings.
  186. */
  187. value: function _setup(element, options) {
  188. this.$element = element;
  189. this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend({}, Tabs.defaults, this.$element.data(), options);
  190. this.className = 'Tabs'; // ie9 back compat
  191. this._init();
  192. _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2__["Keyboard"].register('Tabs', {
  193. 'ENTER': 'open',
  194. 'SPACE': 'open',
  195. 'ARROW_RIGHT': 'next',
  196. 'ARROW_UP': 'previous',
  197. 'ARROW_DOWN': 'next',
  198. 'ARROW_LEFT': 'previous' // 'TAB': 'next',
  199. // 'SHIFT_TAB': 'previous'
  200. });
  201. }
  202. /**
  203. * Initializes the tabs by showing and focusing (if autoFocus=true) the preset active tab.
  204. * @private
  205. */
  206. }, {
  207. key: "_init",
  208. value: function _init() {
  209. var _this2 = this;
  210. var _this = this;
  211. this._isInitializing = true;
  212. this.$element.attr({
  213. 'role': 'tablist'
  214. });
  215. this.$tabTitles = this.$element.find(".".concat(this.options.linkClass));
  216. this.$tabContent = jquery__WEBPACK_IMPORTED_MODULE_0___default()("[data-tabs-content=\"".concat(this.$element[0].id, "\"]"));
  217. this.$tabTitles.each(function () {
  218. var $elem = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this),
  219. $link = $elem.find('a'),
  220. isActive = $elem.hasClass("".concat(_this.options.linkActiveClass)),
  221. hash = $link.attr('data-tabs-target') || $link[0].hash.slice(1),
  222. linkId = $link[0].id ? $link[0].id : "".concat(hash, "-label"),
  223. $tabContent = jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(hash));
  224. $elem.attr({
  225. 'role': 'presentation'
  226. });
  227. $link.attr({
  228. 'role': 'tab',
  229. 'aria-controls': hash,
  230. 'aria-selected': isActive,
  231. 'id': linkId,
  232. 'tabindex': isActive ? '0' : '-1'
  233. });
  234. $tabContent.attr({
  235. 'role': 'tabpanel',
  236. 'aria-labelledby': linkId
  237. }); // Save up the initial hash to return to it later when going back in history
  238. if (isActive) {
  239. _this._initialAnchor = "#".concat(hash);
  240. }
  241. if (!isActive) {
  242. $tabContent.attr('aria-hidden', 'true');
  243. }
  244. if (isActive && _this.options.autoFocus) {
  245. _this.onLoadListener = Object(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__["onLoad"])(jquery__WEBPACK_IMPORTED_MODULE_0___default()(window), function () {
  246. jquery__WEBPACK_IMPORTED_MODULE_0___default()('html, body').animate({
  247. scrollTop: $elem.offset().top
  248. }, _this.options.deepLinkSmudgeDelay, function () {
  249. $link.focus();
  250. });
  251. });
  252. }
  253. });
  254. if (this.options.matchHeight) {
  255. var $images = this.$tabContent.find('img');
  256. if ($images.length) {
  257. Object(_foundation_util_imageLoader__WEBPACK_IMPORTED_MODULE_3__["onImagesLoaded"])($images, this._setHeight.bind(this));
  258. } else {
  259. this._setHeight();
  260. }
  261. } // Current context-bound function to open tabs on page load or history hashchange
  262. this._checkDeepLink = function () {
  263. var anchor = window.location.hash;
  264. if (!anchor.length) {
  265. // If we are still initializing and there is no anchor, then there is nothing to do
  266. if (_this2._isInitializing) return; // Otherwise, move to the initial anchor
  267. if (_this2._initialAnchor) anchor = _this2._initialAnchor;
  268. }
  269. var anchorNoHash = anchor.indexOf('#') >= 0 ? anchor.slice(1) : anchor;
  270. var $anchor = anchorNoHash && jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(anchorNoHash));
  271. var $link = anchor && _this2.$element.find("[href$=\"".concat(anchor, "\"],[data-tabs-target=\"").concat(anchorNoHash, "\"]")).first(); // Whether the anchor element that has been found is part of this element
  272. var isOwnAnchor = !!($anchor.length && $link.length);
  273. if (isOwnAnchor) {
  274. // If there is an anchor for the hash, select it
  275. if ($anchor && $anchor.length && $link && $link.length) {
  276. _this2.selectTab($anchor, true);
  277. } // Otherwise, collapse everything
  278. else {
  279. _this2._collapse();
  280. } // Roll up a little to show the titles
  281. if (_this2.options.deepLinkSmudge) {
  282. var offset = _this2.$element.offset();
  283. jquery__WEBPACK_IMPORTED_MODULE_0___default()('html, body').animate({
  284. scrollTop: offset.top
  285. }, _this2.options.deepLinkSmudgeDelay);
  286. }
  287. /**
  288. * Fires when the plugin has deeplinked at pageload
  289. * @event Tabs#deeplink
  290. */
  291. _this2.$element.trigger('deeplink.zf.tabs', [$link, $anchor]);
  292. }
  293. }; //use browser to open a tab, if it exists in this tabset
  294. if (this.options.deepLink) {
  295. this._checkDeepLink();
  296. }
  297. this._events();
  298. this._isInitializing = false;
  299. }
  300. /**
  301. * Adds event handlers for items within the tabs.
  302. * @private
  303. */
  304. }, {
  305. key: "_events",
  306. value: function _events() {
  307. this._addKeyHandler();
  308. this._addClickHandler();
  309. this._setHeightMqHandler = null;
  310. if (this.options.matchHeight) {
  311. this._setHeightMqHandler = this._setHeight.bind(this);
  312. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).on('changed.zf.mediaquery', this._setHeightMqHandler);
  313. }
  314. if (this.options.deepLink) {
  315. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).on('hashchange', this._checkDeepLink);
  316. }
  317. }
  318. /**
  319. * Adds click handlers for items within the tabs.
  320. * @private
  321. */
  322. }, {
  323. key: "_addClickHandler",
  324. value: function _addClickHandler() {
  325. var _this = this;
  326. this.$element.off('click.zf.tabs').on('click.zf.tabs', ".".concat(this.options.linkClass), function (e) {
  327. e.preventDefault();
  328. _this._handleTabChange(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this));
  329. });
  330. }
  331. /**
  332. * Adds keyboard event handlers for items within the tabs.
  333. * @private
  334. */
  335. }, {
  336. key: "_addKeyHandler",
  337. value: function _addKeyHandler() {
  338. var _this = this;
  339. this.$tabTitles.off('keydown.zf.tabs').on('keydown.zf.tabs', function (e) {
  340. if (e.which === 9) return;
  341. var $element = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this),
  342. $elements = $element.parent('ul').children('li'),
  343. $prevElement,
  344. $nextElement;
  345. $elements.each(function (i) {
  346. if (jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).is($element)) {
  347. if (_this.options.wrapOnKeys) {
  348. $prevElement = i === 0 ? $elements.last() : $elements.eq(i - 1);
  349. $nextElement = i === $elements.length - 1 ? $elements.first() : $elements.eq(i + 1);
  350. } else {
  351. $prevElement = $elements.eq(Math.max(0, i - 1));
  352. $nextElement = $elements.eq(Math.min(i + 1, $elements.length - 1));
  353. }
  354. return;
  355. }
  356. }); // handle keyboard event with keyboard util
  357. _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2__["Keyboard"].handleKey(e, 'Tabs', {
  358. open: function open() {
  359. $element.find('[role="tab"]').focus();
  360. _this._handleTabChange($element);
  361. },
  362. previous: function previous() {
  363. $prevElement.find('[role="tab"]').focus();
  364. _this._handleTabChange($prevElement);
  365. },
  366. next: function next() {
  367. $nextElement.find('[role="tab"]').focus();
  368. _this._handleTabChange($nextElement);
  369. },
  370. handled: function handled() {
  371. e.preventDefault();
  372. }
  373. });
  374. });
  375. }
  376. /**
  377. * Opens the tab `$targetContent` defined by `$target`. Collapses active tab.
  378. * @param {jQuery} $target - Tab to open.
  379. * @param {boolean} historyHandled - browser has already handled a history update
  380. * @fires Tabs#change
  381. * @function
  382. */
  383. }, {
  384. key: "_handleTabChange",
  385. value: function _handleTabChange($target, historyHandled) {
  386. // With `activeCollapse`, if the target is the active Tab, collapse it.
  387. if ($target.hasClass("".concat(this.options.linkActiveClass))) {
  388. if (this.options.activeCollapse) {
  389. this._collapse();
  390. }
  391. return;
  392. }
  393. var $oldTab = this.$element.find(".".concat(this.options.linkClass, ".").concat(this.options.linkActiveClass)),
  394. $tabLink = $target.find('[role="tab"]'),
  395. target = $tabLink.attr('data-tabs-target'),
  396. anchor = target && target.length ? "#".concat(target) : $tabLink[0].hash,
  397. $targetContent = this.$tabContent.find(anchor); //close old tab
  398. this._collapseTab($oldTab); //open new tab
  399. this._openTab($target); //either replace or update browser history
  400. if (this.options.deepLink && !historyHandled) {
  401. if (this.options.updateHistory) {
  402. history.pushState({}, '', anchor);
  403. } else {
  404. history.replaceState({}, '', anchor);
  405. }
  406. }
  407. /**
  408. * Fires when the plugin has successfully changed tabs.
  409. * @event Tabs#change
  410. */
  411. this.$element.trigger('change.zf.tabs', [$target, $targetContent]); //fire to children a mutation event
  412. $targetContent.find("[data-mutate]").trigger("mutateme.zf.trigger");
  413. }
  414. /**
  415. * Opens the tab `$targetContent` defined by `$target`.
  416. * @param {jQuery} $target - Tab to open.
  417. * @function
  418. */
  419. }, {
  420. key: "_openTab",
  421. value: function _openTab($target) {
  422. var $tabLink = $target.find('[role="tab"]'),
  423. hash = $tabLink.attr('data-tabs-target') || $tabLink[0].hash.slice(1),
  424. $targetContent = this.$tabContent.find("#".concat(hash));
  425. $target.addClass("".concat(this.options.linkActiveClass));
  426. $tabLink.attr({
  427. 'aria-selected': 'true',
  428. 'tabindex': '0'
  429. });
  430. $targetContent.addClass("".concat(this.options.panelActiveClass)).removeAttr('aria-hidden');
  431. }
  432. /**
  433. * Collapses `$targetContent` defined by `$target`.
  434. * @param {jQuery} $target - Tab to collapse.
  435. * @function
  436. */
  437. }, {
  438. key: "_collapseTab",
  439. value: function _collapseTab($target) {
  440. var $target_anchor = $target.removeClass("".concat(this.options.linkActiveClass)).find('[role="tab"]').attr({
  441. 'aria-selected': 'false',
  442. 'tabindex': -1
  443. });
  444. jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat($target_anchor.attr('aria-controls'))).removeClass("".concat(this.options.panelActiveClass)).attr({
  445. 'aria-hidden': 'true'
  446. });
  447. }
  448. /**
  449. * Collapses the active Tab.
  450. * @fires Tabs#collapse
  451. * @function
  452. */
  453. }, {
  454. key: "_collapse",
  455. value: function _collapse() {
  456. var $activeTab = this.$element.find(".".concat(this.options.linkClass, ".").concat(this.options.linkActiveClass));
  457. if ($activeTab.length) {
  458. this._collapseTab($activeTab);
  459. /**
  460. * Fires when the plugin has successfully collapsed tabs.
  461. * @event Tabs#collapse
  462. */
  463. this.$element.trigger('collapse.zf.tabs', [$activeTab]);
  464. }
  465. }
  466. /**
  467. * Public method for selecting a content pane to display.
  468. * @param {jQuery | String} elem - jQuery object or string of the id of the pane to display.
  469. * @param {boolean} historyHandled - browser has already handled a history update
  470. * @function
  471. */
  472. }, {
  473. key: "selectTab",
  474. value: function selectTab(elem, historyHandled) {
  475. var idStr, hashIdStr;
  476. if (_typeof(elem) === 'object') {
  477. idStr = elem[0].id;
  478. } else {
  479. idStr = elem;
  480. }
  481. if (idStr.indexOf('#') < 0) {
  482. hashIdStr = "#".concat(idStr);
  483. } else {
  484. hashIdStr = idStr;
  485. idStr = idStr.slice(1);
  486. }
  487. var $target = this.$tabTitles.has("[href$=\"".concat(hashIdStr, "\"],[data-tabs-target=\"").concat(idStr, "\"]")).first();
  488. this._handleTabChange($target, historyHandled);
  489. }
  490. }, {
  491. key: "_setHeight",
  492. /**
  493. * Sets the height of each panel to the height of the tallest panel.
  494. * If enabled in options, gets called on media query change.
  495. * If loading content via external source, can be called directly or with _reflow.
  496. * If enabled with `data-match-height="true"`, tabs sets to equal height
  497. * @function
  498. * @private
  499. */
  500. value: function _setHeight() {
  501. var max = 0,
  502. _this = this; // Lock down the `this` value for the root tabs object
  503. this.$tabContent.find(".".concat(this.options.panelClass)).css('height', '').each(function () {
  504. var panel = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this),
  505. isActive = panel.hasClass("".concat(_this.options.panelActiveClass)); // get the options from the parent instead of trying to get them from the child
  506. if (!isActive) {
  507. panel.css({
  508. 'visibility': 'hidden',
  509. 'display': 'block'
  510. });
  511. }
  512. var temp = this.getBoundingClientRect().height;
  513. if (!isActive) {
  514. panel.css({
  515. 'visibility': '',
  516. 'display': ''
  517. });
  518. }
  519. max = temp > max ? temp : max;
  520. }).css('height', "".concat(max, "px"));
  521. }
  522. /**
  523. * Destroys an instance of tabs.
  524. * @fires Tabs#destroyed
  525. */
  526. }, {
  527. key: "_destroy",
  528. value: function _destroy() {
  529. this.$element.find(".".concat(this.options.linkClass)).off('.zf.tabs').hide().end().find(".".concat(this.options.panelClass)).hide();
  530. if (this.options.matchHeight) {
  531. if (this._setHeightMqHandler != null) {
  532. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off('changed.zf.mediaquery', this._setHeightMqHandler);
  533. }
  534. }
  535. if (this.options.deepLink) {
  536. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off('hashchange', this._checkDeepLink);
  537. }
  538. if (this.onLoadListener) {
  539. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off(this.onLoadListener);
  540. }
  541. }
  542. }]);
  543. return Tabs;
  544. }(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__["Plugin"]);
  545. Tabs.defaults = {
  546. /**
  547. * Link the location hash to the active pane.
  548. * Set the location hash when the active pane changes, and open the corresponding pane when the location changes.
  549. * @option
  550. * @type {boolean}
  551. * @default false
  552. */
  553. deepLink: false,
  554. /**
  555. * If `deepLink` is enabled, adjust the deep link scroll to make sure the top of the tab panel is visible
  556. * @option
  557. * @type {boolean}
  558. * @default false
  559. */
  560. deepLinkSmudge: false,
  561. /**
  562. * If `deepLinkSmudge` is enabled, animation time (ms) for the deep link adjustment
  563. * @option
  564. * @type {number}
  565. * @default 300
  566. */
  567. deepLinkSmudgeDelay: 300,
  568. /**
  569. * If `deepLink` is enabled, update the browser history with the open tab
  570. * @option
  571. * @type {boolean}
  572. * @default false
  573. */
  574. updateHistory: false,
  575. /**
  576. * Allows the window to scroll to content of active pane on load.
  577. * Not recommended if more than one tab panel per page.
  578. * @option
  579. * @type {boolean}
  580. * @default false
  581. */
  582. autoFocus: false,
  583. /**
  584. * Allows keyboard input to 'wrap' around the tab links.
  585. * @option
  586. * @type {boolean}
  587. * @default true
  588. */
  589. wrapOnKeys: true,
  590. /**
  591. * Allows the tab content panes to match heights if set to true.
  592. * @option
  593. * @type {boolean}
  594. * @default false
  595. */
  596. matchHeight: false,
  597. /**
  598. * Allows active tabs to collapse when clicked.
  599. * @option
  600. * @type {boolean}
  601. * @default false
  602. */
  603. activeCollapse: false,
  604. /**
  605. * Class applied to `li`'s in tab link list.
  606. * @option
  607. * @type {string}
  608. * @default 'tabs-title'
  609. */
  610. linkClass: 'tabs-title',
  611. /**
  612. * Class applied to the active `li` in tab link list.
  613. * @option
  614. * @type {string}
  615. * @default 'is-active'
  616. */
  617. linkActiveClass: 'is-active',
  618. /**
  619. * Class applied to the content containers.
  620. * @option
  621. * @type {string}
  622. * @default 'tabs-panel'
  623. */
  624. panelClass: 'tabs-panel',
  625. /**
  626. * Class applied to the active content container.
  627. * @option
  628. * @type {string}
  629. * @default 'is-active'
  630. */
  631. panelActiveClass: 'is-active'
  632. };
  633. /***/ }),
  634. /***/ 18:
  635. /*!*****************************************************!*\
  636. !*** multi ./js/entries/plugins/foundation.tabs.js ***!
  637. \*****************************************************/
  638. /*! no static exports found */
  639. /***/ (function(module, exports, __webpack_require__) {
  640. module.exports = __webpack_require__(/*! /Users/joeworkman/Development/foundation-sites/js/entries/plugins/foundation.tabs.js */"./js/entries/plugins/foundation.tabs.js");
  641. /***/ }),
  642. /***/ "jquery":
  643. /*!********************************************************************************************!*\
  644. !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***!
  645. \********************************************************************************************/
  646. /*! no static exports found */
  647. /***/ (function(module, exports) {
  648. module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__;
  649. /***/ })
  650. /******/ });
  651. });
  652. //# sourceMappingURL=foundation.tabs.js.map