import $ from 'jquery';
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
function _assertThisInitialized(e) {
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
return e;
}
function _callSuper(t, o, e) {
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
}
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 _get() {
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
var p = _superPropBase(e, t);
if (p) {
var n = Object.getOwnPropertyDescriptor(p, t);
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
}
}, _get.apply(null, arguments);
}
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 _isNativeReflectConstruct() {
try {
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
} catch (t) {}
return (_isNativeReflectConstruct = function () {
return !!t;
})();
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = !1;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
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 _setPrototypeOf(t, e) {
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
return t.__proto__ = e, t;
}, _setPrototypeOf(t, e);
}
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _superPropBase(t, o) {
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
return t;
}
function _superPropGet(t, e, o, r) {
var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), e, o);
return 2 & r && "function" == typeof p ? function (t) {
return p.apply(o, t);
} : p;
}
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 _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : i + "";
}
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 _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
// Core Foundation Utilities, utilized in a number of places.
/**
* Returns a boolean for RTL support
*/
function rtl() {
return $('html').attr('dir') === 'rtl';
}
/**
* returns a random base-36 uid with namespacing
* @function
* @param {Number} length - number of random base-36 digits desired. Increase for more random strings.
* @param {String} namespace - name of plugin to be incorporated in uid, optional.
* @default {String} '' - if no plugin name is provided, nothing is appended to the uid.
* @returns {String} - unique id
*/
function GetYoDigits() {
var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 6;
var namespace = arguments.length > 1 ? arguments[1] : undefined;
var str = '';
var chars = '0123456789abcdefghijklmnopqrstuvwxyz';
var charsLength = chars.length;
for (var i = 0; i < length; i++) {
str += chars[Math.floor(Math.random() * charsLength)];
}
return namespace ? "".concat(str, "-").concat(namespace) : str;
}
/**
* Escape a string so it can be used as a regexp pattern
* @function
* @see https://stackoverflow.com/a/9310752/4317384
*
* @param {String} str - string to escape.
* @returns {String} - escaped string
*/
function RegExpEscape(str) {
return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}
function transitionend($elem) {
var transitions = {
'transition': 'transitionend',
'WebkitTransition': 'webkitTransitionEnd',
'MozTransition': 'transitionend',
'OTransition': 'otransitionend'
};
var elem = document.createElement('div'),
end;
for (var transition in transitions) {
if (typeof elem.style[transition] !== 'undefined') {
end = transitions[transition];
}
}
if (end) {
return end;
} else {
setTimeout(function () {
$elem.triggerHandler('transitionend', [$elem]);
}, 1);
return 'transitionend';
}
}
/**
* Return an event type to listen for window load.
*
* If `$elem` is passed, an event will be triggered on `$elem`. If window is already loaded, the event will still be triggered.
* If `handler` is passed, attach it to the event on `$elem`.
* Calling `onLoad` without handler allows you to get the event type that will be triggered before attaching the handler by yourself.
* @function
*
* @param {Object} [] $elem - jQuery element on which the event will be triggered if passed.
* @param {Function} [] handler - function to attach to the event.
* @returns {String} - event type that should or will be triggered.
*/
function onLoad($elem, handler) {
var didLoad = document.readyState === 'complete';
var eventType = (didLoad ? '_didLoad' : 'load') + '.zf.util.onLoad';
var cb = function cb() {
return $elem.triggerHandler(eventType);
};
if ($elem) {
if (handler) $elem.one(eventType, handler);
if (didLoad) setTimeout(cb);else $(window).one('load', cb);
}
return eventType;
}
/**
* Retuns an handler for the `mouseleave` that ignore disappeared mouses.
*
* If the mouse "disappeared" from the document (like when going on a browser UI element, See https://git.io/zf-11410),
* the event is ignored.
* - If the `ignoreLeaveWindow` is `true`, the event is ignored when the user actually left the window
* (like by switching to an other window with [Alt]+[Tab]).
* - If the `ignoreReappear` is `true`, the event will be ignored when the mouse will reappear later on the document
* outside of the element it left.
*
* @function
*
* @param {Function} [] handler - handler for the filtered `mouseleave` event to watch.
* @param {Object} [] options - object of options:
* - {Boolean} [false] ignoreLeaveWindow - also ignore when the user switched windows.
* - {Boolean} [false] ignoreReappear - also ignore when the mouse reappeared outside of the element it left.
* @returns {Function} - filtered handler to use to listen on the `mouseleave` event.
*/
function ignoreMousedisappear(handler) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$ignoreLeaveWindo = _ref.ignoreLeaveWindow,
ignoreLeaveWindow = _ref$ignoreLeaveWindo === void 0 ? false : _ref$ignoreLeaveWindo,
_ref$ignoreReappear = _ref.ignoreReappear,
ignoreReappear = _ref$ignoreReappear === void 0 ? false : _ref$ignoreReappear;
return function leaveEventHandler(eLeave) {
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
rest[_key - 1] = arguments[_key];
}
var callback = handler.bind.apply(handler, [this, eLeave].concat(rest));
// The mouse left: call the given callback if the mouse entered elsewhere
if (eLeave.relatedTarget !== null) {
return callback();
}
// Otherwise, check if the mouse actually left the window.
// In firefox if the user switched between windows, the window sill have the focus by the time
// the event is triggered. We have to debounce the event to test this case.
setTimeout(function leaveEventDebouncer() {
if (!ignoreLeaveWindow && document.hasFocus && !document.hasFocus()) {
return callback();
}
// Otherwise, wait for the mouse to reeapear outside of the element,
if (!ignoreReappear) {
$(document).one('mouseenter', function reenterEventHandler(eReenter) {
if (!$(eLeave.currentTarget).has(eReenter.target).length) {
// Fill where the mouse finally entered.
eLeave.relatedTarget = eReenter.target;
callback();
}
});
}
}, 0);
};
}
var foundation_core_utils = /*#__PURE__*/Object.freeze({
__proto__: null,
rtl: rtl,
GetYoDigits: GetYoDigits,
RegExpEscape: RegExpEscape,
transitionend: transitionend,
onLoad: onLoad,
ignoreMousedisappear: ignoreMousedisappear
});
// Default set of media queries
// const defaultQueries = {
// 'default' : 'only screen',
// landscape : 'only screen and (orientation: landscape)',
// portrait : 'only screen and (orientation: portrait)',
// 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)'
// };
// matchMedia() polyfill - Test a CSS media type/query in JS.
// Authors & copyright © 2012: Scott Jehl, Paul Irish, Nicholas Zakas, David Knight. MIT license
/* eslint-disable */
window.matchMedia || (window.matchMedia = function () {
// For browsers that support matchMedium api such as IE 9 and webkit
var styleMedia = window.styleMedia || window.media;
// For those that don't support matchMedium
if (!styleMedia) {
var style = document.createElement('style'),
script = document.getElementsByTagName('script')[0],
info = null;
style.type = 'text/css';
style.id = 'matchmediajs-test';
if (!script) {
document.head.appendChild(style);
} else {
script.parentNode.insertBefore(style, script);
}
// 'style.currentStyle' is used by IE <= 8 and 'window.getComputedStyle' for all other browsers
info = 'getComputedStyle' in window && window.getComputedStyle(style, null) || style.currentStyle;
styleMedia = {
matchMedium: function matchMedium(media) {
var text = '@media ' + media + '{ #matchmediajs-test { width: 1px; } }';
// 'style.styleSheet' is used by IE <= 8 and 'style.textContent' for all other browsers
if (style.styleSheet) {
style.styleSheet.cssText = text;
} else {
style.textContent = text;
}
// Test if media query is true or false
return info.width === '1px';
}
};
}
return function (media) {
return {
matches: styleMedia.matchMedium(media || 'all'),
media: media || 'all'
};
};
}());
/* eslint-enable */
var MediaQuery = {
queries: [],
current: '',
/**
* Initializes the media query helper, by extracting the breakpoint list from the CSS and activating the breakpoint watcher.
* @function
* @private
*/
_init: function _init() {
// make sure the initialization is only done once when calling _init() several times
if (this.isInitialized === true) {
return this;
} else {
this.isInitialized = true;
}
var self = this;
var $meta = $('meta.foundation-mq');
if (!$meta.length) {
$('').appendTo(document.head);
}
var extractedStyles = $('.foundation-mq').css('font-family');
var namedQueries;
namedQueries = parseStyleToObject(extractedStyles);
self.queries = []; // reset
for (var key in namedQueries) {
if (namedQueries.hasOwnProperty(key)) {
self.queries.push({
name: key,
value: "only screen and (min-width: ".concat(namedQueries[key], ")")
});
}
}
this.current = this._getCurrentSize();
this._watcher();
},
/**
* Reinitializes the media query helper.
* Useful if your CSS breakpoint configuration has just been loaded or has changed since the initialization.
* @function
* @private
*/
_reInit: function _reInit() {
this.isInitialized = false;
this._init();
},
/**
* Checks if the screen is at least as wide as a breakpoint.
* @function
* @param {String} size - Name of the breakpoint to check.
* @returns {Boolean} `true` if the breakpoint matches, `false` if it's smaller.
*/
atLeast: function atLeast(size) {
var query = this.get(size);
if (query) {
return window.matchMedia(query).matches;
}
return false;
},
/**
* Checks if the screen is within the given breakpoint.
* If smaller than the breakpoint of larger than its upper limit it returns false.
* @function
* @param {String} size - Name of the breakpoint to check.
* @returns {Boolean} `true` if the breakpoint matches, `false` otherwise.
*/
only: function only(size) {
return size === this._getCurrentSize();
},
/**
* Checks if the screen is within a breakpoint or smaller.
* @function
* @param {String} size - Name of the breakpoint to check.
* @returns {Boolean} `true` if the breakpoint matches, `false` if it's larger.
*/
upTo: function upTo(size) {
var nextSize = this.next(size);
// If the next breakpoint does not match, the screen is smaller than
// the upper limit of this breakpoint.
if (nextSize) {
return !this.atLeast(nextSize);
}
// If there is no next breakpoint, the "size" breakpoint does not have
// an upper limit and the screen will always be within it or smaller.
return true;
},
/**
* Checks if the screen matches to a breakpoint.
* @function
* @param {String} size - Name of the breakpoint to check, either 'small only' or 'small'. Omitting 'only' falls back to using atLeast() method.
* @returns {Boolean} `true` if the breakpoint matches, `false` if it does not.
*/
is: function is(size) {
var parts = size.trim().split(' ').filter(function (p) {
return !!p.length;
});
var _parts = _slicedToArray(parts, 2),
bpSize = _parts[0],
_parts$ = _parts[1],
bpModifier = _parts$ === void 0 ? '' : _parts$;
// Only the breakpont
if (bpModifier === 'only') {
return this.only(bpSize);
}
// At least the breakpoint (included)
if (!bpModifier || bpModifier === 'up') {
return this.atLeast(bpSize);
}
// Up to the breakpoint (included)
if (bpModifier === 'down') {
return this.upTo(bpSize);
}
throw new Error("\n Invalid breakpoint passed to MediaQuery.is().\n Expected a breakpoint name formatted like \" \", got \"".concat(size, "\".\n "));
},
/**
* Gets the media query of a breakpoint.
* @function
* @param {String} size - Name of the breakpoint to get.
* @returns {String|null} - The media query of the breakpoint, or `null` if the breakpoint doesn't exist.
*/
get: function get(size) {
for (var i in this.queries) {
if (this.queries.hasOwnProperty(i)) {
var query = this.queries[i];
if (size === query.name) return query.value;
}
}
return null;
},
/**
* Get the breakpoint following the given breakpoint.
* @function
* @param {String} size - Name of the breakpoint.
* @returns {String|null} - The name of the following breakpoint, or `null` if the passed breakpoint was the last one.
*/
next: function next(size) {
var _this = this;
var queryIndex = this.queries.findIndex(function (q) {
return _this._getQueryName(q) === size;
});
if (queryIndex === -1) {
throw new Error("\n Unknown breakpoint \"".concat(size, "\" passed to MediaQuery.next().\n Ensure it is present in your Sass \"$breakpoints\" setting.\n "));
}
var nextQuery = this.queries[queryIndex + 1];
return nextQuery ? nextQuery.name : null;
},
/**
* Returns the name of the breakpoint related to the given value.
* @function
* @private
* @param {String|Object} value - Breakpoint name or query object.
* @returns {String} Name of the breakpoint.
*/
_getQueryName: function _getQueryName(value) {
if (typeof value === 'string') return value;
if (_typeof(value) === 'object') return value.name;
throw new TypeError("\n Invalid value passed to MediaQuery._getQueryName().\n Expected a breakpoint name (String) or a breakpoint query (Object), got \"".concat(value, "\" (").concat(_typeof(value), ")\n "));
},
/**
* Gets the current breakpoint name by testing every breakpoint and returning the last one to match (the biggest one).
* @function
* @private
* @returns {String} Name of the current breakpoint.
*/
_getCurrentSize: function _getCurrentSize() {
var matched;
for (var i = 0; i < this.queries.length; i++) {
var query = this.queries[i];
if (window.matchMedia(query.value).matches) {
matched = query;
}
}
return matched && this._getQueryName(matched);
},
/**
* Activates the breakpoint watcher, which fires an event on the window whenever the breakpoint changes.
* @function
* @private
*/
_watcher: function _watcher() {
var _this2 = this;
$(window).on('resize.zf.trigger', function () {
var newSize = _this2._getCurrentSize(),
currentSize = _this2.current;
if (newSize !== currentSize) {
// Change the current media query
_this2.current = newSize;
// Broadcast the media query change on the window
$(window).trigger('changed.zf.mediaquery', [newSize, currentSize]);
}
});
}
};
// Thank you: https://github.com/sindresorhus/query-string
function parseStyleToObject(str) {
var styleObject = {};
if (typeof str !== 'string') {
return styleObject;
}
str = str.trim().slice(1, -1); // browsers re-quote string style values
if (!str) {
return styleObject;
}
styleObject = str.split('&').reduce(function (ret, param) {
var parts = param.replace(/\+/g, ' ').split('=');
var key = parts[0];
var val = parts[1];
key = decodeURIComponent(key);
// missing `=` should be `null`:
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
val = typeof val === 'undefined' ? null : decodeURIComponent(val);
if (!ret.hasOwnProperty(key)) {
ret[key] = val;
} else if (Array.isArray(ret[key])) {
ret[key].push(val);
} else {
ret[key] = [ret[key], val];
}
return ret;
}, {});
return styleObject;
}
var FOUNDATION_VERSION = '6.9.0';
// Global Foundation object
// This is attached to the window, or used as a module for AMD/Browserify
var Foundation = {
version: FOUNDATION_VERSION,
/**
* Stores initialized plugins.
*/
_plugins: {},
/**
* Stores generated unique ids for plugin instances
*/
_uuids: [],
/**
* Defines a Foundation plugin, adding it to the `Foundation` namespace and the list of plugins to initialize when reflowing.
* @param {Object} plugin - The constructor of the plugin.
*/
plugin: function plugin(_plugin, name) {
// Object key to use when adding to global Foundation object
// Examples: Foundation.Reveal, Foundation.OffCanvas
var className = name || functionName(_plugin);
// Object key to use when storing the plugin, also used to create the identifying data attribute for the plugin
// Examples: data-reveal, data-off-canvas
var attrName = hyphenate$1(className);
// Add to the Foundation object and the plugins list (for reflowing)
this._plugins[attrName] = this[className] = _plugin;
},
/**
* @function
* Populates the _uuids array with pointers to each individual plugin instance.
* Adds the `zfPlugin` data-attribute to programmatically created plugins to allow use of $(selector).foundation(method) calls.
* Also fires the initialization event for each plugin, consolidating repetitive code.
* @param {Object} plugin - an instance of a plugin, usually `this` in context.
* @param {String} name - the name of the plugin, passed as a camelCased string.
* @fires Plugin#init
*/
registerPlugin: function registerPlugin(plugin, name) {
var pluginName = name ? hyphenate$1(name) : functionName(plugin.constructor).toLowerCase();
plugin.uuid = GetYoDigits(6, pluginName);
if (!plugin.$element.attr("data-".concat(pluginName))) {
plugin.$element.attr("data-".concat(pluginName), plugin.uuid);
}
if (!plugin.$element.data('zfPlugin')) {
plugin.$element.data('zfPlugin', plugin);
}
/**
* Fires when the plugin has initialized.
* @event Plugin#init
*/
plugin.$element.trigger("init.zf.".concat(pluginName));
this._uuids.push(plugin.uuid);
return;
},
/**
* @function
* Removes the plugins uuid from the _uuids array.
* Removes the zfPlugin data attribute, as well as the data-plugin-name attribute.
* Also fires the destroyed event for the plugin, consolidating repetitive code.
* @param {Object} plugin - an instance of a plugin, usually `this` in context.
* @fires Plugin#destroyed
*/
unregisterPlugin: function unregisterPlugin(plugin) {
var pluginName = hyphenate$1(functionName(plugin.$element.data('zfPlugin').constructor));
this._uuids.splice(this._uuids.indexOf(plugin.uuid), 1);
plugin.$element.removeAttr("data-".concat(pluginName)).removeData('zfPlugin')
/**
* Fires when the plugin has been destroyed.
* @event Plugin#destroyed
*/.trigger("destroyed.zf.".concat(pluginName));
for (var prop in plugin) {
if (typeof plugin[prop] === 'function') {
plugin[prop] = null; //clean up script to prep for garbage collection.
}
}
return;
},
/**
* @function
* Causes one or more active plugins to re-initialize, resetting event listeners, recalculating positions, etc.
* @param {String} plugins - optional string of an individual plugin key, attained by calling `$(element).data('pluginName')`, or string of a plugin class i.e. `'dropdown'`
* @default If no argument is passed, reflow all currently active plugins.
*/
reInit: function reInit(plugins) {
var isJQ = plugins instanceof $;
try {
if (isJQ) {
plugins.each(function () {
$(this).data('zfPlugin')._init();
});
} else {
var type = _typeof(plugins),
_this = this,
fns = {
'object': function object(plgs) {
plgs.forEach(function (p) {
p = hyphenate$1(p);
$('[data-' + p + ']').foundation('_init');
});
},
'string': function string() {
plugins = hyphenate$1(plugins);
$('[data-' + plugins + ']').foundation('_init');
},
'undefined': function undefined$1() {
this.object(Object.keys(_this._plugins));
}
};
fns[type](plugins);
}
} catch (err) {
console.error(err);
} finally {
return plugins;
}
},
/**
* Initialize plugins on any elements within `elem` (and `elem` itself) that aren't already initialized.
* @param {Object} elem - jQuery object containing the element to check inside. Also checks the element itself, unless it's the `document` object.
* @param {String|Array} plugins - A list of plugins to initialize. Leave this out to initialize everything.
*/
reflow: function reflow(elem, plugins) {
// If plugins is undefined, just grab everything
if (typeof plugins === 'undefined') {
plugins = Object.keys(this._plugins);
}
// If plugins is a string, convert it to an array with one item
else if (typeof plugins === 'string') {
plugins = [plugins];
}
var _this = this;
// Iterate through each plugin
$.each(plugins, function (i, name) {
// Get the current plugin
var plugin = _this._plugins[name];
// Localize the search to all elements inside elem, as well as elem itself, unless elem === document
var $elem = $(elem).find('[data-' + name + ']').addBack('[data-' + name + ']').filter(function () {
return typeof $(this).data("zfPlugin") === 'undefined';
});
// For each plugin found, initialize it
$elem.each(function () {
var $el = $(this),
opts = {
reflow: true
};
if ($el.attr('data-options')) {
$el.attr('data-options').split(';').forEach(function (option) {
var opt = option.split(':').map(function (el) {
return el.trim();
});
if (opt[0]) opts[opt[0]] = parseValue(opt[1]);
});
}
try {
$el.data('zfPlugin', new plugin($(this), opts));
} catch (er) {
console.error(er);
} finally {
return;
}
});
});
},
getFnName: functionName,
addToJquery: function addToJquery() {
// TODO: consider not making this a jQuery function
// TODO: need way to reflow vs. re-initialize
/**
* The Foundation jQuery method.
* @param {String|Array} method - An action to perform on the current jQuery object.
*/
var foundation = function foundation(method) {
var type = _typeof(method),
$noJS = $('.no-js');
if ($noJS.length) {
$noJS.removeClass('no-js');
}
if (type === 'undefined') {
//needs to initialize the Foundation object, or an individual plugin.
MediaQuery._init();
Foundation.reflow(this);
} else if (type === 'string') {
//an individual method to invoke on a plugin or group of plugins
var args = Array.prototype.slice.call(arguments, 1); //collect all the arguments, if necessary
var plugClass = this.data('zfPlugin'); //determine the class of plugin
if (typeof plugClass !== 'undefined' && typeof plugClass[method] !== 'undefined') {
//make sure both the class and method exist
if (this.length === 1) {
//if there's only one, call it directly.
plugClass[method].apply(plugClass, args);
} else {
this.each(function (i, el) {
//otherwise loop through the jQuery collection and invoke the method on each
plugClass[method].apply($(el).data('zfPlugin'), args);
});
}
} else {
//error for no class or no method
throw new ReferenceError("We're sorry, '" + method + "' is not an available method for " + (plugClass ? functionName(plugClass) : 'this element') + '.');
}
} else {
//error for invalid argument type
throw new TypeError("We're sorry, ".concat(type, " is not a valid parameter. You must use a string representing the method you wish to invoke."));
}
return this;
};
$.fn.foundation = foundation;
return $;
}
};
Foundation.util = {
/**
* Function for applying a debounce effect to a function call.
* @function
* @param {Function} func - Function to be called at end of timeout.
* @param {Number} delay - Time in ms to delay the call of `func`.
* @returns function
*/
throttle: function throttle(func, delay) {
var timer = null;
return function () {
var context = this,
args = arguments;
if (timer === null) {
timer = setTimeout(function () {
func.apply(context, args);
timer = null;
}, delay);
}
};
}
};
window.Foundation = Foundation;
// Polyfill for requestAnimationFrame
(function () {
if (!Date.now || !window.Date.now) window.Date.now = Date.now = function () {
return new Date().getTime();
};
var vendors = ['webkit', 'moz'];
for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
var vp = vendors[i];
window.requestAnimationFrame = window[vp + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vp + 'CancelAnimationFrame'] || window[vp + 'CancelRequestAnimationFrame'];
}
if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) || !window.requestAnimationFrame || !window.cancelAnimationFrame) {
var lastTime = 0;
window.requestAnimationFrame = function (callback) {
var now = Date.now();
var nextTime = Math.max(lastTime + 16, now);
return setTimeout(function () {
callback(lastTime = nextTime);
}, nextTime - now);
};
window.cancelAnimationFrame = clearTimeout;
}
/**
* Polyfill for performance.now, required by rAF
*/
if (!window.performance || !window.performance.now) {
window.performance = {
start: Date.now(),
now: function now() {
return Date.now() - this.start;
}
};
}
})();
if (!Function.prototype.bind) {
/* eslint-disable no-extend-native */
Function.prototype.bind = function (oThis) {
if (typeof this !== 'function') {
// closest thing possible to the ECMAScript 5
// internal IsCallable function
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function fNOP() {},
fBound = function fBound() {
return fToBind.apply(this instanceof fNOP ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)));
};
if (this.prototype) {
// native functions don't have a prototype
fNOP.prototype = this.prototype;
}
fBound.prototype = new fNOP();
return fBound;
};
}
// Polyfill to get the name of a function in IE9
function functionName(fn) {
if (typeof Function.prototype.name === 'undefined') {
var funcNameRegex = /function\s([^(]{1,})\(/;
var results = funcNameRegex.exec(fn.toString());
return results && results.length > 1 ? results[1].trim() : "";
} else if (typeof fn.prototype === 'undefined') {
return fn.constructor.name;
} else {
return fn.prototype.constructor.name;
}
}
function parseValue(str) {
if ('true' === str) return true;else if ('false' === str) return false;else if (!isNaN(str * 1)) return parseFloat(str);
return str;
}
// Convert PascalCase to kebab-case
// Thank you: http://stackoverflow.com/a/8955580
function hyphenate$1(str) {
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
var Box = {
ImNotTouchingYou: ImNotTouchingYou,
OverlapArea: OverlapArea,
GetDimensions: GetDimensions,
GetExplicitOffsets: GetExplicitOffsets
};
/**
* Compares the dimensions of an element to a container and determines collision events with container.
* @function
* @param {jQuery} element - jQuery object to test for collisions.
* @param {jQuery} parent - jQuery object to use as bounding container.
* @param {Boolean} lrOnly - set to true to check left and right values only.
* @param {Boolean} tbOnly - set to true to check top and bottom values only.
* @default if no parent object passed, detects collisions with `window`.
* @returns {Boolean} - true if collision free, false if a collision in any direction.
*/
function ImNotTouchingYou(element, parent, lrOnly, tbOnly, ignoreBottom) {
return OverlapArea(element, parent, lrOnly, tbOnly, ignoreBottom) === 0;
}
function OverlapArea(element, parent, lrOnly, tbOnly, ignoreBottom) {
var eleDims = GetDimensions(element),
topOver,
bottomOver,
leftOver,
rightOver;
if (parent) {
var parDims = GetDimensions(parent);
bottomOver = parDims.height + parDims.offset.top - (eleDims.offset.top + eleDims.height);
topOver = eleDims.offset.top - parDims.offset.top;
leftOver = eleDims.offset.left - parDims.offset.left;
rightOver = parDims.width + parDims.offset.left - (eleDims.offset.left + eleDims.width);
} else {
bottomOver = eleDims.windowDims.height + eleDims.windowDims.offset.top - (eleDims.offset.top + eleDims.height);
topOver = eleDims.offset.top - eleDims.windowDims.offset.top;
leftOver = eleDims.offset.left - eleDims.windowDims.offset.left;
rightOver = eleDims.windowDims.width - (eleDims.offset.left + eleDims.width);
}
bottomOver = ignoreBottom ? 0 : Math.min(bottomOver, 0);
topOver = Math.min(topOver, 0);
leftOver = Math.min(leftOver, 0);
rightOver = Math.min(rightOver, 0);
if (lrOnly) {
return leftOver + rightOver;
}
if (tbOnly) {
return topOver + bottomOver;
}
// use sum of squares b/c we care about overlap area.
return Math.sqrt(topOver * topOver + bottomOver * bottomOver + leftOver * leftOver + rightOver * rightOver);
}
/**
* Uses native methods to return an object of dimension values.
* @function
* @param {jQuery || HTML} element - jQuery object or DOM element for which to get the dimensions. Can be any element other that document or window.
* @returns {Object} - nested object of integer pixel values
* TODO - if element is window, return only those values.
*/
function GetDimensions(elem) {
elem = elem.length ? elem[0] : elem;
if (elem === window || elem === document) {
throw new Error("I'm sorry, Dave. I'm afraid I can't do that.");
}
var rect = elem.getBoundingClientRect(),
parRect = elem.parentNode.getBoundingClientRect(),
winRect = document.body.getBoundingClientRect(),
winY = window.pageYOffset,
winX = window.pageXOffset;
return {
width: rect.width,
height: rect.height,
offset: {
top: rect.top + winY,
left: rect.left + winX
},
parentDims: {
width: parRect.width,
height: parRect.height,
offset: {
top: parRect.top + winY,
left: parRect.left + winX
}
},
windowDims: {
width: winRect.width,
height: winRect.height,
offset: {
top: winY,
left: winX
}
}
};
}
/**
* Returns an object of top and left integer pixel values for dynamically rendered elements,
* such as: Tooltip, Reveal, and Dropdown. Maintained for backwards compatibility, and where
* you don't know alignment, but generally from
* 6.4 forward you should use GetExplicitOffsets, as GetOffsets conflates position and alignment.
* @function
* @param {jQuery} element - jQuery object for the element being positioned.
* @param {jQuery} anchor - jQuery object for the element's anchor point.
* @param {String} position - a string relating to the desired position of the element, relative to it's anchor
* @param {Number} vOffset - integer pixel value of desired vertical separation between anchor and element.
* @param {Number} hOffset - integer pixel value of desired horizontal separation between anchor and element.
* @param {Boolean} isOverflow - if a collision event is detected, sets to true to default the element to full width - any desired offset.
* TODO alter/rewrite to work with `em` values as well/instead of pixels
*/
function GetExplicitOffsets(element, anchor, position, alignment, vOffset, hOffset, isOverflow) {
var $eleDims = GetDimensions(element),
$anchorDims = anchor ? GetDimensions(anchor) : null;
var topVal, leftVal;
if ($anchorDims !== null) {
// set position related attribute
switch (position) {
case 'top':
topVal = $anchorDims.offset.top - ($eleDims.height + vOffset);
break;
case 'bottom':
topVal = $anchorDims.offset.top + $anchorDims.height + vOffset;
break;
case 'left':
leftVal = $anchorDims.offset.left - ($eleDims.width + hOffset);
break;
case 'right':
leftVal = $anchorDims.offset.left + $anchorDims.width + hOffset;
break;
}
// set alignment related attribute
switch (position) {
case 'top':
case 'bottom':
switch (alignment) {
case 'left':
leftVal = $anchorDims.offset.left + hOffset;
break;
case 'right':
leftVal = $anchorDims.offset.left - $eleDims.width + $anchorDims.width - hOffset;
break;
case 'center':
leftVal = isOverflow ? hOffset : $anchorDims.offset.left + $anchorDims.width / 2 - $eleDims.width / 2 + hOffset;
break;
}
break;
case 'right':
case 'left':
switch (alignment) {
case 'bottom':
topVal = $anchorDims.offset.top - vOffset + $anchorDims.height - $eleDims.height;
break;
case 'top':
topVal = $anchorDims.offset.top + vOffset;
break;
case 'center':
topVal = $anchorDims.offset.top + vOffset + $anchorDims.height / 2 - $eleDims.height / 2;
break;
}
break;
}
}
return {
top: topVal,
left: leftVal
};
}
/**
* Runs a callback function when images are fully loaded.
* @param {Object} images - Image(s) to check if loaded.
* @param {Func} callback - Function to execute when image is fully loaded.
*/
function onImagesLoaded(images, callback) {
var unloaded = images.length;
if (unloaded === 0) {
callback();
}
images.each(function () {
// Check if image is loaded
if (this.complete && typeof this.naturalWidth !== 'undefined') {
singleImageLoaded();
} else {
// If the above check failed, simulate loading on detached element.
var image = new Image();
// Still count image as loaded if it finalizes with an error.
var events = "load.zf.images error.zf.images";
$(image).one(events, function me() {
// Unbind the event listeners. We're using 'one' but only one of the two events will have fired.
$(this).off(events, me);
singleImageLoaded();
});
image.src = $(this).attr('src');
}
});
function singleImageLoaded() {
unloaded--;
if (unloaded === 0) {
callback();
}
}
}
/*******************************************
* *
* This util was created by Marius Olbertz *
* Please thank Marius on GitHub /owlbertz *
* or the web http://www.mariusolbertz.de/ *
* *
******************************************/
var keyCodes = {
9: 'TAB',
13: 'ENTER',
27: 'ESCAPE',
32: 'SPACE',
35: 'END',
36: 'HOME',
37: 'ARROW_LEFT',
38: 'ARROW_UP',
39: 'ARROW_RIGHT',
40: 'ARROW_DOWN'
};
var commands = {};
// Functions pulled out to be referenceable from internals
function findFocusable($element) {
if (!$element) {
return false;
}
return $element.find('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]').filter(function () {
if (!$(this).is(':visible') || $(this).attr('tabindex') < 0) {
return false;
} //only have visible elements and those that have a tabindex greater or equal 0
return true;
}).sort(function (a, b) {
if ($(a).attr('tabindex') === $(b).attr('tabindex')) {
return 0;
}
var aTabIndex = parseInt($(a).attr('tabindex'), 10),
bTabIndex = parseInt($(b).attr('tabindex'), 10);
// Undefined is treated the same as 0
if (typeof $(a).attr('tabindex') === 'undefined' && bTabIndex > 0) {
return 1;
}
if (typeof $(b).attr('tabindex') === 'undefined' && aTabIndex > 0) {
return -1;
}
if (aTabIndex === 0 && bTabIndex > 0) {
return 1;
}
if (bTabIndex === 0 && aTabIndex > 0) {
return -1;
}
if (aTabIndex < bTabIndex) {
return -1;
}
if (aTabIndex > bTabIndex) {
return 1;
}
});
}
function parseKey(event) {
var key = keyCodes[event.which || event.keyCode] || String.fromCharCode(event.which).toUpperCase();
// Remove un-printable characters, e.g. for `fromCharCode` calls for CTRL only events
key = key.replace(/\W+/, '');
if (event.shiftKey) key = "SHIFT_".concat(key);
if (event.ctrlKey) key = "CTRL_".concat(key);
if (event.altKey) key = "ALT_".concat(key);
// Remove trailing underscore, in case only modifiers were used (e.g. only `CTRL_ALT`)
key = key.replace(/_$/, '');
return key;
}
var Keyboard = {
keys: getKeyCodes(keyCodes),
/**
* Parses the (keyboard) event and returns a String that represents its key
* Can be used like Foundation.parseKey(event) === Foundation.keys.SPACE
* @param {Event} event - the event generated by the event handler
* @return String key - String that represents the key pressed
*/
parseKey: parseKey,
/**
* Handles the given (keyboard) event
* @param {Event} event - the event generated by the event handler
* @param {String} component - Foundation component's name, e.g. Slider or Reveal
* @param {Objects} functions - collection of functions that are to be executed
*/
handleKey: function handleKey(event, component, functions) {
var commandList = commands[component],
keyCode = this.parseKey(event),
cmds,
command,
fn;
if (!commandList) return console.warn('Component not defined!');
// Ignore the event if it was already handled
if (event.zfIsKeyHandled === true) return;
// This component does not differentiate between ltr and rtl
if (typeof commandList.ltr === 'undefined') {
cmds = commandList; // use plain list
} else {
// merge ltr and rtl: if document is rtl, rtl overwrites ltr and vice versa
if (rtl()) cmds = $.extend({}, commandList.ltr, commandList.rtl);else cmds = $.extend({}, commandList.rtl, commandList.ltr);
}
command = cmds[keyCode];
fn = functions[command];
// Execute the handler if found
if (fn && typeof fn === 'function') {
var returnValue = fn.apply();
// Mark the event as "handled" to prevent future handlings
event.zfIsKeyHandled = true;
// Execute function when event was handled
if (functions.handled || typeof functions.handled === 'function') {
functions.handled(returnValue);
}
} else {
// Execute function when event was not handled
if (functions.unhandled || typeof functions.unhandled === 'function') {
functions.unhandled();
}
}
},
/**
* Finds all focusable elements within the given `$element`
* @param {jQuery} $element - jQuery object to search within
* @return {jQuery} $focusable - all focusable elements within `$element`
*/
findFocusable: findFocusable,
/**
* Returns the component name name
* @param {Object} component - Foundation component, e.g. Slider or Reveal
* @return String componentName
*/
register: function register(componentName, cmds) {
commands[componentName] = cmds;
},
// TODO9438: These references to Keyboard need to not require global. Will 'this' work in this context?
//
/**
* Traps the focus in the given element.
* @param {jQuery} $element jQuery object to trap the foucs into.
*/
trapFocus: function trapFocus($element) {
var $focusable = findFocusable($element),
$firstFocusable = $focusable.eq(0),
$lastFocusable = $focusable.eq(-1);
$element.on('keydown.zf.trapfocus', function (event) {
if (event.target === $lastFocusable[0] && parseKey(event) === 'TAB') {
event.preventDefault();
$firstFocusable.focus();
} else if (event.target === $firstFocusable[0] && parseKey(event) === 'SHIFT_TAB') {
event.preventDefault();
$lastFocusable.focus();
}
});
},
/**
* Releases the trapped focus from the given element.
* @param {jQuery} $element jQuery object to release the focus for.
*/
releaseFocus: function releaseFocus($element) {
$element.off('keydown.zf.trapfocus');
}
};
/*
* Constants for easier comparing.
* Can be used like Foundation.parseKey(event) === Foundation.keys.SPACE
*/
function getKeyCodes(kcs) {
var k = {};
for (var kc in kcs) {
if (kcs.hasOwnProperty(kc)) k[kcs[kc]] = kcs[kc];
}
return k;
}
/**
* Motion module.
* @module foundation.motion
*/
var initClasses = ['mui-enter', 'mui-leave'];
var activeClasses = ['mui-enter-active', 'mui-leave-active'];
var Motion = {
animateIn: function animateIn(element, animation, cb) {
animate(true, element, animation, cb);
},
animateOut: function animateOut(element, animation, cb) {
animate(false, element, animation, cb);
}
};
function Move(duration, elem, fn) {
var anim,
prog,
start = null;
if (duration === 0) {
fn.apply(elem);
elem.trigger('finished.zf.animate', [elem]).triggerHandler('finished.zf.animate', [elem]);
return;
}
function move(ts) {
if (!start) start = ts;
prog = ts - start;
fn.apply(elem);
if (prog < duration) {
anim = window.requestAnimationFrame(move, elem);
} else {
window.cancelAnimationFrame(anim);
elem.trigger('finished.zf.animate', [elem]).triggerHandler('finished.zf.animate', [elem]);
}
}
anim = window.requestAnimationFrame(move);
}
/**
* Animates an element in or out using a CSS transition class.
* @function
* @private
* @param {Boolean} isIn - Defines if the animation is in or out.
* @param {Object} element - jQuery or HTML object to animate.
* @param {String} animation - CSS class to use.
* @param {Function} cb - Callback to run when animation is finished.
*/
function animate(isIn, element, animation, cb) {
element = $(element).eq(0);
if (!element.length) return;
var initClass = isIn ? initClasses[0] : initClasses[1];
var activeClass = isIn ? activeClasses[0] : activeClasses[1];
// Set up the animation
reset();
element.addClass(animation).css('transition', 'none');
requestAnimationFrame(function () {
element.addClass(initClass);
if (isIn) element.show();
});
// Start the animation
requestAnimationFrame(function () {
// will trigger the browser to synchronously calculate the style and layout
// also called reflow or layout thrashing
// see https://gist.github.com/paulirish/5d52fb081b3570c81e3a
element[0].offsetWidth;
element.css('transition', '').addClass(activeClass);
});
// Clean up the animation when it finishes
element.one(transitionend(element), finish);
// Hides the element (for out animations), resets the element, and runs a callback
function finish() {
if (!isIn) element.hide();
reset();
if (cb) cb.apply(element);
}
// Resets transitions and removes motion-specific classes
function reset() {
element[0].style.transitionDuration = 0;
element.removeClass("".concat(initClass, " ").concat(activeClass, " ").concat(animation));
}
}
var Nest = {
Feather: function Feather(menu) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'zf';
menu.attr('role', 'menubar');
menu.find('a').attr({
'role': 'menuitem'
});
var items = menu.find('li').attr({
'role': 'none'
}),
subMenuClass = "is-".concat(type, "-submenu"),
subItemClass = "".concat(subMenuClass, "-item"),
hasSubClass = "is-".concat(type, "-submenu-parent"),
applyAria = type !== 'accordion'; // Accordions handle their own ARIA attriutes.
items.each(function () {
var $item = $(this),
$sub = $item.children('ul');
if ($sub.length) {
$item.addClass(hasSubClass);
if (applyAria) {
var firstItem = $item.children('a:first');
firstItem.attr({
'aria-haspopup': true,
'aria-label': firstItem.attr('aria-label') || firstItem.text()
});
// Note: Drilldowns behave differently in how they hide, and so need
// additional attributes. We should look if this possibly over-generalized
// utility (Nest) is appropriate when we rework menus in 6.4
if (type === 'drilldown') {
$item.attr({
'aria-expanded': false
});
}
}
$sub.addClass("submenu ".concat(subMenuClass)).attr({
'data-submenu': '',
'role': 'menubar'
});
if (type === 'drilldown') {
$sub.attr({
'aria-hidden': true
});
}
}
if ($item.parent('[data-submenu]').length) {
$item.addClass("is-submenu-item ".concat(subItemClass));
}
});
return;
},
Burn: function Burn(menu, type) {
var
//items = menu.find('li'),
subMenuClass = "is-".concat(type, "-submenu"),
subItemClass = "".concat(subMenuClass, "-item"),
hasSubClass = "is-".concat(type, "-submenu-parent");
menu.find('>li, > li > ul, .menu, .menu > li, [data-submenu] > li').removeClass("".concat(subMenuClass, " ").concat(subItemClass, " ").concat(hasSubClass, " is-submenu-item submenu is-active")).removeAttr('data-submenu').css('display', '');
}
};
function Timer(elem, options, cb) {
var _this = this,
duration = options.duration,
//options is an object for easily adding features later.
nameSpace = Object.keys(elem.data())[0] || 'timer',
remain = -1,
start,
timer;
this.isPaused = false;
this.restart = function () {
remain = -1;
clearTimeout(timer);
this.start();
};
this.start = function () {
this.isPaused = false;
// if(!elem.data('paused')){ return false; }//maybe implement this sanity check if used for other things.
clearTimeout(timer);
remain = remain <= 0 ? duration : remain;
elem.data('paused', false);
start = Date.now();
timer = setTimeout(function () {
if (options.infinite) {
_this.restart(); //rerun the timer.
}
if (cb && typeof cb === 'function') {
cb();
}
}, remain);
elem.trigger("timerstart.zf.".concat(nameSpace));
};
this.pause = function () {
this.isPaused = true;
//if(elem.data('paused')){ return false; }//maybe implement this sanity check if used for other things.
clearTimeout(timer);
elem.data('paused', true);
var end = Date.now();
remain = remain - (end - start);
elem.trigger("timerpaused.zf.".concat(nameSpace));
};
}
var Touch = {};
var startPosX,
startTime,
elapsedTime,
startEvent,
isMoving = false,
didMoved = false;
function onTouchEnd(e) {
this.removeEventListener('touchmove', onTouchMove);
this.removeEventListener('touchend', onTouchEnd);
// If the touch did not move, consider it as a "tap"
if (!didMoved) {
var tapEvent = $.Event('tap', startEvent || e);
$(this).trigger(tapEvent);
}
startEvent = null;
isMoving = false;
didMoved = false;
}
function onTouchMove(e) {
if (true === $.spotSwipe.preventDefault) {
e.preventDefault();
}
if (isMoving) {
var x = e.touches[0].pageX;
// var y = e.touches[0].pageY;
var dx = startPosX - x;
// var dy = startPosY - y;
var dir;
didMoved = true;
elapsedTime = new Date().getTime() - startTime;
if (Math.abs(dx) >= $.spotSwipe.moveThreshold && elapsedTime <= $.spotSwipe.timeThreshold) {
dir = dx > 0 ? 'left' : 'right';
}
// else if(Math.abs(dy) >= $.spotSwipe.moveThreshold && elapsedTime <= $.spotSwipe.timeThreshold) {
// dir = dy > 0 ? 'down' : 'up';
// }
if (dir) {
e.preventDefault();
onTouchEnd.apply(this, arguments);
$(this).trigger($.Event('swipe', Object.assign({}, e)), dir).trigger($.Event("swipe".concat(dir), Object.assign({}, e)));
}
}
}
function onTouchStart(e) {
if (e.touches.length === 1) {
startPosX = e.touches[0].pageX;
startEvent = e;
isMoving = true;
didMoved = false;
startTime = new Date().getTime();
this.addEventListener('touchmove', onTouchMove, {
passive: true === $.spotSwipe.preventDefault
});
this.addEventListener('touchend', onTouchEnd, false);
}
}
function init() {
this.addEventListener && this.addEventListener('touchstart', onTouchStart, {
passive: true
});
}
// function teardown() {
// this.removeEventListener('touchstart', onTouchStart);
// }
var SpotSwipe = /*#__PURE__*/function () {
function SpotSwipe() {
_classCallCheck(this, SpotSwipe);
this.version = '1.0.0';
this.enabled = 'ontouchstart' in document.documentElement;
this.preventDefault = false;
this.moveThreshold = 75;
this.timeThreshold = 200;
this._init();
}
return _createClass(SpotSwipe, [{
key: "_init",
value: function _init() {
$.event.special.swipe = {
setup: init
};
$.event.special.tap = {
setup: init
};
$.each(['left', 'up', 'down', 'right'], function () {
$.event.special["swipe".concat(this)] = {
setup: function setup() {
$(this).on('swipe', $.noop);
}
};
});
}
}]);
}();
/****************************************************
* As far as I can tell, both setupSpotSwipe and *
* setupTouchHandler should be idempotent, *
* because they directly replace functions & *
* values, and do not add event handlers directly. *
****************************************************/
Touch.setupSpotSwipe = function () {
$.spotSwipe = new SpotSwipe($);
};
/****************************************************
* Method for adding pseudo drag events to elements *
***************************************************/
Touch.setupTouchHandler = function () {
$.fn.addTouch = function () {
this.each(function (i, el) {
$(el).bind('touchstart touchmove touchend touchcancel', function (event) {
//we pass the original event object because the jQuery event
//object is normalized to w3c specs and does not provide the TouchList
handleTouch(event);
});
});
var handleTouch = function handleTouch(event) {
var touches = event.changedTouches,
first = touches[0],
eventTypes = {
touchstart: 'mousedown',
touchmove: 'mousemove',
touchend: 'mouseup'
},
type = eventTypes[event.type],
simulatedEvent;
if ('MouseEvent' in window && typeof window.MouseEvent === 'function') {
simulatedEvent = new window.MouseEvent(type, {
'bubbles': true,
'cancelable': true,
'screenX': first.screenX,
'screenY': first.screenY,
'clientX': first.clientX,
'clientY': first.clientY
});
} else {
simulatedEvent = document.createEvent('MouseEvent');
simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0 /*left*/, null);
}
first.target.dispatchEvent(simulatedEvent);
};
};
};
Touch.init = function () {
if (typeof $.spotSwipe === 'undefined') {
Touch.setupSpotSwipe($);
Touch.setupTouchHandler($);
}
};
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) {
$("#".concat(id))[type === 'close' ? 'trigger' : 'triggerHandler']("".concat(type, ".zf.trigger"), [el]);
});
};
var Triggers = {
Listeners: {
Basic: {},
Global: {}
},
Initializers: {}
};
Triggers.Listeners.Basic = {
openListener: function openListener() {
triggers($(this), 'open');
},
closeListener: function closeListener() {
var id = $(this).data('close');
if (id) {
triggers($(this), 'close');
} else {
$(this).trigger('close.zf.trigger');
}
},
toggleListener: function toggleListener() {
var id = $(this).data('toggle');
if (id) {
triggers($(this), 'toggle');
} else {
$(this).trigger('toggle.zf.trigger');
}
},
closeableListener: function closeableListener(e) {
var animation = $(this).data('closable');
// Only close the first closable element. See https://git.io/zf-7833
e.stopPropagation();
if (animation !== '') {
Motion.animateOut($(this), animation, function () {
$(this).trigger('closed.zf');
});
} else {
$(this).fadeOut().trigger('closed.zf');
}
},
toggleFocusListener: function toggleFocusListener() {
var id = $(this).data('toggle-focus');
$("#".concat(id)).triggerHandler('toggle.zf.trigger', [$(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 () {
$(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 () {
$(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 = $("[data-".concat(plugin, "]")).not("[data-yeti-box=\"".concat(pluginId, "\"]"));
plugins.each(function () {
var _this = $(this);
_this.triggerHandler('close.zf.trigger', [_this]);
});
}
};
// Global, parses whole document.
Triggers.Initializers.addClosemeListener = function (pluginName) {
var yetiBoxes = $('[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(' ');
$(window).off(listeners).on(listeners, Triggers.Listeners.Global.closeMeListener);
}
};
function debounceGlobalListener(debounce, trigger, listener) {
var timer,
args = Array.prototype.slice.call(arguments, 3);
$(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 = $('[data-resize]');
if ($nodes.length) {
debounceGlobalListener(debounce, 'resize.zf.trigger', Triggers.Listeners.Global.resizeListener, $nodes);
}
};
Triggers.Initializers.addScrollListener = function (debounce) {
var $nodes = $('[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 = $(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 = $(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 = $(document);
Triggers.Initializers.addMutationEventsListener($document);
Triggers.Initializers.addResizeListener(250);
Triggers.Initializers.addScrollListener();
Triggers.Initializers.addClosemeListener();
};
Triggers.init = function (__, Foundation) {
onLoad($(window), function () {
if ($.triggersInitialized !== true) {
Triggers.Initializers.addSimpleListeners();
Triggers.Initializers.addGlobalListeners();
$.triggersInitialized = true;
}
});
if (Foundation) {
Foundation.Triggers = Triggers;
// Legacy included to be backwards compatible for now.
Foundation.IHearYou = Triggers.Initializers.addGlobalListeners;
}
};
// Abstract class for providing lifecycle hooks. Expect plugins to define AT LEAST
// {function} _setup (replaces previous constructor),
// {function} _destroy (replaces previous destroy)
var Plugin = /*#__PURE__*/function () {
function Plugin(element, options) {
_classCallCheck(this, Plugin);
this._setup(element, options);
var pluginName = getPluginName(this);
this.uuid = GetYoDigits(6, pluginName);
if (!this.$element.attr("data-".concat(pluginName))) {
this.$element.attr("data-".concat(pluginName), this.uuid);
}
if (!this.$element.data('zfPlugin')) {
this.$element.data('zfPlugin', this);
}
/**
* Fires when the plugin has initialized.
* @event Plugin#init
*/
this.$element.trigger("init.zf.".concat(pluginName));
}
return _createClass(Plugin, [{
key: "destroy",
value: function destroy() {
this._destroy();
var pluginName = getPluginName(this);
this.$element.removeAttr("data-".concat(pluginName)).removeData('zfPlugin')
/**
* Fires when the plugin has been destroyed.
* @event Plugin#destroyed
*/.trigger("destroyed.zf.".concat(pluginName));
for (var prop in this) {
if (this.hasOwnProperty(prop)) {
this[prop] = null; //clean up script to prep for garbage collection.
}
}
}
}]);
}(); // Convert PascalCase to kebab-case
// Thank you: http://stackoverflow.com/a/8955580
function hyphenate(str) {
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
function getPluginName(obj) {
return hyphenate(obj.className);
}
/**
* Abide module.
* @module foundation.abide
*/
var Abide = /*#__PURE__*/function (_Plugin) {
function Abide() {
_classCallCheck(this, Abide);
return _callSuper(this, Abide, arguments);
}
_inherits(Abide, _Plugin);
return _createClass(Abide, [{
key: "_setup",
value:
/**
* Creates a new instance of Abide.
* @class
* @name Abide
* @fires Abide#init
* @param {Object} element - jQuery object to add the trigger to.
* @param {Object} options - Overrides to the default plugin settings.
*/
function _setup(element) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.$element = element;
this.options = $.extend(true, {}, Abide.defaults, this.$element.data(), options);
this.isEnabled = true;
this.formnovalidate = null;
this.className = 'Abide'; // ie9 back compat
this._init();
}
/**
* Initializes the Abide plugin and calls functions to get Abide functioning on load.
* @private
*/
}, {
key: "_init",
value: function _init() {
var _this2 = this;
this.$inputs = $.merge(
// Consider as input to validate:
this.$element.find('input').not('[type="submit"]'),
// * all input fields expect submit
this.$element.find('textarea, select') // * all textareas and select fields
);
this.$submits = this.$element.find('[type="submit"]');
var $globalErrors = this.$element.find('[data-abide-error]');
// Add a11y attributes to all fields
if (this.options.a11yAttributes) {
this.$inputs.each(function (i, input) {
return _this2.addA11yAttributes($(input));
});
$globalErrors.each(function (i, error) {
return _this2.addGlobalErrorA11yAttributes($(error));
});
}
this._events();
}
/**
* Initializes events for Abide.
* @private
*/
}, {
key: "_events",
value: function _events() {
var _this3 = this;
this.$element.off('.abide').on('reset.zf.abide', function () {
_this3.resetForm();
}).on('submit.zf.abide', function () {
return _this3.validateForm();
});
this.$submits.off('click.zf.abide keydown.zf.abide').on('click.zf.abide keydown.zf.abide', function (e) {
if (!e.key || e.key === ' ' || e.key === 'Enter') {
e.preventDefault();
_this3.formnovalidate = e.target.getAttribute('formnovalidate') !== null;
_this3.$element.submit();
}
});
if (this.options.validateOn === 'fieldChange') {
this.$inputs.off('change.zf.abide').on('change.zf.abide', function (e) {
_this3.validateInput($(e.target));
});
}
if (this.options.liveValidate) {
this.$inputs.off('input.zf.abide').on('input.zf.abide', function (e) {
_this3.validateInput($(e.target));
});
}
if (this.options.validateOnBlur) {
this.$inputs.off('blur.zf.abide').on('blur.zf.abide', function (e) {
_this3.validateInput($(e.target));
});
}
}
/**
* Calls necessary functions to update Abide upon DOM change
* @private
*/
}, {
key: "_reflow",
value: function _reflow() {
this._init();
}
/**
* Checks whether the submitted form should be validated or not, consodering formnovalidate and isEnabled
* @returns {Boolean}
* @private
*/
}, {
key: "_validationIsDisabled",
value: function _validationIsDisabled() {
if (this.isEnabled === false) {
// whole validation disabled
return true;
} else if (typeof this.formnovalidate === 'boolean') {
// triggered by $submit
return this.formnovalidate;
}
// triggered by Enter in non-submit input
return this.$submits.length ? this.$submits[0].getAttribute('formnovalidate') !== null : false;
}
/**
* Enables the whole validation
*/
}, {
key: "enableValidation",
value: function enableValidation() {
this.isEnabled = true;
}
/**
* Disables the whole validation
*/
}, {
key: "disableValidation",
value: function disableValidation() {
this.isEnabled = false;
}
/**
* Checks whether or not a form element has the required attribute and if it's checked or not
* @param {Object} element - jQuery object to check for required attribute
* @returns {Boolean} Boolean value depends on whether or not attribute is checked or empty
*/
}, {
key: "requiredCheck",
value: function requiredCheck($el) {
if (!$el.attr('required')) return true;
var isGood = true;
switch ($el[0].type) {
case 'checkbox':
isGood = $el[0].checked;
break;
case 'select':
case 'select-one':
case 'select-multiple':
var opt = $el.find('option:selected');
if (!opt.length || !opt.val()) isGood = false;
break;
default:
if (!$el.val() || !$el.val().length) isGood = false;
}
return isGood;
}
/**
* Get:
* - Based on $el, the first element(s) corresponding to `formErrorSelector` in this order:
* 1. The element's direct sibling('s).
* 2. The element's parent's children.
* - Element(s) with the attribute `[data-form-error-for]` set with the element's id.
*
* This allows for multiple form errors per input, though if none are found, no form errors will be shown.
*
* @param {Object} $el - jQuery object to use as reference to find the form error selector.
* @param {String[]} [failedValidators] - List of failed validators.
* @returns {Object} jQuery object with the selector.
*/
}, {
key: "findFormError",
value: function findFormError($el, failedValidators) {
var _this4 = this;
var id = $el.length ? $el[0].id : '';
var $error = $el.siblings(this.options.formErrorSelector);
if (!$error.length) {
$error = $el.parent().find(this.options.formErrorSelector);
}
if (id) {
$error = $error.add(this.$element.find("[data-form-error-for=\"".concat(id, "\"]")));
}
if (!!failedValidators) {
$error = $error.not('[data-form-error-on]');
failedValidators.forEach(function (v) {
$error = $error.add($el.siblings("[data-form-error-on=\"".concat(v, "\"]")));
$error = $error.add(_this4.$element.find("[data-form-error-for=\"".concat(id, "\"][data-form-error-on=\"").concat(v, "\"]")));
});
}
return $error;
}
/**
* Get the first element in this order:
* 2. The