UNPKG

foundation-sites

Version:

The most advanced responsive front-end framework in the world.

964 lines (906 loc) 42.3 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("./foundation.core"), require("jquery"), require("./foundation.util.mediaQuery"), require("./foundation.util.motion")); else if(typeof define === 'function' && define.amd) define(["./foundation.core", "jquery", "./foundation.util.mediaQuery", "./foundation.util.motion"], factory); else if(typeof exports === 'object') exports["__FOUNDATION_EXTERNAL__"] = factory(require("./foundation.core"), require("jquery"), require("./foundation.util.mediaQuery"), require("./foundation.util.motion")); else root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.sticky"] = factory(root["__FOUNDATION_EXTERNAL__"]["foundation.core"], root["jQuery"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.mediaQuery"], root["__FOUNDATION_EXTERNAL__"]["foundation.util.motion"]); })(self, function(__WEBPACK_EXTERNAL_MODULE__foundation_core__, __WEBPACK_EXTERNAL_MODULE_jquery__, __WEBPACK_EXTERNAL_MODULE__foundation_util_mediaQuery__, __WEBPACK_EXTERNAL_MODULE__foundation_util_motion__) { return /******/ (function() { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ "./js/foundation.sticky.js": /*!*********************************!*\ !*** ./js/foundation.sticky.js ***! \*********************************/ /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Sticky: function() { return /* binding */ Sticky; } /* harmony export */ }); /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery"); /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.core.utils */ "./foundation.core"); /* harmony import */ var _foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var _foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.util.mediaQuery */ "./foundation.util.mediaQuery"); /* harmony import */ var _foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_2__); /* harmony import */ var _foundation_util_triggers__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./foundation.util.triggers */ "./js/foundation.util.triggers.js"); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } /** * Sticky module. * @module foundation.sticky * @requires foundation.util.triggers * @requires foundation.util.mediaQuery */ var Sticky = /*#__PURE__*/function (_Plugin) { function Sticky() { _classCallCheck(this, Sticky); return _callSuper(this, Sticky, arguments); } _inherits(Sticky, _Plugin); return _createClass(Sticky, [{ key: "_setup", value: /** * Creates a new instance of a sticky thing. * @class * @name Sticky * @param {jQuery} element - jQuery object to make sticky. * @param {Object} options - options object passed when creating the element programmatically. */ function _setup(element, options) { this.$element = element; this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default().extend({}, Sticky.defaults, this.$element.data(), options); this.className = 'Sticky'; // ie9 back compat // Triggers init is idempotent, just need to make sure it is initialized _foundation_util_triggers__WEBPACK_IMPORTED_MODULE_3__.Triggers.init((jquery__WEBPACK_IMPORTED_MODULE_0___default())); this._init(); } /** * Initializes the sticky element by adding classes, getting/setting dimensions, breakpoints and attributes * @function * @private */ }, { key: "_init", value: function _init() { _foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_2__.MediaQuery._init(); var $parent = this.$element.parent('[data-sticky-container]'), id = this.$element[0].id || (0,_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__.GetYoDigits)(6, 'sticky'), _this = this; if ($parent.length) { this.$container = $parent; } else { this.wasWrapped = true; this.$element.wrap(this.options.container); this.$container = this.$element.parent(); } this.$container.addClass(this.options.containerClass); this.$element.addClass(this.options.stickyClass).attr({ 'data-resize': id, 'data-mutate': id }); if (this.options.anchor !== '') { jquery__WEBPACK_IMPORTED_MODULE_0___default()('#' + _this.options.anchor).attr({ 'data-mutate': id }); } this.scrollCount = this.options.checkEvery; this.isStuck = false; this.onLoadListener = (0,_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__.onLoad)(jquery__WEBPACK_IMPORTED_MODULE_0___default()(window), function () { //We calculate the container height to have correct values for anchor points offset calculation. _this.containerHeight = _this.$element.css("display") === "none" ? 0 : _this.$element[0].getBoundingClientRect().height; _this.$container.css('height', _this.containerHeight); _this.elemHeight = _this.containerHeight; if (_this.options.anchor !== '') { _this.$anchor = jquery__WEBPACK_IMPORTED_MODULE_0___default()('#' + _this.options.anchor); } else { _this._parsePoints(); } _this._setSizes(function () { var scroll = window.pageYOffset; _this._calc(false, scroll); //Unstick the element will ensure that proper classes are set. if (!_this.isStuck) { _this._removeSticky(scroll >= _this.topPoint ? false : true); } }); _this._events(id.split('-').reverse().join('-')); }); } /** * If using multiple elements as anchors, calculates the top and bottom pixel values the sticky thing should stick and unstick on. * @function * @private */ }, { key: "_parsePoints", value: function _parsePoints() { var top = this.options.topAnchor === "" ? 1 : this.options.topAnchor, btm = this.options.btmAnchor === "" ? document.documentElement.scrollHeight : this.options.btmAnchor, pts = [top, btm], breaks = {}; for (var i = 0, len = pts.length; i < len && pts[i]; i++) { var pt; if (typeof pts[i] === 'number') { pt = pts[i]; } else { var place = pts[i].split(':'), anchor = jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(place[0])); pt = anchor.offset().top; if (place[1] && place[1].toLowerCase() === 'bottom') { pt += anchor[0].getBoundingClientRect().height; } } breaks[i] = pt; } this.points = breaks; return; } /** * Adds event handlers for the scrolling element. * @private * @param {String} id - pseudo-random id for unique scroll event listener. */ }, { key: "_events", value: function _events(id) { var _this = this, scrollListener = this.scrollListener = "scroll.zf.".concat(id); if (this.isOn) { return; } if (this.canStick) { this.isOn = true; jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off(scrollListener).on(scrollListener, function () { if (_this.scrollCount === 0) { _this.scrollCount = _this.options.checkEvery; _this._setSizes(function () { _this._calc(false, window.pageYOffset); }); } else { _this.scrollCount--; _this._calc(false, window.pageYOffset); } }); } this.$element.off('resizeme.zf.trigger').on('resizeme.zf.trigger', function () { _this._eventsHandler(id); }); this.$element.on('mutateme.zf.trigger', function () { _this._eventsHandler(id); }); if (this.$anchor) { this.$anchor.on('mutateme.zf.trigger', function () { _this._eventsHandler(id); }); } } /** * Handler for events. * @private * @param {String} id - pseudo-random id for unique scroll event listener. */ }, { key: "_eventsHandler", value: function _eventsHandler(id) { var _this = this, scrollListener = this.scrollListener = "scroll.zf.".concat(id); _this._setSizes(function () { _this._calc(false); if (_this.canStick) { if (!_this.isOn) { _this._events(id); } } else if (_this.isOn) { _this._pauseListeners(scrollListener); } }); } /** * Removes event handlers for scroll and change events on anchor. * @fires Sticky#pause * @param {String} scrollListener - unique, namespaced scroll listener attached to `window` */ }, { key: "_pauseListeners", value: function _pauseListeners(scrollListener) { this.isOn = false; jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off(scrollListener); /** * Fires when the plugin is paused due to resize event shrinking the view. * @event Sticky#pause * @private */ this.$element.trigger('pause.zf.sticky'); } /** * Called on every `scroll` event and on `_init` * fires functions based on booleans and cached values * @param {Boolean} checkSizes - true if plugin should recalculate sizes and breakpoints. * @param {Number} scroll - current scroll position passed from scroll event cb function. If not passed, defaults to `window.pageYOffset`. */ }, { key: "_calc", value: function _calc(checkSizes, scroll) { if (checkSizes) { this._setSizes(); } if (!this.canStick) { if (this.isStuck) { this._removeSticky(true); } return false; } if (!scroll) { scroll = window.pageYOffset; } if (scroll >= this.topPoint) { if (scroll <= this.bottomPoint) { if (!this.isStuck) { this._setSticky(); } } else { if (this.isStuck) { this._removeSticky(false); } } } else { if (this.isStuck) { this._removeSticky(true); } } } /** * Causes the $element to become stuck. * Adds `position: fixed;`, and helper classes. * @fires Sticky#stuckto * @function * @private */ }, { key: "_setSticky", value: function _setSticky() { var _this = this, stickTo = this.options.stickTo, mrgn = stickTo === 'top' ? 'marginTop' : 'marginBottom', notStuckTo = stickTo === 'top' ? 'bottom' : 'top', css = {}; css[mrgn] = "".concat(this.options[mrgn], "em"); css[stickTo] = 0; css[notStuckTo] = 'auto'; this.isStuck = true; this.$element.removeClass("is-anchored is-at-".concat(notStuckTo)).addClass("is-stuck is-at-".concat(stickTo)).css(css) /** * Fires when the $element has become `position: fixed;` * Namespaced to `top` or `bottom`, e.g. `sticky.zf.stuckto:top` * @event Sticky#stuckto */.trigger("sticky.zf.stuckto:".concat(stickTo)); this.$element.on("transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd", function () { _this._setSizes(); }); } /** * Causes the $element to become unstuck. * Removes `position: fixed;`, and helper classes. * Adds other helper classes. * @param {Boolean} isTop - tells the function if the $element should anchor to the top or bottom of its $anchor element. * @fires Sticky#unstuckfrom * @private */ }, { key: "_removeSticky", value: function _removeSticky(isTop) { var stickTo = this.options.stickTo, stickToTop = stickTo === 'top', css = {}, anchorPt = (this.points ? this.points[1] - this.points[0] : this.anchorHeight) - this.elemHeight, mrgn = stickToTop ? 'marginTop' : 'marginBottom', topOrBottom = isTop ? 'top' : 'bottom'; css[mrgn] = 0; css.bottom = 'auto'; if (isTop) { css.top = 0; } else { css.top = anchorPt; } this.isStuck = false; this.$element.removeClass("is-stuck is-at-".concat(stickTo)).addClass("is-anchored is-at-".concat(topOrBottom)).css(css) /** * Fires when the $element has become anchored. * Namespaced to `top` or `bottom`, e.g. `sticky.zf.unstuckfrom:bottom` * @event Sticky#unstuckfrom */.trigger("sticky.zf.unstuckfrom:".concat(topOrBottom)); } /** * Sets the $element and $container sizes for plugin. * Calls `_setBreakPoints`. * @param {Function} cb - optional callback function to fire on completion of `_setBreakPoints`. * @private */ }, { key: "_setSizes", value: function _setSizes(cb) { this.canStick = _foundation_util_mediaQuery__WEBPACK_IMPORTED_MODULE_2__.MediaQuery.is(this.options.stickyOn); if (!this.canStick) { if (cb && typeof cb === 'function') { cb(); } } var newElemWidth = this.$container[0].getBoundingClientRect().width, comp = window.getComputedStyle(this.$container[0]), pdngl = parseInt(comp['padding-left'], 10), pdngr = parseInt(comp['padding-right'], 10); if (this.$anchor && this.$anchor.length) { this.anchorHeight = this.$anchor[0].getBoundingClientRect().height; } else { this._parsePoints(); } this.$element.css({ 'max-width': "".concat(newElemWidth - pdngl - pdngr, "px") }); // Recalculate the height only if it is "dynamic" if (this.options.dynamicHeight || !this.containerHeight) { // Get the sticked element height and apply it to the container to "hold the place" var newContainerHeight = this.$element[0].getBoundingClientRect().height || this.containerHeight; newContainerHeight = this.$element.css("display") === "none" ? 0 : newContainerHeight; this.$container.css('height', newContainerHeight); this.containerHeight = newContainerHeight; } this.elemHeight = this.containerHeight; if (!this.isStuck) { if (this.$element.hasClass('is-at-bottom')) { var anchorPt = (this.points ? this.points[1] - this.$container.offset().top : this.anchorHeight) - this.elemHeight; this.$element.css('top', anchorPt); } } this._setBreakPoints(this.containerHeight, function () { if (cb && typeof cb === 'function') { cb(); } }); } /** * Sets the upper and lower breakpoints for the element to become sticky/unsticky. * @param {Number} elemHeight - px value for sticky.$element height, calculated by `_setSizes`. * @param {Function} cb - optional callback function to be called on completion. * @private */ }, { key: "_setBreakPoints", value: function _setBreakPoints(elemHeight, cb) { if (!this.canStick) { if (cb && typeof cb === 'function') { cb(); } else { return false; } } var mTop = emCalc(this.options.marginTop), mBtm = emCalc(this.options.marginBottom), topPoint = this.points ? this.points[0] : this.$anchor.offset().top, bottomPoint = this.points ? this.points[1] : topPoint + this.anchorHeight, // topPoint = this.$anchor.offset().top || this.points[0], // bottomPoint = topPoint + this.anchorHeight || this.points[1], winHeight = window.innerHeight; if (this.options.stickTo === 'top') { topPoint -= mTop; bottomPoint -= elemHeight + mTop; } else if (this.options.stickTo === 'bottom') { topPoint -= winHeight - (elemHeight + mBtm); bottomPoint -= winHeight - mBtm; } else { //this would be the stickTo: both option... tricky } this.topPoint = topPoint; this.bottomPoint = bottomPoint; if (cb && typeof cb === 'function') { cb(); } } /** * Destroys the current sticky element. * Resets the element to the top position first. * Removes event listeners, JS-added css properties and classes, and unwraps the $element if the JS added the $container. * @function */ }, { key: "_destroy", value: function _destroy() { this._removeSticky(true); this.$element.removeClass("".concat(this.options.stickyClass, " is-anchored is-at-top")).css({ height: '', top: '', bottom: '', 'max-width': '' }).off('resizeme.zf.trigger').off('mutateme.zf.trigger'); if (this.$anchor && this.$anchor.length) { this.$anchor.off('change.zf.sticky'); } if (this.scrollListener) jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off(this.scrollListener); if (this.onLoadListener) jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off(this.onLoadListener); if (this.wasWrapped) { this.$element.unwrap(); } else { this.$container.removeClass(this.options.containerClass).css({ height: '' }); } } }]); }(_foundation_core_plugin__WEBPACK_IMPORTED_MODULE_1__.Plugin); Sticky.defaults = { /** * Customizable container template. Add your own classes for styling and sizing. * @option * @type {string} * @default '&lt;div data-sticky-container&gt;&lt;/div&gt;' */ container: '<div data-sticky-container></div>', /** * Location in the view the element sticks to. Can be `'top'` or `'bottom'`. * @option * @type {string} * @default 'top' */ stickTo: 'top', /** * If anchored to a single element, the id of that element. * @option * @type {string} * @default '' */ anchor: '', /** * If using more than one element as anchor points, the id of the top anchor. * @option * @type {string} * @default '' */ topAnchor: '', /** * If using more than one element as anchor points, the id of the bottom anchor. * @option * @type {string} * @default '' */ btmAnchor: '', /** * Margin, in `em`'s to apply to the top of the element when it becomes sticky. * @option * @type {number} * @default 1 */ marginTop: 1, /** * Margin, in `em`'s to apply to the bottom of the element when it becomes sticky. * @option * @type {number} * @default 1 */ marginBottom: 1, /** * Breakpoint string that is the minimum screen size an element should become sticky. * @option * @type {string} * @default 'medium' */ stickyOn: 'medium', /** * Class applied to sticky element, and removed on destruction. Foundation defaults to `sticky`. * @option * @type {string} * @default 'sticky' */ stickyClass: 'sticky', /** * Class applied to sticky container. Foundation defaults to `sticky-container`. * @option * @type {string} * @default 'sticky-container' */ containerClass: 'sticky-container', /** * If true (by default), keep the sticky container the same height as the element. Otherwise, the container height is set once and does not change. * @option * @type {boolean} * @default true */ dynamicHeight: true, /** * Number of scroll events between the plugin's recalculating sticky points. Setting it to `0` will cause it to recalc every scroll event, setting it to `-1` will prevent recalc on scroll. * @option * @type {number} * @default -1 */ checkEvery: -1 }; /** * Helper function to calculate em values * @param Number {em} - number of em's to calculate into pixels */ function emCalc(em) { return parseInt(window.getComputedStyle(document.body, null).fontSize, 10) * em; } /***/ }), /***/ "./js/foundation.util.triggers.js": /*!****************************************!*\ !*** ./js/foundation.util.triggers.js ***! \****************************************/ /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Triggers: function() { return /* binding */ Triggers; } /* harmony export */ }); /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery"); /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.core.utils */ "./foundation.core"); /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./foundation.util.motion */ "./foundation.util.motion"); /* harmony import */ var _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } var MutationObserver = function () { var prefixes = ['WebKit', 'Moz', 'O', 'Ms', '']; for (var i = 0; i < prefixes.length; i++) { if ("".concat(prefixes[i], "MutationObserver") in window) { return window["".concat(prefixes[i], "MutationObserver")]; } } return false; }(); var triggers = function triggers(el, type) { el.data(type).split(' ').forEach(function (id) { jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(id))[type === 'close' ? 'trigger' : 'triggerHandler']("".concat(type, ".zf.trigger"), [el]); }); }; var Triggers = { Listeners: { Basic: {}, Global: {} }, Initializers: {} }; Triggers.Listeners.Basic = { openListener: function openListener() { triggers(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), 'open'); }, closeListener: function closeListener() { var id = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('close'); if (id) { triggers(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), 'close'); } else { jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('close.zf.trigger'); } }, toggleListener: function toggleListener() { var id = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('toggle'); if (id) { triggers(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), 'toggle'); } else { jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('toggle.zf.trigger'); } }, closeableListener: function closeableListener(e) { var animation = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('closable'); // Only close the first closable element. See https://git.io/zf-7833 e.stopPropagation(); if (animation !== '') { _foundation_util_motion__WEBPACK_IMPORTED_MODULE_2__.Motion.animateOut(jquery__WEBPACK_IMPORTED_MODULE_0___default()(this), animation, function () { jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).trigger('closed.zf'); }); } else { jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).fadeOut().trigger('closed.zf'); } }, toggleFocusListener: function toggleFocusListener() { var id = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).data('toggle-focus'); jquery__WEBPACK_IMPORTED_MODULE_0___default()("#".concat(id)).triggerHandler('toggle.zf.trigger', [jquery__WEBPACK_IMPORTED_MODULE_0___default()(this)]); } }; // Elements with [data-open] will reveal a plugin that supports it when clicked. Triggers.Initializers.addOpenListener = function ($elem) { $elem.off('click.zf.trigger', Triggers.Listeners.Basic.openListener); $elem.on('click.zf.trigger', '[data-open]', Triggers.Listeners.Basic.openListener); }; // Elements with [data-close] will close a plugin that supports it when clicked. // If used without a value on [data-close], the event will bubble, allowing it to close a parent component. Triggers.Initializers.addCloseListener = function ($elem) { $elem.off('click.zf.trigger', Triggers.Listeners.Basic.closeListener); $elem.on('click.zf.trigger', '[data-close]', Triggers.Listeners.Basic.closeListener); }; // Elements with [data-toggle] will toggle a plugin that supports it when clicked. Triggers.Initializers.addToggleListener = function ($elem) { $elem.off('click.zf.trigger', Triggers.Listeners.Basic.toggleListener); $elem.on('click.zf.trigger', '[data-toggle]', Triggers.Listeners.Basic.toggleListener); }; // Elements with [data-closable] will respond to close.zf.trigger events. Triggers.Initializers.addCloseableListener = function ($elem) { $elem.off('close.zf.trigger', Triggers.Listeners.Basic.closeableListener); $elem.on('close.zf.trigger', '[data-closeable], [data-closable]', Triggers.Listeners.Basic.closeableListener); }; // Elements with [data-toggle-focus] will respond to coming in and out of focus Triggers.Initializers.addToggleFocusListener = function ($elem) { $elem.off('focus.zf.trigger blur.zf.trigger', Triggers.Listeners.Basic.toggleFocusListener); $elem.on('focus.zf.trigger blur.zf.trigger', '[data-toggle-focus]', Triggers.Listeners.Basic.toggleFocusListener); }; // More Global/complex listeners and triggers Triggers.Listeners.Global = { resizeListener: function resizeListener($nodes) { if (!MutationObserver) { //fallback for IE 9 $nodes.each(function () { jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).triggerHandler('resizeme.zf.trigger'); }); } //trigger all listening elements and signal a resize event $nodes.attr('data-events', "resize"); }, scrollListener: function scrollListener($nodes) { if (!MutationObserver) { //fallback for IE 9 $nodes.each(function () { jquery__WEBPACK_IMPORTED_MODULE_0___default()(this).triggerHandler('scrollme.zf.trigger'); }); } //trigger all listening elements and signal a scroll event $nodes.attr('data-events', "scroll"); }, closeMeListener: function closeMeListener(e, pluginId) { var plugin = e.namespace.split('.')[0]; var plugins = jquery__WEBPACK_IMPORTED_MODULE_0___default()("[data-".concat(plugin, "]")).not("[data-yeti-box=\"".concat(pluginId, "\"]")); plugins.each(function () { var _this = jquery__WEBPACK_IMPORTED_MODULE_0___default()(this); _this.triggerHandler('close.zf.trigger', [_this]); }); } }; // Global, parses whole document. Triggers.Initializers.addClosemeListener = function (pluginName) { var yetiBoxes = jquery__WEBPACK_IMPORTED_MODULE_0___default()('[data-yeti-box]'), plugNames = ['dropdown', 'tooltip', 'reveal']; if (pluginName) { if (typeof pluginName === 'string') { plugNames.push(pluginName); } else if (_typeof(pluginName) === 'object' && typeof pluginName[0] === 'string') { plugNames = plugNames.concat(pluginName); } else { console.error('Plugin names must be strings'); } } if (yetiBoxes.length) { var listeners = plugNames.map(function (name) { return "closeme.zf.".concat(name); }).join(' '); jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).off(listeners).on(listeners, Triggers.Listeners.Global.closeMeListener); } }; function debounceGlobalListener(debounce, trigger, listener) { var timer, args = Array.prototype.slice.call(arguments, 3); jquery__WEBPACK_IMPORTED_MODULE_0___default()(window).on(trigger, function () { if (timer) { clearTimeout(timer); } timer = setTimeout(function () { listener.apply(null, args); }, debounce || 10); //default time to emit scroll event }); } Triggers.Initializers.addResizeListener = function (debounce) { var $nodes = jquery__WEBPACK_IMPORTED_MODULE_0___default()('[data-resize]'); if ($nodes.length) { debounceGlobalListener(debounce, 'resize.zf.trigger', Triggers.Listeners.Global.resizeListener, $nodes); } }; Triggers.Initializers.addScrollListener = function (debounce) { var $nodes = jquery__WEBPACK_IMPORTED_MODULE_0___default()('[data-scroll]'); if ($nodes.length) { debounceGlobalListener(debounce, 'scroll.zf.trigger', Triggers.Listeners.Global.scrollListener, $nodes); } }; Triggers.Initializers.addMutationEventsListener = function ($elem) { if (!MutationObserver) { return false; } var $nodes = $elem.find('[data-resize], [data-scroll], [data-mutate]'); //element callback var listeningElementsMutation = function listeningElementsMutation(mutationRecordsList) { var $target = jquery__WEBPACK_IMPORTED_MODULE_0___default()(mutationRecordsList[0].target); //trigger the event handler for the element depending on type switch (mutationRecordsList[0].type) { case "attributes": if ($target.attr("data-events") === "scroll" && mutationRecordsList[0].attributeName === "data-events") { $target.triggerHandler('scrollme.zf.trigger', [$target, window.pageYOffset]); } if ($target.attr("data-events") === "resize" && mutationRecordsList[0].attributeName === "data-events") { $target.triggerHandler('resizeme.zf.trigger', [$target]); } if (mutationRecordsList[0].attributeName === "style") { $target.closest("[data-mutate]").attr("data-events", "mutate"); $target.closest("[data-mutate]").triggerHandler('mutateme.zf.trigger', [$target.closest("[data-mutate]")]); } break; case "childList": $target.closest("[data-mutate]").attr("data-events", "mutate"); $target.closest("[data-mutate]").triggerHandler('mutateme.zf.trigger', [$target.closest("[data-mutate]")]); break; default: return false; //nothing } }; if ($nodes.length) { //for each element that needs to listen for resizing, scrolling, or mutation add a single observer for (var i = 0; i <= $nodes.length - 1; i++) { var elementObserver = new MutationObserver(listeningElementsMutation); elementObserver.observe($nodes[i], { attributes: true, childList: true, characterData: false, subtree: true, attributeFilter: ["data-events", "style"] }); } } }; Triggers.Initializers.addSimpleListeners = function () { var $document = jquery__WEBPACK_IMPORTED_MODULE_0___default()(document); Triggers.Initializers.addOpenListener($document); Triggers.Initializers.addCloseListener($document); Triggers.Initializers.addToggleListener($document); Triggers.Initializers.addCloseableListener($document); Triggers.Initializers.addToggleFocusListener($document); }; Triggers.Initializers.addGlobalListeners = function () { var $document = jquery__WEBPACK_IMPORTED_MODULE_0___default()(document); Triggers.Initializers.addMutationEventsListener($document); Triggers.Initializers.addResizeListener(250); Triggers.Initializers.addScrollListener(); Triggers.Initializers.addClosemeListener(); }; Triggers.init = function (__, Foundation) { (0,_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__.onLoad)(jquery__WEBPACK_IMPORTED_MODULE_0___default()(window), function () { if ((jquery__WEBPACK_IMPORTED_MODULE_0___default().triggersInitialized) !== true) { Triggers.Initializers.addSimpleListeners(); Triggers.Initializers.addGlobalListeners(); (jquery__WEBPACK_IMPORTED_MODULE_0___default().triggersInitialized) = true; } }); if (Foundation) { Foundation.Triggers = Triggers; // Legacy included to be backwards compatible for now. Foundation.IHearYou = Triggers.Initializers.addGlobalListeners; } }; /***/ }), /***/ "./foundation.core": /*!****************************************************************************************************************************************************************!*\ !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.core"],"amd":"./foundation.core","commonjs":"./foundation.core","commonjs2":"./foundation.core"} ***! \****************************************************************************************************************************************************************/ /***/ (function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_core__; /***/ }), /***/ "./foundation.util.mediaQuery": /*!************************************************************************************************************************************************************************************************************!*\ !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.util.mediaQuery"],"amd":"./foundation.util.mediaQuery","commonjs":"./foundation.util.mediaQuery","commonjs2":"./foundation.util.mediaQuery"} ***! \************************************************************************************************************************************************************************************************************/ /***/ (function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_util_mediaQuery__; /***/ }), /***/ "./foundation.util.motion": /*!********************************************************************************************************************************************************************************************!*\ !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.util.motion"],"amd":"./foundation.util.motion","commonjs":"./foundation.util.motion","commonjs2":"./foundation.util.motion"} ***! \********************************************************************************************************************************************************************************************/ /***/ (function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_util_motion__; /***/ }), /***/ "jquery": /*!********************************************************************************************!*\ !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***! \********************************************************************************************/ /***/ (function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__; /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/compat get default export */ /******/ !function() { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function() { return module['default']; } : /******/ function() { return module; }; /******/ __webpack_require__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/define property getters */ /******/ !function() { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = function(exports, definition) { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ !function() { /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } /******/ }(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ !function() { /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ }(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. !function() { /*!*************************************************!*\ !*** ./js/entries/plugins/foundation.sticky.js ***! \*************************************************/ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Foundation: function() { return /* reexport safe */ _foundation_core__WEBPACK_IMPORTED_MODULE_0__.Foundation; }, /* harmony export */ Sticky: function() { return /* reexport safe */ _foundation_sticky__WEBPACK_IMPORTED_MODULE_1__.Sticky; } /* harmony export */ }); /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core"); /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _foundation_sticky__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.sticky */ "./js/foundation.sticky.js"); _foundation_core__WEBPACK_IMPORTED_MODULE_0__.Foundation.plugin(_foundation_sticky__WEBPACK_IMPORTED_MODULE_1__.Sticky, 'Sticky'); }(); /******/ return __webpack_exports__; /******/ })() ; }); //# sourceMappingURL=foundation.sticky.js.map