|
24 | 24 | }, |
25 | 25 |
|
26 | 26 | processLinks = function () { |
27 | | - if( links.length === 0 ){ |
28 | | - links = isStyleSheet(); // search for link tags and confirm it's a stylesheet |
29 | | - } |
30 | | - |
31 | 27 | //prepare to match each link |
32 | 28 | for( var i = 0; i < links.length; i++ ){ |
33 | | - xhr( links[i], storeCSS, links[i], i ); |
| 29 | + xhr( links[i], storeCSS ); |
34 | 30 | } |
35 | 31 | }, |
36 | 32 |
|
|
56 | 52 | }, |
57 | 53 |
|
58 | 54 | matchCSS = function ( sheetCSS, link ) { // collect all of the rules from the xhr response texts and match them to a pattern |
59 | | - var clean = removeComments( removeMediaQueries(sheetCSS) ), |
| 55 | + var clean = removeMediaQueries( sheetCSS ).replace(/\/\*[\s\S]*?\*\//g, ''), // remove MediaQueries and comments |
60 | 56 | pattern = /[\w\d\s\-\/\\\[\]:,.'"*()<>+~%#^$_=|@]+\{[\w\d\s\-\/\\%#:!;,.'"*()]+\d*\.?\d+rem[\w\d\s\-\/\\%#:!;,.'"*()]*\}/g, //find selectors that use rem in one or more of their rules |
61 | 57 | current = clean.match(pattern), |
62 | 58 | remPattern =/\d*\.?\d+rem/g, |
|
117 | 113 | } |
118 | 114 | }, |
119 | 115 |
|
120 | | - xhr = function ( url, callback, i ) { // create new XMLHttpRequest object and run it |
| 116 | + xhr = function ( url, callback ) { // create new XMLHttpRequest object and run it |
121 | 117 | try { |
122 | 118 | //try to create a request object |
123 | 119 | //arranging the two conditions this way is for IE7/8's benefit |
|
126 | 122 | //it prefers ActiveX, which means it still works with local files |
127 | 123 | //(Native XHR in IE7/8 is blocked and throws "access is denied", |
128 | 124 | // but ActiveX is permitted if the user allows it [default is to prompt]) |
129 | | - var xhr = window.ActiveXObject ? (new ActiveXObject('Microsoft.XMLHTTP') || new ActiveXObject("Msxml2.XMLHTTP")) : new XMLHttpRequest(); |
| 125 | + var xhr = window.ActiveXObject ? ( new ActiveXObject('Microsoft.XMLHTTP') || new ActiveXObject('Msxml2.XMLHTTP') ) : new XMLHttpRequest(); |
130 | 126 |
|
131 | 127 | xhr.open( 'GET', url, true ); |
132 | 128 | xhr.onreadystatechange = function() { |
133 | 129 | if ( xhr.readyState === 4 ){ |
134 | | - callback(xhr, i); |
| 130 | + callback(xhr, url); |
135 | 131 | } // else { callback function on AJAX error } |
136 | 132 | }; |
137 | 133 |
|
138 | | - xhr.send(null); |
| 134 | + xhr.send( null ); |
139 | 135 | } catch (e){ |
140 | 136 | if ( window.XDomainRequest ) { |
141 | 137 | var xdr = new XDomainRequest(); |
142 | 138 | xdr.open('get', url); |
143 | 139 | xdr.onload = function() { |
144 | | - callback(xdr, i); |
| 140 | + callback(xdr, url); |
145 | 141 | }; |
146 | 142 | xdr.onerror = function() { |
147 | 143 | return false; // xdr load fail |
|
151 | 147 | } |
152 | 148 | }, |
153 | 149 |
|
154 | | - removeComments = function ( css ) { |
155 | | - var start = css.search(/\/\*/), |
156 | | - end = css.search(/\*\//); |
157 | | - while ( (start > -1) && (end > start) ) { |
158 | | - css = css.substring(0, start) + css.substring(end + 2); |
159 | | - start = css.search(/\/\*/); |
160 | | - end = css.search(/\*\//); |
161 | | - } |
162 | | - return css; |
163 | | - }, |
164 | | - |
165 | | - // Test for Media Query support |
166 | | - mediaQuery = function() { |
167 | | - if (window.matchMedia || window.msMatchMedia) { return true; } |
168 | | - return false; |
169 | | - }, |
170 | | - |
171 | 150 | // Remove queries. |
172 | 151 | removeMediaQueries = function(css) { |
173 | | - if (!mediaQuery()) { |
| 152 | + // Test for Media Query support |
| 153 | + if ( !window.matchMedia && !window.msMatchMedia ) { |
174 | 154 | // If the browser doesn't support media queries, we find all @media declarations in the CSS and remove them. |
175 | 155 | // Note: Since @rules can't be nested in the CSS spec, we're safe to just check for the closest following "}}" to the "@media". |
176 | 156 | css = css.replace(/@media[\s\S]*?\}\s*\}/g, ""); |
|
181 | 161 |
|
182 | 162 | if( !cssremunit() ){ // this checks if the rem value is supported |
183 | 163 | var rules = '', // initialize the rules variable in this scope so it can be used later |
184 | | - links = [], // initialize the array holding the sheets urls for use later |
| 164 | + links = isStyleSheet(), // initialize the array holding the sheets urls for use later |
185 | 165 | importLinks = [], //initialize the array holding the import sheet urls for use later |
186 | 166 | found = [], // initialize the array holding the found rules for use later |
187 | 167 | foundProps = [], // initialize the array holding the found properties for use later |
|
0 commit comments