diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index d99b3bd33..27e2a800e 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -402,4 +402,15 @@ exports.getAnimationDuration = function() { return parseInt($tw.wiki.getTiddlerText("$:/config/AnimationDuration","400"),10); }; +/* +Hash a string to a number +Derived from http://stackoverflow.com/a/15710692 +*/ +exports.hashString = function(str) { + return str.split("").reduce(function(a,b) { + a = ((a << 5) - a) + b.charCodeAt(0); + return a & a; + },0); +}; + })(); diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index b892a6390..481df4769 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -188,7 +188,7 @@ Widget.prototype.hasVariable = function(name,value) { }; /* -Construct a qualifying string based on concatenating the values of a given variable in the parent chain +Construct a qualifying string based on a hash of concatenating the values of a given variable in the parent chain */ Widget.prototype.getStateQualifier = function(name) { name = name || "transclusion"; @@ -200,7 +200,7 @@ Widget.prototype.getStateQualifier = function(name) { } node = node.parentWidget; } - return output.join(""); + return "{" + $tw.utils.hashString(output.join("")) + "}"; }; /*