foundation.util.triggers.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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.util.triggers"] = factory(require("./foundation.core"), require("./foundation.util.motion"), require("jquery"));
  8. else
  9. root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.util.triggers"] = 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 = 29);
  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.util.triggers.js":
  115. /*!********************************************************!*\
  116. !*** ./js/entries/plugins/foundation.util.triggers.js ***!
  117. \********************************************************/
  118. /*! exports provided: Foundation, Triggers */
  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 jquery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jquery */ "jquery");
  126. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_1__);
  127. /* harmony import */ var _foundation_util_triggers__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../foundation.util.triggers */ "./js/foundation.util.triggers.js");
  128. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Triggers", function() { return _foundation_util_triggers__WEBPACK_IMPORTED_MODULE_2__["Triggers"]; });
  129. _foundation_util_triggers__WEBPACK_IMPORTED_MODULE_2__["Triggers"].init(jquery__WEBPACK_IMPORTED_MODULE_1___default.a, _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"]);
  130. /***/ }),
  131. /***/ "./js/foundation.util.triggers.js":
  132. /*!****************************************!*\
  133. !*** ./js/foundation.util.triggers.js ***!
  134. \****************************************/
  135. /*! exports provided: Triggers */
  136. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  137. "use strict";
  138. __webpack_require__.r(__webpack_exports__);
  139. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Triggers", function() { return Triggers; });
  140. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
  141. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
  142. /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.core.utils */ "./foundation.core");
  143. /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__);
  144. /* harmony import */ var _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.util.motion */ "./foundation.util.motion");
  145. /* harmony import */ var _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__);
  146. 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); }
  147. var MutationObserver = function () {
  148. var prefixes = ['WebKit', 'Moz', 'O', 'Ms', ''];
  149. for (var i = 0; i < prefixes.length; i++) {
  150. if ("".concat(prefixes[i], "MutationObserver") in window) {
  151. return window["".concat(prefixes[i], "MutationObserver")];
  152. }
  153. }
  154. return false;
  155. }();
  156. var triggers = function triggers(el, type) {
  157. el.data(type).split(' ').forEach(function (id) {
  158. jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(id))[type === 'close' ? 'trigger' : 'triggerHandler']("".concat(type, ".zf.trigger"), [el]);
  159. });
  160. };
  161. var Triggers = {
  162. Listeners: {
  163. Basic: {},
  164. Global: {}
  165. },
  166. Initializers: {}
  167. };
  168. Triggers.Listeners.Basic = {
  169. openListener: function openListener() {
  170. triggers(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), 'open');
  171. },
  172. closeListener: function closeListener() {
  173. var id = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('close');
  174. if (id) {
  175. triggers(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), 'close');
  176. } else {
  177. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('close.zf.trigger');
  178. }
  179. },
  180. toggleListener: function toggleListener() {
  181. var id = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('toggle');
  182. if (id) {
  183. triggers(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), 'toggle');
  184. } else {
  185. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('toggle.zf.trigger');
  186. }
  187. },
  188. closeableListener: function closeableListener(e) {
  189. var animation = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('closable'); // Only close the first closable element. See https://git.io/zf-7833
  190. e.stopPropagation();
  191. if (animation !== '') {
  192. _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__["Motion"].animateOut(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), animation, function () {
  193. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('closed.zf');
  194. });
  195. } else {
  196. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).fadeOut().trigger('closed.zf');
  197. }
  198. },
  199. toggleFocusListener: function toggleFocusListener() {
  200. var id = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('toggle-focus');
  201. jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(id)).triggerHandler('toggle.zf.trigger', [jquery__WEBPACK_IMPORTED_MODULE_0___default()(this)]);
  202. }
  203. }; // Elements with [data-open] will reveal a plugin that supports it when clicked.
  204. Triggers.Initializers.addOpenListener = function ($elem) {
  205. $elem.off('click.zf.trigger', Triggers.Listeners.Basic.openListener);
  206. $elem.on('click.zf.trigger', '[data-open]', Triggers.Listeners.Basic.openListener);
  207. }; // Elements with [data-close] will close a plugin that supports it when clicked.
  208. // If used without a value on [data-close], the event will bubble, allowing it to close a parent component.
  209. Triggers.Initializers.addCloseListener = function ($elem) {
  210. $elem.off('click.zf.trigger', Triggers.Listeners.Basic.closeListener);
  211. $elem.on('click.zf.trigger', '[data-close]', Triggers.Listeners.Basic.closeListener);
  212. }; // Elements with [data-toggle] will toggle a plugin that supports it when clicked.
  213. Triggers.Initializers.addToggleListener = function ($elem) {
  214. $elem.off('click.zf.trigger', Triggers.Listeners.Basic.toggleListener);
  215. $elem.on('click.zf.trigger', '[data-toggle]', Triggers.Listeners.Basic.toggleListener);
  216. }; // Elements with [data-closable] will respond to close.zf.trigger events.
  217. Triggers.Initializers.addCloseableListener = function ($elem) {
  218. $elem.off('close.zf.trigger', Triggers.Listeners.Basic.closeableListener);
  219. $elem.on('close.zf.trigger', '[data-closeable], [data-closable]', Triggers.Listeners.Basic.closeableListener);
  220. }; // Elements with [data-toggle-focus] will respond to coming in and out of focus
  221. Triggers.Initializers.addToggleFocusListener = function ($elem) {
  222. $elem.off('focus.zf.trigger blur.zf.trigger', Triggers.Listeners.Basic.toggleFocusListener);
  223. $elem.on('focus.zf.trigger blur.zf.trigger', '[data-toggle-focus]', Triggers.Listeners.Basic.toggleFocusListener);
  224. }; // More Global/complex listeners and triggers
  225. Triggers.Listeners.Global = {
  226. resizeListener: function resizeListener($nodes) {
  227. if (!MutationObserver) {
  228. //fallback for IE 9
  229. $nodes.each(function () {
  230. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).triggerHandler('resizeme.zf.trigger');
  231. });
  232. } //trigger all listening elements and signal a resize event
  233. $nodes.attr('data-events', "resize");
  234. },
  235. scrollListener: function scrollListener($nodes) {
  236. if (!MutationObserver) {
  237. //fallback for IE 9
  238. $nodes.each(function () {
  239. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).triggerHandler('scrollme.zf.trigger');
  240. });
  241. } //trigger all listening elements and signal a scroll event
  242. $nodes.attr('data-events', "scroll");
  243. },
  244. closeMeListener: function closeMeListener(e, pluginId) {
  245. var plugin = e.namespace.split('.')[0];
  246. var plugins = jquery__WEBPACK_IMPORTED_MODULE_0___default()("[data-".concat(plugin, "]")).not("[data-yeti-box=\"".concat(pluginId, "\"]"));
  247. plugins.each(function () {
  248. var _this = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this);
  249. _this.triggerHandler('close.zf.trigger', [_this]);
  250. });
  251. } // Global, parses whole document.
  252. };
  253. Triggers.Initializers.addClosemeListener = function (pluginName) {
  254. var yetiBoxes = jquery__WEBPACK_IMPORTED_MODULE_0___default()('[data-yeti-box]'),
  255. plugNames = ['dropdown', 'tooltip', 'reveal'];
  256. if (pluginName) {
  257. if (typeof pluginName === 'string') {
  258. plugNames.push(pluginName);
  259. } else if (_typeof(pluginName) === 'object' && typeof pluginName[0] === 'string') {
  260. plugNames = plugNames.concat(pluginName);
  261. } else {
  262. console.error('Plugin names must be strings');
  263. }
  264. }
  265. if (yetiBoxes.length) {
  266. var listeners = plugNames.map(function (name) {
  267. return "closeme.zf.".concat(name);
  268. }).join(' ');
  269. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off(listeners).on(listeners, Triggers.Listeners.Global.closeMeListener);
  270. }
  271. };
  272. function debounceGlobalListener(debounce, trigger, listener) {
  273. var timer,
  274. args = Array.prototype.slice.call(arguments, 3);
  275. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off(trigger).on(trigger, function (e) {
  276. if (timer) {
  277. clearTimeout(timer);
  278. }
  279. timer = setTimeout(function () {
  280. listener.apply(null, args);
  281. }, debounce || 10); //default time to emit scroll event
  282. });
  283. }
  284. Triggers.Initializers.addResizeListener = function (debounce) {
  285. var $nodes = jquery__WEBPACK_IMPORTED_MODULE_0___default()('[data-resize]');
  286. if ($nodes.length) {
  287. debounceGlobalListener(debounce, 'resize.zf.trigger', Triggers.Listeners.Global.resizeListener, $nodes);
  288. }
  289. };
  290. Triggers.Initializers.addScrollListener = function (debounce) {
  291. var $nodes = jquery__WEBPACK_IMPORTED_MODULE_0___default()('[data-scroll]');
  292. if ($nodes.length) {
  293. debounceGlobalListener(debounce, 'scroll.zf.trigger', Triggers.Listeners.Global.scrollListener, $nodes);
  294. }
  295. };
  296. Triggers.Initializers.addMutationEventsListener = function ($elem) {
  297. if (!MutationObserver) {
  298. return false;
  299. }
  300. var $nodes = $elem.find('[data-resize], [data-scroll], [data-mutate]'); //element callback
  301. var listeningElementsMutation = function listeningElementsMutation(mutationRecordsList) {
  302. var $target = jquery__WEBPACK_IMPORTED_MODULE_0___default()(mutationRecordsList[0].target); //trigger the event handler for the element depending on type
  303. switch (mutationRecordsList[0].type) {
  304. case "attributes":
  305. if ($target.attr("data-events") === "scroll" && mutationRecordsList[0].attributeName === "data-events") {
  306. $target.triggerHandler('scrollme.zf.trigger', [$target, window.pageYOffset]);
  307. }
  308. if ($target.attr("data-events") === "resize" && mutationRecordsList[0].attributeName === "data-events") {
  309. $target.triggerHandler('resizeme.zf.trigger', [$target]);
  310. }
  311. if (mutationRecordsList[0].attributeName === "style") {
  312. $target.closest("[data-mutate]").attr("data-events", "mutate");
  313. $target.closest("[data-mutate]").triggerHandler('mutateme.zf.trigger', [$target.closest("[data-mutate]")]);
  314. }
  315. break;
  316. case "childList":
  317. $target.closest("[data-mutate]").attr("data-events", "mutate");
  318. $target.closest("[data-mutate]").triggerHandler('mutateme.zf.trigger', [$target.closest("[data-mutate]")]);
  319. break;
  320. default:
  321. return false;
  322. //nothing
  323. }
  324. };
  325. if ($nodes.length) {
  326. //for each element that needs to listen for resizing, scrolling, or mutation add a single observer
  327. for (var i = 0; i <= $nodes.length - 1; i++) {
  328. var elementObserver = new MutationObserver(listeningElementsMutation);
  329. elementObserver.observe($nodes[i], {
  330. attributes: true,
  331. childList: true,
  332. characterData: false,
  333. subtree: true,
  334. attributeFilter: ["data-events", "style"]
  335. });
  336. }
  337. }
  338. };
  339. Triggers.Initializers.addSimpleListeners = function () {
  340. var $document = jquery__WEBPACK_IMPORTED_MODULE_0___default()(document);
  341. Triggers.Initializers.addOpenListener($document);
  342. Triggers.Initializers.addCloseListener($document);
  343. Triggers.Initializers.addToggleListener($document);
  344. Triggers.Initializers.addCloseableListener($document);
  345. Triggers.Initializers.addToggleFocusListener($document);
  346. };
  347. Triggers.Initializers.addGlobalListeners = function () {
  348. var $document = jquery__WEBPACK_IMPORTED_MODULE_0___default()(document);
  349. Triggers.Initializers.addMutationEventsListener($document);
  350. Triggers.Initializers.addResizeListener();
  351. Triggers.Initializers.addScrollListener();
  352. Triggers.Initializers.addClosemeListener();
  353. };
  354. Triggers.init = function ($, Foundation) {
  355. Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__["onLoad"])($(window), function () {
  356. if ($.triggersInitialized !== true) {
  357. Triggers.Initializers.addSimpleListeners();
  358. Triggers.Initializers.addGlobalListeners();
  359. $.triggersInitialized = true;
  360. }
  361. });
  362. if (Foundation) {
  363. Foundation.Triggers = Triggers; // Legacy included to be backwards compatible for now.
  364. Foundation.IHearYou = Triggers.Initializers.addGlobalListeners;
  365. }
  366. };
  367. /***/ }),
  368. /***/ 29:
  369. /*!**************************************************************!*\
  370. !*** multi ./js/entries/plugins/foundation.util.triggers.js ***!
  371. \**************************************************************/
  372. /*! no static exports found */
  373. /***/ (function(module, exports, __webpack_require__) {
  374. module.exports = __webpack_require__(/*! /Users/joeworkman/Development/foundation-sites/js/entries/plugins/foundation.util.triggers.js */"./js/entries/plugins/foundation.util.triggers.js");
  375. /***/ }),
  376. /***/ "jquery":
  377. /*!********************************************************************************************!*\
  378. !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***!
  379. \********************************************************************************************/
  380. /*! no static exports found */
  381. /***/ (function(module, exports) {
  382. module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__;
  383. /***/ })
  384. /******/ });
  385. });
  386. //# sourceMappingURL=foundation.util.triggers.js.map