Setting up the Class
Added 26 Jul 2008
To begin, let's compose a very basic CSS stylesheet from which we can work. Open a blank document in your favorite text editor (or code editor) and save it as 'myStyles.css'. Enter the following code:
style1 {
font-family: Arial;
font-size: 16;
}
style2 {
font-family: Georgia;
font-size: 10;
}We'll use this simple stylesheet as our example stylesheet. Here we
only have two styles, each with two properties: font-family and
font-size. Later on we'll add a few more styles and properties as
needed.Now we can turn to the class. Before we start writing
the class itself, we need to include a few custom String methods which
strip a string of any extra spaces (whitespace) before and after the
string. So to begin, open up a new blank document in your favorite text
editor (or code editor such as Dreamweaver), save it as
'Stylesheet.as', and copy the following code:// ------------------------------------------------------------- //
// Some String Methods for stripping white space //
// ------------------------------------------------------------- //
String.prototype.trimL = function () {
for (var i = 0; i < this.length; i++) {
if (this.charCodeAt (i) > 32) {
return this.substr (i, this.length);
} // end if (this.charCodeAt (i) > 32)
} // end looping through characters
return this;
} // end String.trimL ()
String.prototype.trimR = function () {
for (var i = this.length; i > 0; i--) {
if (this.charCodeAt (i) > 32) {
return this.substring (0, i + 1);
} // end if (this.charCodeAt (i) > 32)
} // end looping through characters backwards
return this;
} // end String.trimR ()
String.prototype.trimWhite = function() {
this = this.trimL ();
return this.trimR ();
} // end String.trimWhiteThoth ()
// End String Methods //
// ------------------------------------------------------------- //