-
Notifications
You must be signed in to change notification settings - Fork 0
/
enquire.min.js
5 lines (4 loc) · 1.99 KB
/
enquire.min.js
1
2
3
4
5
// enquire v1.3.0 - Awesome Media Queries in JavaScript
// Copyright (c) 2012 Nick Williams - https://www.github.com/WickyNilliams/enquire.js
// License: MIT (http://www.opensource.org/licenses/mit-license.php)
window.enquire=function(e){"use strict";function t(e,t){var n=0,r=e.length,i;for(n;n<r;n++){i=t(e[n],n);if(i===!1)break}}function n(e){return Object.prototype.toString.apply(e)==="[object Array]"}function r(e){return typeof e=="function"}function i(e){this.initialised=!1,this.options=e,e.deferSetup||this.setup()}function s(t,n){this.mql=e(t),this.handlers=[],this.matched=!1,this.isUnconditional=n}function o(){if(!e)throw new Error("matchMedia is required");var t=new s("only all");this.queries=[],this.listening=!1,this.browserIsIncapable=!t.matchMedia()}return i.prototype={setup:function(){this.options.setup&&this.options.setup(),this.initialised=!0},on:function(e){this.initialised||this.setup(),this.options.match(e)},off:function(e){this.options.unmatch&&this.options.unmatch(e)}},s.prototype={matchMedia:function(){return this.mql.matches},addHandler:function(e){var t=new i(e);this.handlers.push(t)},assess:function(){this.matchMedia()||this.isUnconditional?this.match():this.unmatch()},match:function(e){if(this.matched)return;t(this.handlers,function(t){t.on(e)}),this.matched=!0},unmatch:function(e){if(!this.matched)return;t(this.handlers,function(t){t.off(e)}),this.matched=!1}},o.prototype={register:function(e,i,o){var u=this.queries,a,f=o&&this.browserIsIncapable;return u.hasOwnProperty(e)||(u[e]=new s(e,f)),a=u[e],r(i)&&(i={match:i}),n(i)||(i=[i]),t(i,function(e){a.addHandler(e)}),this},fire:function(e){var t=this.queries,n;for(n in t){if(!t.hasOwnProperty(n))continue;t[n].assess()}return this},listen:function(e){function r(r){var i;t(r,function(t){i&&clearTimeout(i),i=setTimeout(function(){n.fire(t)},e)})}var t=window.addEventListener||window.attachEvent,n=this;return e=e||500,this.listening?this:(n.fire(),r("resize"),r("orientationChange"),this.listening=!0,this)}},new o}(window.matchMedia);