Javascript::Menu 2.02 review
DownloadJavascript::Menu is a NumberedTree that generates HTML and Javascript code for a menu. SYNOPSIS use Javascript::Menu;
|
|
Javascript::Menu is a NumberedTree that generates HTML and Javascript code for
a menu.
SYNOPSIS
use Javascript::Menu;
# Give it something to do (example changes the menu's caption):
my $action = sub {
my $self = shift;
my ($level, $unique) = @_;
my $value = $self->getValue;
return "getElementById(caption_$unique).innerHTML='$value'";
};
# Build the tree:
my $menu = Javascript::Menu->convert(tree => $otherTree, action => $action);
my $menu = Javascript::Menu->readDB(source_name => $table, source => $dbh,
action => $action);
my $menu = Javascript::Menu->new(value => 'Please select a parrot',
action => $action);
my $blue = $menu->append(value => 'Norwegian Blue');
$blue->append(value => 'Pushing up the daisies');
$menu->append(value => 'A Snail');
# Or maybe you just want a navigational menu?
my $menu = Javascript::Menu->new(value => 'Please select a prime minister');
$menu->append(value => 'Ariel Sharon',
URL => 'www.corruption.org/ariel_sharon.htm');
$menu->append(value => 'Benjamin Netanyahu',
URL => 'www.corruption.org/bibi.htm');
$menu->append(value => 'Shaul Mofaz', URL => 'www.martial_law.org');
# Print it out as a right-to-left menu:
my $css = $menu->buildCSS($menu->reasonableCSS);
print $cgi->start_html(-script => $menu->baseJS('rtl'),
-style => $css); #CSS plays an important role.
print $tree->getHTML;
Javascript::Menu is an object that helps in creating the HTML, Javascript, and some of the CSS required for a table-based menu. There are a few other modules that deal with menus, But as I browsed through them, I found that none of them exactly fitted my needs. So I designed this module, with the following goals in mind:
Flexibility
The main feature of this module is the ability to supply all nodes or any specific node with a subroutine that is activated in time of the code generation to help decide what the item will do when it is clicked. This allows customisation far beyond associating a link with every item. Multy-level selection menus become very easy to do (and this is, in fact, what I needed when I started writing this).
I18n
Working with i18n (internationalization) can be a big headache. Working with Hebrew (or Arabic) forces you not only to change your charachters, but also to change your direction of writing. I incorporated into this module the ability to produce right-to-left menus and tested it using a legacy ASCII-based encoding (iso-8859-8).
Object Hierarchy
I designed the module to work with two other modules of mine, Tree::Numbered and Tree::Numbered::DB, which simplify the task of building the menu and allow for construction of a menu from database information.
The current version adds support for highlighting the item that's hovered over. You'll find that having made some preliminary steps, like tweaking the CSS to look the way you like it to, the rest is fairly easy.
Requirements:
Perl
Javascript::Menu 2.02 search tags