|
168 | 168 | //get path from current hash, or from a file path |
169 | 169 | get: function( newPath ) { |
170 | 170 | if( newPath === undefined ) { |
171 | | - newPath = location.hash; |
| 171 | + if( $.support.pushState && !location.hash ){ |
| 172 | + newPath = location.href; |
| 173 | + } |
| 174 | + else{ |
| 175 | + newPath = location.hash; |
| 176 | + |
| 177 | + } |
172 | 178 | } |
173 | | - return path.stripHash( newPath ).replace( /[^\/]*\.[^\/*]+$/, '' ); |
| 179 | + return path.stripHash( newPath ); |
| 180 | + // Todo Todo Todo: this return used to apply the following: .replace( /[^\/]*\.[^\/*]+$/, '' ). |
| 181 | + // It doesn't work with pushstate, but WHY was it there??? |
174 | 182 | }, |
175 | 183 |
|
176 | 184 | //return the substring of a filepath before the sub-page key, for making a server request |
|
300 | 308 |
|
301 | 309 | //disable hashchange event listener internally to ignore one change |
302 | 310 | //toggled internally when location.hash is updated to match the url of a successful page load |
303 | | - ignoreNextHashChange: false |
| 311 | + ignoreNextHashChange: false, |
| 312 | + |
| 313 | + ignoreNextPopState: false |
304 | 314 | }, |
305 | 315 |
|
306 | 316 | //define first selector to receive focus when a page is shown |
|
862 | 872 | // for the dialog content to be used in the hash. Instead, we want |
863 | 873 | // to append the dialogHashKey to the url of the current page. |
864 | 874 | if ( isDialog && active ) { |
865 | | - url = active.url + dialogHashKey; |
| 875 | + //if pushState is enabled, we only need to set the hash to the dialogkey + something random |
| 876 | + url = ( $.support.pushState ? "" : active.url ) + dialogHashKey + ( Math.random().toString().slice(2,6) ); |
866 | 877 | } |
867 | 878 |
|
868 | 879 | // Set the location hash. |
|
1113 | 1124 | }); |
1114 | 1125 |
|
1115 | 1126 | //hashchange event handler |
1116 | | - $window.bind( "hashchange", function( e, triggered ) { |
| 1127 | + $window.bind( "hashchange popstate", function( e, triggered ) { |
1117 | 1128 | //find first page via hash |
1118 | | - var to = path.stripHash( location.hash ), |
| 1129 | + var to = path.get(), |
1119 | 1130 | //transition is false if it's the first page, undefined otherwise (and may be overridden by default) |
1120 | | - transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined; |
1121 | | - |
| 1131 | + transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined, |
| 1132 | + isDialog = urlHistory.stack.length > 1 && to.indexOf( dialogHashKey ) > -1, |
| 1133 | + isGeneratedPage = to.indexOf( $.mobile.subPageUrlKey ) > -1, |
| 1134 | + pushStateSupported = $.support.pushState, |
| 1135 | + currHref = location.href.split("#")[0]; |
| 1136 | + |
| 1137 | + if( e.type === "hashchange" && pushStateSupported && !isDialog ){ |
| 1138 | + if( isGeneratedPage ){ |
| 1139 | + var splitter = '&' + $.mobile.subPageUrlKey; |
| 1140 | + to = to.split( splitter ).join( "#" + splitter ); |
| 1141 | + } |
| 1142 | + //use replacestate to swap the hash-based url with something real |
| 1143 | + history.replaceState( {}, document.title, to ); |
| 1144 | + |
| 1145 | + //if it worked, return here. |
| 1146 | + if( location.href.split("#")[0] !== currHref ){ |
| 1147 | + return; |
| 1148 | + } |
| 1149 | + } |
| 1150 | + |
| 1151 | + |
| 1152 | + |
1122 | 1153 | //if listening is disabled (either globally or temporarily), or it's a dialog hash |
1123 | | - if( !$.mobile.hashListeningEnabled || urlHistory.ignoreNextHashChange ) { |
| 1154 | + // seems this ignored hashchange stuff is unnecessary with pushstate in play |
| 1155 | + if( e.type === "hashchange" && !pushStateSupported && ( !$.mobile.hashListeningEnabled || urlHistory.ignoreNextHashChange ) ) { |
1124 | 1156 | urlHistory.ignoreNextHashChange = false; |
1125 | 1157 | return; |
1126 | 1158 | } |
| 1159 | + |
| 1160 | + //if it's a generated subpage, like a nested list, only use the |
1127 | 1161 |
|
1128 | 1162 | // special case for dialogs |
1129 | | - if( urlHistory.stack.length > 1 && |
1130 | | - to.indexOf( dialogHashKey ) > -1 ) { |
1131 | | - |
| 1163 | + if( isDialog ) { |
| 1164 | + |
1132 | 1165 | // If current active page is not a dialog skip the dialog and continue |
1133 | 1166 | // in the same direction |
1134 | 1167 | if(!$.mobile.activePage.is( ".ui-dialog" )) { |
|
0 commit comments