@@ -1011,4 +1011,50 @@ if ($.support.pjax) {
1011
1011
ok ( frame . $ . pjax . state . id )
1012
1012
oldId = frame . $ . pjax . state . id
1013
1013
} )
1014
+
1015
+ asyncTest ( "handles going back to pjaxed state after reloading a fragment navigation" , function ( ) {
1016
+ var iframe = this . iframe
1017
+ var frame = this . frame
1018
+ var supportsHistoryState = 'state' in window . history
1019
+
1020
+ // Get some pjax state in the history.
1021
+ frame . $ . pjax ( {
1022
+ url : "hello.html" ,
1023
+ container : "#main" ,
1024
+ } )
1025
+ frame . $ ( "#main" ) . on ( "pjax:complete" , function ( ) {
1026
+ var state = frame . history . state
1027
+ ok ( frame . $ . pjax . state )
1028
+ if ( supportsHistoryState )
1029
+ ok ( frame . history . state )
1030
+
1031
+ // Navigate to a fragment, which will result in a new history entry with
1032
+ // no state object. $.pjax.state remains unchanged however.
1033
+ iframe . src = frame . location . href + '#foo'
1034
+ ok ( frame . $ . pjax . state )
1035
+ if ( supportsHistoryState )
1036
+ ok ( ! frame . history . state )
1037
+
1038
+ // Reload the frame. This will clear out $.pjax.state.
1039
+ frame . location . reload ( )
1040
+ $ ( iframe ) . one ( "load" , function ( ) {
1041
+ ok ( ! frame . $ . pjax . state )
1042
+ if ( supportsHistoryState )
1043
+ ok ( ! frame . history . state )
1044
+
1045
+ // Go back to #main. We'll get a popstate event with a pjax state
1046
+ // object attached from the initial pjax navigation, even though
1047
+ // $.pjax.state is null.
1048
+ window . iframeLoad = function ( ) {
1049
+ ok ( frame . $ . pjax . state )
1050
+ if ( supportsHistoryState ) {
1051
+ ok ( frame . history . state )
1052
+ equal ( frame . $ . pjax . state . id , state . id )
1053
+ }
1054
+ start ( )
1055
+ }
1056
+ frame . history . back ( )
1057
+ } )
1058
+ } )
1059
+ } )
1014
1060
}
0 commit comments