Subject: | Support partial matches in URLs |
The attached patch will highlight the navigation menu item matching
partial URLs.
Here, a partial match is a URL that begins with the same string as the
URL to a configured menu item).
Take the following example menu:
- Administration
- Users
- Domains
With this patch this will highlight the user link even for URLs such
as http://example.com/admin/users/ola/edit, not only
http://example.com/admin/users
It also makes the currently highlighted menu item a link, useful to
navigate back if matching a partial URL.
Subject: | perl-HTML-Widgets-NavMenu.diff |
Index: HTML/Widgets/NavMenu.pm
===================================================================
--- HTML/Widgets/NavMenu.pm (revisjon 878)
+++ HTML/Widgets/NavMenu.pm (arbeidskopi)
@@ -99,6 +99,19 @@
);
}
+sub item_matches_partial {
+ my $self = shift;
+ my $item = $self->top();
+ my $url = $item->_node()->url();
+ my $nav_menu = $self->nav_menu();
+ return
+ (
+ ($item->_accum_state()->{'host'} eq $nav_menu->current_host()) &&
+ (defined($url) && (0 eq index $nav_menu->path_info(), $url))
+ );
+
+}
+
sub does_item_expand
{
my $self = shift;
@@ -123,6 +136,10 @@
my @coords = @{$self->get_coords()};
$self->{'leading_path_coords'} = [ @coords];
}
+ elsif ($self->item_matches_partial())
+ {
+ $self->top()->_node()->mark_as_current();
+ }
}
sub node_end
Index: HTML/Widgets/NavMenu/Iterator/NavMenu.pm
===================================================================
--- HTML/Widgets/NavMenu/Iterator/NavMenu.pm (revisjon 878)
+++ HTML/Widgets/NavMenu/Iterator/NavMenu.pm (arbeidskopi)
@@ -80,7 +80,7 @@
{
my $self = shift;
my $node = shift;
- return "<b>" . $node->text() . "</b>";
+ return "<b>" . $self->get_a_tag() . "</b>";
}
=head2 $self->get_link_tag()