-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjRespond-1.0.0.min.js
21 lines (16 loc) · 2.5 KB
/
jRespond-1.0.0.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
License
-------
jRespond copyright (c) 2013 Dave Porter.
Available [on GitHub](https://github.com/dcporter/jrespond).
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License
[here](http://www.apache.org/licenses/LICENSE-2.0).
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
(function(h){h.extend({respondToHeights:function(k,j,l,m,i){a(SET_TYPE_HEIGHT,k,j,l,m,i)},respondToWidths:function(k,j,l,m,i){a(SET_TYPE_WIDTH,k,j,l,m,i)},respondToAspectRatios:function(k,j,l,m,i){a(SET_TYPE_ASPECT_RATIO,k,j,l,m,i)},respondCurrentState:function(i){return b[i]},respondCancel:function(l){delete f[l];delete b[l];var k,j=e.length;for(k=0;k<j;k++){if(e[k]&&e[k].namespace===l){e.splice(k,1);return}}}});SET_TYPE_WIDTH="width";SET_TYPE_HEIGHT="height";SET_TYPE_ASPECT_RATIO="ratio";var e=[],f={},g,b={};var c=function(n,k,o){var m,j=k.length,l;for(m=0;m<j;m++){if(n<=o[m]){l=k[m];break}}if(!l){l=k[j-1]}return l};var d=function(p){if(!g||!g.length){g=window.$("body")}if(!g||!g.length){return}var k=p&&p.isResponsiveJSSet?[p]:e;if(!k.length){return}var j=window.innerWidth,t=window.innerHeight,o=j/t,q,n,m=k.length,l,s,r;for(l=0;l<m;l++){s=k[l];switch(s.type){case SET_TYPE_WIDTH:r=j;break;case SET_TYPE_HEIGHT:r=t;break;case SET_TYPE_ASPECT_RATIO:r=o;break;default:continue}q=b[s.namespace];n=c(r,s.states,s.thresholds);if(q!==n){var u=s.selector?g.find(s.selector):null;if(u){if(q){u.removeClass(s.namespace+"-"+q)}u.addClass(s.namespace+"-"+n)}b[s.namespace]=n;if(s.callback){s.callback(s.namespace,n,q)}}}};if(window.addEventListener){window.addEventListener("resize",d)}else{if(window.attachEvent){window.attachEvent("onresize",d)}else{window.onresize=d}}function a(l,k,j,m,o,i){if(!k||!j||!m){throw"ResponsiveJS Error: Attempted to add set without specifying namespace, states or thresholds."}if(f[k]){throw"ResponsiveJS Error: Attempted to add class sets with duplicate namespace."}if(j.length-1!==m.length){throw"ResponsiveJS Error: class list must include one more item than thresholds list."}var n={type:l,namespace:k,states:j,thresholds:m,selector:i||null,callback:o instanceof Function?o:null,isResponsiveJSSet:true};e.push(n);f[k]=n;window.setTimeout(function(){d(n)},1)}})(jQuery);