foundation.dropdownMenu.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  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("./foundation.util.touch"), require("jquery"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["./foundation.core", "./foundation.util.box", "./foundation.util.keyboard", "./foundation.util.nest", "./foundation.util.touch", "jquery"], factory);
  6. else if(typeof exports === 'object')
  7. exports["foundation.dropdownMenu"] = factory(require("./foundation.core"), require("./foundation.util.box"), require("./foundation.util.keyboard"), require("./foundation.util.nest"), require("./foundation.util.touch"), require("jquery"));
  8. else
  9. root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.dropdownMenu"] = 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["__FOUNDATION_EXTERNAL__"]["foundation.util.touch"], 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__foundation_util_touch__, __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 = 5);
  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. /***/ "./foundation.util.touch":
  131. /*!****************************************************************************************************************************************************************************************!*\
  132. !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.util.touch"],"amd":"./foundation.util.touch","commonjs":"./foundation.util.touch","commonjs2":"./foundation.util.touch"} ***!
  133. \****************************************************************************************************************************************************************************************/
  134. /*! no static exports found */
  135. /***/ (function(module, exports) {
  136. module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_util_touch__;
  137. /***/ }),
  138. /***/ "./js/entries/plugins/foundation.dropdownMenu.js":
  139. /*!*******************************************************!*\
  140. !*** ./js/entries/plugins/foundation.dropdownMenu.js ***!
  141. \*******************************************************/
  142. /*! exports provided: Foundation, DropdownMenu */
  143. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  144. "use strict";
  145. __webpack_require__.r(__webpack_exports__);
  146. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core");
  147. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_0__);
  148. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Foundation", function() { return _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"]; });
  149. /* harmony import */ var _foundation_dropdownMenu__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.dropdownMenu */ "./js/foundation.dropdownMenu.js");
  150. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DropdownMenu", function() { return _foundation_dropdownMenu__WEBPACK_IMPORTED_MODULE_1__["DropdownMenu"]; });
  151. _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"].plugin(_foundation_dropdownMenu__WEBPACK_IMPORTED_MODULE_1__["DropdownMenu"], 'DropdownMenu');
  152. /***/ }),
  153. /***/ "./js/foundation.dropdownMenu.js":
  154. /*!***************************************!*\
  155. !*** ./js/foundation.dropdownMenu.js ***!
  156. \***************************************/
  157. /*! exports provided: DropdownMenu */
  158. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  159. "use strict";
  160. __webpack_require__.r(__webpack_exports__);
  161. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DropdownMenu", function() { return DropdownMenu; });
  162. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
  163. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
  164. /* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.core.plugin */ "./foundation.core");
  165. /* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__);
  166. /* harmony import */ var _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.util.keyboard */ "./foundation.util.keyboard");
  167. /* harmony import */ var _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2__);
  168. /* harmony import */ var _foundation_util_nest__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./foundation.util.nest */ "./foundation.util.nest");
  169. /* harmony import */ var _foundation_util_nest__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_nest__WEBPACK_IMPORTED_MODULE_3__);
  170. /* harmony import */ var _foundation_util_box__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./foundation.util.box */ "./foundation.util.box");
  171. /* harmony import */ var _foundation_util_box__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_box__WEBPACK_IMPORTED_MODULE_4__);
  172. /* harmony import */ var _foundation_util_touch__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./foundation.util.touch */ "./foundation.util.touch");
  173. /* harmony import */ var _foundation_util_touch__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_touch__WEBPACK_IMPORTED_MODULE_5__);
  174. 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); }
  175. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  176. 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); } }
  177. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  178. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  179. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  180. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  181. 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); }
  182. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  183. /**
  184. * DropdownMenu module.
  185. * @module foundation.dropdownMenu
  186. * @requires foundation.util.keyboard
  187. * @requires foundation.util.box
  188. * @requires foundation.util.nest
  189. * @requires foundation.util.touch
  190. */
  191. var DropdownMenu =
  192. /*#__PURE__*/
  193. function (_Plugin) {
  194. _inherits(DropdownMenu, _Plugin);
  195. function DropdownMenu() {
  196. _classCallCheck(this, DropdownMenu);
  197. return _possibleConstructorReturn(this, _getPrototypeOf(DropdownMenu).apply(this, arguments));
  198. }
  199. _createClass(DropdownMenu, [{
  200. key: "_setup",
  201. /**
  202. * Creates a new instance of DropdownMenu.
  203. * @class
  204. * @name DropdownMenu
  205. * @fires DropdownMenu#init
  206. * @param {jQuery} element - jQuery object to make into a dropdown menu.
  207. * @param {Object} options - Overrides to the default plugin settings.
  208. */
  209. value: function _setup(element, options) {
  210. this.$element = element;
  211. this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend({}, DropdownMenu.defaults, this.$element.data(), options);
  212. this.className = 'DropdownMenu'; // ie9 back compat
  213. _foundation_util_touch__WEBPACK_IMPORTED_MODULE_5__["Touch"].init(jquery__WEBPACK_IMPORTED_MODULE_0___default.a); // Touch init is idempotent, we just need to make sure it's initialied.
  214. this._init();
  215. _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2__["Keyboard"].register('DropdownMenu', {
  216. 'ENTER': 'open',
  217. 'SPACE': 'open',
  218. 'ARROW_RIGHT': 'next',
  219. 'ARROW_UP': 'up',
  220. 'ARROW_DOWN': 'down',
  221. 'ARROW_LEFT': 'previous',
  222. 'ESCAPE': 'close'
  223. });
  224. }
  225. /**
  226. * Initializes the plugin, and calls _prepareMenu
  227. * @private
  228. * @function
  229. */
  230. }, {
  231. key: "_init",
  232. value: function _init() {
  233. _foundation_util_nest__WEBPACK_IMPORTED_MODULE_3__["Nest"].Feather(this.$element, 'dropdown');
  234. var subs = this.$element.find('li.is-dropdown-submenu-parent');
  235. this.$element.children('.is-dropdown-submenu-parent').children('.is-dropdown-submenu').addClass('first-sub');
  236. this.$menuItems = this.$element.find('li[role="none"]');
  237. this.$tabs = this.$element.children('li[role="none"]');
  238. this.$tabs.find('ul.is-dropdown-submenu').addClass(this.options.verticalClass);
  239. if (this.options.alignment === 'auto') {
  240. if (this.$element.hasClass(this.options.rightClass) || Object(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__["rtl"])() || this.$element.parents('.top-bar-right').is('*')) {
  241. this.options.alignment = 'right';
  242. subs.addClass('opens-left');
  243. } else {
  244. this.options.alignment = 'left';
  245. subs.addClass('opens-right');
  246. }
  247. } else {
  248. if (this.options.alignment === 'right') {
  249. subs.addClass('opens-left');
  250. } else {
  251. subs.addClass('opens-right');
  252. }
  253. }
  254. this.changed = false;
  255. this._events();
  256. }
  257. }, {
  258. key: "_isVertical",
  259. value: function _isVertical() {
  260. return this.$tabs.css('display') === 'block' || this.$element.css('flex-direction') === 'column';
  261. }
  262. }, {
  263. key: "_isRtl",
  264. value: function _isRtl() {
  265. return this.$element.hasClass('align-right') || Object(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__["rtl"])() && !this.$element.hasClass('align-left');
  266. }
  267. /**
  268. * Adds event listeners to elements within the menu
  269. * @private
  270. * @function
  271. */
  272. }, {
  273. key: "_events",
  274. value: function _events() {
  275. var _this = this,
  276. hasTouch = 'ontouchstart' in window || typeof window.ontouchstart !== 'undefined',
  277. parClass = 'is-dropdown-submenu-parent'; // used for onClick and in the keyboard handlers
  278. var handleClickFn = function handleClickFn(e) {
  279. var $elem = jquery__WEBPACK_IMPORTED_MODULE_0___default()(e.target).parentsUntil('ul', ".".concat(parClass)),
  280. hasSub = $elem.hasClass(parClass),
  281. hasClicked = $elem.attr('data-is-click') === 'true',
  282. $sub = $elem.children('.is-dropdown-submenu');
  283. if (hasSub) {
  284. if (hasClicked) {
  285. if (!_this.options.closeOnClick || !_this.options.clickOpen && !hasTouch || _this.options.forceFollow && hasTouch) {
  286. return;
  287. }
  288. e.stopImmediatePropagation();
  289. e.preventDefault();
  290. _this._hide($elem);
  291. } else {
  292. e.stopImmediatePropagation();
  293. e.preventDefault();
  294. _this._show($sub);
  295. $elem.add($elem.parentsUntil(_this.$element, ".".concat(parClass))).attr('data-is-click', true);
  296. }
  297. }
  298. };
  299. if (this.options.clickOpen || hasTouch) {
  300. this.$menuItems.on('click.zf.dropdownMenu touchstart.zf.dropdownMenu', handleClickFn);
  301. } // Handle Leaf element Clicks
  302. if (_this.options.closeOnClickInside) {
  303. this.$menuItems.on('click.zf.dropdownMenu', function (e) {
  304. var $elem = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this),
  305. hasSub = $elem.hasClass(parClass);
  306. if (!hasSub) {
  307. _this._hide();
  308. }
  309. });
  310. }
  311. if (!this.options.disableHover) {
  312. this.$menuItems.on('mouseenter.zf.dropdownMenu', function (e) {
  313. var $elem = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this),
  314. hasSub = $elem.hasClass(parClass);
  315. if (hasSub) {
  316. clearTimeout($elem.data('_delay'));
  317. $elem.data('_delay', setTimeout(function () {
  318. _this._show($elem.children('.is-dropdown-submenu'));
  319. }, _this.options.hoverDelay));
  320. }
  321. }).on('mouseleave.zf.dropdownMenu', Object(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__["ignoreMousedisappear"])(function (e) {
  322. var $elem = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this),
  323. hasSub = $elem.hasClass(parClass);
  324. if (hasSub && _this.options.autoclose) {
  325. if ($elem.attr('data-is-click') === 'true' && _this.options.clickOpen) {
  326. return false;
  327. }
  328. clearTimeout($elem.data('_delay'));
  329. $elem.data('_delay', setTimeout(function () {
  330. _this._hide($elem);
  331. }, _this.options.closingTime));
  332. }
  333. }));
  334. }
  335. this.$menuItems.on('keydown.zf.dropdownMenu', function (e) {
  336. var $element = jquery__WEBPACK_IMPORTED_MODULE_0___default()(e.target).parentsUntil('ul', '[role="none"]'),
  337. isTab = _this.$tabs.index($element) > -1,
  338. $elements = isTab ? _this.$tabs : $element.siblings('li').add($element),
  339. $prevElement,
  340. $nextElement;
  341. $elements.each(function (i) {
  342. if (jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).is($element)) {
  343. $prevElement = $elements.eq(i - 1);
  344. $nextElement = $elements.eq(i + 1);
  345. return;
  346. }
  347. });
  348. var nextSibling = function nextSibling() {
  349. $nextElement.children('a:first').focus();
  350. e.preventDefault();
  351. },
  352. prevSibling = function prevSibling() {
  353. $prevElement.children('a:first').focus();
  354. e.preventDefault();
  355. },
  356. openSub = function openSub() {
  357. var $sub = $element.children('ul.is-dropdown-submenu');
  358. if ($sub.length) {
  359. _this._show($sub);
  360. $element.find('li > a:first').focus();
  361. e.preventDefault();
  362. } else {
  363. return;
  364. }
  365. },
  366. closeSub = function closeSub() {
  367. //if ($element.is(':first-child')) {
  368. var close = $element.parent('ul').parent('li');
  369. close.children('a:first').focus();
  370. _this._hide(close);
  371. e.preventDefault(); //}
  372. };
  373. var functions = {
  374. open: openSub,
  375. close: function close() {
  376. _this._hide(_this.$element);
  377. _this.$menuItems.eq(0).children('a').focus(); // focus to first element
  378. e.preventDefault();
  379. }
  380. };
  381. if (isTab) {
  382. if (_this._isVertical()) {
  383. // vertical menu
  384. if (_this._isRtl()) {
  385. // right aligned
  386. jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend(functions, {
  387. down: nextSibling,
  388. up: prevSibling,
  389. next: closeSub,
  390. previous: openSub
  391. });
  392. } else {
  393. // left aligned
  394. jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend(functions, {
  395. down: nextSibling,
  396. up: prevSibling,
  397. next: openSub,
  398. previous: closeSub
  399. });
  400. }
  401. } else {
  402. // horizontal menu
  403. if (_this._isRtl()) {
  404. // right aligned
  405. jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend(functions, {
  406. next: prevSibling,
  407. previous: nextSibling,
  408. down: openSub,
  409. up: closeSub
  410. });
  411. } else {
  412. // left aligned
  413. jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend(functions, {
  414. next: nextSibling,
  415. previous: prevSibling,
  416. down: openSub,
  417. up: closeSub
  418. });
  419. }
  420. }
  421. } else {
  422. // not tabs -> one sub
  423. if (_this._isRtl()) {
  424. // right aligned
  425. jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend(functions, {
  426. next: closeSub,
  427. previous: openSub,
  428. down: nextSibling,
  429. up: prevSibling
  430. });
  431. } else {
  432. // left aligned
  433. jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend(functions, {
  434. next: openSub,
  435. previous: closeSub,
  436. down: nextSibling,
  437. up: prevSibling
  438. });
  439. }
  440. }
  441. _foundation_util_keyboard__WEBPACK_IMPORTED_MODULE_2__["Keyboard"].handleKey(e, 'DropdownMenu', functions);
  442. });
  443. }
  444. /**
  445. * Adds an event handler to the body to close any dropdowns on a click.
  446. * @function
  447. * @private
  448. */
  449. }, {
  450. key: "_addBodyHandler",
  451. value: function _addBodyHandler() {
  452. var _this2 = this;
  453. var $body = jquery__WEBPACK_IMPORTED_MODULE_0___default()(document.body);
  454. this._removeBodyHandler();
  455. $body.on('click.zf.dropdownMenu tap.zf.dropdownMenu', function (e) {
  456. var isItself = !!jquery__WEBPACK_IMPORTED_MODULE_0___default()(e.target).closest(_this2.$element).length;
  457. if (isItself) return;
  458. _this2._hide();
  459. _this2._removeBodyHandler();
  460. });
  461. }
  462. /**
  463. * Remove the body event handler. See `_addBodyHandler`.
  464. * @function
  465. * @private
  466. */
  467. }, {
  468. key: "_removeBodyHandler",
  469. value: function _removeBodyHandler() {
  470. jquery__WEBPACK_IMPORTED_MODULE_0___default()(document.body).off('click.zf.dropdownMenu tap.zf.dropdownMenu');
  471. }
  472. /**
  473. * Opens a dropdown pane, and checks for collisions first.
  474. * @param {jQuery} $sub - ul element that is a submenu to show
  475. * @function
  476. * @private
  477. * @fires DropdownMenu#show
  478. */
  479. }, {
  480. key: "_show",
  481. value: function _show($sub) {
  482. var idx = this.$tabs.index(this.$tabs.filter(function (i, el) {
  483. return jquery__WEBPACK_IMPORTED_MODULE_0___default()(el).find($sub).length > 0;
  484. }));
  485. var $sibs = $sub.parent('li.is-dropdown-submenu-parent').siblings('li.is-dropdown-submenu-parent');
  486. this._hide($sibs, idx);
  487. $sub.css('visibility', 'hidden').addClass('js-dropdown-active').parent('li.is-dropdown-submenu-parent').addClass('is-active');
  488. var clear = _foundation_util_box__WEBPACK_IMPORTED_MODULE_4__["Box"].ImNotTouchingYou($sub, null, true);
  489. if (!clear) {
  490. var oldClass = this.options.alignment === 'left' ? '-right' : '-left',
  491. $parentLi = $sub.parent('.is-dropdown-submenu-parent');
  492. $parentLi.removeClass("opens".concat(oldClass)).addClass("opens-".concat(this.options.alignment));
  493. clear = _foundation_util_box__WEBPACK_IMPORTED_MODULE_4__["Box"].ImNotTouchingYou($sub, null, true);
  494. if (!clear) {
  495. $parentLi.removeClass("opens-".concat(this.options.alignment)).addClass('opens-inner');
  496. }
  497. this.changed = true;
  498. }
  499. $sub.css('visibility', '');
  500. if (this.options.closeOnClick) {
  501. this._addBodyHandler();
  502. }
  503. /**
  504. * Fires when the new dropdown pane is visible.
  505. * @event DropdownMenu#show
  506. */
  507. this.$element.trigger('show.zf.dropdownMenu', [$sub]);
  508. }
  509. /**
  510. * Hides a single, currently open dropdown pane, if passed a parameter, otherwise, hides everything.
  511. * @function
  512. * @param {jQuery} $elem - element with a submenu to hide
  513. * @param {Number} idx - index of the $tabs collection to hide
  514. * @fires DropdownMenu#hide
  515. * @private
  516. */
  517. }, {
  518. key: "_hide",
  519. value: function _hide($elem, idx) {
  520. var $toClose;
  521. if ($elem && $elem.length) {
  522. $toClose = $elem;
  523. } else if (typeof idx !== 'undefined') {
  524. $toClose = this.$tabs.not(function (i, el) {
  525. return i === idx;
  526. });
  527. } else {
  528. $toClose = this.$element;
  529. }
  530. var somethingToClose = $toClose.hasClass('is-active') || $toClose.find('.is-active').length > 0;
  531. if (somethingToClose) {
  532. var $activeItem = $toClose.find('li.is-active');
  533. $activeItem.add($toClose).attr({
  534. 'data-is-click': false
  535. }).removeClass('is-active');
  536. $toClose.find('ul.js-dropdown-active').removeClass('js-dropdown-active');
  537. if (this.changed || $toClose.find('opens-inner').length) {
  538. var oldClass = this.options.alignment === 'left' ? 'right' : 'left';
  539. $toClose.find('li.is-dropdown-submenu-parent').add($toClose).removeClass("opens-inner opens-".concat(this.options.alignment)).addClass("opens-".concat(oldClass));
  540. this.changed = false;
  541. }
  542. clearTimeout($activeItem.data('_delay'));
  543. this._removeBodyHandler();
  544. /**
  545. * Fires when the open menus are closed.
  546. * @event DropdownMenu#hide
  547. */
  548. this.$element.trigger('hide.zf.dropdownMenu', [$toClose]);
  549. }
  550. }
  551. /**
  552. * Destroys the plugin.
  553. * @function
  554. */
  555. }, {
  556. key: "_destroy",
  557. value: function _destroy() {
  558. this.$menuItems.off('.zf.dropdownMenu').removeAttr('data-is-click').removeClass('is-right-arrow is-left-arrow is-down-arrow opens-right opens-left opens-inner');
  559. jquery__WEBPACK_IMPORTED_MODULE_0___default()(document.body).off('.zf.dropdownMenu');
  560. _foundation_util_nest__WEBPACK_IMPORTED_MODULE_3__["Nest"].Burn(this.$element, 'dropdown');
  561. }
  562. }]);
  563. return DropdownMenu;
  564. }(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__["Plugin"]);
  565. /**
  566. * Default settings for plugin
  567. */
  568. DropdownMenu.defaults = {
  569. /**
  570. * Disallows hover events from opening submenus
  571. * @option
  572. * @type {boolean}
  573. * @default false
  574. */
  575. disableHover: false,
  576. /**
  577. * Allow a submenu to automatically close on a mouseleave event, if not clicked open.
  578. * @option
  579. * @type {boolean}
  580. * @default true
  581. */
  582. autoclose: true,
  583. /**
  584. * Amount of time to delay opening a submenu on hover event.
  585. * @option
  586. * @type {number}
  587. * @default 50
  588. */
  589. hoverDelay: 50,
  590. /**
  591. * Allow a submenu to open/remain open on parent click event. Allows cursor to move away from menu.
  592. * @option
  593. * @type {boolean}
  594. * @default false
  595. */
  596. clickOpen: false,
  597. /**
  598. * Amount of time to delay closing a submenu on a mouseleave event.
  599. * @option
  600. * @type {number}
  601. * @default 500
  602. */
  603. closingTime: 500,
  604. /**
  605. * Position of the menu relative to what direction the submenus should open. Handled by JS. Can be `'auto'`, `'left'` or `'right'`.
  606. * @option
  607. * @type {string}
  608. * @default 'auto'
  609. */
  610. alignment: 'auto',
  611. /**
  612. * Allow clicks on the body to close any open submenus.
  613. * @option
  614. * @type {boolean}
  615. * @default true
  616. */
  617. closeOnClick: true,
  618. /**
  619. * Allow clicks on leaf anchor links to close any open submenus.
  620. * @option
  621. * @type {boolean}
  622. * @default true
  623. */
  624. closeOnClickInside: true,
  625. /**
  626. * Class applied to vertical oriented menus, Foundation default is `vertical`. Update this if using your own class.
  627. * @option
  628. * @type {string}
  629. * @default 'vertical'
  630. */
  631. verticalClass: 'vertical',
  632. /**
  633. * Class applied to right-side oriented menus, Foundation default is `align-right`. Update this if using your own class.
  634. * @option
  635. * @type {string}
  636. * @default 'align-right'
  637. */
  638. rightClass: 'align-right',
  639. /**
  640. * Boolean to force overide the clicking of links to perform default action, on second touch event for mobile.
  641. * @option
  642. * @type {boolean}
  643. * @default true
  644. */
  645. forceFollow: true
  646. };
  647. /***/ }),
  648. /***/ 5:
  649. /*!*************************************************************!*\
  650. !*** multi ./js/entries/plugins/foundation.dropdownMenu.js ***!
  651. \*************************************************************/
  652. /*! no static exports found */
  653. /***/ (function(module, exports, __webpack_require__) {
  654. module.exports = __webpack_require__(/*! /Users/joeworkman/Development/foundation-sites/js/entries/plugins/foundation.dropdownMenu.js */"./js/entries/plugins/foundation.dropdownMenu.js");
  655. /***/ }),
  656. /***/ "jquery":
  657. /*!********************************************************************************************!*\
  658. !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***!
  659. \********************************************************************************************/
  660. /*! no static exports found */
  661. /***/ (function(module, exports) {
  662. module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__;
  663. /***/ })
  664. /******/ });
  665. });
  666. //# sourceMappingURL=foundation.dropdownMenu.js.map