var hashchange = (function () { var exports = {}; var expected_hash; var changing_hash = false; // Some browsers zealously URI-decode the contents of // window.location.hash. So we hide our URI-encoding // by replacing % with . (like MediaWiki). exports.encodeHashComponent = function (str) { return encodeURIComponent(str) .replace(/\./g, '%2E') .replace(/%/g, '.'); }; function decodeHashComponent(str) { return decodeURIComponent(str.replace(/\./g, '%')); } exports.changehash = function (newhash) { if (changing_hash) { return; } $(document).trigger($.Event('hashchange.zulip')); expected_hash = newhash; window.location.hash = newhash; util.reset_favicon(); }; // Encodes an operator list into the // corresponding hash: the # component // of the narrow URL exports.operators_to_hash = function (operators) { var hash = '#'; if (operators !== undefined) { hash = '#narrow'; _.each(operators, function (elem) { // Support legacy tuples. var operator = elem.operator || elem[0]; var operand = elem.operand || elem[1]; hash += '/' + hashchange.encodeHashComponent(operator) + '/' + hashchange.encodeHashComponent(operand); }); } return hash; }; exports.save_narrow = function (operators) { if (changing_hash) { return; } var new_hash = exports.operators_to_hash(operators); exports.changehash(new_hash); }; function parse_narrow(hash) { var i, operators = []; for (i=1; i