|
122 | 122 | **/
|
123 | 123 | if (supportHistory == false) return Mobilebone;
|
124 | 124 |
|
| 125 | + /** |
| 126 | + * don't excute window.onpopstate when page load |
| 127 | + **/ |
| 128 | + history.popstate = false; |
125 | 129 |
|
126 | 130 | /**
|
127 | 131 | * Function for transition
|
|
326 | 330 | if (url_push && /^#/.test(url_push) == false) {
|
327 | 331 | url_push = "#" + url_push;
|
328 | 332 | }
|
| 333 | + |
329 | 334 | if (supportHistory && this.pushStateEnabled && options.history !== false && url_push) {
|
| 335 | + // don't trigger 'popstate' events |
| 336 | + history.popstate = false; |
330 | 337 | // if only pageIn, use 'replaceState'
|
331 | 338 | history[pageOut? "pushState": "replaceState"](null, document.title, url_push.replace(/^#/, "#&"));
|
332 | 339 | }
|
| 340 | + // reset to popable state |
| 341 | + history.popstate = true; |
333 | 342 |
|
334 | 343 | // store page-id, just once
|
335 | 344 | if (!store[pageid]) {
|
|
782 | 791 | * Initialization. Load page according to location.hash. And bind link-catch events.
|
783 | 792 | **/
|
784 | 793 | Mobilebone.init = function() {
|
785 |
| - if (hasInited == true) return 'Don\'t repeat initialization!'; |
| 794 | + if (hasInited == true) return 'Don\'t repeat initialization!'; |
| 795 | + |
786 | 796 | var hash = location.hash.replace("#&", "#"), ele_in = null;
|
787 | 797 | if (hash == "" || hash == "#") {
|
788 | 798 | this.transition(document.querySelector("." + this.classPage));
|
|
995 | 1005 | * page change when history change
|
996 | 1006 | **/
|
997 | 1007 | window.addEventListener("popstate", function() {
|
| 1008 | + console.log(history.popstate); |
| 1009 | + if (history.popstate == false) { |
| 1010 | + history.popstate = true; |
| 1011 | + return; |
| 1012 | + } |
| 1013 | + |
998 | 1014 | var hash = location.hash.replace("#&", "").replace("#", ""), page_in = null;
|
999 | 1015 | if (hash == "") {
|
1000 | 1016 | // if no hash, get first page as 'page_in'
|
|
0 commit comments