Created
July 5, 2013 10:25
-
-
Save c3ry5/5933621 to your computer and use it in GitHub Desktop.
override backbone.js _updateHash to replace location.replace for old devices with window.history.replaceState
This file contains 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
var oldBrowser = (reContainsAll([/mozilla\/5.0/i, /android/i, /applewebkit/i], navigator.userAgent) | |
|| reContainsAll([/mozilla\/5.0/i, /iphone os (5|4|3|2|1){1}/i, /applewebkit/i], navigator.userAgent)) | |
&& !reContainsAll([/chrome/i], navigator.userAgent); | |
Backbone.History.prototype._updateHash = function(location, fragment, replace) { | |
var base = location.toString().replace(/(javascript:|#).*$/, '') + '#'; | |
if (replace) { | |
if (oldBrowser) { | |
window.history.replaceState({}, document.title, base + fragment); | |
} else { | |
location.replace(base + fragment); | |
} | |
} else { | |
location.hash = fragment; | |
} | |
} |
This file contains 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
var reContainsAll = function (arr, str) { | |
var ret = true; | |
_.each(arr, function (val) { | |
if (!str.match(val)) { | |
ret = false; | |
return; | |
} | |
}) | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment