@@ -130,6 +130,12 @@ javaxt.express.app.Horizon = function(parent, config) {
130130 autoLogoff : false ,
131131
132132
133+ /** If true, will enable users to navigate between tabs using the
134+ * browser's forward and back buttons. Default is false.
135+ */
136+ useBrowserHistory : false ,
137+
138+
133139 /** A shared array of javaxt.dhtml.Window components. All the windows in
134140 * the array are automatically closed when a user logs off or when the
135141 * logoff() method is called. You are encouraged to create your own
@@ -928,6 +934,7 @@ javaxt.express.app.Horizon = function(parent, config) {
928934 //** updateState
929935 //**************************************************************************
930936 var updateState = function ( params , replace ) {
937+ if ( config . useBrowserHistory !== true ) return ;
931938
932939 var title = params . title ;
933940 if ( ! title ) title = document . title ;
@@ -942,10 +949,6 @@ javaxt.express.app.Horizon = function(parent, config) {
942949 if ( ! state ) state = { } ;
943950
944951 state [ me . className ] = params ;
945- state [ me . className ] . lastUpdate = {
946- date : new Date ( ) . getTime ( ) ,
947- event : replace ? "replaceState" : "pushState"
948- } ;
949952
950953 if ( replace ) {
951954 document . title = title ;
@@ -963,12 +966,18 @@ javaxt.express.app.Horizon = function(parent, config) {
963966 //**************************************************************************
964967 var enablePopstateListener = function ( ) {
965968 disablePopstateListener ( ) ;
966- window . addEventListener ( 'popstate' , popstateListener ) ;
967969
968- //Set initial history. This is critical for the popstate listener
969- var state = window . history . state ;
970- if ( ! state ) state = { } ;
971- if ( ! state [ me . className ] ) history . replaceState ( { } , null , '' ) ;
970+ if ( config . useBrowserHistory === true ) {
971+
972+ //Add popstate listener
973+ window . addEventListener ( 'popstate' , popstateListener ) ;
974+
975+ //Set initial history. This is critical for the popstate listener
976+ var state = window . history . state ;
977+ if ( ! state ) state = { } ;
978+ if ( ! state [ me . className ] ) state [ me . className ] = { } ;
979+ history . replaceState ( state , null , '' ) ;
980+ }
972981 } ;
973982
974983
@@ -987,12 +996,14 @@ javaxt.express.app.Horizon = function(parent, config) {
987996 */
988997 var popstateListener = function ( e ) {
989998
990- if ( e . state [ me . className ] ) { //event emanated from this class
999+ if ( e . state [ me . className ] ) {
9911000
992- //Get tab name/label
1001+ //Get tab name/label from the history
9931002 var label = e . state [ me . className ] . tab ;
9941003
995- //Check if the label matches the requested tab in the url
1004+ //If the "requestedTab" keyword is set and a matching key/value pair
1005+ //is found in the url, update the label to match the requested tab
1006+ //in the url.
9961007 var t = getParameter ( config . keywords . requestedTab ) . toLowerCase ( ) ;
9971008 if ( t && t . length > 0 ) {
9981009 if ( t !== label . toLowerCase ( ) ) {
@@ -1010,14 +1021,10 @@ javaxt.express.app.Horizon = function(parent, config) {
10101021 }
10111022 }
10121023
1024+ //Raise tab
10131025 var tab = tabs [ label ] ;
10141026 if ( tab ) tab . raise ( ) ;
10151027 }
1016- else { //user clicked browser back button but there's no state?
1017-
1018- //Don't call history.back(); It may cause unintended side effects
1019- //in panels with thier own popstate listeners...
1020- }
10211028 } ;
10221029
10231030
@@ -1278,14 +1285,16 @@ javaxt.express.app.Horizon = function(parent, config) {
12781285
12791286
12801287 //Update URL
1281- var state = window . history . state ;
1282- if ( ! state ) state = { } ;
1283- var url = window . location . href ;
1284- var idx = url . indexOf ( "?" ) ;
1285- if ( idx > - 1 ) url = url . substring ( 0 , idx ) ;
1286- document . title = config . name ;
1287- history . replaceState ( state , config . name , url ) ;
1288-
1288+ if ( config . useBrowserHistory === true ) {
1289+ var state = window . history . state ;
1290+ if ( ! state ) state = { } ;
1291+ var url = window . location . href ;
1292+ var idx = url . indexOf ( "?" ) ;
1293+ if ( idx > - 1 ) url = url . substring ( 0 , idx ) ;
1294+ document . title = config . name ;
1295+ history . replaceState ( state , config . name , url ) ;
1296+ }
1297+
12891298
12901299 //Disable event listeners
12911300 disableEventListeners ( ) ;
0 commit comments