HTML_Progress2 : The Definitive Guide |
This section is intended to provide a HOWTO guide that you should follow step by step to discover the new feature of HTML_Progress2 version 2.2.0
Until now we should used HTML_Progress2 API to set all styles (color,
size, font, ...) of our progress bars. We will discover now with
HTML_Progress2::importStyle()
method
that it can be done in one step and PHP code is more reusable. We can
change look and feel only on modify CSS data source.
We will use the Ancestor example (included into the package distribution), all long of this demonstration.
Here are the original source code (without header).
Example 14.1. script: examples/horizontal/ancestor.php
Due to minor fix we have to do later in javascript code, lets begin by replace this line by a reference to an external JS file.
What content is :
Example 14.2. script: progress2BasicHandler.js
First, identify the progress bar with a static identifier, for
example PB1
. (see line 5), rather than
used the default identifier that change on each run.
Replace dynamic reference HTML_Progress2::getStyle()
to inline
stylesheet by a reference to a static file ancestor.css
.
What content is :
Example 14.3. ancestor.css
And don't forget to add the new method HTML_Progress2::importStyle()
to your PHP
script, with url of your external stylesheet.
If you have followed all previous explains, your code should be something like this one :
These lines corresponding to same CSS properties from
.progressPercentLabelpct1PB1
class
selector.
Defines the progress bar position (relative) into browser frame.
Give percent text label alignment. There is no CSS property equivalence.
Important | |
---|---|
Don't forget to remove lines 10-11, 14-15 to get PHP code without CSS references. |
To get possibility to handle all your progress bar look and feel (style) with only a stylesheet, we still need to modify the PHP script and a little line in JS script.
Begin with PHP source code :
Add this line to change the progress border CSS class selector.
Remember, default is : progressBorder%s
, where %s is the placeholder
to include progress bar identifier (return by HTML_Progress2::getIdent()
).
Add this line to change the cell CSS class selector. Remember,
default is : cell%s
, where %s is
the placeholder to include progress bar identifier (return by
HTML_Progress2::getIdent()
).
Add this line to change the progress percent label CSS class
selector. Remember, default is : progressPercentLabel%s
, where %s is the
placeholder to include label and progress bar identifiers.
Last, to finish our modifications, we need to remove the progress bar
identifier placeholder into JS script: progress2BasicHandler.js
at line 22. From :
To :
Modify again the stylesheet to identify by another way the progress bar identifier that was removed from CSS class selector, in previous step.
Example 14.4. New content of ancestor.css
Remove reference to progress bar identifier PB1
, and add the <div> identifier
#pbarPB1
for each cell class
selector (active, inactive).
Caution | |
---|---|
Don't forget to add a blank between #pbarPB1 and .cellI (or .cellA )
|
Remove reference to progress bar identifier PB1
, and add the <div> identifier
#pbrdPB1
.
Remove reference to progress bar identifier PB1
, percent label pct1
, and add the <div> identifier
#plblpct1PB1
.
All components (PHP script and CSS file) are ready to play with them and change color, size, ... Almost what you want.
Tip | |
---|---|
To switch from a skin to another, you just have to change
progress bar identifier in PHP script.
|
Example 14.5. ancestor.css
with two skins
HTML_Progress2 : The Definitive Guide | v 2.4.0 : April 20, 2007 |