Skip to content

Commit a03c7c1

Browse files
committed
Tweaked logic used to manage history in the Horizon app
1 parent aa16e80 commit a03c7c1

File tree

1 file changed

+92
-24
lines changed

1 file changed

+92
-24
lines changed

ui/javascript/app/Horizon.js

Lines changed: 92 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ javaxt.express.app.Horizon = function(parent, config) {
440440
currTab = key;
441441
}
442442
if (key.toLowerCase()===t){
443-
requestedTab = tab;
443+
requestedTab = key;
444444
}
445445
}
446446
}
@@ -452,33 +452,57 @@ javaxt.express.app.Horizon = function(parent, config) {
452452
user.preferences = new javaxt.express.UserPreferences(()=>{
453453

454454

455-
//Click on a tab
455+
//Raise tab
456456
if (requestedTab){
457457

458-
//Click on the requested tab
459-
requestedTab.click();
460-
461-
462458
//Remove tab parameter from the url
463-
var state = window.history.state;
464-
if (!state) state = {};
465459
var url = window.location.href;
466460
url = url.replace("tab="+getParameter("tab"),"");
467461
if (url.lastIndexOf("&")===url.length-1) url = url.substring(0, url.length-1);
468462
if (url.lastIndexOf("?")===url.length-1) url = url.substring(0, url.length-1);
469-
history.replaceState(state, document.title, url);
463+
464+
465+
//Update history
466+
updateHistory({
467+
title: config.name + " - " + requestedTab,
468+
tab: requestedTab,
469+
url: url
470+
});
471+
472+
473+
//Raise the tab
474+
tabs[requestedTab].raise();
470475

471476
}
472477
else{
473478

474479
//Click on user's last tab
475480
if (!currTab) currTab = user.preferences.get("Tab");
476481
if (currTab && tabs[currTab]){
477-
tabs[currTab].click();
482+
483+
updateHistory({
484+
title: config.name + " - " + currTab,
485+
tab: currTab
486+
});
487+
488+
tabs[currTab].raise();
478489
}
479490
else{
480-
var tab = Object.values(tabs)[0];
481-
if (tab) tab.click();
491+
492+
for (var tabLabel in tabs) {
493+
if (tabs.hasOwnProperty(tabLabel)){
494+
495+
updateHistory({
496+
title: config.name + " - " + tabLabel,
497+
tab: tabLabel
498+
});
499+
500+
tabs[tabLabel].raise();
501+
502+
break;
503+
}
504+
}
505+
482506
}
483507
}
484508

@@ -717,18 +741,11 @@ javaxt.express.app.Horizon = function(parent, config) {
717741
if (this.className==="active") return;
718742

719743
//Update history. Do this BEFORE raising the tab so that whatever
720-
//history the tab panel has happens AFTER the tab change event.
721-
var state = window.history.state;
722-
if (state==null) state = {};
723-
state[me.className] = {
724-
tab: label,
725-
lastUpdate: {
726-
date: new Date().getTime(),
727-
event: "pushState"
728-
}
729-
};
730-
var url = "";
731-
history.pushState(state, document.title, url);
744+
//history the tab panel wants to modify happens AFTER the tab change.
745+
addHistory({
746+
title: config.name + " - " + label,
747+
tab: label
748+
});
732749

733750

734751
//Raise the tab
@@ -740,6 +757,56 @@ javaxt.express.app.Horizon = function(parent, config) {
740757
};
741758

742759

760+
//**************************************************************************
761+
//** addHistory
762+
//**************************************************************************
763+
var addHistory = function(params){
764+
updateState(params, false);
765+
};
766+
767+
768+
//**************************************************************************
769+
//** updateHistory
770+
//**************************************************************************
771+
var updateHistory = function(params){
772+
updateState(params, true);
773+
};
774+
775+
776+
//**************************************************************************
777+
//** updateState
778+
//**************************************************************************
779+
var updateState = function(params, replace){
780+
781+
var title = params.title;
782+
if (!title) title = document.title;
783+
784+
var url = "";
785+
if (params.url){
786+
url = params.url;
787+
delete params.url;
788+
}
789+
790+
var state = window.history.state;
791+
if (!state) state = {};
792+
793+
state[me.className] = params;
794+
state[me.className].lastUpdate = {
795+
date: new Date().getTime(),
796+
event: replace ? "replaceState" : "pushState"
797+
};
798+
799+
if (replace){
800+
document.title = title;
801+
history.replaceState(state, title, url);
802+
}
803+
else{
804+
history.pushState(state, title, url);
805+
document.title = title;
806+
}
807+
};
808+
809+
743810
//**************************************************************************
744811
//** enablePopstateListener
745812
//**************************************************************************
@@ -1040,6 +1107,7 @@ javaxt.express.app.Horizon = function(parent, config) {
10401107
var url = window.location.href;
10411108
var idx = url.indexOf("?");
10421109
if (idx>-1) url = url.substring(0, idx);
1110+
document.title = config.name;
10431111
history.replaceState(state, config.name, url);
10441112

10451113

0 commit comments

Comments
 (0)