Many web sites include drop-down navigation boxes which let the user quickly find the page they're looking for, while simultaneously saving screen real-estate in their site design. The DropDownNav macro is a simple macro that inserts a drop-down navigation box. The choices that the user is given are provided as arguments to the macro.
A few limitations: DropDownNav accepts only WikiNames or names of pages containing no spaces. There is also no validation of page names. I'd love to know if anybody finds this useful. If you like this patch, drop me a message at yo_daddy at comcast dot net. --Qualidafial
Sites that have examples of drop-down navigation boxes:
[[DropDownNav PageOne PageTwo PageThree PageFour...]]
Affected files:
This script is made available under the Apache License 2.0 [1]. Essentially the license states you can use the code royalty-free for fun or profit.
<?php
function view_macro_drop_down_nav($args) {
global $ScriptBase, $SeparateLinkWords, $DropDownNavPrompt;
$navigateScript =
"if(event.srcElement.selectedIndex)" .
"document.location.href='$ScriptBase?page='+event.srcElement.item(" .
"event.srcElement.selectedIndex).value";
$r = '<select class="navCombo" onchange="' .
"javascript:$navigateScript; return false;\">\n";
$r .= "<option selected>$DropDownNavPrompt\n";
foreach(split(' ',$args) as $arg) {
$r .= "<option value=\"$arg\">";
if ($SeparateLinkWords) $arg = html_split_name($arg);
$r .= "$arg\n";
}
$r .= '</select>';
return $r;
}
?>
Anywhere in the file:
$DropDownNavPrompt = 'Select a page';
Insert a line into the $ViewMacroEngine array near the end of the file:
$ViewMacroEngine = array(
//...
'DropDownNav' => 'view_macro_drop_down_nav'
);
Immediately before the closing ?> script delimiter.
require_once('macros/drop_down_nav.php');
The following causes the drop-down navigation box to be hidden on printouts.
@media print {
// ...
select.navCombo { display: none; }
}
This next code fragment is for demonstrative purposes, and is optional.
select.navCombo {
width: 200px;
float: right;
}
If you want to change the default prompt in the drop-down box, add the following to config.php.
$DropDownNavPrompt = 'Alternative prompt text';
Suggested enhancements (open for votes):
Thanks to [Mike Hall] for his help. The "event.srcElement" is an Internet Explorer only function. The new "this" function works fine, especially in Firefox. --Frank Katzenberger
<?php
function view_macro_drop_down_nav($args) {
global $ScriptBase, $SeparateLinkWords, $DropDownNavPrompt;
$navigateScript =
"if(this.selectedIndex)" .
"document.location.href='$ScriptBase?page='+this.item(" .
"this.selectedIndex).value";
$r = '<select class="navCombo" onchange="' .
"javascript:$navigateScript; return false;\">\n";
$r .= "<option selected>$DropDownNavPrompt\n";
foreach(split(' ',$args) as $arg) {
$r .= "<option value=\"$arg\">";
if ($SeparateLinkWords) $arg = html_split_name($arg);
$r .= "$arg\n";
}
$r .= '</select>';
return $r;
}
?>