tag.
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
=head2 menu_buttons($Boolean) |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
Set the option to make menu items text (0) or buttons (1). |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
The default is 0. |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
Note: See split_buttons() for what happens when you try to set both |
427
|
|
|
|
|
|
|
menu_buttons(1) and split_buttons(1). |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
See the L for details. |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
=head2 run() |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
Generate the HTML and JS. |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
=head2 split_buttons($Boolean) |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
Set the option to make menu buttons normal (0) or split (1). |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
The default is 0. |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
See the L for details. |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
In the constructor, if you specify both menu_buttons => 1 and split_buttons => 1, |
444
|
|
|
|
|
|
|
menu_buttons is forced to be 0, so you get split buttons. |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
However, if you call these methods after creating the object, and wish to set split_buttons |
447
|
|
|
|
|
|
|
to 1, you must also explicitly set menu_buttons to 0, otherwise the output will be not as |
448
|
|
|
|
|
|
|
expected. |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
=head2 switch_js($Boolean) |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
Skip (0) or add (1) the contents of switch.statement.tx into the generated Javascript. |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
The default is 0. |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
Using 0 means you want a request to be sent to the url (if any) of each menu item |
457
|
|
|
|
|
|
|
when the user clicks that item. |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
Using 1 means you want the url to be disabled. In this case, the urls are used to generate |
460
|
|
|
|
|
|
|
a set of Javascript function names, and when the user clicks on a menu item, the corresponding |
461
|
|
|
|
|
|
|
function is executed. That could, for instance, set up an Ajax request to the server. |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
You must write the code for these Javascript functions, and include them (preferably) in the |
464
|
|
|
|
|
|
|
part of the web page. |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
See the L for details. |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
=head2 template_path($path) |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
Set the path to the Text::Xslate templates. |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
These templates are shipped in htdocs/assets/templates/html/yui3/menu/. |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
See L for instructions on installing them, and the L for |
475
|
|
|
|
|
|
|
a discussion on the template_path option in the config file. |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
The default is ''. |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
It is mandatory to use new(template_path => $a_path) or template_path($a_path) before calling run(). |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
=head2 tree($tree) |
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
Set the L object holding the menu. |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
This option is mandatory. |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
=head1 Testing this module |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
# 1: Prepare to use Postgres, or whatever. |
490
|
|
|
|
|
|
|
DBI_DSN=dbi:Pg:dbname=menus |
491
|
|
|
|
|
|
|
export DBI_DSN |
492
|
|
|
|
|
|
|
DBI_USER=me |
493
|
|
|
|
|
|
|
export DBI_USER |
494
|
|
|
|
|
|
|
DBI_PASS=seekret |
495
|
|
|
|
|
|
|
export DBI_PASS |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
# 2 Somehow create a new, empty database called 'menus'. |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
# 3: Install: |
500
|
|
|
|
|
|
|
cpanm Tree::DAG_Node::Persist |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
# 4: Create a suitable table 'items' in the 'menus' database, |
503
|
|
|
|
|
|
|
# giving it an extra column called 'url'. |
504
|
|
|
|
|
|
|
# create.table.pl also ships with Tree::DAG_Node::Persist V 1.03. |
505
|
|
|
|
|
|
|
scripts/create.table.pl -e "url:varchar(255)" -t items |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
# 5: Generate a menu and store it in the database, |
508
|
|
|
|
|
|
|
# using Tree::DAG_Node and Tree::DAG_Node::Persist. |
509
|
|
|
|
|
|
|
scripts/generate.menu.pl |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
# 6: If desired, plot the menu. |
512
|
|
|
|
|
|
|
# Install graphviz: http://www.graphviz.org/. |
513
|
|
|
|
|
|
|
# Install the Perl interface. |
514
|
|
|
|
|
|
|
# $DR represents your web server's doc root. |
515
|
|
|
|
|
|
|
cpanm GraphViz |
516
|
|
|
|
|
|
|
scripts/plot.menu.pl > $DR/menu.svg |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
# 7: Install this module. |
519
|
|
|
|
|
|
|
cpanm HTML::YUI3::Menu |
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
# 8: Copy the config file to ~/.perl/HTML-YUI3-Menu. |
522
|
|
|
|
|
|
|
# You'll need to download the distro to do this. |
523
|
|
|
|
|
|
|
scripts/copy.config.pl |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
# 9: Edit ~/.perl/HTML-YUI3-Menu/.hthtml.yui3.menu.config as desired. |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
# 10: Install YUI3's yui-min.js to the directory under your web server's |
528
|
|
|
|
|
|
|
# doc root, as you've specified in the config file. |
529
|
|
|
|
|
|
|
# Download from http://developer.yahoo.com/yui/3/. |
530
|
|
|
|
|
|
|
cp yui-min.js $DR/assets/js/yui3 |
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
# 11: Copy the templates shipped with this module to a directory under |
533
|
|
|
|
|
|
|
# your doc root, also as you've specified in the config file. |
534
|
|
|
|
|
|
|
cp -r htdocs/assets/* $DR/assets |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
# 11: Generate the HTML. |
537
|
|
|
|
|
|
|
perl scripts/generate.html.pl > $DR/menu.html |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
# 12: Experiment with options. |
540
|
|
|
|
|
|
|
# Edit scripts/generate.html.pl to set either menu_buttons => 1 |
541
|
|
|
|
|
|
|
# or split_buttons => 1. |
542
|
|
|
|
|
|
|
perl scripts/generate.html.pl > $DR/menu.html |
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
=head1 FAQ |
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
=over 4 |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
=item o What is YUI? |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
A Javascript library. YUI stands for the Yahoo User Interface. See L. |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
=item o How do I create the tree? |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
Use L and give each node in the tree, i.e. each menu item, a name and, optionally, a url. |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
The name is set by $node -> name($name) and the url is set by ${$node -> attribute}{url}. |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
If you wish, save the menu to a database using L. |
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
See scripts/generate.menu.pl. |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
=item o What is a split button? |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
With YUI3, menu items can be of 3 types: |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
A menu item which is text is just the text. |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
A menu item which is a button has a down arrow and a vertical bar on the right side (of the text), separating it from the next button. |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
A menu item which is a split button has a vertical bar on its right, a down arrow, and another vertical bar. |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
The down arrows indicate submenus. |
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
=item o Are urls mandatory? |
575
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
No. Any menu item will be ok without a url. |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
=item o Can menu buttons have their own urls? |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
Yes, but they don't have to have them. |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
For menu items which don't have submenus, the item is useless if it does not have a url. |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
But see the next question. |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
=item o What are name and url? |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
The node name appears as the text in the menu. |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
The url is used in a href, so that when the user clicks that menu item, the web client sends a request to that url. |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
At least, that's true for text items and split button items. |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
There is complexity in the behaviour of menu buttons 'v' split buttons. |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
With menu buttons, the url is not used, since the href must point to the submenu. That's part of the design of YUI3. |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
Split buttons can have their own url, and for both menu buttons and split buttons, each submenu item can have its own url. |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
=item o What is switch_js? |
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
If you wish to stop the user's click on a menu item actually doing a submit to the url, you can set switch_js => 1, |
603
|
|
|
|
|
|
|
and this module makes various changes to the generated HTML, as described above. |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
See the next 2 questions. |
606
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
=item o How are urls converted into Javascript function names? |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
Some examples: '/Build' becomes build(), and '/UpdateVersionNumber' becomes update_version_number(). |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
=item o What is switch.statement.tx? |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
This module will fabricate a switch statement, using switch.statement.tx, and insert the Javascript into |
614
|
|
|
|
|
|
|
yui.js.tx, for output just before the tag. |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
The generated switch statement will look like: |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
menu.on("click", function(e) |
619
|
|
|
|
|
|
|
{ |
620
|
|
|
|
|
|
|
e.preventDefault(); |
621
|
|
|
|
|
|
|
switch (e.target.getAttribute('href') ) |
622
|
|
|
|
|
|
|
{ |
623
|
|
|
|
|
|
|
case "/Build": |
624
|
|
|
|
|
|
|
build(); |
625
|
|
|
|
|
|
|
break; |
626
|
|
|
|
|
|
|
// Etc, down to... |
627
|
|
|
|
|
|
|
case "/UpdateVersionNumber": |
628
|
|
|
|
|
|
|
update_version_number(); |
629
|
|
|
|
|
|
|
break; |
630
|
|
|
|
|
|
|
default: |
631
|
|
|
|
|
|
|
break; |
632
|
|
|
|
|
|
|
} |
633
|
|
|
|
|
|
|
}); |
634
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
So, clicking on a menu item calls the Javascript funtion, which you write and put in the of the web page. |
636
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
=item o What goes into the config file? |
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
A sample config file is shipped as config/.hthtml.yui3.menu.conf. |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
=item o In the config file, why is template_path so long? |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
My doc root is L's RAM disk, /dev/shm/, and within that a directory html/. |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
Under that directory, all my modules use /assets/templates/..., where the ... comes from |
646
|
|
|
|
|
|
|
the name of the module. |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
So, L will become html/yui3/menu/. Hence the template path is: |
649
|
|
|
|
|
|
|
/dev/shm/html/assets/templates/html/yui3/menu/. |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
For other modules, beside templates/ there would be css/ or js/, depending on what ships with |
652
|
|
|
|
|
|
|
each module. |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
=item o Why is the default for horizontal 0 when every program has to set it to 1? |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
Because when that code is working, all defaults will be 0, which is much less confusing. |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
=item o Is there any sample code? |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
Yes, see L. |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
=item o What is scripts/copy.config.pl? |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
After this module is installed, you will probably need to edit the config file. |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
But before editing it, use copy.config.pl to copy it from config/ to ~/.perl/HTML-YUI3-Menu/. |
667
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
Check the docs for L to see what your operating system returns for a |
669
|
|
|
|
|
|
|
call to my_dist_config(). |
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
The point of this is that after the module is installed, the config file will be |
672
|
|
|
|
|
|
|
easily accessible and editable without needing permission to write to the directory |
673
|
|
|
|
|
|
|
structure in which modules are stored. |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
That's why L and L are pre-requisites for this module. |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
All modules which ship with their own config file are advised to use the same mechanism |
678
|
|
|
|
|
|
|
for storing such files. |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
=back |
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
=head1 Machine-Readable Change Log |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
The file CHANGES was converted into Changelog.ini by L. |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
=head1 Support |
687
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
Email the author, or log a bug on RT: |
689
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
L. |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
=head1 Author |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
L was written by Ron Savage Iron@savage.net.auE> in 2011. |
695
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
Home page: L. |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
=head1 Copyright |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
Australian copyright (c) 2011, Ron Savage. |
701
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
All Programs of mine are 'OSI Certified Open Source Software'; |
703
|
|
|
|
|
|
|
you can redistribute them and/or modify them under the terms of |
704
|
|
|
|
|
|
|
The Artistic License, a copy of which is available at: |
705
|
|
|
|
|
|
|
http://www.opensource.org/licenses/index.html |
706
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
=cut |