Skip to content

Commit

Permalink
Updated JS to remove comments from parsed rules
Browse files Browse the repository at this point in the history
The JavaScript was extended to remove comments from all rules being parsed. Additionally, a small bug, where the foundProps variable was incorrectly defined and would cause certain cases to fail, was fixed.
  • Loading branch information
squat committed Aug 3, 2012
1 parent 6dc65b2 commit f302811
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions js/rem.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
var remCurrent = response.responseText.match(remPattern);
if( current !== null && current.length !== 0 ){
found = found.concat( current ); //save all of the blocks of rules with rem in a property
foundProps = found.concat( remCurrent ); //save all of the properties with rem
foundProps = foundProps.concat( remCurrent ); //save all of the properties with rem
}
if( i === sheets.og-1 ){
buildIt();
Expand Down Expand Up @@ -90,10 +90,10 @@
rules = rules.replace( found[i],css[i] ); //replace old rules with our processed rules
}
}
rules = removeComments( rules );
var remcss = document.createElement( 'style' );
remcss.setAttribute( 'type', 'text/css' );
remcss.id = 'remReplace';
alert(rules);
remcss.innerHTML = rules;
document.getElementsByTagName( 'head' )[0].appendChild( remcss ); //create the new element
},
Expand All @@ -112,7 +112,7 @@
},

removeComments = function( css ) {
return css.replace(/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+/, ""); //work in progress
return css.replace(/\/\*[\w\d\.\,\[\]\^\>\<\+\~\|\-\_\$\#\"\'\/\*\\\=\s\{\}\(\)]*\*\//g, "");
},

getXMLHttpRequest = function () { //we're gonna check if our browser will let us use AJAX
Expand All @@ -125,6 +125,7 @@
var rules = ''; //initialize the rules variable in this scope so it can be used later
var sheets = []; //initialize the array holding the sheets for use later
var found = []; //initialize the array holding the found rules for use later
var foundProps = []; //initialize the array holding the found properties for use later
var css = []; //initialize the array holding the parsed rules for use later
var body = document.getElementsByTagName("body")[0];
var fontSize = "";
Expand Down

0 comments on commit f302811

Please sign in to comment.