Skip to content

Commit

Permalink
Add support to preserve last selected server
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Sep 25, 2023
1 parent 14b8113 commit 0f3519d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions navigation-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ sub nav_virtualmin_menu
$rv .= nav_theme_links();
$rv .= nav_links($menu->{'mode'});
$rv .= nav_menu_html_snippet();
$rv .= nav_detect_page($page);
$rv .= nav_detect_script();
$rv .= nav_detect_page($page, 1);
$rv .= nav_detect_script(1);
return $rv;
}

Expand Down Expand Up @@ -427,27 +427,42 @@ sub nav_get_server_id
return $default;
}

sub nav_set_last_id
{
my ($link) = @_;
if ($link && $link =~ /(id|dom)=(\d+)/) {
return "vars.navigation.select.last='$2';";
}
return undef;
}

sub nav_detect_page
{
my ($page) = @_;
my ($page, $set_last) = @_;
my $rv;
if ($page) {
$page = quote_escape($page);
$page =~ s/&/&/g;
$rv .= "<li data-goto=\"$page\" class=\"hidden\"></li>\n";
my $last_id = $set_last ? nav_set_last_id($page) : undef;
if ($last_id) {
$last_id = "<script>$last_id</script>";
}
$rv .= "<li data-goto=\"$page\" class=\"hidden\">$last_id</li>\n";
}
return $rv;
}

sub nav_detect_script
{
# Get goto hidden li element
my ($set_last) = @_;
my $rv;
if ($server_x_goto) {
my $link = quote_escape($server_x_goto);
$link =~ s/&amp;/&/g;
my $last_id = $set_last ? nav_set_last_id($link) : undef;
$rv =
"<li data-script-goto><script>plugins.navigation.detect(\"$link\");plugins.navigation.detect(\"$link\", 1);\$(\"li[data-script-goto]\").remove();</script></li>\n";
"<li data-script-goto><script>plugins.navigation.detect(\"$link\");plugins.navigation.detect(\"$link\", 1);\$(\"li[data-script-goto]\").remove();${last_id}</script></li>\n";
}
return $rv;
}
Expand Down
2 changes: 1 addition & 1 deletion unauthenticated/js/bundle.min.js

Large diffs are not rendered by default.

Binary file modified unauthenticated/js/bundle.min.js.gz
Binary file not shown.

0 comments on commit 0f3519d

Please sign in to comment.