Extract encode_operand/decode_operand in hashchange.js.

These are just one-liners for now, but they will set us up
to do different encodings for different narrows.
This commit is contained in:
Steve Howell
2017-01-05 14:36:02 -08:00
committed by Tim Abbott
parent 030c6649ae
commit 3ee733eb51

View File

@@ -15,10 +15,18 @@ exports.encodeHashComponent = function (str) {
.replace(/%/g, '.');
};
exports.encode_operand = function (operator, operand) {
return exports.encodeHashComponent(operand);
};
function decodeHashComponent(str) {
return decodeURIComponent(str.replace(/\./g, '%'));
}
exports.decode_operand = function (operator, operand) {
return decodeHashComponent(operand);
};
function set_hash(hash) {
var location = window.location;
@@ -67,7 +75,7 @@ exports.operators_to_hash = function (operators) {
var sign = elem.negated ? '-' : '';
hash += '/' + sign + hashchange.encodeHashComponent(operator)
+ '/' + hashchange.encodeHashComponent(operand);
+ '/' + hashchange.encode_operand(operator, operand);
});
}
@@ -90,7 +98,7 @@ exports.parse_narrow = function (hash) {
// but the user might write one.
try {
var operator = decodeHashComponent(hash[i]);
var operand = decodeHashComponent(hash[i+1] || '');
var operand = exports.decode_operand(operator, hash[i+1] || '');
var negated = false;
if (operator[0] === '-') {
negated = true;