Skip to content

Commit e7a48aa

Browse files
committed
Updated 'popstate' related logic in the Horizon app
1 parent 91f9970 commit e7a48aa

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

ui/javascript/app/Horizon.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ javaxt.express.app.Horizon = function(parent, config) {
130130
//**************************************************************************
131131
//** update
132132
//**************************************************************************
133+
/** Used to initialize the app with a new user and a set of tabs
134+
* @param user Simple json object with an id. Additional attributes such
135+
* as name, contact info, etc may be present and used by the renderers
136+
* defined in the config (e.g. profileButton)
137+
* @param tabs Either an array or json object with tabs. Each entry should
138+
* have a name and a fully-qualified class (e.g. com.javaxt.Test). The
139+
* class will be instantiated at runtime. Note if the class has a public
140+
* update() method, it will be called after the class is instantiated.
141+
*/
133142
this.update = function(user, tabs){
134143

135144
//Update title
@@ -408,7 +417,9 @@ javaxt.express.app.Horizon = function(parent, config) {
408417
//Instantiate panel
409418
var cls = eval(className);
410419
panel = new cls(body, cfg);
420+
addShowHide(panel);
411421
panels[label] = panel;
422+
if (panel.update) panel.update();
412423
}
413424
};
414425

@@ -428,16 +439,24 @@ javaxt.express.app.Horizon = function(parent, config) {
428439

429440
tab.onclick = function(){
430441
if (this.className==="active") return;
431-
this.raise();
432442

443+
//Update history. Do this BEFORE raising the tab so that whatever
444+
//history the tab panel has happens AFTER the tab change event.
433445
var state = window.history.state;
434446
if (state==null) state = {};
435447
state[me.className] = {
436-
tab: label
448+
tab: label,
449+
lastUpdate: {
450+
date: new Date().getTime(),
451+
event: "pushState"
452+
}
437453
};
438-
439-
var url = ""; //window.location.href;
454+
var url = "";
440455
history.pushState(state, document.title, url);
456+
457+
458+
//Raise the tab
459+
this.raise();
441460
};
442461

443462
tabs[label] = tab;
@@ -471,9 +490,15 @@ javaxt.express.app.Horizon = function(parent, config) {
471490
/** Used to processes forward and back events from the browser
472491
*/
473492
var popstateListener = function(e) {
474-
var label = e.state[me.className].tab;
475-
var tab = tabs[label];
476-
tab.raise();
493+
494+
if (e.state[me.className]){
495+
var label = e.state[me.className].tab;
496+
var tab = tabs[label];
497+
if (tab) tab.raise();
498+
}
499+
else{
500+
history.back();
501+
}
477502
};
478503

479504

@@ -528,7 +553,7 @@ javaxt.express.app.Horizon = function(parent, config) {
528553
if (!profileMenu){
529554
var div = createElement("div", config.style.header.menuPopup);
530555
div.appendChild(createMenuOption("Account Settings", "edit", function(){
531-
console.log("Show Accout");
556+
console.log("Show Account");
532557
}));
533558
div.appendChild(createMenuOption("Sign Out", "times", function(){
534559
me.logoff();

0 commit comments

Comments
 (0)