/** * @license enquire.js v2.1.2 - Awesome Media Queries in JavaScript Copyright (c) 2014 Nick Williams - http://wicky.nillia.ms/enquire.js License: MIT (http://www.opensource.org/licenses/mit-license.php) */ 'use strict'; !function(name, context, factory) { /** @type {function(this:Window, string): (MediaQueryList|null)} */ var matchMedia = window.matchMedia; if ("undefined" != typeof module && module.exports) { module.exports = factory(matchMedia); } else { if ("function" == typeof define && define.amd) { define(function() { return context[name] = factory(matchMedia); }); } else { context[name] = factory(matchMedia); } } }("enquire", this, function(matchMedia) { /** * @param {string} a * @param {!Function} b * @return {undefined} */ function b(a, b) { var c; /** @type {number} */ var d = 0; var l = a.length; d; for (; l > d && (c = b(a[d], d), c !== false); d++) { } } /** * @param {string} fn * @return {?} */ function c(fn) { return "[object Array]" === Object.prototype.toString.apply(fn); } /** * @param {string} b * @return {?} */ function d(b) { return "function" == typeof b; } /** * @param {!Object} options * @return {undefined} */ function QueryHandler(options) { /** @type {!Object} */ this.options = options; if (!options.deferSetup) { this.setup(); } } /** * @param {string} query * @param {boolean} isUnconditional * @return {undefined} */ function MediaQuery(query, isUnconditional) { /** @type {string} */ this.query = query; /** @type {boolean} */ this.isUnconditional = isUnconditional; /** @type {!Array} */ this.handlers = []; this.mql = matchMedia(query); var d = this; /** * @param {!Object} a * @return {undefined} */ this.listener = function(a) { /** @type {!Object} */ d.mql = a; d.assess(); }; this.mql.addListener(this.listener); } /** * @return {undefined} */ function MediaQueryDispatch() { if (!matchMedia) { throw new Error("matchMedia not present, legacy browsers require a polyfill"); } this.queries = {}; /** @type {boolean} */ this.browserIsIncapable = !matchMedia("only all").matches; } return QueryHandler.prototype = { setup : function() { if (this.options.setup) { this.options.setup(); } /** @type {boolean} */ this.initialised = true; }, on : function() { if (!this.initialised) { this.setup(); } if (this.options.match) { this.options.match(); } }, off : function() { if (this.options.unmatch) { this.options.unmatch(); } }, destroy : function() { if (this.options.destroy) { this.options.destroy(); } else { this.off(); } }, equals : function(a) { return this.options === a || this.options.match === a; } }, MediaQuery.prototype = { addHandler : function(handler) { var qh = new QueryHandler(handler); this.handlers.push(qh); if (this.matches()) { qh.on(); } }, removeHandler : function(a) { var c = this.handlers; b(c, function(b, d) { return b.equals(a) ? (b.destroy(), !c.splice(d, 1)) : void 0; }); }, matches : function() { return this.mql.matches || this.isUnconditional; }, clear : function() { b(this.handlers, function(anAlertDialog) { anAlertDialog.destroy(); }); this.mql.removeListener(this.listener); /** @type {number} */ this.handlers.length = 0; }, assess : function() { /** @type {string} */ var method = this.matches() ? "on" : "off"; b(this.handlers, function(groupRouter) { groupRouter[method](); }); } }, MediaQueryDispatch.prototype = { register : function(q, e, shouldDegrade) { var queries = this.queries; var isUnconditional = shouldDegrade && this.browserIsIncapable; return queries[q] || (queries[q] = new MediaQuery(q, isUnconditional)), d(e) && (e = { match : e }), c(e) || (e = [e]), b(e, function(b) { if (d(b)) { b = { match : b }; } queries[q].addHandler(b); }), this; }, unregister : function(a, b) { var c = this.queries[a]; return c && (b ? c.removeHandler(b) : (c.clear(), delete this.queries[a])), this; } }, new MediaQueryDispatch; });