mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-25 18:38:30 +00:00
Use localStorage first, location.hash later.
This commit is contained in:
parent
5f38fb4015
commit
592034ee28
2 changed files with 30 additions and 13 deletions
|
@ -17,15 +17,33 @@ $("div#munin_nodeview_tab>div").each(function (index) {
|
|||
/*
|
||||
* Update the URL with selected tab and active selected tab on page refresh
|
||||
*/
|
||||
$(document).ready(function () {
|
||||
if (location.hash) {
|
||||
$('a[href="' + location.hash + '"]').tab('show');
|
||||
}
|
||||
$(document.body).on("click", "a[data-toggle=tab]", function (event) {
|
||||
location.hash = this.getAttribute("href");
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||||
var id = $(this).parents('[role="tablist"]').attr('id');
|
||||
var key = 'lastTag';
|
||||
if (id) {
|
||||
key += ':' + id;
|
||||
}
|
||||
|
||||
localStorage.setItem(key, $(e.target).attr('href'));
|
||||
location.hash = $(e.target).attr('href');
|
||||
});
|
||||
});
|
||||
$(window).on('popstate', function () {
|
||||
var anchor = location.hash || $("a[data-toggle=tab]").first().attr("href");
|
||||
$('a[href="' + anchor + '"]').tab('show');
|
||||
});
|
||||
|
||||
$('[role="tablist"]').each(function (idx, elem) {
|
||||
var id = $(elem).attr('id');
|
||||
var key = 'lastTag';
|
||||
if (id) {
|
||||
key += ':' + id;
|
||||
}
|
||||
|
||||
var lastTab = localStorage.getItem(key);
|
||||
if (!lastTab) {
|
||||
lastTab = location.hash;
|
||||
}
|
||||
if (lastTab) {
|
||||
$('[href="' + lastTab + '"]').tab('show');
|
||||
}
|
||||
});
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue