Fixes for permalinks not working on Firefox

Sigh. It’s frustrating that the few browser differences I’m running
into in 2014 are mostly horribly familiar from 2005
This commit is contained in:
Jermolene 2014-05-05 19:21:57 +01:00
parent ffb6c8ab81
commit 986a20b22b
2 changed files with 16 additions and 4 deletions

View File

@ -202,6 +202,14 @@ $tw.utils.htmlDecode = function(s) {
return s.toString().replace(/&lt;/mg,"<").replace(/&nbsp;/mg,"\xA0").replace(/&gt;/mg,">").replace(/&quot;/mg,"\"").replace(/&amp;/mg,"&");
};
/*
Get the browser location.hash. We don't use location.hash because of the way that Firefox auto-urldecodes it (see http://stackoverflow.com/questions/1703552/encoding-of-window-location-hash)
*/
$tw.utils.getLocationHash = function() {
var parts = window.location.href.split('#');
return "#" + (parts.length > 1 ? parts[1] : "");
};
/*
Pad a string to a given length with "0"s. Length defaults to 2
*/
@ -1627,7 +1635,7 @@ $tw.boot.startup = function(options) {
if(location.hash === "#:safe") {
$tw.safeMode = true;
} else {
$tw.locationHash = location.hash;
$tw.locationHash = $tw.utils.getLocationHash();
}
}
// Initialise some more $tw properties

View File

@ -36,8 +36,9 @@ exports.startup = function() {
});
// Listen for changes to the browser location hash
window.addEventListener("hashchange",function() {
if(window.location.hash !== $tw.locationHash) {
$tw.locationHash = window.location.hash;
var hash = $tw.utils.getLocationHash();
if(hash !== $tw.locationHash) {
$tw.locationHash = hash;
openStartupTiddlers({defaultToCurrentStory: true});
}
},false)
@ -104,8 +105,11 @@ function updateLocationHash() {
}
$tw.locationHash = "#" + encodeURIComponent(targetTiddler) + ":" + encodeURIComponent($tw.utils.stringifyList(storyList));
// Only change the location hash if we must, thus avoiding unnecessary onhashchange events
if(window.location.hash !== $tw.locationHash) {
// console.log("Testing",$tw.utils.getLocationHash(),$tw.locationHash)
if($tw.utils.getLocationHash() !== $tw.locationHash) {
window.location.hash = $tw.locationHash;
console.log("Just set",$tw.locationHash,$tw.utils.getLocationHash())
}
}