foundation.interchange.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("./foundation.core"), require("./foundation.util.mediaQuery"), require("./foundation.util.motion"), require("jquery"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["./foundation.core", "./foundation.util.mediaQuery", "./foundation.util.motion", "jquery"], factory);
  6. else if(typeof exports === 'object')
  7. exports["foundation.interchange"] = factory(require("./foundation.core"), require("./foundation.util.mediaQuery"), require("./foundation.util.motion"), require("jquery"));
  8. else
  9. root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.interchange"] = factory(root["__FOUNDATION_EXTERNAL__"]["foundation.core"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.mediaQuery"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.motion"], root["jQuery"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE__foundation_core__, __WEBPACK_EXTERNAL_MODULE__foundation_util_mediaQuery__, __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 = 7);
  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.mediaQuery":
  107. /*!************************************************************************************************************************************************************************************************************!*\
  108. !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.util.mediaQuery"],"amd":"./foundation.util.mediaQuery","commonjs":"./foundation.util.mediaQuery","commonjs2":"./foundation.util.mediaQuery"} ***!
  109. \************************************************************************************************************************************************************************************************************/
  110. /*! no static exports found */
  111. /***/ (function(module, exports) {
  112. module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_util_mediaQuery__;
  113. /***/ }),
  114. /***/ "./foundation.util.motion":
  115. /*!********************************************************************************************************************************************************************************************!*\
  116. !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.util.motion"],"amd":"./foundation.util.motion","commonjs":"./foundation.util.motion","commonjs2":"./foundation.util.motion"} ***!
  117. \********************************************************************************************************************************************************************************************/
  118. /*! no static exports found */
  119. /***/ (function(module, exports) {
  120. module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_util_motion__;
  121. /***/ }),
  122. /***/ "./js/entries/plugins/foundation.interchange.js":
  123. /*!******************************************************!*\
  124. !*** ./js/entries/plugins/foundation.interchange.js ***!
  125. \******************************************************/
  126. /*! exports provided: Foundation, Interchange */
  127. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  128. "use strict";
  129. __webpack_require__.r(__webpack_exports__);
  130. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core");
  131. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_0__);
  132. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Foundation", function() { return _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"]; });
  133. /* harmony import */ var _foundation_interchange__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.interchange */ "./js/foundation.interchange.js");
  134. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Interchange", function() { return _foundation_interchange__WEBPACK_IMPORTED_MODULE_1__["Interchange"]; });
  135. _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"].plugin(_foundation_interchange__WEBPACK_IMPORTED_MODULE_1__["Interchange"], 'Interchange');
  136. /***/ }),
  137. /***/ "./js/foundation.interchange.js":
  138. /*!**************************************!*\
  139. !*** ./js/foundation.interchange.js ***!
  140. \**************************************/
  141. /*! exports provided: Interchange */
  142. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  143. "use strict";
  144. __webpack_require__.r(__webpack_exports__);
  145. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Interchange", function() { return Interchange; });
  146. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
  147. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
  148. /* harmony import */ var _foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.util.mediaQuery */ "./foundation.util.mediaQuery");
  149. /* harmony import */ var _foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_1__);
  150. /* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.core.plugin */ "./foundation.core");
  151. /* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_2__);
  152. /* harmony import */ var _foundation_util_triggers__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./foundation.util.triggers */ "./js/foundation.util.triggers.js");
  153. 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); }
  154. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  155. 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); } }
  156. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  157. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  158. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  159. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  160. 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); }
  161. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  162. /**
  163. * Interchange module.
  164. * @module foundation.interchange
  165. * @requires foundation.util.mediaQuery
  166. */
  167. var Interchange =
  168. /*#__PURE__*/
  169. function (_Plugin) {
  170. _inherits(Interchange, _Plugin);
  171. function Interchange() {
  172. _classCallCheck(this, Interchange);
  173. return _possibleConstructorReturn(this, _getPrototypeOf(Interchange).apply(this, arguments));
  174. }
  175. _createClass(Interchange, [{
  176. key: "_setup",
  177. /**
  178. * Creates a new instance of Interchange.
  179. * @class
  180. * @name Interchange
  181. * @fires Interchange#init
  182. * @param {Object} element - jQuery object to add the trigger to.
  183. * @param {Object} options - Overrides to the default plugin settings.
  184. */
  185. value: function _setup(element, options) {
  186. this.$element = element;
  187. this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend({}, Interchange.defaults, this.$element.data(), options);
  188. this.rules = [];
  189. this.currentPath = '';
  190. this.className = 'Interchange'; // ie9 back compat
  191. // Triggers init is idempotent, just need to make sure it is initialized
  192. _foundation_util_triggers__WEBPACK_IMPORTED_MODULE_3__["Triggers"].init(jquery__WEBPACK_IMPORTED_MODULE_0___default.a);
  193. this._init();
  194. this._events();
  195. }
  196. /**
  197. * Initializes the Interchange plugin and calls functions to get interchange functioning on load.
  198. * @function
  199. * @private
  200. */
  201. }, {
  202. key: "_init",
  203. value: function _init() {
  204. _foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_1__["MediaQuery"]._init();
  205. var id = this.$element[0].id || Object(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_2__["GetYoDigits"])(6, 'interchange');
  206. this.$element.attr({
  207. 'data-resize': id,
  208. 'id': id
  209. });
  210. this._parseOptions();
  211. this._addBreakpoints();
  212. this._generateRules();
  213. this._reflow();
  214. }
  215. /**
  216. * Initializes events for Interchange.
  217. * @function
  218. * @private
  219. */
  220. }, {
  221. key: "_events",
  222. value: function _events() {
  223. var _this = this;
  224. this.$element.off('resizeme.zf.trigger').on('resizeme.zf.trigger', function () {
  225. return _this._reflow();
  226. });
  227. }
  228. /**
  229. * Calls necessary functions to update Interchange upon DOM change
  230. * @function
  231. * @private
  232. */
  233. }, {
  234. key: "_reflow",
  235. value: function _reflow() {
  236. var match; // Iterate through each rule, but only save the last match
  237. for (var i in this.rules) {
  238. if (this.rules.hasOwnProperty(i)) {
  239. var rule = this.rules[i];
  240. if (window.matchMedia(rule.query).matches) {
  241. match = rule;
  242. }
  243. }
  244. }
  245. if (match) {
  246. this.replace(match.path);
  247. }
  248. }
  249. /**
  250. * Check options valifity and set defaults for:
  251. * - `data-interchange-type`: if set, enforce the type of replacement (auto, src, background or html)
  252. * @function
  253. * @private
  254. */
  255. }, {
  256. key: "_parseOptions",
  257. value: function _parseOptions() {
  258. var types = ['auto', 'src', 'background', 'html'];
  259. if (typeof this.options.type === 'undefined') this.options.type = 'auto';else if (types.indexOf(this.options.type) === -1) {
  260. console.log("Warning: invalid value \"".concat(this.options.type, "\" for Interchange option \"type\""));
  261. this.options.type = 'auto';
  262. }
  263. }
  264. /**
  265. * Gets the Foundation breakpoints and adds them to the Interchange.SPECIAL_QUERIES object.
  266. * @function
  267. * @private
  268. */
  269. }, {
  270. key: "_addBreakpoints",
  271. value: function _addBreakpoints() {
  272. for (var i in _foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_1__["MediaQuery"].queries) {
  273. if (_foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_1__["MediaQuery"].queries.hasOwnProperty(i)) {
  274. var query = _foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_1__["MediaQuery"].queries[i];
  275. Interchange.SPECIAL_QUERIES[query.name] = query.value;
  276. }
  277. }
  278. }
  279. /**
  280. * Checks the Interchange element for the provided media query + content pairings
  281. * @function
  282. * @private
  283. * @param {Object} element - jQuery object that is an Interchange instance
  284. * @returns {Array} scenarios - Array of objects that have 'mq' and 'path' keys with corresponding keys
  285. */
  286. }, {
  287. key: "_generateRules",
  288. value: function _generateRules(element) {
  289. var rulesList = [];
  290. var rules;
  291. if (this.options.rules) {
  292. rules = this.options.rules;
  293. } else {
  294. rules = this.$element.data('interchange');
  295. }
  296. rules = typeof rules === 'string' ? rules.match(/\[.*?, .*?\]/g) : rules;
  297. for (var i in rules) {
  298. if (rules.hasOwnProperty(i)) {
  299. var rule = rules[i].slice(1, -1).split(', ');
  300. var path = rule.slice(0, -1).join('');
  301. var query = rule[rule.length - 1];
  302. if (Interchange.SPECIAL_QUERIES[query]) {
  303. query = Interchange.SPECIAL_QUERIES[query];
  304. }
  305. rulesList.push({
  306. path: path,
  307. query: query
  308. });
  309. }
  310. }
  311. this.rules = rulesList;
  312. }
  313. /**
  314. * Update the `src` property of an image, or change the HTML of a container, to the specified path.
  315. * @function
  316. * @param {String} path - Path to the image or HTML partial.
  317. * @fires Interchange#replaced
  318. */
  319. }, {
  320. key: "replace",
  321. value: function replace(path) {
  322. var _this2 = this;
  323. if (this.currentPath === path) return;
  324. var trigger = 'replaced.zf.interchange';
  325. var type = this.options.type;
  326. if (type === 'auto') {
  327. if (this.$element[0].nodeName === 'IMG') type = 'src';else if (path.match(/\.(gif|jpe?g|png|svg|tiff)([?#].*)?/i)) type = 'background';else type = 'html';
  328. } // Replacing images
  329. if (type === 'src') {
  330. this.$element.attr('src', path).on('load', function () {
  331. _this2.currentPath = path;
  332. }).trigger(trigger);
  333. } // Replacing background images
  334. else if (type === 'background') {
  335. path = path.replace(/\(/g, '%28').replace(/\)/g, '%29');
  336. this.$element.css({
  337. 'background-image': 'url(' + path + ')'
  338. }).trigger(trigger);
  339. } // Replacing HTML
  340. else if (type === 'html') {
  341. jquery__WEBPACK_IMPORTED_MODULE_0___default.a.get(path, function (response) {
  342. _this2.$element.html(response).trigger(trigger);
  343. jquery__WEBPACK_IMPORTED_MODULE_0___default()(response).foundation();
  344. _this2.currentPath = path;
  345. });
  346. }
  347. /**
  348. * Fires when content in an Interchange element is done being loaded.
  349. * @event Interchange#replaced
  350. */
  351. // this.$element.trigger('replaced.zf.interchange');
  352. }
  353. /**
  354. * Destroys an instance of interchange.
  355. * @function
  356. */
  357. }, {
  358. key: "_destroy",
  359. value: function _destroy() {
  360. this.$element.off('resizeme.zf.trigger');
  361. }
  362. }]);
  363. return Interchange;
  364. }(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_2__["Plugin"]);
  365. /**
  366. * Default settings for plugin
  367. */
  368. Interchange.defaults = {
  369. /**
  370. * Rules to be applied to Interchange elements. Set with the `data-interchange` array notation.
  371. * @option
  372. * @type {?array}
  373. * @default null
  374. */
  375. rules: null,
  376. /**
  377. * Type of the responsive ressource to replace. It can take the following options:
  378. * - `auto` (default): choose the type according to the element tag or the ressource extension,
  379. * - `src`: replace the `[src]` attribute, recommended for images `<img>`.
  380. * - `background`: replace the `background-image` CSS property.
  381. * - `html`: replace the element content.
  382. * @option
  383. * @type {string}
  384. * @default 'auto'
  385. */
  386. type: 'auto'
  387. };
  388. Interchange.SPECIAL_QUERIES = {
  389. 'landscape': 'screen and (orientation: landscape)',
  390. 'portrait': 'screen and (orientation: portrait)',
  391. 'retina': 'only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min--moz-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx)'
  392. };
  393. /***/ }),
  394. /***/ "./js/foundation.util.triggers.js":
  395. /*!****************************************!*\
  396. !*** ./js/foundation.util.triggers.js ***!
  397. \****************************************/
  398. /*! exports provided: Triggers */
  399. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  400. "use strict";
  401. __webpack_require__.r(__webpack_exports__);
  402. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Triggers", function() { return Triggers; });
  403. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
  404. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
  405. /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.core.utils */ "./foundation.core");
  406. /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__);
  407. /* harmony import */ var _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.util.motion */ "./foundation.util.motion");
  408. /* harmony import */ var _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__);
  409. 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); }
  410. var MutationObserver = function () {
  411. var prefixes = ['WebKit', 'Moz', 'O', 'Ms', ''];
  412. for (var i = 0; i < prefixes.length; i++) {
  413. if ("".concat(prefixes[i], "MutationObserver") in window) {
  414. return window["".concat(prefixes[i], "MutationObserver")];
  415. }
  416. }
  417. return false;
  418. }();
  419. var triggers = function triggers(el, type) {
  420. el.data(type).split(' ').forEach(function (id) {
  421. jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(id))[type === 'close' ? 'trigger' : 'triggerHandler']("".concat(type, ".zf.trigger"), [el]);
  422. });
  423. };
  424. var Triggers = {
  425. Listeners: {
  426. Basic: {},
  427. Global: {}
  428. },
  429. Initializers: {}
  430. };
  431. Triggers.Listeners.Basic = {
  432. openListener: function openListener() {
  433. triggers(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), 'open');
  434. },
  435. closeListener: function closeListener() {
  436. var id = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('close');
  437. if (id) {
  438. triggers(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), 'close');
  439. } else {
  440. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('close.zf.trigger');
  441. }
  442. },
  443. toggleListener: function toggleListener() {
  444. var id = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('toggle');
  445. if (id) {
  446. triggers(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), 'toggle');
  447. } else {
  448. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('toggle.zf.trigger');
  449. }
  450. },
  451. closeableListener: function closeableListener(e) {
  452. var animation = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('closable'); // Only close the first closable element. See https://git.io/zf-7833
  453. e.stopPropagation();
  454. if (animation !== '') {
  455. _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__["Motion"].animateOut(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), animation, function () {
  456. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('closed.zf');
  457. });
  458. } else {
  459. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).fadeOut().trigger('closed.zf');
  460. }
  461. },
  462. toggleFocusListener: function toggleFocusListener() {
  463. var id = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('toggle-focus');
  464. jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(id)).triggerHandler('toggle.zf.trigger', [jquery__WEBPACK_IMPORTED_MODULE_0___default()(this)]);
  465. }
  466. }; // Elements with [data-open] will reveal a plugin that supports it when clicked.
  467. Triggers.Initializers.addOpenListener = function ($elem) {
  468. $elem.off('click.zf.trigger', Triggers.Listeners.Basic.openListener);
  469. $elem.on('click.zf.trigger', '[data-open]', Triggers.Listeners.Basic.openListener);
  470. }; // Elements with [data-close] will close a plugin that supports it when clicked.
  471. // If used without a value on [data-close], the event will bubble, allowing it to close a parent component.
  472. Triggers.Initializers.addCloseListener = function ($elem) {
  473. $elem.off('click.zf.trigger', Triggers.Listeners.Basic.closeListener);
  474. $elem.on('click.zf.trigger', '[data-close]', Triggers.Listeners.Basic.closeListener);
  475. }; // Elements with [data-toggle] will toggle a plugin that supports it when clicked.
  476. Triggers.Initializers.addToggleListener = function ($elem) {
  477. $elem.off('click.zf.trigger', Triggers.Listeners.Basic.toggleListener);
  478. $elem.on('click.zf.trigger', '[data-toggle]', Triggers.Listeners.Basic.toggleListener);
  479. }; // Elements with [data-closable] will respond to close.zf.trigger events.
  480. Triggers.Initializers.addCloseableListener = function ($elem) {
  481. $elem.off('close.zf.trigger', Triggers.Listeners.Basic.closeableListener);
  482. $elem.on('close.zf.trigger', '[data-closeable], [data-closable]', Triggers.Listeners.Basic.closeableListener);
  483. }; // Elements with [data-toggle-focus] will respond to coming in and out of focus
  484. Triggers.Initializers.addToggleFocusListener = function ($elem) {
  485. $elem.off('focus.zf.trigger blur.zf.trigger', Triggers.Listeners.Basic.toggleFocusListener);
  486. $elem.on('focus.zf.trigger blur.zf.trigger', '[data-toggle-focus]', Triggers.Listeners.Basic.toggleFocusListener);
  487. }; // More Global/complex listeners and triggers
  488. Triggers.Listeners.Global = {
  489. resizeListener: function resizeListener($nodes) {
  490. if (!MutationObserver) {
  491. //fallback for IE 9
  492. $nodes.each(function () {
  493. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).triggerHandler('resizeme.zf.trigger');
  494. });
  495. } //trigger all listening elements and signal a resize event
  496. $nodes.attr('data-events', "resize");
  497. },
  498. scrollListener: function scrollListener($nodes) {
  499. if (!MutationObserver) {
  500. //fallback for IE 9
  501. $nodes.each(function () {
  502. jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).triggerHandler('scrollme.zf.trigger');
  503. });
  504. } //trigger all listening elements and signal a scroll event
  505. $nodes.attr('data-events', "scroll");
  506. },
  507. closeMeListener: function closeMeListener(e, pluginId) {
  508. var plugin = e.namespace.split('.')[0];
  509. var plugins = jquery__WEBPACK_IMPORTED_MODULE_0___default()("[data-".concat(plugin, "]")).not("[data-yeti-box=\"".concat(pluginId, "\"]"));
  510. plugins.each(function () {
  511. var _this = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this);
  512. _this.triggerHandler('close.zf.trigger', [_this]);
  513. });
  514. } // Global, parses whole document.
  515. };
  516. Triggers.Initializers.addClosemeListener = function (pluginName) {
  517. var yetiBoxes = jquery__WEBPACK_IMPORTED_MODULE_0___default()('[data-yeti-box]'),
  518. plugNames = ['dropdown', 'tooltip', 'reveal'];
  519. if (pluginName) {
  520. if (typeof pluginName === 'string') {
  521. plugNames.push(pluginName);
  522. } else if (_typeof(pluginName) === 'object' && typeof pluginName[0] === 'string') {
  523. plugNames = plugNames.concat(pluginName);
  524. } else {
  525. console.error('Plugin names must be strings');
  526. }
  527. }
  528. if (yetiBoxes.length) {
  529. var listeners = plugNames.map(function (name) {
  530. return "closeme.zf.".concat(name);
  531. }).join(' ');
  532. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off(listeners).on(listeners, Triggers.Listeners.Global.closeMeListener);
  533. }
  534. };
  535. function debounceGlobalListener(debounce, trigger, listener) {
  536. var timer,
  537. args = Array.prototype.slice.call(arguments, 3);
  538. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off(trigger).on(trigger, function (e) {
  539. if (timer) {
  540. clearTimeout(timer);
  541. }
  542. timer = setTimeout(function () {
  543. listener.apply(null, args);
  544. }, debounce || 10); //default time to emit scroll event
  545. });
  546. }
  547. Triggers.Initializers.addResizeListener = function (debounce) {
  548. var $nodes = jquery__WEBPACK_IMPORTED_MODULE_0___default()('[data-resize]');
  549. if ($nodes.length) {
  550. debounceGlobalListener(debounce, 'resize.zf.trigger', Triggers.Listeners.Global.resizeListener, $nodes);
  551. }
  552. };
  553. Triggers.Initializers.addScrollListener = function (debounce) {
  554. var $nodes = jquery__WEBPACK_IMPORTED_MODULE_0___default()('[data-scroll]');
  555. if ($nodes.length) {
  556. debounceGlobalListener(debounce, 'scroll.zf.trigger', Triggers.Listeners.Global.scrollListener, $nodes);
  557. }
  558. };
  559. Triggers.Initializers.addMutationEventsListener = function ($elem) {
  560. if (!MutationObserver) {
  561. return false;
  562. }
  563. var $nodes = $elem.find('[data-resize], [data-scroll], [data-mutate]'); //element callback
  564. var listeningElementsMutation = function listeningElementsMutation(mutationRecordsList) {
  565. var $target = jquery__WEBPACK_IMPORTED_MODULE_0___default()(mutationRecordsList[0].target); //trigger the event handler for the element depending on type
  566. switch (mutationRecordsList[0].type) {
  567. case "attributes":
  568. if ($target.attr("data-events") === "scroll" && mutationRecordsList[0].attributeName === "data-events") {
  569. $target.triggerHandler('scrollme.zf.trigger', [$target, window.pageYOffset]);
  570. }
  571. if ($target.attr("data-events") === "resize" && mutationRecordsList[0].attributeName === "data-events") {
  572. $target.triggerHandler('resizeme.zf.trigger', [$target]);
  573. }
  574. if (mutationRecordsList[0].attributeName === "style") {
  575. $target.closest("[data-mutate]").attr("data-events", "mutate");
  576. $target.closest("[data-mutate]").triggerHandler('mutateme.zf.trigger', [$target.closest("[data-mutate]")]);
  577. }
  578. break;
  579. case "childList":
  580. $target.closest("[data-mutate]").attr("data-events", "mutate");
  581. $target.closest("[data-mutate]").triggerHandler('mutateme.zf.trigger', [$target.closest("[data-mutate]")]);
  582. break;
  583. default:
  584. return false;
  585. //nothing
  586. }
  587. };
  588. if ($nodes.length) {
  589. //for each element that needs to listen for resizing, scrolling, or mutation add a single observer
  590. for (var i = 0; i <= $nodes.length - 1; i++) {
  591. var elementObserver = new MutationObserver(listeningElementsMutation);
  592. elementObserver.observe($nodes[i], {
  593. attributes: true,
  594. childList: true,
  595. characterData: false,
  596. subtree: true,
  597. attributeFilter: ["data-events", "style"]
  598. });
  599. }
  600. }
  601. };
  602. Triggers.Initializers.addSimpleListeners = function () {
  603. var $document = jquery__WEBPACK_IMPORTED_MODULE_0___default()(document);
  604. Triggers.Initializers.addOpenListener($document);
  605. Triggers.Initializers.addCloseListener($document);
  606. Triggers.Initializers.addToggleListener($document);
  607. Triggers.Initializers.addCloseableListener($document);
  608. Triggers.Initializers.addToggleFocusListener($document);
  609. };
  610. Triggers.Initializers.addGlobalListeners = function () {
  611. var $document = jquery__WEBPACK_IMPORTED_MODULE_0___default()(document);
  612. Triggers.Initializers.addMutationEventsListener($document);
  613. Triggers.Initializers.addResizeListener();
  614. Triggers.Initializers.addScrollListener();
  615. Triggers.Initializers.addClosemeListener();
  616. };
  617. Triggers.init = function ($, Foundation) {
  618. Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__["onLoad"])($(window), function () {
  619. if ($.triggersInitialized !== true) {
  620. Triggers.Initializers.addSimpleListeners();
  621. Triggers.Initializers.addGlobalListeners();
  622. $.triggersInitialized = true;
  623. }
  624. });
  625. if (Foundation) {
  626. Foundation.Triggers = Triggers; // Legacy included to be backwards compatible for now.
  627. Foundation.IHearYou = Triggers.Initializers.addGlobalListeners;
  628. }
  629. };
  630. /***/ }),
  631. /***/ 7:
  632. /*!************************************************************!*\
  633. !*** multi ./js/entries/plugins/foundation.interchange.js ***!
  634. \************************************************************/
  635. /*! no static exports found */
  636. /***/ (function(module, exports, __webpack_require__) {
  637. module.exports = __webpack_require__(/*! /Users/joeworkman/Development/foundation-sites/js/entries/plugins/foundation.interchange.js */"./js/entries/plugins/foundation.interchange.js");
  638. /***/ }),
  639. /***/ "jquery":
  640. /*!********************************************************************************************!*\
  641. !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***!
  642. \********************************************************************************************/
  643. /*! no static exports found */
  644. /***/ (function(module, exports) {
  645. module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__;
  646. /***/ })
  647. /******/ });
  648. });
  649. //# sourceMappingURL=foundation.interchange.js.map