@@ -46,6 +46,57 @@ function baseTagTest(){
4646 return rebase . indexOf ( fauxBase ) === 0 ;
4747} ;
4848
49+ //support test for whether a hash change makes a history entry
50+ //not called until the page navigation needs to make sure ajax usage is safe
51+ function testHashMakesHistory ( ) {
52+ var win = window ,
53+ count = 0 ,
54+ addItem = function ( ) {
55+ win . location . hash += "*" ;
56+ } ,
57+ prevHash ,
58+ histLength ,
59+ historyMade ;
60+
61+ //set prevHash to current hash
62+ prevHash = win . location . hash ;
63+
64+ //disable hash listening
65+ $ . mobile . urlHistory . listeningEnabled = false ;
66+
67+ //bind to resulting hashchange, set back again after 2 changes
68+ $ ( win ) . bind ( "hashchange.hashMakesHistory" , function ( ) {
69+ count ++ ;
70+ if ( count == 2 ) {
71+ $ . mobile . urlHistory . listeningEnabled = true ;
72+ $ ( win ) . unbind ( "hashchange.hashMakesHistory" ) ;
73+ }
74+ } ) ;
75+
76+ //change hash, clears forward "history"
77+ addItem ( ) ;
78+
79+ //get hist length
80+ histLength = win . history . length ;
81+
82+ //add another item for comparison
83+ addItem ( ) ;
84+
85+ //define support bool
86+ historyMade = histLength < win . history . length ;
87+
88+ //if it made a history entry, we can go back one to remove the faux entry
89+ if ( historyMade ) {
90+ history . go ( - 2 ) ;
91+ }
92+ //otherwise, just put things where they were before because it doesn't matter
93+ else {
94+ win . location . hash = prevHash ;
95+ }
96+
97+ return historyMade ;
98+ } ;
99+
49100$ . extend ( $ . support , {
50101 orientation : "orientation" in window ,
51102 touch : "ontouchend" in document ,
@@ -63,4 +114,8 @@ fakeBody.remove();
63114//for ruling out shadows via css
64115if ( ! $ . support . boxShadow ) { $ ( 'html' ) . addClass ( 'ui-mobile-nosupport-boxshadow' ) ; }
65116
117+ $ ( function ( ) {
118+ $ . support . hashMakesHistory = testHashMakesHistory ( ) ;
119+ } ) ;
120+
66121} ) ( jQuery ) ;
0 commit comments