Dynamically create vertical CSS menus.
Based on ?superfish? type CSS menus (see link), this class
allows dynamic generation of CSS and HTML to produce horizantal
menus at runtime.
This does not actually product Superfish functionality, but the code
should be compatible with adding Superfish.
It is advisable to cache the menu if possible, as there is
considerable overhead to running this every time the script is
accessed and on a busy site with many buttons and layers could
have a significant detrimental effect on performance.
Simple example adding a three button menu where second button has a sub-button:
$vmenu = new VMenu;
$vmenu->addButton('Home', '/');
$parentid = $vmenu->getNextButton(); // next button will be a parent
$vmenu->addButton('Products' '');
$vmenu->addButton('Product One', '/prod1/', 'Product One', 2, $parentid);
$vmenu->addButton('Product Two', '/prod2/', 'Product Two', 2, $parentid);
$vmenu->addButton('Contact Us', '/contact/');
// then use...
// $vmenu->generateCSS() at the end of your section
// optionally use $vmenu->generateConditionalStatements()
// and $vmenu->generateHTML() where the menu would go
| link | http://users.tpg.com.au/j_birch/plugins/superfish/ |
|---|---|
| see | \global\HMenu |
| package | dstruct_presentation |
| todo | This was written some years ago and probably needs updating to fit more recent menu technologies |
| todo | Add method to get last button id rather than next button as it is counter-intuitive. |
addButton(string $text, string $url, string $title, integer $level, integer $parentid, boolean $topbutton, string $onclick)
If the button is $level 2 or 3, you will need to set the $parentid. Example:
addButton('Button 1'); // add a button
$parentid = $menu->getNextButton(); // get the ID of the next button. This will be the parent button.
$menu->addButton('Button 2');
$menu->addButton('Button 2-2','','',2,$parentid); // add a sub-button
?>
stringText for the button
string
stringSet the title attribute of the anchor element
integerLevel of the button in the structure - 1, 2 or 3
integerSee above
booleanIf the button is the first of its group
stringInsert into the onclick attribute of the anchor element
generateCSS() : string
generateConditionalStatements() : string
stringgenerateHTML() : string
echo this where your menu should be in the HTML
stringgetBGCol() : string
stringgetBGHover() : string
stringgetFontCol() : string
stringgetFontHoverCol() : string
stringgetFontItalic() : boolean
booleangetFontSize() : integer
integergetFontWeight() : string
stringgetIncludeDiv() : boolean
booleangetIncludeStyleTags() : boolean
booleangetMenuWidth() : integer
integergetNextButton() : integer
integergetPadding() : array
arraysetBGCol(string $bgcol)
stringHex colour code e.g. ec4a8f
setBGHoverCol(string $bghovercol)
stringHex colour code e.g. ec4a8f
setBorderCols(array $bordercols)
Array with 4 elements for top, right, bottom and left. Elements should be hex colour codes e.g. ec4a8f
array
setBorderWidths(array $borderwidths)
Array with 4 integer elements for top, right, bottom and left.
array
setFontCol(string $fontcol)
stringHex colour code e.g. ec4a8f
setFontHoverCol(string $fonthovercol)
stringHex colour code e.g. ec4a8f
setFontItalic(boolean $fontitalic)
boolean
setFontSize(float $fontsize)
float
setFontWeight(\strong $fontweight)
e.g. 'bolder'
\strong
setIncludeDiv(boolean $includediv)
boolean
setIncludeStyleTags(boolean $includestyletags)
If you already have a script with CSS in your page, you may want to exclude the script tags and just include the CSS in the existing block.
boolean
setMenuWidth(integer $menuwidth)
integer
setPadding(integer $padding)
integerIn pixels
setTopBorder(array $topborder)
Array with two elements to set width in px and colour in hex.
| todo | confirm usage of this method. |
|---|---|
| see | \addButton() |
array
multiarray_search(array $arr, mixed $dimension, mixed $needle)
arrayMulti-dimensional array to search
mixed
mixed
$bgcol : string
$bghovercol : string
$bordercols : array
$borderwidths : array
$fontcol : string
$fonthovercol : string
$fontitalic : boolean
$fontsize : float
$fontweight : string
$includediv : boolean
$level1 : array
$level2 : array
$level3 : array
$padding : array
$topborder : array