UNPKG

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