mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Keep the opened tab open after submit or reload of a page.
Also we can now jump to tabs using a hash link, which is useful, for editing quickjumps.
This commit is contained in:
parent
c94d3cdc68
commit
edabaeaced
1 changed files with 40 additions and 0 deletions
|
@ -264,6 +264,46 @@ $(document).on("ajaxUI:start", function registerJumpToTop() {
|
|||
}).tooltip();
|
||||
});
|
||||
|
||||
/**
|
||||
* This listener keeps track of which tab is currently selected (using hash and localstorage) and will try to open
|
||||
* that tab on reload. That means that if the user changes something, he does not have to switch back to the tab
|
||||
* where he was before submit.
|
||||
*/
|
||||
$(document).on("ajaxUI:reload ajaxUI:start", function () {
|
||||
//Determine which tab should be shown (use hash if specified, otherwise use localstorage)
|
||||
var $activeTab = null;
|
||||
if (location.hash) {
|
||||
$activeTab = $('a[href=\'' + location.hash + '\']');
|
||||
} else if(localStorage.getItem('activeTab')) {
|
||||
$activeTab = $('a[href="' + localStorage.getItem('activeTab') + '"]');
|
||||
}
|
||||
|
||||
if($activeTab) {
|
||||
//Findout if the tab has any parent tab we have to show before
|
||||
var parents = $($activeTab).parents('.tab-pane');
|
||||
parents.each(function(n) {
|
||||
$('a[href="#' + $(this).attr('id') + '"]').tab('show');
|
||||
});
|
||||
//Finally show the active tab itself
|
||||
$activeTab.tab('show');
|
||||
}
|
||||
|
||||
$('body').on('click', 'a[data-toggle=\'tab\']', function (e) {
|
||||
e.preventDefault()
|
||||
var tab_name = this.getAttribute('href')
|
||||
if (history.pushState) {
|
||||
history.pushState(null, null, tab_name)
|
||||
}
|
||||
else {
|
||||
location.hash = tab_name
|
||||
}
|
||||
localStorage.setItem('activeTab', tab_name)
|
||||
|
||||
$(this).tab('show');
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
//Need for proper body padding, with every navbar height
|
||||
$(window).resize(function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue