This document is intended to provide more in-depth coverage of the code that powers the Styleswitcher. It is assumed that the reader has some basic knowledge of PHP and of Object Oriented Programming.
For general information on how to install and set up the styleswitcher, refer to either the Styleswitcher Tutorial or the Upgrade Guide.
The code is broken down into three sections: the Styleswitcher class, the StyleSet class,
and the Style class. The Styleswitcher class uses both of the other smaller classes;
the StyleSet class uses the Style class.
The primary programming and user interaction is with the Styleswitcher class which implements most
of the script's logic. The other two classes are supporting classes.
This is the primary class for the style switcher. It uses the two classes StyleSet and Style.
true
by default.true by
default.true by default.new Styleswitcher([home, domain])
addStyle(style [, file, media, title, static])
This method adds a style to the Styleswitcher object.
false by default.Example
$ss = new Styleswitcher();
$ss->addStyle("basic", "css/basic.css");
addStyleToSet(setName, style [, default])
This method adds a style to a set of styles. Both the set and the style must be created before this method can be used. If a style is marked as the default style, it will be used when no other style has been selected for this set (or if, in the bizarre circumstance, more than one style is selected for a set, including the default).
false by default.Example
$ss = new Styleswitcher();
$ss->addStyle("large", "css/large-text.css");
$ss->addStyle("small", "css/small-text.css");
$ss->createSet("fonts");
$ss->addStyleToSet("fonts", "large");
$ss->addStyleToSet("fonts", "small");
createSet(setName [, setItems])
This method creates a new style set. Style sets are used to handle multiple styles that are mutually exclusive (i.e., only one style from a set may be present at a time.)
Example
$ss = new Styleswitcher();
$ss->addStyle("large", "css/large-text.css");
$ss->addStyle("small", "css/small-text.css");
$ss->createSet("fonts");
$ss->addStyleToSet("fonts", "large");
$ss->addStyleToSet("fonts", "small");
printAlternateStyles([printAll])
This method prints out the alternate stylesheets for a page. If the printAll argument is true,
then it will print out alternate links for all stylesheets, including those that are printed for immediate use and
those that are static.
true by default.See Also: printStyles()
printSetInputChecked(set, input)
This method is useful when using form-based style changers (for instance, checkboxes or radio buttons) because
it will print out the proper checked="checked" for the element depending on whether or not
it is set in the user's cookies or is the default for a style set (in the case that no styles from that set are
located in the user's cookies).
Example
<form action="php/switcher.php" method="post">
<input type="radio" name="fontSet" id="fontSet1"\
<?php $ss->printSetInputChecked("fonts", "large"); ?> />
<label for="fontSet1">Large Text<label>
<input type="radio" name="fontSet" id="fontSet2"
<?php $ss->printSetInputChecked("fonts", "small"); ?> />
<label for="fontSet2">Small Text<label>
This method prints out the correct styles for each available set. The "correct" style is either: the default style in the absence of all other styles, the default in the case that default is present along with other styles, the first style within the set (in the case that there are more than one from each set), or the one style choosen for each set.
See Also: printStyles()
This is a method which encapsulates all the other print style methods. Typically, this is the only one that needs to be called.
This method is used to print out all styles marked as being "static" (and not within a set static styles should not be within sets.
See Also: printStyles()
This prints styles selected by the user that are not within sets (i.e., those styles that are not mutually exclusive.
See Also: printStyles()
A simple method for setting the Styleswitcher's home.
This method is used when accepting information about setting cookies for remembering a user's style changes.
This method is handy for checking if the style cookie has been set. It returns true if the cookie
is present and false if not.
Example
if($ss->styleCookieSet){
print "You have chosen a different style.";
}
This is the first of two supporting classes for the Styleswitcher class. This class
implements a set (an array) of Styles. You do not need to call any of the
methods from this class to use the styleswitcher.
Styleswitcher
printStyles() method.addStyle(style [, file, media, title, static])
This method adds a style to this set. Typically you may use the addStyleToSet() method to add a style to the styleswitcher.
This method checks whether a style exists within a style set.
This method returns the Style object for the specified style.
This class models a stylesheet. It is used to hold information regarding stylesheets for the styleswitcher.
new Style(name [, file, media, title, static])
The arguments to this constructor are the same as the fields list above.
Copyright © 2003 Rob Ballou. All Rights Reserved.
Last updated: May 16, 2007 14:36