Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 330220e

Browse files
merge remaining commits from #49
2 parents 10e54ed + 9f36d2f commit 330220e

File tree

4 files changed

+15
-35
lines changed

4 files changed

+15
-35
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "REM-unit-polyfill",
3-
"version": "1.2.4",
3+
"version": "1.3.2",
44
"homepage": "https://github.com/chuckcarpenter/REM-unit-polyfill",
55
"authors": [
66
"Chuck Carpenter <chuck.carpenter@me.com>",

js/rem.js

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@
2424
},
2525

2626
processLinks = function () {
27-
if( links.length === 0 ){
28-
links = isStyleSheet(); // search for link tags and confirm it's a stylesheet
29-
}
30-
3127
//prepare to match each link
3228
for( var i = 0; i < links.length; i++ ){
33-
xhr( links[i], storeCSS, links[i], i );
29+
xhr( links[i], storeCSS );
3430
}
3531
},
3632

@@ -56,7 +52,7 @@
5652
},
5753

5854
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
6056
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
6157
current = clean.match(pattern),
6258
remPattern =/\d*\.?\d+rem/g,
@@ -117,7 +113,7 @@
117113
}
118114
},
119115

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
121117
try {
122118
//try to create a request object
123119
//arranging the two conditions this way is for IE7/8's benefit
@@ -126,22 +122,22 @@
126122
//it prefers ActiveX, which means it still works with local files
127123
//(Native XHR in IE7/8 is blocked and throws "access is denied",
128124
// 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();
130126

131127
xhr.open( 'GET', url, true );
132128
xhr.onreadystatechange = function() {
133129
if ( xhr.readyState === 4 ){
134-
callback(xhr, i);
130+
callback(xhr, url);
135131
} // else { callback function on AJAX error }
136132
};
137133

138-
xhr.send(null);
134+
xhr.send( null );
139135
} catch (e){
140136
if ( window.XDomainRequest ) {
141137
var xdr = new XDomainRequest();
142138
xdr.open('get', url);
143139
xdr.onload = function() {
144-
callback(xdr, i);
140+
callback(xdr, url);
145141
};
146142
xdr.onerror = function() {
147143
return false; // xdr load fail
@@ -151,26 +147,10 @@
151147
}
152148
},
153149

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-
171150
// Remove queries.
172151
removeMediaQueries = function(css) {
173-
if (!mediaQuery()) {
152+
// Test for Media Query support
153+
if ( !window.matchMedia && !window.msMatchMedia ) {
174154
// If the browser doesn't support media queries, we find all @media declarations in the CSS and remove them.
175155
// Note: Since @rules can't be nested in the CSS spec, we're safe to just check for the closest following "}}" to the "@media".
176156
css = css.replace(/@media[\s\S]*?\}\s*\}/g, "");
@@ -181,7 +161,7 @@
181161

182162
if( !cssremunit() ){ // this checks if the rem value is supported
183163
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
185165
importLinks = [], //initialize the array holding the import sheet urls for use later
186166
found = [], // initialize the array holding the found rules for use later
187167
foundProps = [], // initialize the array holding the found properties for use later

js/rem.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "rem",
33
"description": "A polyfill to parse CSS links and rewrite pixel equivalents into head for non supporting browsers",
44
"main": "js/rem.js",
5-
"version": "1.3.1",
5+
"version": "1.3.2",
66
"authors": [
77
"Chuck Carpenter <chuck.carpenter@me.com>",
88
"Lucas Serven <lserven@gmail.com>"

0 commit comments

Comments
 (0)