foundation.drilldown.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("./foundation.core"), require("./foundation.util.box"), require("./foundation.util.keyboard"), require("./foundation.util.nest"), require("jquery"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["./foundation.core", "./foundation.util.box", "./foundation.util.keyboard", "./foundation.util.nest", "jquery"], factory);
  6. else if(typeof exports === 'object')
  7. exports["foundation.drilldown"] = factory(require("./foundation.core"), require("./foundation.util.box"), require("./foundation.util.keyboard"), require("./foundation.util.nest"), require("jquery"));
  8. else
  9. root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.drilldown"] = factory(root["__FOUNDATION_EXTERNAL__"]["foundation.core"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.box"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.keyboard"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.nest"], root["jQuery"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE__foundation_core__, __WEBPACK_EXTERNAL_MODULE__foundation_util_box__, __WEBPACK_EXTERNAL_MODULE__foundation_util_keyboard__, __WEBPACK_EXTERNAL_MODULE__foundation_util_nest__, __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 = 3);
  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.box":
  107. /*!********************************************************************************************************************************************************************************!*\
  108. !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.util.box"],"amd":"./foundation.util.box","commonjs":"./foundation.util.box","commonjs2":"./foundation.util.box"} ***!
  109. \********************************************************************************************************************************************************************************/
  110. /*! no static exports found */
  111. /***/ (function(module, exports) {
  112. module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_util_box__;
  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. /***/ "./foundation.util.nest":
  123. /*!************************************************************************************************************************************************************************************!*\
  124. !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.util.nest"],"amd":"./foundation.util.nest","commonjs":"./foundation.util.nest","commonjs2":"./foundation.util.nest"} ***!
  125. \************************************************************************************************************************************************************************************/
  126. /*! no static exports found */
  127. /***/ (function(module, exports) {
  128. module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_util_nest__;
  129. /***/ }),
  130. /***/ "./js/entries/plugins/foundation.drilldown.js":
  131. /*!****************************************************!*\
  132. !*** ./js/entries/plugins/foundation.drilldown.js ***!
  133. \****************************************************/
  134. /*! exports provided: Foundation, Drilldown */
  135. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  136. "use strict";
  137. __webpack_require__.r(__webpack_exports__);
  138. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core");
  139. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_0__);
  140. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Foundation", function() { return _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"]; });
  141. /* harmony import */ var _foundation_drilldown__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.drilldown */ "./js/foundation.drilldown.js");
  142. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Drilldown", function() { return _foundation_drilldown__WEBPACK_IMPORTED_MODULE_1__["Drilldown"]; });
  143. _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"].plugin(_foundation_drilldown__WEBPACK_IMPORTED_MODULE_1__["Drilldown"], 'Drilldown');
  144. /***/ }),
  145. /***/ "./js/foundation.drilldown.js":
  146. /*!************************************!*\
  147. !*** ./js/foundation.drilldown.js ***!
  148. \************************************/
  149. /*! exports provided: Drilldown */
  150. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  151. "use strict";
  152. __webpack_require__.r(__webpack_exports__);
  153. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Drilldown", function() { return Drilldown; });
  154. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
  155. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
  156. /* harmony import */ var _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.util.keyboard */ "./foundation.util.keyboard");
  157. /* harmony import */ var _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1__);
  158. /* harmony import */ var _foundation_util_nest__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.util.nest */ "./foundation.util.nest");
  159. /* harmony import */ var _foundation_util_nest__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_nest__WEBPACK_IMPORTED_MODULE_2__);
  160. /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./foundation.core.utils */ "./foundation.core");
  161. /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__);
  162. /* harmony import */ var _foundation_util_box__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./foundation.util.box */ "./foundation.util.box");
  163. /* harmony import */ var _foundation_util_box__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_box__WEBPACK_IMPORTED_MODULE_4__);
  164. 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); }
  165. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  166. 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); } }
  167. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  168. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  169. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  170. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  171. 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); }
  172. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  173. /**
  174. * Drilldown module.
  175. * @module foundation.drilldown
  176. * @requires foundation.util.keyboard
  177. * @requires foundation.util.nest
  178. * @requires foundation.util.box
  179. */
  180. var Drilldown =
  181. /*#__PURE__*/
  182. function (_Plugin) {
  183. _inherits(Drilldown, _Plugin);
  184. function Drilldown() {
  185. _classCallCheck(this, Drilldown);
  186. return _possibleConstructorReturn(this, _getPrototypeOf(Drilldown).apply(this, arguments));
  187. }
  188. _createClass(Drilldown, [{
  189. key: "_setup",
  190. /**
  191. * Creates a new instance of a drilldown menu.
  192. * @class
  193. * @name Drilldown
  194. * @param {jQuery} element - jQuery object to make into an accordion menu.
  195. * @param {Object} options - Overrides to the default plugin settings.
  196. */
  197. value: function _setup(element, options) {
  198. this.$element = element;
  199. this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend({}, Drilldown.defaults, this.$element.data(), options);
  200. this.className = 'Drilldown'; // ie9 back compat
  201. this._init();
  202. _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1__["Keyboard"].register('Drilldown', {
  203. 'ENTER': 'open',
  204. 'SPACE': 'open',
  205. 'ARROW_RIGHT': 'next',
  206. 'ARROW_UP': 'up',
  207. 'ARROW_DOWN': 'down',
  208. 'ARROW_LEFT': 'previous',
  209. 'ESCAPE': 'close',
  210. 'TAB': 'down',
  211. 'SHIFT_TAB': 'up'
  212. });
  213. }
  214. /**
  215. * Initializes the drilldown by creating jQuery collections of elements
  216. * @private
  217. */
  218. }, {
  219. key: "_init",
  220. value: function _init() {
  221. _foundation_util_nest__WEBPACK_IMPORTED_MODULE_2__["Nest"].Feather(this.$element, 'drilldown');
  222. if (this.options.autoApplyClass) {
  223. this.$element.addClass('drilldown');
  224. }
  225. this.$element.attr({
  226. 'role': 'tree',
  227. 'aria-multiselectable': false
  228. });
  229. this.$submenuAnchors = this.$element.find('li.is-drilldown-submenu-parent').children('a');
  230. this.$submenus = this.$submenuAnchors.parent('li').children('[data-submenu]').attr('role', 'group');
  231. this.$menuItems = this.$element.find('li').not('.js-drilldown-back').attr('role', 'treeitem').find('a'); // Set the main menu as current by default (unless a submenu is selected)
  232. // Used to set the wrapper height when the drilldown is closed/reopened from any (sub)menu
  233. this.$currentMenu = this.$element;
  234. this.$element.attr('data-mutate', this.$element.attr('data-drilldown') || Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__["GetYoDigits"])(6, 'drilldown'));
  235. this._prepareMenu();
  236. this._registerEvents();
  237. this._keyboardEvents();
  238. }
  239. /**
  240. * prepares drilldown menu by setting attributes to links and elements
  241. * sets a min height to prevent content jumping
  242. * wraps the element if not already wrapped
  243. * @private
  244. * @function
  245. */
  246. }, {
  247. key: "_prepareMenu",
  248. value: function _prepareMenu() {
  249. var _this = this; // if(!this.options.holdOpen){
  250. // this._menuLinkEvents();
  251. // }
  252. this.$submenuAnchors.each(function () {
  253. var $link = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this);
  254. var $sub = $link.parent();
  255. if (_this.options.parentLink) {
  256. $link.clone().prependTo($sub.children('[data-submenu]')).wrap('<li data-is-parent-link class="is-submenu-parent-item is-submenu-item is-drilldown-submenu-item" role="none"></li>');
  257. }
  258. $link.data('savedHref', $link.attr('href')).removeAttr('href').attr('tabindex', 0);
  259. $link.children('[data-submenu]').attr({
  260. 'aria-hidden': true,
  261. 'tabindex': 0,
  262. 'role': 'group'
  263. });
  264. _this._events($link);
  265. });
  266. this.$submenus.each(function () {
  267. var $menu = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this),
  268. $back = $menu.find('.js-drilldown-back');
  269. if (!$back.length) {
  270. switch (_this.options.backButtonPosition) {
  271. case "bottom":
  272. $menu.append(_this.options.backButton);
  273. break;
  274. case "top":
  275. $menu.prepend(_this.options.backButton);
  276. break;
  277. default:
  278. console.error("Unsupported backButtonPosition value '" + _this.options.backButtonPosition + "'");
  279. }
  280. }
  281. _this._back($menu);
  282. });
  283. this.$submenus.addClass('invisible');
  284. if (!this.options.autoHeight) {
  285. this.$submenus.addClass('drilldown-submenu-cover-previous');
  286. } // create a wrapper on element if it doesn't exist.
  287. if (!this.$element.parent().hasClass('is-drilldown')) {
  288. this.$wrapper = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this.options.wrapper).addClass('is-drilldown');
  289. if (this.options.animateHeight) this.$wrapper.addClass('animate-height');
  290. this.$element.wrap(this.$wrapper);
  291. } // set wrapper
  292. this.$wrapper = this.$element.parent();
  293. this.$wrapper.css(this._getMaxDims());
  294. }
  295. }, {
  296. key: "_resize",
  297. value: function _resize() {
  298. this.$wrapper.css({
  299. 'max-width': 'none',
  300. 'min-height': 'none'
  301. }); // _getMaxDims has side effects (boo) but calling it should update all other necessary heights & widths
  302. this.$wrapper.css(this._getMaxDims());
  303. }
  304. /**
  305. * Adds event handlers to elements in the menu.
  306. * @function
  307. * @private
  308. * @param {jQuery} $elem - the current menu item to add handlers to.
  309. */
  310. }, {
  311. key: "_events",
  312. value: function _events($elem) {
  313. var _this = this;
  314. $elem.off('click.zf.drilldown').on('click.zf.drilldown', function (e) {
  315. if (jquery__WEBPACK_IMPORTED_MODULE_0___default()(e.target).parentsUntil('ul', 'li').hasClass('is-drilldown-submenu-parent')) {
  316. e.preventDefault();
  317. } // if(e.target !== e.currentTarget.firstElementChild){
  318. // return false;
  319. // }
  320. _this._show($elem.parent('li'));
  321. if (_this.options.closeOnClick) {
  322. var $body = jquery__WEBPACK_IMPORTED_MODULE_0___default()('body');
  323. $body.off('.zf.drilldown').on('click.zf.drilldown', function (e) {
  324. if (e.target === _this.$element[0] || jquery__WEBPACK_IMPORTED_MODULE_0___default.a.contains(_this.$element[0], e.target)) {
  325. return;
  326. }
  327. e.preventDefault();
  328. _this._hideAll();
  329. $body.off('.zf.drilldown');
  330. });
  331. }
  332. });
  333. }
  334. /**
  335. * Adds event handlers to the menu element.
  336. * @function
  337. * @private
  338. */
  339. }, {
  340. key: "_registerEvents",
  341. value: function _registerEvents() {
  342. if (this.options.scrollTop) {
  343. this._bindHandler = this._scrollTop.bind(this);
  344. this.$element.on('open.zf.drilldown hide.zf.drilldown close.zf.drilldown closed.zf.drilldown', this._bindHandler);
  345. }
  346. this.$element.on('mutateme.zf.trigger', this._resize.bind(this));
  347. }
  348. /**
  349. * Scroll to Top of Element or data-scroll-top-element
  350. * @function
  351. * @fires Drilldown#scrollme
  352. */
  353. }, {
  354. key: "_scrollTop",
  355. value: function _scrollTop() {
  356. var _this = this;
  357. var $scrollTopElement = _this.options.scrollTopElement != '' ? jquery__WEBPACK_IMPORTED_MODULE_0___default()(_this.options.scrollTopElement) : _this.$element,
  358. scrollPos = parseInt($scrollTopElement.offset().top + _this.options.scrollTopOffset, 10);
  359. jquery__WEBPACK_IMPORTED_MODULE_0___default()('html, body').stop(true).animate({
  360. scrollTop: scrollPos
  361. }, _this.options.animationDuration, _this.options.animationEasing, function () {
  362. /**
  363. * Fires after the menu has scrolled
  364. * @event Drilldown#scrollme
  365. */
  366. if (this === jquery__WEBPACK_IMPORTED_MODULE_0___default()('html')[0]) _this.$element.trigger('scrollme.zf.drilldown');
  367. });
  368. }
  369. /**
  370. * Adds keydown event listener to `li`'s in the menu.
  371. * @private
  372. */
  373. }, {
  374. key: "_keyboardEvents",
  375. value: function _keyboardEvents() {
  376. var _this = this;
  377. this.$menuItems.add(this.$element.find('.js-drilldown-back > a, .is-submenu-parent-item > a')).on('keydown.zf.drilldown', function (e) {
  378. var $element = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this),
  379. $elements = $element.parent('li').parent('ul').children('li').children('a'),
  380. $prevElement,
  381. $nextElement;
  382. $elements.each(function (i) {
  383. if (jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).is($element)) {
  384. $prevElement = $elements.eq(Math.max(0, i - 1));
  385. $nextElement = $elements.eq(Math.min(i + 1, $elements.length - 1));
  386. return;
  387. }
  388. });
  389. _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_1__["Keyboard"].handleKey(e, 'Drilldown', {
  390. next: function next() {
  391. if ($element.is(_this.$submenuAnchors)) {
  392. _this._show($element.parent('li'));
  393. $element.parent('li').one(Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__["transitionend"])($element), function () {
  394. $element.parent('li').find('ul li a').not('.js-drilldown-back a').first().focus();
  395. });
  396. return true;
  397. }
  398. },
  399. previous: function previous() {
  400. _this._hide($element.parent('li').parent('ul'));
  401. $element.parent('li').parent('ul').one(Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__["transitionend"])($element), function () {
  402. setTimeout(function () {
  403. $element.parent('li').parent('ul').parent('li').children('a').first().focus();
  404. }, 1);
  405. });
  406. return true;
  407. },
  408. up: function up() {
  409. $prevElement.focus(); // Don't tap focus on first element in root ul
  410. return !$element.is(_this.$element.find('> li:first-child > a'));
  411. },
  412. down: function down() {
  413. $nextElement.focus(); // Don't tap focus on last element in root ul
  414. return !$element.is(_this.$element.find('> li:last-child > a'));
  415. },
  416. close: function close() {
  417. // Don't close on element in root ul
  418. if (!$element.is(_this.$element.find('> li > a'))) {
  419. _this._hide($element.parent().parent());
  420. $element.parent().parent().siblings('a').focus();
  421. }
  422. },
  423. open: function open() {
  424. if (_this.options.parentLink && $element.attr('href')) {
  425. // Link with href
  426. return false;
  427. } else if (!$element.is(_this.$menuItems)) {
  428. // not menu item means back button
  429. _this._hide($element.parent('li').parent('ul'));
  430. $element.parent('li').parent('ul').one(Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__["transitionend"])($element), function () {
  431. setTimeout(function () {
  432. $element.parent('li').parent('ul').parent('li').children('a').first().focus();
  433. }, 1);
  434. });
  435. return true;
  436. } else if ($element.is(_this.$submenuAnchors)) {
  437. // Sub menu item
  438. _this._show($element.parent('li'));
  439. $element.parent('li').one(Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__["transitionend"])($element), function () {
  440. $element.parent('li').find('ul li a').not('.js-drilldown-back a').first().focus();
  441. });
  442. return true;
  443. }
  444. },
  445. handled: function handled(preventDefault) {
  446. if (preventDefault) {
  447. e.preventDefault();
  448. }
  449. }
  450. });
  451. }); // end keyboardAccess
  452. }
  453. /**
  454. * Closes all open elements, and returns to root menu.
  455. * @function
  456. * @fires Drilldown#close
  457. * @fires Drilldown#closed
  458. */
  459. }, {
  460. key: "_hideAll",
  461. value: function _hideAll() {
  462. var _this2 = this;
  463. var $elem = this.$element.find('.is-drilldown-submenu.is-active');
  464. $elem.addClass('is-closing');
  465. if (this.options.autoHeight) {
  466. var calcHeight = $elem.parent().closest('ul').data('calcHeight');
  467. this.$wrapper.css({
  468. height: calcHeight
  469. });
  470. }
  471. /**
  472. * Fires when the menu is closing.
  473. * @event Drilldown#close
  474. */
  475. this.$element.trigger('close.zf.drilldown');
  476. $elem.one(Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__["transitionend"])($elem), function () {
  477. $elem.removeClass('is-active is-closing');
  478. /**
  479. * Fires when the menu is fully closed.
  480. * @event Drilldown#closed
  481. */
  482. _this2.$element.trigger('closed.zf.drilldown');
  483. });
  484. }
  485. /**
  486. * Adds event listener for each `back` button, and closes open menus.
  487. * @function
  488. * @fires Drilldown#back
  489. * @param {jQuery} $elem - the current sub-menu to add `back` event.
  490. */
  491. }, {
  492. key: "_back",
  493. value: function _back($elem) {
  494. var _this = this;
  495. $elem.off('click.zf.drilldown');
  496. $elem.children('.js-drilldown-back').on('click.zf.drilldown', function (e) {
  497. // console.log('mouseup on back');
  498. _this._hide($elem); // If there is a parent submenu, call show
  499. var parentSubMenu = $elem.parent('li').parent('ul').parent('li');
  500. if (parentSubMenu.length) {
  501. _this._show(parentSubMenu);
  502. }
  503. });
  504. }
  505. /**
  506. * Adds event listener to menu items w/o submenus to close open menus on click.
  507. * @function
  508. * @private
  509. */
  510. }, {
  511. key: "_menuLinkEvents",
  512. value: function _menuLinkEvents() {
  513. var _this = this;
  514. this.$menuItems.not('.is-drilldown-submenu-parent').off('click.zf.drilldown').on('click.zf.drilldown', function (e) {
  515. setTimeout(function () {
  516. _this._hideAll();
  517. }, 0);
  518. });
  519. }
  520. /**
  521. * Sets the CSS classes for submenu to show it.
  522. * @function
  523. * @private
  524. * @param {jQuery} $elem - the target submenu (`ul` tag)
  525. * @param {boolean} trigger - trigger drilldown event
  526. */
  527. }, {
  528. key: "_setShowSubMenuClasses",
  529. value: function _setShowSubMenuClasses($elem, trigger) {
  530. $elem.addClass('is-active').removeClass('invisible').attr('aria-hidden', false);
  531. $elem.parent('li').attr('aria-expanded', true);
  532. if (trigger === true) {
  533. this.$element.trigger('open.zf.drilldown', [$elem]);
  534. }
  535. }
  536. /**
  537. * Sets the CSS classes for submenu to hide it.
  538. * @function
  539. * @private
  540. * @param {jQuery} $elem - the target submenu (`ul` tag)
  541. * @param {boolean} trigger - trigger drilldown event
  542. */
  543. }, {
  544. key: "_setHideSubMenuClasses",
  545. value: function _setHideSubMenuClasses($elem, trigger) {
  546. $elem.removeClass('is-active').addClass('invisible').attr('aria-hidden', true);
  547. $elem.parent('li').attr('aria-expanded', false);
  548. if (trigger === true) {
  549. $elem.trigger('hide.zf.drilldown', [$elem]);
  550. }
  551. }
  552. /**
  553. * Opens a specific drilldown (sub)menu no matter which (sub)menu in it is currently visible.
  554. * Compared to _show() this lets you jump into any submenu without clicking through every submenu on the way to it.
  555. * @function
  556. * @fires Drilldown#open
  557. * @param {jQuery} $elem - the target (sub)menu (`ul` tag)
  558. * @param {boolean} autoFocus - if true the first link in the target (sub)menu gets auto focused
  559. */
  560. }, {
  561. key: "_showMenu",
  562. value: function _showMenu($elem, autoFocus) {
  563. var _this = this; // Reset drilldown
  564. var $expandedSubmenus = this.$element.find('li[aria-expanded="true"] > ul[data-submenu]');
  565. $expandedSubmenus.each(function (index) {
  566. _this._setHideSubMenuClasses(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this));
  567. }); // Save the menu as the currently displayed one.
  568. this.$currentMenu = $elem; // If target menu is root, focus first link & exit
  569. if ($elem.is('[data-drilldown]')) {
  570. if (autoFocus === true) $elem.find('li[role="treeitem"] > a').first().focus();
  571. if (this.options.autoHeight) this.$wrapper.css('height', $elem.data('calcHeight'));
  572. return;
  573. } // Find all submenus on way to root incl. the element itself
  574. var $submenus = $elem.children().first().parentsUntil('[data-drilldown]', '[data-submenu]'); // Open target menu and all submenus on its way to root
  575. $submenus.each(function (index) {
  576. // Update height of first child (target menu) if autoHeight option true
  577. if (index === 0 && _this.options.autoHeight) {
  578. _this.$wrapper.css('height', jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('calcHeight'));
  579. }
  580. var isLastChild = index == $submenus.length - 1; // Add transitionsend listener to last child (root due to reverse order) to open target menu's first link
  581. // Last child makes sure the event gets always triggered even if going through several menus
  582. if (isLastChild === true) {
  583. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).one(Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__["transitionend"])(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this)), function () {
  584. if (autoFocus === true) {
  585. $elem.find('li[role="treeitem"] > a').first().focus();
  586. }
  587. });
  588. }
  589. _this._setShowSubMenuClasses(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), isLastChild);
  590. });
  591. }
  592. /**
  593. * Opens a submenu.
  594. * @function
  595. * @fires Drilldown#open
  596. * @param {jQuery} $elem - the current element with a submenu to open, i.e. the `li` tag.
  597. */
  598. }, {
  599. key: "_show",
  600. value: function _show($elem) {
  601. var $submenu = $elem.children('[data-submenu]');
  602. $elem.attr('aria-expanded', true);
  603. this.$currentMenu = $submenu;
  604. $submenu.addClass('is-active').removeClass('invisible').attr('aria-hidden', false);
  605. if (this.options.autoHeight) {
  606. this.$wrapper.css({
  607. height: $submenu.data('calcHeight')
  608. });
  609. }
  610. /**
  611. * Fires when the submenu has opened.
  612. * @event Drilldown#open
  613. */
  614. this.$element.trigger('open.zf.drilldown', [$elem]);
  615. }
  616. /**
  617. * Hides a submenu
  618. * @function
  619. * @fires Drilldown#hide
  620. * @param {jQuery} $elem - the current sub-menu to hide, i.e. the `ul` tag.
  621. */
  622. }, {
  623. key: "_hide",
  624. value: function _hide($elem) {
  625. if (this.options.autoHeight) this.$wrapper.css({
  626. height: $elem.parent().closest('ul').data('calcHeight')
  627. });
  628. var _this = this;
  629. $elem.parent('li').attr('aria-expanded', false);
  630. $elem.attr('aria-hidden', true);
  631. $elem.addClass('is-closing').one(Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__["transitionend"])($elem), function () {
  632. $elem.removeClass('is-active is-closing');
  633. $elem.blur().addClass('invisible');
  634. });
  635. /**
  636. * Fires when the submenu has closed.
  637. * @event Drilldown#hide
  638. */
  639. $elem.trigger('hide.zf.drilldown', [$elem]);
  640. }
  641. /**
  642. * Iterates through the nested menus to calculate the min-height, and max-width for the menu.
  643. * Prevents content jumping.
  644. * @function
  645. * @private
  646. */
  647. }, {
  648. key: "_getMaxDims",
  649. value: function _getMaxDims() {
  650. var maxHeight = 0,
  651. result = {},
  652. _this = this; // Recalculate menu heights and total max height
  653. this.$submenus.add(this.$element).each(function () {
  654. var numOfElems = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).children('li').length;
  655. var height = _foundation_util_box__WEBPACK_IMPORTED_MODULE_4__["Box"].GetDimensions(this).height;
  656. maxHeight = height > maxHeight ? height : maxHeight;
  657. if (_this.options.autoHeight) {
  658. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('calcHeight', height);
  659. }
  660. });
  661. if (this.options.autoHeight) result['height'] = this.$currentMenu.data('calcHeight');else result['min-height'] = "".concat(maxHeight, "px");
  662. result['max-width'] = "".concat(this.$element[0].getBoundingClientRect().width, "px");
  663. return result;
  664. }
  665. /**
  666. * Destroys the Drilldown Menu
  667. * @function
  668. */
  669. }, {
  670. key: "_destroy",
  671. value: function _destroy() {
  672. if (this.options.scrollTop) this.$element.off('.zf.drilldown', this._bindHandler);
  673. this._hideAll();
  674. this.$element.off('mutateme.zf.trigger');
  675. _foundation_util_nest__WEBPACK_IMPORTED_MODULE_2__["Nest"].Burn(this.$element, 'drilldown');
  676. this.$element.unwrap().find('.js-drilldown-back, .is-submenu-parent-item').remove().end().find('.is-active, .is-closing, .is-drilldown-submenu').removeClass('is-active is-closing is-drilldown-submenu').end().find('[data-submenu]').removeAttr('aria-hidden tabindex role');
  677. this.$submenuAnchors.each(function () {
  678. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).off('.zf.drilldown');
  679. });
  680. this.$element.find('[data-is-parent-link]').detach();
  681. this.$submenus.removeClass('drilldown-submenu-cover-previous invisible');
  682. this.$element.find('a').each(function () {
  683. var $link = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this);
  684. $link.removeAttr('tabindex');
  685. if ($link.data('savedHref')) {
  686. $link.attr('href', $link.data('savedHref')).removeData('savedHref');
  687. } else {
  688. return;
  689. }
  690. });
  691. }
  692. }]);
  693. return Drilldown;
  694. }(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_3__["Plugin"]);
  695. Drilldown.defaults = {
  696. /**
  697. * Drilldowns depend on styles in order to function properly; in the default build of Foundation these are
  698. * on the `drilldown` class. This option auto-applies this class to the drilldown upon initialization.
  699. * @option
  700. * @type {boolean}
  701. * @default true
  702. */
  703. autoApplyClass: true,
  704. /**
  705. * Markup used for JS generated back button. Prepended or appended (see backButtonPosition) to submenu lists and deleted on `destroy` method, 'js-drilldown-back' class required. Remove the backslash (`\`) if copy and pasting.
  706. * @option
  707. * @type {string}
  708. * @default '<li class="js-drilldown-back"><a tabindex="0">Back</a></li>'
  709. */
  710. backButton: '<li class="js-drilldown-back"><a tabindex="0">Back</a></li>',
  711. /**
  712. * Position the back button either at the top or bottom of drilldown submenus. Can be `'left'` or `'bottom'`.
  713. * @option
  714. * @type {string}
  715. * @default top
  716. */
  717. backButtonPosition: 'top',
  718. /**
  719. * Markup used to wrap drilldown menu. Use a class name for independent styling; the JS applied class: `is-drilldown` is required. Remove the backslash (`\`) if copy and pasting.
  720. * @option
  721. * @type {string}
  722. * @default '<div></div>'
  723. */
  724. wrapper: '<div></div>',
  725. /**
  726. * Adds the parent link to the submenu.
  727. * @option
  728. * @type {boolean}
  729. * @default false
  730. */
  731. parentLink: false,
  732. /**
  733. * Allow the menu to return to root list on body click.
  734. * @option
  735. * @type {boolean}
  736. * @default false
  737. */
  738. closeOnClick: false,
  739. /**
  740. * Allow the menu to auto adjust height.
  741. * @option
  742. * @type {boolean}
  743. * @default false
  744. */
  745. autoHeight: false,
  746. /**
  747. * Animate the auto adjust height.
  748. * @option
  749. * @type {boolean}
  750. * @default false
  751. */
  752. animateHeight: false,
  753. /**
  754. * Scroll to the top of the menu after opening a submenu or navigating back using the menu back button
  755. * @option
  756. * @type {boolean}
  757. * @default false
  758. */
  759. scrollTop: false,
  760. /**
  761. * String jquery selector (for example 'body') of element to take offset().top from, if empty string the drilldown menu offset().top is taken
  762. * @option
  763. * @type {string}
  764. * @default ''
  765. */
  766. scrollTopElement: '',
  767. /**
  768. * ScrollTop offset
  769. * @option
  770. * @type {number}
  771. * @default 0
  772. */
  773. scrollTopOffset: 0,
  774. /**
  775. * Scroll animation duration
  776. * @option
  777. * @type {number}
  778. * @default 500
  779. */
  780. animationDuration: 500,
  781. /**
  782. * Scroll animation easing. Can be `'swing'` or `'linear'`.
  783. * @option
  784. * @type {string}
  785. * @see {@link https://api.jquery.com/animate|JQuery animate}
  786. * @default 'swing'
  787. */
  788. animationEasing: 'swing' // holdOpen: false
  789. };
  790. /***/ }),
  791. /***/ 3:
  792. /*!**********************************************************!*\
  793. !*** multi ./js/entries/plugins/foundation.drilldown.js ***!
  794. \**********************************************************/
  795. /*! no static exports found */
  796. /***/ (function(module, exports, __webpack_require__) {
  797. module.exports = __webpack_require__(/*! /Users/joeworkman/Development/foundation-sites/js/entries/plugins/foundation.drilldown.js */"./js/entries/plugins/foundation.drilldown.js");
  798. /***/ }),
  799. /***/ "jquery":
  800. /*!********************************************************************************************!*\
  801. !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***!
  802. \********************************************************************************************/
  803. /*! no static exports found */
  804. /***/ (function(module, exports) {
  805. module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__;
  806. /***/ })
  807. /******/ });
  808. });
  809. //# sourceMappingURL=foundation.drilldown.js.map