Created
January 25, 2017 21:06
-
-
Save sadasant/8ec220c07764c36180f885cb11f934c7 to your computer and use it in GitHub Desktop.
Duranda's History checkUrl fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks the current URL to see if it has changed, and if it has, calls `loadUrl`, normalizing across the hidden iframe. | |
* @method checkUrl | |
* @return {boolean} Returns true/false from loading the url. | |
*/ | |
function cleanFragment(s) { | |
return s | |
.replace(/%7E/g, "~") | |
.replace(/%21/g, "!") | |
.replace(/%2A/g, "*") | |
.replace(/%28/g, "(") | |
.replace(/%29/g, ")") | |
.replace(/%27/g, "'") | |
.replace(/%2D/g, "-") | |
.replace(/%2E/g, ".") | |
.replace(/%5F/g, "_") | |
} | |
history.checkUrl = function() { | |
var current = history.getFragment(); | |
var compareCurrent = cleanFragment(current); | |
var historyFragment = cleanFragment(history.fragment); | |
if (compareCurrent === historyFragment && history.iframe) { | |
current = history.getFragment(history.getHash(history.iframe)); | |
} | |
if (compareCurrent === historyFragment) { | |
return false; | |
} | |
if (history.iframe) { | |
history.navigate(current, false); | |
} | |
history.loadUrl(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment