Skip to content
This repository
Browse code

improvements to code quality after running through jshint.

  • Loading branch information...
commit 8991f5d0d73e84a6b73d60994659b7936d170d5f 1 parent b21c578
Scott Jehl authored

Showing 2 changed files with 138 additions and 125 deletions. Show diff stats Hide diff stats

  1. +2 2 respond.min.js
  2. +136 123 respond.src.js
4 respond.min.js
... ... @@ -1,6 +1,6 @@
1 1 /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
2 2 /*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */
3   -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.style.background="none";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);
  3 +window.matchMedia=window.matchMedia||function(a){"use strict";var c,d=a.documentElement,e=d.firstElementChild||d.firstChild,f=a.createElement("body"),g=a.createElement("div");return g.id="mq-test-1",g.style.cssText="position:absolute;top:-100em",f.style.background="none",f.appendChild(g),function(a){return g.innerHTML='&shy;<style media="'+a+'"> #mq-test-1 { width: 42px; }</style>',d.insertBefore(f,e),c=42===g.offsetWidth,d.removeChild(f),{matches:c,media:a}}}(document);
4 4
5 5 /*! Respond.js v1.1.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
6   -(function(e){e.respond={};respond.update=function(){};respond.mediaQueriesSupported=e.matchMedia&&e.matchMedia("only all").matches;if(respond.mediaQueriesSupported){return}var w=e.document,s=w.documentElement,i=[],k=[],q=[],o={},h=30,f=w.getElementsByTagName("head")[0]||s,g=w.getElementsByTagName("base")[0],b=f.getElementsByTagName("link"),d=[],a=function(){var D=b,y=D.length,B=0,A,z,C,x;for(;B<y;B++){A=D[B],z=A.href,C=A.media,x=A.rel&&A.rel.toLowerCase()==="stylesheet";if(!!z&&x&&!o[z]){if(A.styleSheet&&A.styleSheet.rawCssText){m(A.styleSheet.rawCssText,z,C);o[z]=true}else{if((!/^([a-zA-Z:]*\/\/)/.test(z)&&!g)||z.replace(RegExp.$1,"").split("/")[0]===e.location.host){d.push({href:z,media:C})}}}}u()},u=function(){if(d.length){var x=d.shift();n(x.href,function(y){m(y,x.href,x.media);o[x.href]=true;u()})}},m=function(I,x,z){var G=I.match(/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi),J=G&&G.length||0,x=x.substring(0,x.lastIndexOf("/")),y=function(K){return K.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,"$1"+x+"$2$3")},A=!J&&z,D=0,C,E,F,B,H;if(x.length){x+="/"}if(A){J=1}for(;D<J;D++){C=0;if(A){E=z;k.push(y(I))}else{E=G[D].match(/@media *([^\{]+)\{([\S\s]+?)$/)&&RegExp.$1;k.push(RegExp.$2&&y(RegExp.$2))}B=E.split(",");H=B.length;for(;C<H;C++){F=B[C];i.push({media:F.split("(")[0].match(/(only\s+)?([a-zA-Z]+)\s?/)&&RegExp.$2||"all",rules:k.length-1,hasquery:F.indexOf("(")>-1,minw:F.match(/\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:F.match(/\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}}j()},l,r,v=function(){var z,A=w.createElement("div"),x=w.body,y=false;A.style.cssText="position:absolute;font-size:1em;width:1em";if(!x){x=y=w.createElement("body");x.style.background="none"}x.appendChild(A);s.insertBefore(x,s.firstChild);z=A.offsetWidth;if(y){s.removeChild(x)}else{x.removeChild(A)}z=p=parseFloat(z);return z},p,j=function(I){var x="clientWidth",B=s[x],H=w.compatMode==="CSS1Compat"&&B||w.body[x]||B,D={},G=b[b.length-1],z=(new Date()).getTime();if(I&&l&&z-l<h){clearTimeout(r);r=setTimeout(j,h);return}else{l=z}for(var E in i){var K=i[E],C=K.minw,J=K.maxw,A=C===null,L=J===null,y="em";if(!!C){C=parseFloat(C)*(C.indexOf(y)>-1?(p||v()):1)}if(!!J){J=parseFloat(J)*(J.indexOf(y)>-1?(p||v()):1)}if(!K.hasquery||(!A||!L)&&(A||H>=C)&&(L||H<=J)){if(!D[K.media]){D[K.media]=[]}D[K.media].push(k[K.rules])}}for(var E in q){if(q[E]&&q[E].parentNode===f){f.removeChild(q[E])}}for(var E in D){var M=w.createElement("style"),F=D[E].join("\n");M.type="text/css";M.media=E;f.insertBefore(M,G.nextSibling);if(M.styleSheet){M.styleSheet.cssText=F}else{M.appendChild(w.createTextNode(F))}q.push(M)}},n=function(x,z){var y=c();if(!y){return}y.open("GET",x,true);y.onreadystatechange=function(){if(y.readyState!=4||y.status!=200&&y.status!=304){return}z(y.responseText)};if(y.readyState==4){return}y.send(null)},c=(function(){var x=false;try{x=new XMLHttpRequest()}catch(y){x=new ActiveXObject("Microsoft.XMLHTTP")}return function(){return x}})();a();respond.update=a;function t(){j(true)}if(e.addEventListener){e.addEventListener("resize",t,false)}else{if(e.attachEvent){e.attachEvent("onresize",t)}}})(this);
  6 +(function(a){"use strict";function x(){u(!0)}var b={};if(a.respond=b,b.update=function(){},b.mediaQueriesSupported=a.matchMedia&&a.matchMedia("only all").matches,!b.mediaQueriesSupported){var q,r,t,c=a.document,d=c.documentElement,e=[],f=[],g=[],h={},i=30,j=c.getElementsByTagName("head")[0]||d,k=c.getElementsByTagName("base")[0],l=j.getElementsByTagName("link"),m=[],n=function(){for(var b=0;l.length>b;b++){var c=l[b],d=c.href,e=c.media,f=c.rel&&"stylesheet"===c.rel.toLowerCase();d&&f&&!h[d]&&(c.styleSheet&&c.styleSheet.rawCssText?(p(c.styleSheet.rawCssText,d,e),h[d]=!0):(!/^([a-zA-Z:]*\/\/)/.test(d)&&!k||d.replace(RegExp.$1,"").split("/")[0]===a.location.host)&&m.push({href:d,media:e}))}o()},o=function(){if(m.length){var a=m.shift();v(a.href,function(b){p(b,a.href,a.media),h[a.href]=!0,o()})}},p=function(a,b,c){var d=a.match(/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi),g=d&&d.length||0;b=b.substring(0,b.lastIndexOf("/"));var h=function(a){return a.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,"$1"+b+"$2$3")},i=!g&&c;b.length&&(b+="/"),i&&(g=1);for(var j=0;g>j;j++){var k,l,m,n;i?(k=c,f.push(h(a))):(k=d[j].match(/@media *([^\{]+)\{([\S\s]+?)$/)&&RegExp.$1,f.push(RegExp.$2&&h(RegExp.$2))),m=k.split(","),n=m.length;for(var o=0;n>o;o++)l=m[o],e.push({media:l.split("(")[0].match(/(only\s+)?([a-zA-Z]+)\s?/)&&RegExp.$2||"all",rules:f.length-1,hasquery:l.indexOf("(")>-1,minw:l.match(/\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:l.match(/\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}u()},s=function(){var a,b=c.createElement("div"),e=c.body,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",e||(e=f=c.createElement("body"),e.style.background="none"),e.appendChild(b),d.insertBefore(e,d.firstChild),a=b.offsetWidth,f?d.removeChild(e):e.removeChild(b),a=t=parseFloat(a)},u=function(a){var b="clientWidth",h=d[b],k="CSS1Compat"===c.compatMode&&h||c.body[b]||h,m={},n=l[l.length-1],o=(new Date).getTime();if(a&&q&&i>o-q)return clearTimeout(r),r=setTimeout(u,i),void 0;q=o;for(var p in e)if(e.hasOwnProperty(p)){var v=e[p],w=v.minw,x=v.maxw,y=null===w,z=null===x,A="em";w&&(w=parseFloat(w)*(w.indexOf(A)>-1?t||s():1)),x&&(x=parseFloat(x)*(x.indexOf(A)>-1?t||s():1)),v.hasquery&&(y&&z||!(y||k>=w)||!(z||x>=k))||(m[v.media]||(m[v.media]=[]),m[v.media].push(f[v.rules]))}for(var B in g)g.hasOwnProperty(B)&&g[B]&&g[B].parentNode===j&&j.removeChild(g[B]);for(var C in m)if(m.hasOwnProperty(C)){var D=c.createElement("style"),E=m[p].join("\n");D.type="text/css",D.media=C,j.insertBefore(D,n.nextSibling),D.styleSheet?D.styleSheet.cssText=E:D.appendChild(c.createTextNode(E)),g.push(D)}},v=function(a,b){var c=w();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))},w=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}();n(),b.update=n,a.addEventListener?a.addEventListener("resize",x,!1):a.attachEvent&&a.attachEvent("onresize",x)}})(this);
259 respond.src.js
... ... @@ -1,75 +1,84 @@
1 1 /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
2 2 /*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */
3   -window.matchMedia = window.matchMedia || (function(doc, undefined){
4   -
  3 +
  4 +window.matchMedia = window.matchMedia || (function( doc, undefined ) {
  5 +
  6 + "use strict";
  7 +
5 8 var bool,
6   - docElem = doc.documentElement,
7   - refNode = docElem.firstElementChild || docElem.firstChild,
  9 + docElem = doc.documentElement,
  10 + refNode = docElem.firstElementChild || docElem.firstChild,
8 11 // fakeBody required for <FF4 when executed in <head>
9   - fakeBody = doc.createElement('body'),
10   - div = doc.createElement('div');
11   -
12   - div.id = 'mq-test-1';
  12 + fakeBody = doc.createElement( "body" ),
  13 + div = doc.createElement( "div" );
  14 +
  15 + div.id = "mq-test-1";
13 16 div.style.cssText = "position:absolute;top:-100em";
14 17 fakeBody.style.background = "none";
15 18 fakeBody.appendChild(div);
16   -
  19 +
17 20 return function(q){
18   -
19   - div.innerHTML = '&shy;<style media="'+q+'"> #mq-test-1 { width: 42px; }</style>';
20   -
21   - docElem.insertBefore(fakeBody, refNode);
22   - bool = div.offsetWidth == 42;
23   - docElem.removeChild(fakeBody);
24   -
25   - return { matches: bool, media: q };
  21 +
  22 + div.innerHTML = "&shy;<style media=\"" + q + "\"> #mq-test-1 { width: 42px; }</style>";
  23 +
  24 + docElem.insertBefore( fakeBody, refNode );
  25 + bool = div.offsetWidth === 42;
  26 + docElem.removeChild( fakeBody );
  27 +
  28 + return {
  29 + matches: bool,
  30 + media: q
  31 + };
  32 +
26 33 };
27   -
28   -})(document);
  34 +
  35 +}( document ));
  36 +
29 37
30 38
31 39
32 40
33 41 /*! Respond.js v1.1.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
34 42 (function( win ){
  43 +
  44 + "use strict";
  45 +
35 46 //exposed namespace
36   - win.respond = {};
  47 + var respond = {};
  48 + win.respond = respond;
37 49
38 50 //define update even in native-mq-supporting browsers, to avoid errors
39   - respond.update = function(){};
  51 + respond.update = function(){};
40 52
41 53 //expose media query support flag for external use
42 54 respond.mediaQueriesSupported = win.matchMedia && win.matchMedia( "only all" ).matches;
43 55
44 56 //if media queries are supported, exit here
45   - if( respond.mediaQueriesSupported ){ return; }
  57 + if( respond.mediaQueriesSupported ){
  58 + return;
  59 + }
46 60
47 61 //define vars
48   - var doc = win.document,
49   - docElem = doc.documentElement,
50   - mediastyles = [],
51   - rules = [],
52   - appendedEls = [],
53   - parsedSheets = {},
54   - resizeThrottle = 30,
55   - head = doc.getElementsByTagName( "head" )[0] || docElem,
56   - base = doc.getElementsByTagName( "base" )[0],
57   - links = head.getElementsByTagName( "link" ),
58   - requestQueue = [],
  62 + var doc = win.document,
  63 + docElem = doc.documentElement,
  64 + mediastyles = [],
  65 + rules = [],
  66 + appendedEls = [],
  67 + parsedSheets = {},
  68 + resizeThrottle = 30,
  69 + head = doc.getElementsByTagName( "head" )[0] || docElem,
  70 + base = doc.getElementsByTagName( "base" )[0],
  71 + links = head.getElementsByTagName( "link" ),
  72 + requestQueue = [],
59 73
60 74 //loop stylesheets, send text content to translate
61   - ripCSS = function(){
62   - var sheets = links,
63   - sl = sheets.length,
64   - i = 0,
65   - //vars for loop:
66   - sheet, href, media, isCSS;
  75 + ripCSS = function(){
67 76
68   - for( ; i < sl; i++ ){
69   - sheet = sheets[ i ],
70   - href = sheet.href,
71   - media = sheet.media,
72   - isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet";
  77 + for( var i = 0; i < links.length; i++ ){
  78 + var sheet = links[ i ],
  79 + href = sheet.href,
  80 + media = sheet.media,
  81 + isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet";
73 82
74 83 //only links plz and prevent re-parsing
75 84 if( !!href && isCSS && !parsedSheets[ href ] ){
@@ -78,8 +87,8 @@ window.matchMedia = window.matchMedia || (function(doc, undefined){
78 87 translate( sheet.styleSheet.rawCssText, href, media );
79 88 parsedSheets[ href ] = true;
80 89 } else {
81   - if( (!/^([a-zA-Z:]*\/\/)/.test( href ) && !base)
82   - || href.replace( RegExp.$1, "" ).split( "/" )[0] === win.location.host ){
  90 + if( (!/^([a-zA-Z:]*\/\/)/.test( href ) && !base) ||
  91 + href.replace( RegExp.$1, "" ).split( "/" )[0] === win.location.host ){
83 92 requestQueue.push( {
84 93 href: href,
85 94 media: media
@@ -105,18 +114,17 @@ window.matchMedia = window.matchMedia || (function(doc, undefined){
105 114 },
106 115
107 116 //find media blocks in css text, convert to style blocks
108   - translate = function( styles, href, media ){
109   - var qs = styles.match( /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi ),
110   - ql = qs && qs.length || 0,
111   - //try to get CSS path
112   - href = href.substring( 0, href.lastIndexOf( "/" )),
113   - repUrls = function( css ){
  117 + translate = function( styles, href, media ){
  118 + var qs = styles.match( /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi ),
  119 + ql = qs && qs.length || 0;
  120 +
  121 + //try to get CSS path
  122 + href = href.substring( 0, href.lastIndexOf( "/" ) );
  123 +
  124 + var repUrls = function( css ){
114 125 return css.replace( /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, "$1" + href + "$2$3" );
115 126 },
116   - useMedia = !ql && media,
117   - //vars used in loop
118   - i = 0,
119   - j, fullq, thisq, eachq, eql;
  127 + useMedia = !ql && media;
120 128
121 129 //if path exists, tack on trailing slash
122 130 if( href.length ){ href += "/"; }
@@ -128,11 +136,10 @@ window.matchMedia = window.matchMedia || (function(doc, undefined){
128 136 if( useMedia ){
129 137 ql = 1;
130 138 }
131   -
132 139
133   - for( ; i < ql; i++ ){
134   - j = 0;
135   -
  140 + for( var i = 0; i < ql; i++ ){
  141 + var fullq, thisq, eachq, eql;
  142 +
136 143 //media attr
137 144 if( useMedia ){
138 145 fullq = media;
@@ -140,34 +147,34 @@ window.matchMedia = window.matchMedia || (function(doc, undefined){
140 147 }
141 148 //parse for styles
142 149 else{
143   - fullq = qs[ i ].match( /@media *([^\{]+)\{([\S\s]+?)$/ ) && RegExp.$1;
  150 + fullq = qs[ i ].match( /@media *([^\{]+)\{([\S\s]+?)$/ ) && RegExp.$1;
144 151 rules.push( RegExp.$2 && repUrls( RegExp.$2 ) );
145 152 }
146 153
147   - eachq = fullq.split( "," );
148   - eql = eachq.length;
  154 + eachq = fullq.split( "," );
  155 + eql = eachq.length;
149 156
150   - for( ; j < eql; j++ ){
151   - thisq = eachq[ j ];
  157 + for( var j = 0; j < eql; j++ ){
  158 + thisq = eachq[ j ];
152 159 mediastyles.push( {
153   - media : thisq.split( "(" )[ 0 ].match( /(only\s+)?([a-zA-Z]+)\s?/ ) && RegExp.$2 || "all",
154   - rules : rules.length - 1,
155   - hasquery: thisq.indexOf("(") > -1,
156   - minw : thisq.match( /\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ),
157   - maxw : thisq.match( /\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" )
  160 + media : thisq.split( "(" )[ 0 ].match( /(only\s+)?([a-zA-Z]+)\s?/ ) && RegExp.$2 || "all",
  161 + rules : rules.length - 1,
  162 + hasquery : thisq.indexOf("(") > -1,
  163 + minw : thisq.match( /\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ),
  164 + maxw : thisq.match( /\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" )
158 165 } );
159 166 }
160 167 }
161 168
162 169 applyMedia();
163 170 },
164   -
  171 +
165 172 lastCall,
166 173
167 174 resizeDefer,
168 175
169 176 // returns the value of 1em in pixels
170   - getEmValue = function() {
  177 + getEmValue = function() {
171 178 var ret,
172 179 div = doc.createElement('div'),
173 180 body = doc.body,
@@ -203,13 +210,13 @@ window.matchMedia = window.matchMedia || (function(doc, undefined){
203 210 eminpx,
204 211
205 212 //enable/disable styles
206   - applyMedia = function( fromResize ){
207   - var name = "clientWidth",
208   - docElemProp = docElem[ name ],
209   - currWidth = doc.compatMode === "CSS1Compat" && docElemProp || doc.body[ name ] || docElemProp,
  213 + applyMedia = function( fromResize ){
  214 + var name = "clientWidth",
  215 + docElemProp = docElem[ name ],
  216 + currWidth = doc.compatMode === "CSS1Compat" && docElemProp || doc.body[ name ] || docElemProp,
210 217 styleBlocks = {},
211   - lastLink = links[ links.length-1 ],
212   - now = (new Date()).getTime();
  218 + lastLink = links[ links.length-1 ],
  219 + now = (new Date()).getTime();
213 220
214 221 //throttle resize calls
215 222 if( fromResize && lastCall && now - lastCall < resizeThrottle ){
@@ -218,61 +225,67 @@ window.matchMedia = window.matchMedia || (function(doc, undefined){
218 225 return;
219 226 }
220 227 else {
221   - lastCall = now;
  228 + lastCall = now;
222 229 }
223 230
224 231 for( var i in mediastyles ){
225   - var thisstyle = mediastyles[ i ],
226   - min = thisstyle.minw,
227   - max = thisstyle.maxw,
228   - minnull = min === null,
229   - maxnull = max === null,
230   - em = "em";
231   -
232   - if( !!min ){
233   - min = parseFloat( min ) * ( min.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
234   - }
235   - if( !!max ){
236   - max = parseFloat( max ) * ( max.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
237   - }
238   -
239   - // if there's no media query at all (the () part), or min or max is not null, and if either is present, they're true
240   - if( !thisstyle.hasquery || ( !minnull || !maxnull ) && ( minnull || currWidth >= min ) && ( maxnull || currWidth <= max ) ){
  232 + if( mediastyles.hasOwnProperty( i ) ){
  233 + var thisstyle = mediastyles[ i ],
  234 + min = thisstyle.minw,
  235 + max = thisstyle.maxw,
  236 + minnull = min === null,
  237 + maxnull = max === null,
  238 + em = "em";
  239 +
  240 + if( !!min ){
  241 + min = parseFloat( min ) * ( min.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
  242 + }
  243 + if( !!max ){
  244 + max = parseFloat( max ) * ( max.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
  245 + }
  246 +
  247 + // if there's no media query at all (the () part), or min or max is not null, and if either is present, they're true
  248 + if( !thisstyle.hasquery || ( !minnull || !maxnull ) && ( minnull || currWidth >= min ) && ( maxnull || currWidth <= max ) ){
241 249 if( !styleBlocks[ thisstyle.media ] ){
242 250 styleBlocks[ thisstyle.media ] = [];
243 251 }
244 252 styleBlocks[ thisstyle.media ].push( rules[ thisstyle.rules ] );
  253 + }
245 254 }
246 255 }
247 256
248 257 //remove any existing respond style element(s)
249   - for( var i in appendedEls ){
250   - if( appendedEls[ i ] && appendedEls[ i ].parentNode === head ){
251   - head.removeChild( appendedEls[ i ] );
  258 + for( var j in appendedEls ){
  259 + if( appendedEls.hasOwnProperty( j ) ){
  260 + if( appendedEls[ j ] && appendedEls[ j ].parentNode === head ){
  261 + head.removeChild( appendedEls[ j ] );
  262 + }
252 263 }
253 264 }
254 265
255 266 //inject active styles, grouped by media type
256   - for( var i in styleBlocks ){
257   - var ss = doc.createElement( "style" ),
258   - css = styleBlocks[ i ].join( "\n" );
259   -
260   - ss.type = "text/css";
261   - ss.media = i;
262   -
263   - //originally, ss was appended to a documentFragment and sheets were appended in bulk.
264   - //this caused crashes in IE in a number of circumstances, such as when the HTML element had a bg image set, so appending beforehand seems best. Thanks to @dvelyk for the initial research on this one!
265   - head.insertBefore( ss, lastLink.nextSibling );
266   -
267   - if ( ss.styleSheet ){
268   - ss.styleSheet.cssText = css;
269   - }
270   - else {
271   - ss.appendChild( doc.createTextNode( css ) );
272   - }
273   -
274   - //push to appendedEls to track for later removal
275   - appendedEls.push( ss );
  267 + for( var k in styleBlocks ){
  268 + if( styleBlocks.hasOwnProperty( k ) ){
  269 + var ss = doc.createElement( "style" ),
  270 + css = styleBlocks[ i ].join( "\n" );
  271 +
  272 + ss.type = "text/css";
  273 + ss.media = k;
  274 +
  275 + //originally, ss was appended to a documentFragment and sheets were appended in bulk.
  276 + //this caused crashes in IE in a number of circumstances, such as when the HTML element had a bg image set, so appending beforehand seems best. Thanks to @dvelyk for the initial research on this one!
  277 + head.insertBefore( ss, lastLink.nextSibling );
  278 +
  279 + if ( ss.styleSheet ){
  280 + ss.styleSheet.cssText = css;
  281 + }
  282 + else {
  283 + ss.appendChild( doc.createTextNode( css ) );
  284 + }
  285 +
  286 + //push to appendedEls to track for later removal
  287 + appendedEls.push( ss );
  288 + }
276 289 }
277 290 },
278 291 //tweaked Ajax functions from Quirksmode
@@ -283,12 +296,12 @@ window.matchMedia = window.matchMedia || (function(doc, undefined){
283 296 }
284 297 req.open( "GET", url, true );
285 298 req.onreadystatechange = function () {
286   - if ( req.readyState != 4 || req.status != 200 && req.status != 304 ){
  299 + if ( req.readyState !== 4 || req.status !== 200 && req.status !== 304 ){
287 300 return;
288 301 }
289 302 callback( req.responseText );
290   - }
291   - if ( req.readyState == 4 ){
  303 + };
  304 + if ( req.readyState === 4 ){
292 305 return;
293 306 }
294 307 req.send( null );
@@ -297,10 +310,10 @@ window.matchMedia = window.matchMedia || (function(doc, undefined){
297 310 xmlHttp = (function() {
298 311 var xmlhttpmethod = false;
299 312 try {
300   - xmlhttpmethod = new XMLHttpRequest();
  313 + xmlhttpmethod = new win.XMLHttpRequest();
301 314 }
302 315 catch( e ){
303   - xmlhttpmethod = new ActiveXObject( "Microsoft.XMLHTTP" );
  316 + xmlhttpmethod = new win.ActiveXObject( "Microsoft.XMLHTTP" );
304 317 }
305 318 return function(){
306 319 return xmlhttpmethod;

0 comments on commit 8991f5d

Please sign in to comment.
Something went wrong with that request. Please try again.