foundation.toggler.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("./foundation.core"), require("./foundation.util.motion"), require("jquery"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["./foundation.core", "./foundation.util.motion", "jquery"], factory);
  6. else if(typeof exports === 'object')
  7. exports["foundation.toggler"] = factory(require("./foundation.core"), require("./foundation.util.motion"), require("jquery"));
  8. else
  9. root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.toggler"] = factory(root["__FOUNDATION_EXTERNAL__"]["foundation.core"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.motion"], root["jQuery"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE__foundation_core__, __WEBPACK_EXTERNAL_MODULE__foundation_util_motion__, __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 = 19);
  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.motion":
  107. /*!********************************************************************************************************************************************************************************************!*\
  108. !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.util.motion"],"amd":"./foundation.util.motion","commonjs":"./foundation.util.motion","commonjs2":"./foundation.util.motion"} ***!
  109. \********************************************************************************************************************************************************************************************/
  110. /*! no static exports found */
  111. /***/ (function(module, exports) {
  112. module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_util_motion__;
  113. /***/ }),
  114. /***/ "./js/entries/plugins/foundation.toggler.js":
  115. /*!**************************************************!*\
  116. !*** ./js/entries/plugins/foundation.toggler.js ***!
  117. \**************************************************/
  118. /*! exports provided: Foundation, Toggler */
  119. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  120. "use strict";
  121. __webpack_require__.r(__webpack_exports__);
  122. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core");
  123. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_0__);
  124. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Foundation", function() { return _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"]; });
  125. /* harmony import */ var _foundation_toggler__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.toggler */ "./js/foundation.toggler.js");
  126. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Toggler", function() { return _foundation_toggler__WEBPACK_IMPORTED_MODULE_1__["Toggler"]; });
  127. _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"].plugin(_foundation_toggler__WEBPACK_IMPORTED_MODULE_1__["Toggler"], 'Toggler');
  128. /***/ }),
  129. /***/ "./js/foundation.toggler.js":
  130. /*!**********************************!*\
  131. !*** ./js/foundation.toggler.js ***!
  132. \**********************************/
  133. /*! exports provided: Toggler */
  134. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  135. "use strict";
  136. __webpack_require__.r(__webpack_exports__);
  137. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Toggler", function() { return Toggler; });
  138. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
  139. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
  140. /* harmony import */ var _foundation_util_motion__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.util.motion */ "./foundation.util.motion");
  141. /* harmony import */ var _foundation_util_motion__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_motion__WEBPACK_IMPORTED_MODULE_1__);
  142. /* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.core.plugin */ "./foundation.core");
  143. /* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_2__);
  144. /* harmony import */ var _foundation_util_triggers__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./foundation.util.triggers */ "./js/foundation.util.triggers.js");
  145. 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); }
  146. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  147. 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); } }
  148. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  149. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  150. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  151. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  152. 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); }
  153. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  154. /**
  155. * Toggler module.
  156. * @module foundation.toggler
  157. * @requires foundation.util.motion
  158. * @requires foundation.util.triggers
  159. */
  160. var Toggler =
  161. /*#__PURE__*/
  162. function (_Plugin) {
  163. _inherits(Toggler, _Plugin);
  164. function Toggler() {
  165. _classCallCheck(this, Toggler);
  166. return _possibleConstructorReturn(this, _getPrototypeOf(Toggler).apply(this, arguments));
  167. }
  168. _createClass(Toggler, [{
  169. key: "_setup",
  170. /**
  171. * Creates a new instance of Toggler.
  172. * @class
  173. * @name Toggler
  174. * @fires Toggler#init
  175. * @param {Object} element - jQuery object to add the trigger to.
  176. * @param {Object} options - Overrides to the default plugin settings.
  177. */
  178. value: function _setup(element, options) {
  179. this.$element = element;
  180. this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend({}, Toggler.defaults, element.data(), options);
  181. this.className = '';
  182. this.className = 'Toggler'; // ie9 back compat
  183. // Triggers init is idempotent, just need to make sure it is initialized
  184. _foundation_util_triggers__WEBPACK_IMPORTED_MODULE_3__["Triggers"].init(jquery__WEBPACK_IMPORTED_MODULE_0___default.a);
  185. this._init();
  186. this._events();
  187. }
  188. /**
  189. * Initializes the Toggler plugin by parsing the toggle class from data-toggler, or animation classes from data-animate.
  190. * @function
  191. * @private
  192. */
  193. }, {
  194. key: "_init",
  195. value: function _init() {
  196. // Collect triggers to set ARIA attributes to
  197. var id = this.$element[0].id,
  198. $triggers = jquery__WEBPACK_IMPORTED_MODULE_0___default()("[data-open~=\"".concat(id, "\"], [data-close~=\"").concat(id, "\"], [data-toggle~=\"").concat(id, "\"]"));
  199. var input; // Parse animation classes if they were set
  200. if (this.options.animate) {
  201. input = this.options.animate.split(' ');
  202. this.animationIn = input[0];
  203. this.animationOut = input[1] || null; // - aria-expanded: according to the element visibility.
  204. $triggers.attr('aria-expanded', !this.$element.is(':hidden'));
  205. } // Otherwise, parse toggle class
  206. else {
  207. input = this.options.toggler;
  208. if (typeof input !== 'string' || !input.length) {
  209. throw new Error("The 'toogler' option containing the target class is required, got \"".concat(input, "\""));
  210. } // Allow for a . at the beginning of the string
  211. this.className = input[0] === '.' ? input.slice(1) : input; // - aria-expanded: according to the elements class set.
  212. $triggers.attr('aria-expanded', this.$element.hasClass(this.className));
  213. } // - aria-controls: adding the element id to it if not already in it.
  214. $triggers.each(function (index, trigger) {
  215. var $trigger = jquery__WEBPACK_IMPORTED_MODULE_0___default()(trigger);
  216. var controls = $trigger.attr('aria-controls') || '';
  217. var containsId = new RegExp("\\b".concat(Object(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_2__["RegExpEscape"])(id), "\\b")).test(controls);
  218. if (!containsId) $trigger.attr('aria-controls', controls ? "".concat(controls, " ").concat(id) : id);
  219. });
  220. }
  221. /**
  222. * Initializes events for the toggle trigger.
  223. * @function
  224. * @private
  225. */
  226. }, {
  227. key: "_events",
  228. value: function _events() {
  229. this.$element.off('toggle.zf.trigger').on('toggle.zf.trigger', this.toggle.bind(this));
  230. }
  231. /**
  232. * Toggles the target class on the target element. An event is fired from the original trigger depending on if the resultant state was "on" or "off".
  233. * @function
  234. * @fires Toggler#on
  235. * @fires Toggler#off
  236. */
  237. }, {
  238. key: "toggle",
  239. value: function toggle() {
  240. this[this.options.animate ? '_toggleAnimate' : '_toggleClass']();
  241. }
  242. }, {
  243. key: "_toggleClass",
  244. value: function _toggleClass() {
  245. this.$element.toggleClass(this.className);
  246. var isOn = this.$element.hasClass(this.className);
  247. if (isOn) {
  248. /**
  249. * Fires if the target element has the class after a toggle.
  250. * @event Toggler#on
  251. */
  252. this.$element.trigger('on.zf.toggler');
  253. } else {
  254. /**
  255. * Fires if the target element does not have the class after a toggle.
  256. * @event Toggler#off
  257. */
  258. this.$element.trigger('off.zf.toggler');
  259. }
  260. this._updateARIA(isOn);
  261. this.$element.find('[data-mutate]').trigger('mutateme.zf.trigger');
  262. }
  263. }, {
  264. key: "_toggleAnimate",
  265. value: function _toggleAnimate() {
  266. var _this = this;
  267. if (this.$element.is(':hidden')) {
  268. _foundation_util_motion__WEBPACK_IMPORTED_MODULE_1__["Motion"].animateIn(this.$element, this.animationIn, function () {
  269. _this._updateARIA(true);
  270. this.trigger('on.zf.toggler');
  271. this.find('[data-mutate]').trigger('mutateme.zf.trigger');
  272. });
  273. } else {
  274. _foundation_util_motion__WEBPACK_IMPORTED_MODULE_1__["Motion"].animateOut(this.$element, this.animationOut, function () {
  275. _this._updateARIA(false);
  276. this.trigger('off.zf.toggler');
  277. this.find('[data-mutate]').trigger('mutateme.zf.trigger');
  278. });
  279. }
  280. }
  281. }, {
  282. key: "_updateARIA",
  283. value: function _updateARIA(isOn) {
  284. var id = this.$element[0].id;
  285. jquery__WEBPACK_IMPORTED_MODULE_0___default()("[data-open=\"".concat(id, "\"], [data-close=\"").concat(id, "\"], [data-toggle=\"").concat(id, "\"]")).attr({
  286. 'aria-expanded': isOn ? true : false
  287. });
  288. }
  289. /**
  290. * Destroys the instance of Toggler on the element.
  291. * @function
  292. */
  293. }, {
  294. key: "_destroy",
  295. value: function _destroy() {
  296. this.$element.off('.zf.toggler');
  297. }
  298. }]);
  299. return Toggler;
  300. }(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_2__["Plugin"]);
  301. Toggler.defaults = {
  302. /**
  303. * Class of the element to toggle. It can be provided with or without "."
  304. * @option
  305. * @type {string}
  306. */
  307. toggler: undefined,
  308. /**
  309. * Tells the plugin if the element should animated when toggled.
  310. * @option
  311. * @type {boolean}
  312. * @default false
  313. */
  314. animate: false
  315. };
  316. /***/ }),
  317. /***/ "./js/foundation.util.triggers.js":
  318. /*!****************************************!*\
  319. !*** ./js/foundation.util.triggers.js ***!
  320. \****************************************/
  321. /*! exports provided: Triggers */
  322. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  323. "use strict";
  324. __webpack_require__.r(__webpack_exports__);
  325. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Triggers", function() { return Triggers; });
  326. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
  327. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
  328. /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.core.utils */ "./foundation.core");
  329. /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__);
  330. /* harmony import */ var _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.util.motion */ "./foundation.util.motion");
  331. /* harmony import */ var _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__);
  332. 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); }
  333. var MutationObserver = function () {
  334. var prefixes = ['WebKit', 'Moz', 'O', 'Ms', ''];
  335. for (var i = 0; i < prefixes.length; i++) {
  336. if ("".concat(prefixes[i], "MutationObserver") in window) {
  337. return window["".concat(prefixes[i], "MutationObserver")];
  338. }
  339. }
  340. return false;
  341. }();
  342. var triggers = function triggers(el, type) {
  343. el.data(type).split(' ').forEach(function (id) {
  344. jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(id))[type === 'close' ? 'trigger' : 'triggerHandler']("".concat(type, ".zf.trigger"), [el]);
  345. });
  346. };
  347. var Triggers = {
  348. Listeners: {
  349. Basic: {},
  350. Global: {}
  351. },
  352. Initializers: {}
  353. };
  354. Triggers.Listeners.Basic = {
  355. openListener: function openListener() {
  356. triggers(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), 'open');
  357. },
  358. closeListener: function closeListener() {
  359. var id = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('close');
  360. if (id) {
  361. triggers(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), 'close');
  362. } else {
  363. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('close.zf.trigger');
  364. }
  365. },
  366. toggleListener: function toggleListener() {
  367. var id = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('toggle');
  368. if (id) {
  369. triggers(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), 'toggle');
  370. } else {
  371. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('toggle.zf.trigger');
  372. }
  373. },
  374. closeableListener: function closeableListener(e) {
  375. var animation = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('closable'); // Only close the first closable element. See https://git.io/zf-7833
  376. e.stopPropagation();
  377. if (animation !== '') {
  378. _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__["Motion"].animateOut(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), animation, function () {
  379. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('closed.zf');
  380. });
  381. } else {
  382. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).fadeOut().trigger('closed.zf');
  383. }
  384. },
  385. toggleFocusListener: function toggleFocusListener() {
  386. var id = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('toggle-focus');
  387. jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(id)).triggerHandler('toggle.zf.trigger', [jquery__WEBPACK_IMPORTED_MODULE_0___default()(this)]);
  388. }
  389. }; // Elements with [data-open] will reveal a plugin that supports it when clicked.
  390. Triggers.Initializers.addOpenListener = function ($elem) {
  391. $elem.off('click.zf.trigger', Triggers.Listeners.Basic.openListener);
  392. $elem.on('click.zf.trigger', '[data-open]', Triggers.Listeners.Basic.openListener);
  393. }; // Elements with [data-close] will close a plugin that supports it when clicked.
  394. // If used without a value on [data-close], the event will bubble, allowing it to close a parent component.
  395. Triggers.Initializers.addCloseListener = function ($elem) {
  396. $elem.off('click.zf.trigger', Triggers.Listeners.Basic.closeListener);
  397. $elem.on('click.zf.trigger', '[data-close]', Triggers.Listeners.Basic.closeListener);
  398. }; // Elements with [data-toggle] will toggle a plugin that supports it when clicked.
  399. Triggers.Initializers.addToggleListener = function ($elem) {
  400. $elem.off('click.zf.trigger', Triggers.Listeners.Basic.toggleListener);
  401. $elem.on('click.zf.trigger', '[data-toggle]', Triggers.Listeners.Basic.toggleListener);
  402. }; // Elements with [data-closable] will respond to close.zf.trigger events.
  403. Triggers.Initializers.addCloseableListener = function ($elem) {
  404. $elem.off('close.zf.trigger', Triggers.Listeners.Basic.closeableListener);
  405. $elem.on('close.zf.trigger', '[data-closeable], [data-closable]', Triggers.Listeners.Basic.closeableListener);
  406. }; // Elements with [data-toggle-focus] will respond to coming in and out of focus
  407. Triggers.Initializers.addToggleFocusListener = function ($elem) {
  408. $elem.off('focus.zf.trigger blur.zf.trigger', Triggers.Listeners.Basic.toggleFocusListener);
  409. $elem.on('focus.zf.trigger blur.zf.trigger', '[data-toggle-focus]', Triggers.Listeners.Basic.toggleFocusListener);
  410. }; // More Global/complex listeners and triggers
  411. Triggers.Listeners.Global = {
  412. resizeListener: function resizeListener($nodes) {
  413. if (!MutationObserver) {
  414. //fallback for IE 9
  415. $nodes.each(function () {
  416. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).triggerHandler('resizeme.zf.trigger');
  417. });
  418. } //trigger all listening elements and signal a resize event
  419. $nodes.attr('data-events', "resize");
  420. },
  421. scrollListener: function scrollListener($nodes) {
  422. if (!MutationObserver) {
  423. //fallback for IE 9
  424. $nodes.each(function () {
  425. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).triggerHandler('scrollme.zf.trigger');
  426. });
  427. } //trigger all listening elements and signal a scroll event
  428. $nodes.attr('data-events', "scroll");
  429. },
  430. closeMeListener: function closeMeListener(e, pluginId) {
  431. var plugin = e.namespace.split('.')[0];
  432. var plugins = jquery__WEBPACK_IMPORTED_MODULE_0___default()("[data-".concat(plugin, "]")).not("[data-yeti-box=\"".concat(pluginId, "\"]"));
  433. plugins.each(function () {
  434. var _this = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this);
  435. _this.triggerHandler('close.zf.trigger', [_this]);
  436. });
  437. } // Global, parses whole document.
  438. };
  439. Triggers.Initializers.addClosemeListener = function (pluginName) {
  440. var yetiBoxes = jquery__WEBPACK_IMPORTED_MODULE_0___default()('[data-yeti-box]'),
  441. plugNames = ['dropdown', 'tooltip', 'reveal'];
  442. if (pluginName) {
  443. if (typeof pluginName === 'string') {
  444. plugNames.push(pluginName);
  445. } else if (_typeof(pluginName) === 'object' && typeof pluginName[0] === 'string') {
  446. plugNames = plugNames.concat(pluginName);
  447. } else {
  448. console.error('Plugin names must be strings');
  449. }
  450. }
  451. if (yetiBoxes.length) {
  452. var listeners = plugNames.map(function (name) {
  453. return "closeme.zf.".concat(name);
  454. }).join(' ');
  455. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off(listeners).on(listeners, Triggers.Listeners.Global.closeMeListener);
  456. }
  457. };
  458. function debounceGlobalListener(debounce, trigger, listener) {
  459. var timer,
  460. args = Array.prototype.slice.call(arguments, 3);
  461. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off(trigger).on(trigger, function (e) {
  462. if (timer) {
  463. clearTimeout(timer);
  464. }
  465. timer = setTimeout(function () {
  466. listener.apply(null, args);
  467. }, debounce || 10); //default time to emit scroll event
  468. });
  469. }
  470. Triggers.Initializers.addResizeListener = function (debounce) {
  471. var $nodes = jquery__WEBPACK_IMPORTED_MODULE_0___default()('[data-resize]');
  472. if ($nodes.length) {
  473. debounceGlobalListener(debounce, 'resize.zf.trigger', Triggers.Listeners.Global.resizeListener, $nodes);
  474. }
  475. };
  476. Triggers.Initializers.addScrollListener = function (debounce) {
  477. var $nodes = jquery__WEBPACK_IMPORTED_MODULE_0___default()('[data-scroll]');
  478. if ($nodes.length) {
  479. debounceGlobalListener(debounce, 'scroll.zf.trigger', Triggers.Listeners.Global.scrollListener, $nodes);
  480. }
  481. };
  482. Triggers.Initializers.addMutationEventsListener = function ($elem) {
  483. if (!MutationObserver) {
  484. return false;
  485. }
  486. var $nodes = $elem.find('[data-resize], [data-scroll], [data-mutate]'); //element callback
  487. var listeningElementsMutation = function listeningElementsMutation(mutationRecordsList) {
  488. var $target = jquery__WEBPACK_IMPORTED_MODULE_0___default()(mutationRecordsList[0].target); //trigger the event handler for the element depending on type
  489. switch (mutationRecordsList[0].type) {
  490. case "attributes":
  491. if ($target.attr("data-events") === "scroll" && mutationRecordsList[0].attributeName === "data-events") {
  492. $target.triggerHandler('scrollme.zf.trigger', [$target, window.pageYOffset]);
  493. }
  494. if ($target.attr("data-events") === "resize" && mutationRecordsList[0].attributeName === "data-events") {
  495. $target.triggerHandler('resizeme.zf.trigger', [$target]);
  496. }
  497. if (mutationRecordsList[0].attributeName === "style") {
  498. $target.closest("[data-mutate]").attr("data-events", "mutate");
  499. $target.closest("[data-mutate]").triggerHandler('mutateme.zf.trigger', [$target.closest("[data-mutate]")]);
  500. }
  501. break;
  502. case "childList":
  503. $target.closest("[data-mutate]").attr("data-events", "mutate");
  504. $target.closest("[data-mutate]").triggerHandler('mutateme.zf.trigger', [$target.closest("[data-mutate]")]);
  505. break;
  506. default:
  507. return false;
  508. //nothing
  509. }
  510. };
  511. if ($nodes.length) {
  512. //for each element that needs to listen for resizing, scrolling, or mutation add a single observer
  513. for (var i = 0; i <= $nodes.length - 1; i++) {
  514. var elementObserver = new MutationObserver(listeningElementsMutation);
  515. elementObserver.observe($nodes[i], {
  516. attributes: true,
  517. childList: true,
  518. characterData: false,
  519. subtree: true,
  520. attributeFilter: ["data-events", "style"]
  521. });
  522. }
  523. }
  524. };
  525. Triggers.Initializers.addSimpleListeners = function () {
  526. var $document = jquery__WEBPACK_IMPORTED_MODULE_0___default()(document);
  527. Triggers.Initializers.addOpenListener($document);
  528. Triggers.Initializers.addCloseListener($document);
  529. Triggers.Initializers.addToggleListener($document);
  530. Triggers.Initializers.addCloseableListener($document);
  531. Triggers.Initializers.addToggleFocusListener($document);
  532. };
  533. Triggers.Initializers.addGlobalListeners = function () {
  534. var $document = jquery__WEBPACK_IMPORTED_MODULE_0___default()(document);
  535. Triggers.Initializers.addMutationEventsListener($document);
  536. Triggers.Initializers.addResizeListener();
  537. Triggers.Initializers.addScrollListener();
  538. Triggers.Initializers.addClosemeListener();
  539. };
  540. Triggers.init = function ($, Foundation) {
  541. Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__["onLoad"])($(window), function () {
  542. if ($.triggersInitialized !== true) {
  543. Triggers.Initializers.addSimpleListeners();
  544. Triggers.Initializers.addGlobalListeners();
  545. $.triggersInitialized = true;
  546. }
  547. });
  548. if (Foundation) {
  549. Foundation.Triggers = Triggers; // Legacy included to be backwards compatible for now.
  550. Foundation.IHearYou = Triggers.Initializers.addGlobalListeners;
  551. }
  552. };
  553. /***/ }),
  554. /***/ 19:
  555. /*!********************************************************!*\
  556. !*** multi ./js/entries/plugins/foundation.toggler.js ***!
  557. \********************************************************/
  558. /*! no static exports found */
  559. /***/ (function(module, exports, __webpack_require__) {
  560. module.exports = __webpack_require__(/*! /Users/joeworkman/Development/foundation-sites/js/entries/plugins/foundation.toggler.js */"./js/entries/plugins/foundation.toggler.js");
  561. /***/ }),
  562. /***/ "jquery":
  563. /*!********************************************************************************************!*\
  564. !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***!
  565. \********************************************************************************************/
  566. /*! no static exports found */
  567. /***/ (function(module, exports) {
  568. module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__;
  569. /***/ })
  570. /******/ });
  571. });
  572. //# sourceMappingURL=foundation.toggler.js.map