mirror of https://github.com/zulip/zulip.git
js dependencies: Split hash_util.js from hashchange.js.
This commit is contained in:
parent
767f57ef03
commit
19d8d16126
|
@ -19,6 +19,7 @@ add_dependencies({
|
|||
compose_fade: 'js/compose_fade.js',
|
||||
people: 'js/people.js',
|
||||
unread: 'js/unread.js',
|
||||
hash_util: 'js/hash_util.js',
|
||||
hashchange: 'js/hashchange.js',
|
||||
narrow: 'js/narrow.js',
|
||||
activity: 'js/activity.js',
|
||||
|
@ -28,10 +29,6 @@ set_global('resize', {
|
|||
resize_page_components: function () {},
|
||||
});
|
||||
|
||||
set_global('hash_util', {
|
||||
encodeHashComponent: global.hashchange.encodeHashComponent,
|
||||
});
|
||||
|
||||
var me = {
|
||||
email: 'me@zulip.com',
|
||||
user_id: 999,
|
||||
|
@ -350,4 +347,3 @@ activity.presence_info[norbert.user_id] = { status: activity.ACTIVE };
|
|||
},
|
||||
]);
|
||||
}());
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ add_dependencies({
|
|||
emoji: 'js/emoji.js',
|
||||
people: 'js/people.js',
|
||||
stream_data: 'js/stream_data.js',
|
||||
hash_util: 'js/hash_util',
|
||||
hashchange: 'js/hashchange',
|
||||
fenced_code: 'js/fenced_code.js',
|
||||
});
|
||||
|
@ -54,10 +55,6 @@ set_global('$', function (obj) {
|
|||
|
||||
set_global('feature_flags', {local_echo: true});
|
||||
|
||||
set_global('hash_util', {
|
||||
encodeHashComponent: global.hashchange.encodeHashComponent,
|
||||
});
|
||||
|
||||
|
||||
jsdom.changeURL(window, 'http://zulip.zulipdev.com');
|
||||
set_global('window', window);
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
global.stub_out_jquery();
|
||||
|
||||
add_dependencies({
|
||||
hash_util: 'js/hash_util.js',
|
||||
people: 'js/people.js',
|
||||
});
|
||||
|
||||
var hashchange = require('js/hashchange.js');
|
||||
|
||||
set_global('hash_util', {
|
||||
encodeHashComponent: hashchange.encodeHashComponent,
|
||||
});
|
||||
|
||||
|
||||
(function test_operators_round_trip() {
|
||||
var operators;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
global.stub_out_jquery();
|
||||
|
||||
add_dependencies({
|
||||
hash_util: 'js/hash_util.js',
|
||||
hashchange: 'js/hashchange.js',
|
||||
people: 'js/people.js',
|
||||
stream_data: 'js/stream_data.js',
|
||||
|
@ -12,10 +13,6 @@ var Filter = global.Filter;
|
|||
var stream_data = global.stream_data;
|
||||
var _ = global._;
|
||||
|
||||
set_global('hash_util', {
|
||||
encodeHashComponent: global.hashchange.encodeHashComponent,
|
||||
});
|
||||
|
||||
function set_filter(operators) {
|
||||
operators = _.map(operators, function (op) {
|
||||
return {operator: op[0], operand: op[1]};
|
||||
|
@ -135,7 +132,7 @@ function set_filter(operators) {
|
|||
uri = narrow.by_sender_uri(ray.email);
|
||||
assert.equal(uri, '#narrow/sender/22-ray');
|
||||
|
||||
var emails = global.hashchange.decode_operand('pm-with', '22,23-group');
|
||||
var emails = global.hash_util.decode_operand('pm-with', '22,23-group');
|
||||
assert.equal(emails, 'alice@example.com,ray@example.com');
|
||||
}());
|
||||
|
||||
|
@ -224,4 +221,3 @@ function set_filter(operators) {
|
|||
assert.deepEqual(filter.operands('sender'), ['showell@foo.com']);
|
||||
assert.deepEqual(filter.operands('stream'), ['steve@foo.com']);
|
||||
}());
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ global.stub_out_jquery();
|
|||
add_dependencies({
|
||||
Handlebars: 'handlebars',
|
||||
templates: 'js/templates',
|
||||
hash_util: 'js/hash_util',
|
||||
hashchange: 'js/hashchange',
|
||||
narrow: 'js/narrow',
|
||||
people: 'js/people',
|
||||
|
@ -14,10 +15,6 @@ set_global('message_store', {
|
|||
|
||||
set_global('unread', {});
|
||||
|
||||
set_global('hash_util', {
|
||||
encodeHashComponent: global.hashchange.encodeHashComponent,
|
||||
});
|
||||
|
||||
// TODO: move pm_list-related tests to their own module
|
||||
var pm_list = require('js/pm_list.js');
|
||||
|
||||
|
@ -70,4 +67,3 @@ global.people.initialize_current_user(me.user_id);
|
|||
var conversation = $(convos_html).find('a').text().trim();
|
||||
assert.equal(conversation, 'Alice, Bob');
|
||||
}());
|
||||
|
||||
|
|
|
@ -9,16 +9,13 @@ add_dependencies({
|
|||
people: 'js/people.js',
|
||||
stream_color: 'js/stream_color.js',
|
||||
narrow: 'js/narrow.js',
|
||||
hash_util: 'js/hash_util.js',
|
||||
hashchange: 'js/hashchange.js',
|
||||
util: 'js/util.js',
|
||||
});
|
||||
|
||||
set_global('blueslip', {});
|
||||
|
||||
set_global('hash_util', {
|
||||
encodeHashComponent: global.hashchange.encodeHashComponent,
|
||||
});
|
||||
|
||||
var stream_data = require('js/stream_data.js');
|
||||
var people = global.people;
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ global.stub_out_jquery();
|
|||
add_dependencies({
|
||||
Handlebars: 'handlebars',
|
||||
colorspace: 'js/colorspace',
|
||||
hash_util: 'js/hash_util',
|
||||
hashchange: 'js/hashchange',
|
||||
muting: 'js/muting',
|
||||
narrow: 'js/narrow',
|
||||
|
@ -16,10 +17,6 @@ add_dependencies({
|
|||
|
||||
var stream_list = require('js/stream_list.js');
|
||||
|
||||
set_global('hash_util', {
|
||||
encodeHashComponent: global.hashchange.encodeHashComponent,
|
||||
});
|
||||
|
||||
|
||||
var jsdom = require("jsdom");
|
||||
var window = jsdom.jsdom().defaultView;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
add_dependencies({
|
||||
Handlebars: 'handlebars',
|
||||
hash_util: 'js/hash_util',
|
||||
hashchange: 'js/hashchange',
|
||||
muting: 'js/muting',
|
||||
narrow: 'js/narrow',
|
||||
|
@ -15,10 +16,6 @@ global.$ = require('jquery')(window);
|
|||
|
||||
var topic_list = require('js/topic_list.js');
|
||||
|
||||
set_global('hash_util', {
|
||||
encodeHashComponent: global.hashchange.encodeHashComponent,
|
||||
});
|
||||
|
||||
global.compile_template('topic_list_item');
|
||||
|
||||
(function test_topic_list_build_widget() {
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
var hash_util = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
// 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, '.');
|
||||
};
|
||||
|
||||
exports.encode_operand = function (operator, operand) {
|
||||
if ((operator === 'pm-with') || (operator === 'sender')) {
|
||||
var slug = people.emails_to_slug(operand);
|
||||
if (slug) {
|
||||
return slug;
|
||||
}
|
||||
}
|
||||
|
||||
return exports.encodeHashComponent(operand);
|
||||
};
|
||||
|
||||
exports.decodeHashComponent = function (str) {
|
||||
return decodeURIComponent(str.replace(/\./g, '%'));
|
||||
};
|
||||
|
||||
exports.decode_operand = function (operator, operand) {
|
||||
if ((operator === 'pm-with') || (operator === 'sender')) {
|
||||
var emails = people.slug_to_emails(operand);
|
||||
if (emails) {
|
||||
return emails;
|
||||
}
|
||||
}
|
||||
|
||||
return exports.decodeHashComponent(operand);
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
||||
}());
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = hash_util;
|
||||
}
|
|
@ -5,42 +5,6 @@ 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, '.');
|
||||
};
|
||||
|
||||
exports.encode_operand = function (operator, operand) {
|
||||
if ((operator === 'pm-with') || (operator === 'sender')) {
|
||||
var slug = people.emails_to_slug(operand);
|
||||
if (slug) {
|
||||
return slug;
|
||||
}
|
||||
}
|
||||
|
||||
return exports.encodeHashComponent(operand);
|
||||
};
|
||||
|
||||
function decodeHashComponent(str) {
|
||||
return decodeURIComponent(str.replace(/\./g, '%'));
|
||||
}
|
||||
|
||||
exports.decode_operand = function (operator, operand) {
|
||||
if ((operator === 'pm-with') || (operator === 'sender')) {
|
||||
var emails = people.slug_to_emails(operand);
|
||||
if (emails) {
|
||||
return emails;
|
||||
}
|
||||
}
|
||||
|
||||
return decodeHashComponent(operand);
|
||||
};
|
||||
|
||||
function set_hash(hash) {
|
||||
var location = window.location;
|
||||
|
||||
|
@ -89,7 +53,7 @@ exports.operators_to_hash = function (operators) {
|
|||
|
||||
var sign = elem.negated ? '-' : '';
|
||||
hash += '/' + sign + hash_util.encodeHashComponent(operator)
|
||||
+ '/' + hashchange.encode_operand(operator, operand);
|
||||
+ '/' + hash_util.encode_operand(operator, operand);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -111,8 +75,8 @@ exports.parse_narrow = function (hash) {
|
|||
// We don't construct URLs with an odd number of components,
|
||||
// but the user might write one.
|
||||
try {
|
||||
var operator = decodeHashComponent(hash[i]);
|
||||
var operand = exports.decode_operand(operator, hash[i+1] || '');
|
||||
var operator = hash_util.decodeHashComponent(hash[i]);
|
||||
var operand = hash_util.decode_operand(operator, hash[i+1] || '');
|
||||
var negated = false;
|
||||
if (operator[0] === '-') {
|
||||
negated = true;
|
||||
|
|
|
@ -603,7 +603,7 @@ exports.huddle_with_uri = function (user_ids_string) {
|
|||
// This method is convenient is convenient for callers
|
||||
// that have already converted emails to a comma-delimited
|
||||
// list of user_ids. We should be careful to keep this
|
||||
// consistent with hashchange.decode_operand.
|
||||
// consistent with hash_util.decode_operand.
|
||||
return "#narrow/pm-with/" + user_ids_string + '-group';
|
||||
};
|
||||
|
||||
|
|
|
@ -13,9 +13,6 @@ var compose_actions = {};
|
|||
compose_actions.start = compose.start;
|
||||
compose_actions.cancel = compose.cancel;
|
||||
|
||||
var hash_util = {};
|
||||
hash_util.encodeHashComponent = hashchange.encodeHashComponent;
|
||||
|
||||
var compose_state = {};
|
||||
compose_state.has_message_content = compose.has_message_content;
|
||||
compose_state.recipient = compose.recipient;
|
||||
|
|
|
@ -50,7 +50,7 @@ def one_click_unsubscribe_link(user_profile, endpoint):
|
|||
|
||||
def hashchange_encode(string):
|
||||
# type: (Text) -> Text
|
||||
# Do the same encoding operation as hashchange.encodeHashComponent on the
|
||||
# Do the same encoding operation as hash_util.encodeHashComponent on the
|
||||
# frontend.
|
||||
# `safe` has a default value of "/", but we want those encoded, too.
|
||||
return urllib.parse.quote(
|
||||
|
|
|
@ -866,6 +866,7 @@ JS_SPECS = {
|
|||
'js/hotkey.js',
|
||||
'js/favicon.js',
|
||||
'js/notifications.js',
|
||||
'js/hash_util.js',
|
||||
'js/hashchange.js',
|
||||
'js/invite.js',
|
||||
'js/message_flags.js',
|
||||
|
|
Loading…
Reference in New Issue