mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +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
|
* Update the URL with selected tab and active selected tab on page refresh
|
||||||
*/
|
*/
|
||||||
$(document).ready(function () {
|
(function () {
|
||||||
if (location.hash) {
|
'use strict';
|
||||||
$('a[href="' + location.hash + '"]').tab('show');
|
|
||||||
}
|
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||||||
$(document.body).on("click", "a[data-toggle=tab]", function (event) {
|
var id = $(this).parents('[role="tablist"]').attr('id');
|
||||||
location.hash = this.getAttribute("href");
|
var key = 'lastTag';
|
||||||
|
if (id) {
|
||||||
|
key += ':' + id;
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.setItem(key, $(e.target).attr('href'));
|
||||||
|
location.hash = $(e.target).attr('href');
|
||||||
});
|
});
|
||||||
});
|
|
||||||
$(window).on('popstate', function () {
|
$('[role="tablist"]').each(function (idx, elem) {
|
||||||
var anchor = location.hash || $("a[data-toggle=tab]").first().attr("href");
|
var id = $(elem).attr('id');
|
||||||
$('a[href="' + anchor + '"]').tab('show');
|
var key = 'lastTag';
|
||||||
});
|
if (id) {
|
||||||
|
key += ':' + id;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastTab = localStorage.getItem(key);
|
||||||
|
if (!lastTab) {
|
||||||
|
lastTab = location.hash;
|
||||||
|
}
|
||||||
|
if (lastTab) {
|
||||||
|
$('[href="' + lastTab + '"]').tab('show');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
3
templates/munstrap/static/js/munstrap.min.js
vendored
3
templates/munstrap/static/js/munstrap.min.js
vendored
|
@ -1,2 +1 @@
|
||||||
$("ul#tabs>li>a").each(function(a){a=$(this).attr("href").replace(/[^#\w]/gi,"_");$(this).attr("href",a)});$("div#munin_nodeview_tab>div").each(function(a){a=$(this).attr("id").replace(/[^\w]/gi,"_");$(this).attr("id",a)});$(document).ready(function(){location.hash&&$('a[href="'+location.hash+'"]').tab("show");$(document.body).on("click","a[data-toggle=tab]",function(a){location.hash=this.getAttribute("href")})});
|
$("ul#tabs>li>a").each(function(index){var eid=$(this).attr("href").replace(/[^#\w]/gi,"_");$(this).attr("href",eid)});$("div#munin_nodeview_tab>div").each(function(index){var eid=$(this).attr("id").replace(/[^\w]/gi,"_");$(this).attr("id",eid)});(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")});$('[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")}})})();
|
||||||
$(window).on("popstate",function(){var a=location.hash||$("a[data-toggle=tab]").first().attr("href");$('a[href="'+a+'"]').tab("show")});
|
|
Loading…
Add table
Add a link
Reference in a new issue