forked from ryanve/response.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse.min.js
19 lines (19 loc) · 8.96 KB
/
response.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*! Response 0.7.8 | @link responsejs.com | @author ryanve | @license MIT */
(function(e,q,v){var w=e.jQuery||e.Zepto||e.ender||e.elo;"undefined"!=typeof module&&module.exports?module.exports=v(w):e[q]=v(w)})(this,"Response",function(e){function q(a){throw new TypeError(a?r+"."+a:r);}function v(a){return"number"==typeof a&&a===a}function w(a,b,c){var d,h=a.length,l=[];for(d=0;d<h;d++)l[d]=b.call(c,a[d],d,a);return l}function G(a){return"string"==typeof a?u(a.split(" ")):S(a)?u(a):[]}function j(a,b,c){if(null==a)return a;for(var d=0,h=a.length;d<h;)b.call(c||a[d],a[d],d++,
a);return a}function T(a,b,c){var d=[],h=a.length,l=0,f;b=b||"";for(c=c||"";l<h;)f=a[l++],null==f||d.push(b+f+c);return d}function u(a,b,c){var d,h=0,l=0,f,e=[],g,j="function"==typeof b;if(!a)return e;c=(g=!0===c)?null:c;for(d=a.length;l<d;l++)f=a[l],g===!(j?b.call(c,f,l,a):b?typeof f===b:f)&&(e[h++]=f);return e}function U(a,b){var c,d;if(!a||!b)return a;if("function"!=typeof b&&v(d=b.length)){for(c=0;c<d;c++)void 0===b[c]||(a[c]=b[c]);a.length>c||(a.length=c)}else for(c in b)ua.call(b,c)&&void 0!==
b[c]&&(a[c]=b[c]);return a}function x(a,b,c){if(null==a)return a;"object"==typeof a&&!a.nodeType&&v(a.length)?j(a,b,c):b.call(c||a,a);return a}function H(a){return function(b,c){var d=a();b=d>=(b||0);return c?b&&d<=c:b}}function y(a){var b=k.devicePixelRatio;if(null==a)return b||(y(2)?2:y(1.5)?1.5:y(1)?1:0);if(!isFinite(a))return!1;if(b&&0<b)return b>=a;a="only all and (min--moz-device-pixel-ratio:"+a+")";return V(a).matches?!0:!!V(a.replace("-moz-","")).matches}function da(a){return a.replace(W,
"$1").replace(va,function(a,c){return c.toUpperCase()})}function I(a){return"data-"+(a?a.replace(W,"$1").replace(wa,"$1-$2").toLowerCase():a)}function ea(a){var b;return!a||"string"!=typeof a?a:"true"===a?!0:"false"===a?!1:"undefined"===a?b:"null"===a?null:(b=parseFloat(a))===+b?b:a}function J(a){return!a?!1:1===a.nodeType?a:a[0]&&1===a[0].nodeType?a[0]:!1}function K(a,b){var c=arguments.length,d=J(this),h={},e=!1,f;if(c){S(a)&&(e=!0,a=a[0]);if("string"===typeof a){a=I(a);if(1===c)return h=d.getAttribute(a),
e?ea(h):h;if(this===d||2>(f=this.length||1))d.setAttribute(a,b);else for(;f--;)f in this&&K.apply(this[f],arguments)}else if(a instanceof Object)for(f in a)a.hasOwnProperty(f)&&K.call(this,f,a[f]);return this}if(d.dataset&&DOMStringMap)return d.dataset;j(d.attributes,function(a){if(a&&(f=String(a.name).match(W)))h[da(f[1])]=a.value});return h}function fa(a){this&&"string"===typeof a&&(a=G(a),x(this,function(b){j(a,function(a){a&&b.removeAttribute(I(a))})}));return this}function L(a,b,c){return K.apply(a,
xa.call(arguments,1))}function ga(a,b){return fa.call(a,b)}function ha(a){for(var b,c=[],d=0,h=a.length;d<h;)(b=a[d++])&&c.push("["+I(b.replace(X,"").replace(".","\\."))+"]");return c.join()}function Y(a,b){var c=a.getBoundingClientRect?a.getBoundingClientRect():{};b="number"==typeof b?b||0:0;return{top:(c.top||0)-b,left:(c.left||0)-b,bottom:(c.bottom||0)+b,right:(c.right||0)+b}}function Z(a,b){var c=Y(J(a),b);return!!c&&0<=c.bottom&&c.top<=z()&&0<=c.right&&c.left<=A()}function ia(a){var b={img:1,
input:1,source:3,embed:3,track:3,iframe:5,audio:5,video:5,script:5}[a.nodeName.toLowerCase()]||-1;return 4>b?b:null!=a.getAttribute("src")?5:-5}function ja(a,b,c){var d;(!a||null==b)&&q("store");c="string"==typeof c&&c;x(a,function(a){d=c?a.getAttribute(c):0<ia(a)?a.getAttribute("src"):a.innerHTML;null==d?ga(a,b):L(a,b,d)});return g}function $(a,b){var c=[];a&&b&&j(G(b),function(b){c.push(L(a,b))},a);return c}function aa(a){B.on("resize",a);return g}function ka(a){x(a,function(a){"object"==typeof a||
q("create @args");var c=ba(la).configure(a),d,h=c.verge;a=c.breakpoints;var e=M("scroll"),f=M("resize");a.length&&(d=a[0]||a[1]||!1,N(function(){function a(){c.reset();j(c.$e,function(a,b){c[b].decideValue().updateDOM()}).trigger(g)}function b(){j(c.$e,function(a,b){Z(c[b].$e,h)&&c[b].updateDOM()})}var g=ca.allLoaded,k=!!c.lazy;j(c.target().$e,function(a,b){c[b]=ba(c).prepareData(a);(!k||Z(c[b].$e,h))&&c[b].updateDOM()});c.dynamic&&(c.custom||d<C)&&aa(a,f);k&&(B.on(e,b),c.$e.one(g,function(){B.off(e,
b)}))}))});return g}function ma(a,b){if("function"==typeof a&&a.fn){if(b||void 0===a.fn.dataset)a.fn.dataset=K;if(b||void 0===a.fn.deletes)a.fn.deletes=fa;var c=a.fn;j(["inX","inY","inViewport"],function(d){(b||!c[d])&&(c[d]=function(b,c){return a(u(this,function(a){return!!a&&!c===g[d](a,b)}))})})}return g}if("function"!=typeof e)try{console.log("Response was unable to run due to missing dependency.")}catch(Ga){}var g,O=this,r="Response",ya=O[r],na="init"+r,k=window,oa=document,m=oa.documentElement,
N=e.domReady||e,B=e(k),D=k.screen,n=Array.prototype,E=Object.prototype,xa=n.slice,za=n.concat,Aa=E.toString,ua=E.hasOwnProperty,S=Array.isArray||function(a){return"[object Array]"===Aa.call(a)},pa={width:[0,320,481,641,961,1025,1281],height:[0,481],ratio:[1,1.5,2]},la,p,s,n={},t={},qa={},P={all:[]},Ba=1,Q=D.width,R=D.height,C=Q>R?Q:R,Ca=Q+R-C,D=function(){return Q},E=function(){return R},Da=/[^a-z0-9_\-\.]/gi,X=/^[\W\s]+|[\W\s]+$|/g,wa=/([a-z])([A-Z])/g,va=/-(.)/g,W=/^data-(.+)$/,ba=Object.create||
function(a){function b(){}b.prototype=a;return new b},M=function(a,b){b=b||r;return a.replace(X,"")+"."+b.replace(X,"")},ca={allLoaded:M("allLoaded"),crossover:M("crossover")},V=(p=k.matchMedia||k.msMatchMedia)||function(){return{}},A,ra=k;s=m.clientWidth;var F=ra.innerWidth;A=p&&s<F&&!0===p("(min-width:"+F+"px)").matches?function(){return ra.innerWidth}:function(){return m.clientWidth};var z,sa=k;s=m.clientHeight;F=sa.innerHeight;z=p&&s<F&&!0===p("(min-height:"+F+"px)").matches?function(){return sa.innerHeight}:
function(){return m.clientHeight};p=H(A);s=H(z);n.band=H(D);n.wave=H(E);var Ea=function(a){return"string"==typeof a?a.toLowerCase().replace(Da,""):""},ta=ca.crossover,Fa=Math.min;la={$e:0,mode:0,breakpoints:null,prefix:null,prop:"width",keys:[],dynamic:null,custom:0,values:[],fn:0,verge:null,newValue:0,currValue:1,aka:null,lazy:null,i:0,uid:null,reset:function(){for(var a=this.breakpoints,b=a.length,c=0;!c&&b--;)this.fn(a[b])&&(c=b);c!==this.i&&(B.trigger(ta).trigger(this.prop+ta),this.i=c||0);return this},
configure:function(a){U(this,a);var b,c,d=!0;b=this.prop;this.uid=Ba++;this.verge=isFinite(this.verge)?this.verge:Fa(C,500);this.fn=t[b]||q("create @fn");"boolean"!=typeof this.dynamic&&(this.dynamic="device"!==b.substring(0,6));this.custom=qa[b];c=this.prefix?u(w(G(this.prefix),Ea)):["min-"+b+"-"];a=1<c.length?c.slice(1):0;this.prefix=c[0];c=this.breakpoints;S(c)?(j(c,function(a){if(!a&&0!==a)throw"invalid breakpoint";d=d&&isFinite(a)}),c=d?c.sort(function(a,b){return a-b}):c,c.length||q("create @breakpoints")):
c=pa[b]||pa[b.split("-").pop()]||q("create @prop");this.breakpoints=d?u(c,function(a){return a<=C}):c;this.keys=T(this.breakpoints,this.prefix);this.aka=null;if(a){c=[];for(b=a.length;b--;)c.push(T(this.breakpoints,a[b]));this.aka=c;this.keys=za.apply(this.keys,c)}P.all=P.all.concat(P[this.uid]=this.keys);return this},target:function(){this.$e=e(ha(P[this.uid]));ja(this.$e,na);this.keys.push(na);return this},decideValue:function(){for(var a=null,b=this.breakpoints,c=b.length,d=c;null==a&&d--;)this.fn(b[d])&&
(a=this.values[d]);this.newValue="string"===typeof a?a:this.values[c];return this},prepareData:function(a){this.$e=e(a);this.mode=ia(a);this.values=$(this.$e,this.keys);if(this.aka)for(a=this.aka.length;a--;)this.values=U(this.values,$(this.$e,this.aka[a]));return this.decideValue()},updateDOM:function(){if(this.currValue===this.newValue)return this;this.currValue=this.newValue;0<this.mode?this.$e[0].setAttribute("src",this.newValue):null==this.newValue?this.$e.empty&&this.$e.empty():this.$e.html?
this.$e.html(this.newValue):(this.$e.empty&&this.$e.empty(),this.$e[0].innerHTML=this.newValue);return this}};t.width=p;t.height=s;t["device-width"]=n.band;t["device-height"]=n.wave;t["device-pixel-ratio"]=y;g={deviceMin:function(){return Ca},deviceMax:function(){return C},noConflict:function(a){O[r]===g&&(O[r]=ya);"function"==typeof a&&a.call(O,g);return g},chain:function(a,b){a=arguments.length?a:e;return ma(a,b)},bridge:ma,create:ka,addTest:function(a,b){"string"==typeof a&&"function"==typeof b&&
(t[a]=b,qa[a]=1);return g},datatize:I,camelize:da,render:ea,store:ja,access:$,target:function(a){return e(ha(G(a)))},object:ba,crossover:function(a,b){var c,d=ca.crossover;"function"==typeof a&&(c=b,b=a,a=c);B.on(a?""+a+d:d,b);return g},action:function(a){x(a,function(a){N(a);aa(a)});return g},resize:aa,ready:N,affix:T,sift:u,dpr:y,deletes:ga,scrollX:function(){return window.pageXOffset||m.scrollLeft},scrollY:function(){return window.pageYOffset||m.scrollTop},deviceW:D,deviceH:E,device:n,inX:function(a,
b){var c=Y(J(a),b);return!!c&&0<=c.right&&c.left<=A()},inY:function(a,b){var c=Y(J(a),b);return!!c&&0<=c.bottom&&c.top<=z()},route:x,merge:U,media:V,wave:s,band:p,map:w,each:j,inViewport:Z,dataset:L,viewportH:z,viewportW:A};N(function(){var a,b=L(oa.body,"responsejs");b&&((a=!!k.JSON&&JSON.parse)?b=a(b):e.parseJSON&&(b=e.parseJSON(b)),b&&b.create&&ka(b.create));m.className=m.className.replace(/(^|\s)(no-)?responsejs(\s|$)/,"$1$3")+" responsejs "});return g});