foundation.responsiveToggle.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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.responsiveToggle"] = 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.responsiveToggle"] = 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 = 13);
  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.responsiveToggle.js":
  123. /*!***********************************************************!*\
  124. !*** ./js/entries/plugins/foundation.responsiveToggle.js ***!
  125. \***********************************************************/
  126. /*! exports provided: Foundation, ResponsiveToggle */
  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_responsiveToggle__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.responsiveToggle */ "./js/foundation.responsiveToggle.js");
  134. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ResponsiveToggle", function() { return _foundation_responsiveToggle__WEBPACK_IMPORTED_MODULE_1__["ResponsiveToggle"]; });
  135. _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"].plugin(_foundation_responsiveToggle__WEBPACK_IMPORTED_MODULE_1__["ResponsiveToggle"], 'ResponsiveToggle');
  136. /***/ }),
  137. /***/ "./js/foundation.responsiveToggle.js":
  138. /*!*******************************************!*\
  139. !*** ./js/foundation.responsiveToggle.js ***!
  140. \*******************************************/
  141. /*! exports provided: ResponsiveToggle */
  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__, "ResponsiveToggle", function() { return ResponsiveToggle; });
  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_util_motion__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.util.motion */ "./foundation.util.motion");
  151. /* harmony import */ var _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__);
  152. /* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./foundation.core.plugin */ "./foundation.core");
  153. /* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_3__);
  154. 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); }
  155. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  156. 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); } }
  157. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  158. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  159. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  160. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  161. 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); }
  162. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  163. /**
  164. * ResponsiveToggle module.
  165. * @module foundation.responsiveToggle
  166. * @requires foundation.util.mediaQuery
  167. * @requires foundation.util.motion
  168. */
  169. var ResponsiveToggle =
  170. /*#__PURE__*/
  171. function (_Plugin) {
  172. _inherits(ResponsiveToggle, _Plugin);
  173. function ResponsiveToggle() {
  174. _classCallCheck(this, ResponsiveToggle);
  175. return _possibleConstructorReturn(this, _getPrototypeOf(ResponsiveToggle).apply(this, arguments));
  176. }
  177. _createClass(ResponsiveToggle, [{
  178. key: "_setup",
  179. /**
  180. * Creates a new instance of Tab Bar.
  181. * @class
  182. * @name ResponsiveToggle
  183. * @fires ResponsiveToggle#init
  184. * @param {jQuery} element - jQuery object to attach tab bar functionality to.
  185. * @param {Object} options - Overrides to the default plugin settings.
  186. */
  187. value: function _setup(element, options) {
  188. this.$element = jquery__WEBPACK_IMPORTED_MODULE_0___default()(element);
  189. this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend({}, ResponsiveToggle.defaults, this.$element.data(), options);
  190. this.className = 'ResponsiveToggle'; // ie9 back compat
  191. this._init();
  192. this._events();
  193. }
  194. /**
  195. * Initializes the tab bar by finding the target element, toggling element, and running update().
  196. * @function
  197. * @private
  198. */
  199. }, {
  200. key: "_init",
  201. value: function _init() {
  202. _foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_1__["MediaQuery"]._init();
  203. var targetID = this.$element.data('responsive-toggle');
  204. if (!targetID) {
  205. console.error('Your tab bar needs an ID of a Menu as the value of data-tab-bar.');
  206. }
  207. this.$targetMenu = jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(targetID));
  208. this.$toggler = this.$element.find('[data-toggle]').filter(function () {
  209. var target = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('toggle');
  210. return target === targetID || target === "";
  211. });
  212. this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend({}, this.options, this.$targetMenu.data()); // If they were set, parse the animation classes
  213. if (this.options.animate) {
  214. var input = this.options.animate.split(' ');
  215. this.animationIn = input[0];
  216. this.animationOut = input[1] || null;
  217. }
  218. this._update();
  219. }
  220. /**
  221. * Adds necessary event handlers for the tab bar to work.
  222. * @function
  223. * @private
  224. */
  225. }, {
  226. key: "_events",
  227. value: function _events() {
  228. var _this = this;
  229. this._updateMqHandler = this._update.bind(this);
  230. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).on('changed.zf.mediaquery', this._updateMqHandler);
  231. this.$toggler.on('click.zf.responsiveToggle', this.toggleMenu.bind(this));
  232. }
  233. /**
  234. * Checks the current media query to determine if the tab bar should be visible or hidden.
  235. * @function
  236. * @private
  237. */
  238. }, {
  239. key: "_update",
  240. value: function _update() {
  241. // Mobile
  242. if (!_foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_1__["MediaQuery"].atLeast(this.options.hideFor)) {
  243. this.$element.show();
  244. this.$targetMenu.hide();
  245. } // Desktop
  246. else {
  247. this.$element.hide();
  248. this.$targetMenu.show();
  249. }
  250. }
  251. /**
  252. * Toggles the element attached to the tab bar. The toggle only happens if the screen is small enough to allow it.
  253. * @function
  254. * @fires ResponsiveToggle#toggled
  255. */
  256. }, {
  257. key: "toggleMenu",
  258. value: function toggleMenu() {
  259. var _this2 = this;
  260. if (!_foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_1__["MediaQuery"].atLeast(this.options.hideFor)) {
  261. /**
  262. * Fires when the element attached to the tab bar toggles.
  263. * @event ResponsiveToggle#toggled
  264. */
  265. if (this.options.animate) {
  266. if (this.$targetMenu.is(':hidden')) {
  267. _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__["Motion"].animateIn(this.$targetMenu, this.animationIn, function () {
  268. _this2.$element.trigger('toggled.zf.responsiveToggle');
  269. _this2.$targetMenu.find('[data-mutate]').triggerHandler('mutateme.zf.trigger');
  270. });
  271. } else {
  272. _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__["Motion"].animateOut(this.$targetMenu, this.animationOut, function () {
  273. _this2.$element.trigger('toggled.zf.responsiveToggle');
  274. });
  275. }
  276. } else {
  277. this.$targetMenu.toggle(0);
  278. this.$targetMenu.find('[data-mutate]').trigger('mutateme.zf.trigger');
  279. this.$element.trigger('toggled.zf.responsiveToggle');
  280. }
  281. }
  282. }
  283. }, {
  284. key: "_destroy",
  285. value: function _destroy() {
  286. this.$element.off('.zf.responsiveToggle');
  287. this.$toggler.off('.zf.responsiveToggle');
  288. jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off('changed.zf.mediaquery', this._updateMqHandler);
  289. }
  290. }]);
  291. return ResponsiveToggle;
  292. }(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_3__["Plugin"]);
  293. ResponsiveToggle.defaults = {
  294. /**
  295. * The breakpoint after which the menu is always shown, and the tab bar is hidden.
  296. * @option
  297. * @type {string}
  298. * @default 'medium'
  299. */
  300. hideFor: 'medium',
  301. /**
  302. * To decide if the toggle should be animated or not.
  303. * @option
  304. * @type {boolean}
  305. * @default false
  306. */
  307. animate: false
  308. };
  309. /***/ }),
  310. /***/ 13:
  311. /*!*****************************************************************!*\
  312. !*** multi ./js/entries/plugins/foundation.responsiveToggle.js ***!
  313. \*****************************************************************/
  314. /*! no static exports found */
  315. /***/ (function(module, exports, __webpack_require__) {
  316. module.exports = __webpack_require__(/*! /Users/joeworkman/Development/foundation-sites/js/entries/plugins/foundation.responsiveToggle.js */"./js/entries/plugins/foundation.responsiveToggle.js");
  317. /***/ }),
  318. /***/ "jquery":
  319. /*!********************************************************************************************!*\
  320. !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***!
  321. \********************************************************************************************/
  322. /*! no static exports found */
  323. /***/ (function(module, exports) {
  324. module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__;
  325. /***/ })
  326. /******/ });
  327. });
  328. //# sourceMappingURL=foundation.responsiveToggle.js.map