@@ -440,7 +440,7 @@ javaxt.express.app.Horizon = function(parent, config) {
440
440
currTab = key ;
441
441
}
442
442
if ( key . toLowerCase ( ) === t ) {
443
- requestedTab = tab ;
443
+ requestedTab = key ;
444
444
}
445
445
}
446
446
}
@@ -452,33 +452,57 @@ javaxt.express.app.Horizon = function(parent, config) {
452
452
user . preferences = new javaxt . express . UserPreferences ( ( ) => {
453
453
454
454
455
- //Click on a tab
455
+ //Raise tab
456
456
if ( requestedTab ) {
457
457
458
- //Click on the requested tab
459
- requestedTab . click ( ) ;
460
-
461
-
462
458
//Remove tab parameter from the url
463
- var state = window . history . state ;
464
- if ( ! state ) state = { } ;
465
459
var url = window . location . href ;
466
460
url = url . replace ( "tab=" + getParameter ( "tab" ) , "" ) ;
467
461
if ( url . lastIndexOf ( "&" ) === url . length - 1 ) url = url . substring ( 0 , url . length - 1 ) ;
468
462
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 ( ) ;
470
475
471
476
}
472
477
else {
473
478
474
479
//Click on user's last tab
475
480
if ( ! currTab ) currTab = user . preferences . get ( "Tab" ) ;
476
481
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 ( ) ;
478
489
}
479
490
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
+
482
506
}
483
507
}
484
508
@@ -717,18 +741,11 @@ javaxt.express.app.Horizon = function(parent, config) {
717
741
if ( this . className === "active" ) return ;
718
742
719
743
//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
+ } ) ;
732
749
733
750
734
751
//Raise the tab
@@ -740,6 +757,56 @@ javaxt.express.app.Horizon = function(parent, config) {
740
757
} ;
741
758
742
759
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
+
743
810
//**************************************************************************
744
811
//** enablePopstateListener
745
812
//**************************************************************************
@@ -1040,6 +1107,7 @@ javaxt.express.app.Horizon = function(parent, config) {
1040
1107
var url = window . location . href ;
1041
1108
var idx = url . indexOf ( "?" ) ;
1042
1109
if ( idx > - 1 ) url = url . substring ( 0 , idx ) ;
1110
+ document . title = config . name ;
1043
1111
history . replaceState ( state , config . name , url ) ;
1044
1112
1045
1113
0 commit comments