Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

included the window.matchMedia polyfill externally from the main resp…

…ond.js function. The source code for this polyfill is here https://github.com/paulirish/matchMedia.js, and including it out-of-the-box will make things easier to keep updated, and allow for smaller file compression for those already including it via Modernizr or otherwise (if you are, you can delete it from Respond.js).
  • Loading branch information...
commit 4d60f45716b8395e6f24238f9dc5e34c857e87f2 1 parent 8016973
scottjehl authored
Showing with 40 additions and 40 deletions.
  1. +5 −1 respond.min.js
  2. +35 −39 respond.src.js
View
6 respond.min.js
@@ -1,2 +1,6 @@
+/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
+/*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */
+window.matchMedia=window.matchMedia||(function(e,f){var c,a=e.documentElement,b=a.firstElementChild||a.firstChild,d=e.createElement("body"),g=e.createElement("div");g.id="mq-test-1";g.style.cssText="position:absolute;top:-100em";d.appendChild(g);return function(h){g.innerHTML='&shy;<style media="'+h+'"> #mq-test-1 { width: 42px; }</style>';a.insertBefore(d,b);c=g.offsetWidth==42;a.removeChild(d);return{matches:c,media:h}}})(document);
+
/*! Respond.js v1.0.1pre: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
-(function(e,h){e.respond={};respond.update=function(){};respond.mediaQueriesSupported=h;if(h){return}var u=e.document,r=u.documentElement,i=[],k=[],p=[],o={},g=30,f=u.getElementsByTagName("head")[0]||r,b=f.getElementsByTagName("link"),d=[],a=function(){var B=b,w=B.length,z=0,y,x,A,v;for(;z<w;z++){y=B[z],x=y.href,A=y.media,v=y.rel&&y.rel.toLowerCase()==="stylesheet";if(!!x&&v&&!o[x]){if(y.styleSheet&&y.styleSheet.rawCssText){m(y.styleSheet.rawCssText,x,A);o[x]=true}else{if(!/^([a-zA-Z]+?:(\/\/)?)/.test(x)||x.replace(RegExp.$1,"").split("/")[0]===e.location.host){d.push({href:x,media:A})}}}}t()},t=function(){if(d.length){var v=d.shift();n(v.href,function(w){m(w,v.href,v.media);o[v.href]=true;t()})}},m=function(G,v,x){var E=G.match(/@media[^\{]+\{([^\{\}]+\{[^\}\{]+\})+/gi),H=E&&E.length||0,v=v.substring(0,v.lastIndexOf("/")),w=function(I){return I.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,"$1"+v+"$2$3")},y=!H&&x,B=0,A,C,D,z,F;if(v.length){v+="/"}if(y){H=1}for(;B<H;B++){A=0;if(y){C=x;k.push(w(G))}else{C=E[B].match(/@media *([^\{]+)\{([\S\s]+?)$/)&&RegExp.$1;k.push(RegExp.$2&&w(RegExp.$2))}z=C.split(",");F=z.length;for(;A<F;A++){D=z[A];i.push({media:D.match(/(only\s+)?([a-zA-Z]+)(\sand)?/)&&RegExp.$2,rules:k.length-1,minw:D.match(/\(min\-width:[\s]*([\s]*[0-9]+)px[\s]*\)/)&&parseFloat(RegExp.$1),maxw:D.match(/\(max\-width:[\s]*([\s]*[0-9]+)px[\s]*\)/)&&parseFloat(RegExp.$1)})}}j()},l,q,j=function(D){var v="clientWidth",x=r[v],C=u.compatMode==="CSS1Compat"&&x||u.body[v]||x,y={},B=b[b.length-1],w=(new Date()).getTime();if(D&&l&&w-l<g){clearTimeout(q);q=setTimeout(j,g);return}else{l=w}for(var z in i){var E=i[z];if(!E.minw&&!E.maxw||(!E.minw||E.minw&&C>=E.minw)&&(!E.maxw||E.maxw&&C<=E.maxw)){if(!y[E.media]){y[E.media]=[]}y[E.media].push(k[E.rules])}}for(var z in p){if(p[z]&&p[z].parentNode===f){f.removeChild(p[z])}}for(var z in y){var F=u.createElement("style"),A=y[z].join("\n");F.type="text/css";F.media=z;f.insertBefore(F,B.nextSibling);if(F.styleSheet){F.styleSheet.cssText=A}else{F.appendChild(u.createTextNode(A))}p.push(F)}},n=function(v,x){var w=c();if(!w){return}w.open("GET",v,true);w.onreadystatechange=function(){if(w.readyState!=4||w.status!=200&&w.status!=304){return}x(w.responseText)};if(w.readyState==4){return}w.send(null)},c=(function(){var v=false;try{v=new XMLHttpRequest()}catch(w){v=new ActiveXObject("Microsoft.XMLHTTP")}return function(){return v}})();a();respond.update=a;function s(){j(true)}if(e.addEventListener){e.addEventListener("resize",s,false)}else{if(e.attachEvent){e.attachEvent("onresize",s)}}})(this,(function(f){if(f.matchMedia){return true}var e,i=document,c=i.documentElement,g=c.firstElementChild||c.firstChild,h=!i.body,d=i.body||i.createElement("body"),b=i.createElement("div"),a="only all";b.id="mq-test-1";b.style.cssText="position:absolute;top:-99em";d.appendChild(b);b.innerHTML='_<style media="'+a+'"> #mq-test-1 { width: 9px; }</style>';if(h){c.insertBefore(d,g)}b.removeChild(b.firstChild);e=b.offsetWidth==9;if(h){c.removeChild(d)}else{d.removeChild(b)}return e})(this));
+(function(e){e.respond={};respond.update=function(){};respond.mediaQueriesSupported=e.matchMedia&&e.matchMedia("only all").matches;if(respond.mediaQueriesSupported){return}var t=e.document,q=t.documentElement,h=[],j=[],o=[],n={},g=30,f=t.getElementsByTagName("head")[0]||q,b=f.getElementsByTagName("link"),d=[],a=function(){var A=b,v=A.length,y=0,x,w,z,u;for(;y<v;y++){x=A[y],w=x.href,z=x.media,u=x.rel&&x.rel.toLowerCase()==="stylesheet";if(!!w&&u&&!n[w]){if(x.styleSheet&&x.styleSheet.rawCssText){l(x.styleSheet.rawCssText,w,z);n[w]=true}else{if(!/^([a-zA-Z]+?:(\/\/)?)/.test(w)||w.replace(RegExp.$1,"").split("/")[0]===e.location.host){d.push({href:w,media:z})}}}}s()},s=function(){if(d.length){var u=d.shift();m(u.href,function(v){l(v,u.href,u.media);n[u.href]=true;s()})}},l=function(F,u,w){var D=F.match(/@media[^\{]+\{([^\{\}]+\{[^\}\{]+\})+/gi),G=D&&D.length||0,u=u.substring(0,u.lastIndexOf("/")),v=function(H){return H.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,"$1"+u+"$2$3")},x=!G&&w,A=0,z,B,C,y,E;if(u.length){u+="/"}if(x){G=1}for(;A<G;A++){z=0;if(x){B=w;j.push(v(F))}else{B=D[A].match(/@media *([^\{]+)\{([\S\s]+?)$/)&&RegExp.$1;j.push(RegExp.$2&&v(RegExp.$2))}y=B.split(",");E=y.length;for(;z<E;z++){C=y[z];h.push({media:C.match(/(only\s+)?([a-zA-Z]+)(\sand)?/)&&RegExp.$2,rules:j.length-1,minw:C.match(/\(min\-width:[\s]*([\s]*[0-9]+)px[\s]*\)/)&&parseFloat(RegExp.$1),maxw:C.match(/\(max\-width:[\s]*([\s]*[0-9]+)px[\s]*\)/)&&parseFloat(RegExp.$1)})}}i()},k,p,i=function(C){var u="clientWidth",w=q[u],B=t.compatMode==="CSS1Compat"&&w||t.body[u]||w,x={},A=b[b.length-1],v=(new Date()).getTime();if(C&&k&&v-k<g){clearTimeout(p);p=setTimeout(i,g);return}else{k=v}for(var y in h){var D=h[y];if(!D.minw&&!D.maxw||(!D.minw||D.minw&&B>=D.minw)&&(!D.maxw||D.maxw&&B<=D.maxw)){if(!x[D.media]){x[D.media]=[]}x[D.media].push(j[D.rules])}}for(var y in o){if(o[y]&&o[y].parentNode===f){f.removeChild(o[y])}}for(var y in x){var E=t.createElement("style"),z=x[y].join("\n");E.type="text/css";E.media=y;f.insertBefore(E,A.nextSibling);if(E.styleSheet){E.styleSheet.cssText=z}else{E.appendChild(t.createTextNode(z))}o.push(E)}},m=function(u,w){var v=c();if(!v){return}v.open("GET",u,true);v.onreadystatechange=function(){if(v.readyState!=4||v.status!=200&&v.status!=304){return}w(v.responseText)};if(v.readyState==4){return}v.send(null)},c=(function(){var u=false;try{u=new XMLHttpRequest()}catch(v){u=new ActiveXObject("Microsoft.XMLHTTP")}return function(){return u}})();a();respond.update=a;function r(){i(true)}if(e.addEventListener){e.addEventListener("resize",r,false)}else{if(e.attachEvent){e.attachEvent("onresize",r)}}})(this);
View
74 respond.src.js
@@ -1,5 +1,36 @@
+/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
+/*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */
+window.matchMedia = window.matchMedia || (function(doc, undefined){
+
+ var bool,
+ docElem = doc.documentElement,
+ refNode = docElem.firstElementChild || docElem.firstChild,
+ // fakeBody required for <FF4 when executed in <head>
+ fakeBody = doc.createElement('body'),
+ div = doc.createElement('div');
+
+ div.id = 'mq-test-1';
+ div.style.cssText = "position:absolute;top:-100em";
+ fakeBody.appendChild(div);
+
+ return function(q){
+
+ div.innerHTML = '&shy;<style media="'+q+'"> #mq-test-1 { width: 42px; }</style>';
+
+ docElem.insertBefore(fakeBody, refNode);
+ bool = div.offsetWidth == 42;
+ docElem.removeChild(fakeBody);
+
+ return { matches: bool, media: q };
+ };
+
+})(document);
+
+
+
+
/*! Respond.js v1.0.1pre: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
-(function( win, mqSupported ){
+(function( win ){
//exposed namespace
win.respond = {};
@@ -7,10 +38,10 @@
respond.update = function(){};
//expose media query support flag for external use
- respond.mediaQueriesSupported = mqSupported;
+ respond.mediaQueriesSupported = win.matchMedia && win.matchMedia( "only all" ).matches;
//if media queries are supported, exit here
- if( mqSupported ){ return; }
+ if( respond.mediaQueriesSupported ){ return; }
//define vars
var doc = win.document,
@@ -243,39 +274,4 @@
else if( win.attachEvent ){
win.attachEvent( "onresize", callMedia );
}
-})(
- this,
- (function( win ){
-
- //for speed, flag browsers with window.matchMedia support and IE 9 as supported
- if( win.matchMedia ){ return true; }
-
- var bool,
- doc = document,
- docElem = doc.documentElement,
- refNode = docElem.firstElementChild || docElem.firstChild,
- // fakeBody required for <FF4 when executed in <head>
- fakeUsed = !doc.body,
- fakeBody = doc.body || doc.createElement( "body" ),
- div = doc.createElement( "div" ),
- q = "only all";
-
- div.id = "mq-test-1";
- div.style.cssText = "position:absolute;top:-99em";
- fakeBody.appendChild( div );
-
- div.innerHTML = '_<style media="'+q+'"> #mq-test-1 { width: 9px; }</style>';
- if( fakeUsed ){
- docElem.insertBefore( fakeBody, refNode );
- }
- div.removeChild( div.firstChild );
- bool = div.offsetWidth == 9;
- if( fakeUsed ){
- docElem.removeChild( fakeBody );
- }
- else{
- fakeBody.removeChild( div );
- }
- return bool;
- })( this )
-);
+})(this);
Please sign in to comment.
Something went wrong with that request. Please try again.