1 package SL::Presenter::JavascriptMenu;
4 use SL::Presenter::EscapedText qw(escape is_escaped);
5 use SL::Presenter::Tag qw( html_tag link_tag);
6 use SL::Locale::String qw(t8);
7 use SL::System::ResourceCache;
9 use List::Util qw(max);
11 use Exporter qw(import);
12 our @EXPORT_OK = qw(render_menu);
17 html_tag('div', '', id => 'main_menu_div') .
18 html_tag('ul', render_children($menu, 100, $menu->{tree}),
19 id => "main_menu_model",
20 style => 'display:none',
25 my ($menu, $node, $id) = @_;
26 return '' if !$node->{visible};
28 my $icon = get_icon($node->{icon});
29 my $link = $menu->href_for_node($node) || '#';
30 my $name = $menu->name_for_node($node);
33 link_tag($link, $name, target => $node->{target})
34 . html_tag('ul', render_children($menu, $id * 100, $node->{children} // []),
35 width => max_width($node)
38 (itemIcon => $icon)x!!$icon,
43 my ($menu, $id, $children) = @_;
47 render_node($menu, $_, 100 * $id + $sub_id++)
52 11 * ( max( map { length $::locale->text($_->{name}) } @{ $_[0]{children} || [] } ) // 1 )
58 return undef if !defined $name;
60 my $simg = "image/icons/svg/$name.svg";
61 my $pimg = "image/icons/16x16/$name.png";
63 SL::System::ResourceCache->get($simg) ? $simg
64 : SL::System::ResourceCache->get($pimg) ? $pimg