eslint: Enable prefer-arrow-callback.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-07-01 16:45:54 -07:00 committed by Tim Abbott
parent 960174408f
commit a79322bc94
160 changed files with 873 additions and 1012 deletions

View File

@ -118,6 +118,7 @@
"space-unary-ops": "error",
"no-whitespace-before-property": "error",
"one-var": [ "error", "never" ],
"prefer-arrow-callback": "error",
"prefer-const": [ "error",
{
"ignoreReadBeforeAssign": true
@ -366,7 +367,9 @@
"frontend_tests/casper_lib/*.js"
],
"rules": {
"no-var": "off" // PhantomJS doesnt support let, const
// Dont require ES features that PhantomJS doesnt support
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
{

View File

@ -248,7 +248,7 @@ run_test('retry', () => {
},
check_ajax_options: function (options) {
global.patch_builtin('setTimeout', function (f, delay) {
global.patch_builtin('setTimeout', (f, delay) => {
assert.equal(delay, 0);
f();
});
@ -276,7 +276,7 @@ run_test('too_many_pending', () => {
blueslip.expect('warn',
'The length of pending_requests is over 50. ' +
'Most likely they are not being correctly removed.');
_.times(50, function () {
_.times(50, () => {
channel.post({});
});
});

View File

@ -91,20 +91,20 @@ run_test('adjust_mac_shortcuts', () => {
common.has_mac_keyboard = function () { return false; };
key_no = 1;
keys_to_test_non_mac.forEach(function (value, key) {
keys_to_test_non_mac.forEach((value, key) => {
keys_elem_list.push(get_key_stub_html(key, value, "hotkey_non_mac_" + key_no));
key_no += 1;
});
common.adjust_mac_shortcuts(".markdown_content");
keys_elem_list.forEach(function (key_elem) {
keys_elem_list.forEach((key_elem) => {
assert(key_elem.text(), key_elem.expected_key());
});
keys_elem_list = [];
key_no = 1;
common.has_mac_keyboard = function () { return true; };
keys_to_test_mac.forEach(function (value, key) {
keys_to_test_mac.forEach((value, key) => {
keys_elem_list.push(get_key_stub_html(key, value, "hotkey_" + key_no));
key_no += 1;
});
@ -115,7 +115,7 @@ run_test('adjust_mac_shortcuts', () => {
}
};
common.adjust_mac_shortcuts(".markdown_content");
keys_elem_list.forEach(function (key_elem) {
keys_elem_list.forEach((key_elem) => {
assert.equal(key_elem.text(), key_elem.expected_key());
});

View File

@ -108,7 +108,7 @@ run_test('basics', () => {
return self;
}());
set_global('$', function (sel) {
set_global('$', (sel) => {
if (sel.stub) {
// The component often redundantly re-wraps objects.
return sel;

View File

@ -142,7 +142,7 @@ run_test('validate_stream_message_address_info', () => {
sub.subscribed = false;
stream_data.add_sub(sub);
global.stub_templates(function (template_name) {
global.stub_templates((template_name) => {
assert.equal(template_name, 'compose_not_subscribed');
return 'compose_not_subscribed_stub';
});
@ -204,7 +204,7 @@ run_test('validate', () => {
$("#zephyr-mirror-error").is = noop;
$("#private_message_recipient").select(noop);
global.stub_templates(function (fn) {
global.stub_templates((fn) => {
assert.equal(fn, 'input_pill');
return '<div>pill-html</div>';
});
@ -325,7 +325,7 @@ run_test('validate_stream_message', () => {
assert.equal(stream_name, 'social');
return 16;
};
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
assert.equal(template_name, 'compose_all_everyone');
assert.equal(data.count, 16);
return 'compose_all_everyone_stub';
@ -601,7 +601,7 @@ run_test('send_message', () => {
return stub_state;
}
global.patch_builtin('setTimeout', function (func) {
global.patch_builtin('setTimeout', (func) => {
func();
});
global.server_events = {
@ -868,7 +868,7 @@ run_test('warn_if_private_stream_is_linked', () => {
const checks = [
(function () {
let called;
global.stub_templates(function (template_name, context) {
global.stub_templates((template_name, context) => {
called = true;
assert.equal(template_name, 'compose_private_stream_alert');
assert.equal(context.stream_name, 'Denmark');
@ -1144,7 +1144,7 @@ run_test('warn_if_mentioning_unsubscribed_user', () => {
(function () {
let called;
global.stub_templates(function (template_name, context) {
global.stub_templates((template_name, context) => {
called = true;
assert.equal(template_name, 'compose_invite_users');
assert.equal(context.user_id, 34);

View File

@ -14,9 +14,7 @@ zrequire('composebox_typeahead');
zrequire('recent_senders');
zrequire('settings_org');
const settings_config = zrequire('settings_config');
set_global('md5', function (s) {
return 'md5-' + s;
});
set_global('md5', (s) => 'md5-' + s);
// To be eliminated in next commit:
stream_data.update_calculated_fields = () => {};
@ -320,7 +318,7 @@ run_test('content_typeahead_selected', () => {
},
});
let set_timeout_called = false;
global.patch_builtin('setTimeout', function (f, time) {
global.patch_builtin('setTimeout', (f, time) => {
f();
assert.equal(time, 0);
set_timeout_called = true;

View File

@ -129,7 +129,7 @@ function assert_same(actual, expected) {
const with_overrides = global.with_overrides; // make lint happy
with_overrides(function (override) {
with_overrides((override) => {
// alert_words
assert(!alert_words.has_alert_word('fire'));
assert(!alert_words.has_alert_word('lunch'));
@ -146,21 +146,21 @@ with_overrides(function (override) {
assert(alert_words.has_alert_word('lunch'));
});
with_overrides(function (override) {
with_overrides((override) => {
// attachments
const event = event_fixtures.attachment;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('attachments_ui.update_attachments', stub.f);
dispatch(event);
assert_same(stub.get_args('event').event, event);
});
});
with_overrides(function (override) {
with_overrides((override) => {
// User groups
let event = event_fixtures.user_group__add;
override('settings_user_groups.reload', noop);
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('user_groups.add', stub.f);
dispatch(event);
const args = stub.get_args('group');
@ -168,7 +168,7 @@ with_overrides(function (override) {
});
event = event_fixtures.user_group__add_members;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('user_groups.add_members', stub.f);
dispatch(event);
const args = stub.get_args('group_id', 'user_ids');
@ -177,7 +177,7 @@ with_overrides(function (override) {
});
event = event_fixtures.user_group__remove_members;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('user_groups.remove_members', stub.f);
dispatch(event);
const args = stub.get_args('group_id', 'user_ids');
@ -186,7 +186,7 @@ with_overrides(function (override) {
});
event = event_fixtures.user_group__update;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('user_groups.update', stub.f);
dispatch(event);
const args = stub.get_args('event');
@ -196,7 +196,7 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// custom profile fields
const event = event_fixtures.custom_profile_fields;
override('settings_profile_fields.populate_profile_fields', noop);
@ -206,11 +206,11 @@ with_overrides(function (override) {
});
with_overrides(function (override) {
with_overrides((override) => {
// default_streams
const event = event_fixtures.default_streams;
override('settings_streams.update_default_streams_table', noop);
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('stream_data.set_realm_default_streams', stub.f);
dispatch(event);
const args = stub.get_args('realm_default_streams');
@ -219,7 +219,7 @@ with_overrides(function (override) {
});
with_overrides(function (override) {
with_overrides((override) => {
// hotspots
const event = event_fixtures.hotspots;
override('hotspots.load_new', noop);
@ -227,21 +227,21 @@ with_overrides(function (override) {
assert_same(page_params.hotspots, event.hotspots);
});
with_overrides(function (override) {
with_overrides((override) => {
// invites_changed
const event = event_fixtures.invites_changed;
$('#admin-invites-list').length = 1;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('settings_invites.set_up', stub.f);
dispatch(event); // stub automatically checks if stub.f is called once
});
});
with_overrides(function (override) {
with_overrides((override) => {
// muted_topics
const event = event_fixtures.muted_topics;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('muting_ui.handle_updates', stub.f);
dispatch(event);
const args = stub.get_args('muted_topics');
@ -249,11 +249,11 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// presence
const event = event_fixtures.presence;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('activity.update_presence_info', stub.f);
dispatch(event);
const args = stub.get_args('user_id', 'presence', 'server_time');
@ -263,10 +263,10 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// reaction
let event = event_fixtures.reaction__add;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('reactions.add_reaction', stub.f);
dispatch(event);
const args = stub.get_args('event');
@ -275,7 +275,7 @@ with_overrides(function (override) {
});
event = event_fixtures.reaction__remove;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('reactions.remove_reaction', stub.f);
dispatch(event);
const args = stub.get_args('event');
@ -284,7 +284,7 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// realm
function test_realm_boolean(event, parameter_name) {
page_params[parameter_name] = true;
@ -417,11 +417,11 @@ with_overrides(function (override) {
assert_same(window.location.href, "/accounts/deactivated/");
});
with_overrides(function (override) {
with_overrides((override) => {
// realm_bot
let event = event_fixtures.realm_bot__add;
global.with_stub(function (bot_stub) {
global.with_stub(function (admin_stub) {
global.with_stub((bot_stub) => {
global.with_stub((admin_stub) => {
override('bot_data.add', bot_stub.f);
override('settings_users.update_bot_data', admin_stub.f);
dispatch(event);
@ -433,8 +433,8 @@ with_overrides(function (override) {
});
event = event_fixtures.realm_bot__remove;
global.with_stub(function (bot_stub) {
global.with_stub(function (admin_stub) {
global.with_stub((bot_stub) => {
global.with_stub((admin_stub) => {
override('bot_data.deactivate', bot_stub.f);
override('settings_users.update_bot_data', admin_stub.f);
dispatch(event);
@ -450,8 +450,8 @@ with_overrides(function (override) {
dispatch(event);
event = event_fixtures.realm_bot__update;
global.with_stub(function (bot_stub) {
global.with_stub(function (admin_stub) {
global.with_stub((bot_stub) => {
global.with_stub((admin_stub) => {
override('bot_data.update', bot_stub.f);
override('settings_users.update_bot_data', admin_stub.f);
@ -467,11 +467,11 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// realm_emoji
const event = event_fixtures.realm_emoji;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('emoji.update_emojis', stub.f);
override('settings_emoji.populate_emoji', noop);
override('emoji_picker.generate_emoji_picker_data', noop);
@ -482,7 +482,7 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// realm_filters
const event = event_fixtures.realm_filters;
page_params.realm_filters = [];
@ -492,7 +492,7 @@ with_overrides(function (override) {
});
with_overrides(function (override) {
with_overrides((override) => {
// realm_domains
let event = event_fixtures.realm_domains__add;
page_params.realm_domains = [];
@ -509,7 +509,7 @@ with_overrides(function (override) {
assert_same(page_params.realm_domains, []);
});
with_overrides(function (override) {
with_overrides((override) => {
// realm_user
let event = event_fixtures.realm_user__add;
dispatch(event);
@ -527,7 +527,7 @@ with_overrides(function (override) {
assert(!people.is_active_user_for_popover(event.person.user_id));
event = event_fixtures.realm_user__update;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('user_events.update_person', stub.f);
dispatch(event);
const args = stub.get_args('person');
@ -535,10 +535,10 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// restart
const event = event_fixtures.restart;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('reload.initiate', stub.f);
dispatch(event);
const args = stub.get_args('options');
@ -547,11 +547,11 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// stream update
let event = event_fixtures.stream__update;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('stream_events.update_property', stub.f);
override('settings_streams.update_default_streams_table', noop);
dispatch(event);
@ -563,7 +563,7 @@ with_overrides(function (override) {
// stream create
event = event_fixtures.stream__create;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('stream_data.create_streams', stub.f);
override('stream_data.get_sub_by_id', noop);
override('stream_data.update_calculated_fields', noop);
@ -575,15 +575,13 @@ with_overrides(function (override) {
// stream delete
event = event_fixtures.stream__delete;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('subs.remove_stream', noop);
override('stream_data.delete_sub', noop);
override('settings_streams.update_default_streams_table', noop);
override('stream_data.remove_default_stream', noop);
override('stream_data.get_sub_by_id', function (id) {
return id === 42 ? {subscribed: true} : {subscribed: false};
});
override('stream_data.get_sub_by_id', (id) => id === 42 ? {subscribed: true} : {subscribed: false});
override('stream_list.remove_sidebar_row', stub.f);
dispatch(event);
const args = stub.get_args('stream_id');
@ -600,10 +598,10 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// submessage
const event = event_fixtures.submessage;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('submessage.handle_event', stub.f);
dispatch(event);
const submsg = stub.get_args('submsg').submsg;
@ -619,10 +617,10 @@ with_overrides(function (override) {
// For subscriptions, see dispatch_subs.js
with_overrides(function (override) {
with_overrides((override) => {
// typing
let event = event_fixtures.typing__start;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('typing_events.display_notification', stub.f);
dispatch(event);
const args = stub.get_args('event');
@ -630,7 +628,7 @@ with_overrides(function (override) {
});
event = event_fixtures.typing__stop;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('typing_events.hide_notification', stub.f);
dispatch(event);
const args = stub.get_args('event');
@ -642,7 +640,7 @@ with_overrides(function (override) {
dispatch(event); // get line coverage
});
with_overrides(function (override) {
with_overrides((override) => {
// update_display_settings
let event = event_fixtures.update_display_settings__default_language;
page_params.default_language = 'en';
@ -691,7 +689,7 @@ with_overrides(function (override) {
$("body").fadeOut = (secs) => { assert_same(secs, 300); };
$("body").fadeIn = (secs) => { assert_same(secs, 300); };
global.with_stub(function (stub) {
global.with_stub((stub) => {
event = event_fixtures.update_display_settings__color_scheme_dark;
page_params.color_scheme = 1;
override('night_mode.enable', stub.f); // automatically checks if called
@ -700,7 +698,7 @@ with_overrides(function (override) {
assert(page_params.color_scheme, 2);
});
global.with_stub(function (stub) {
global.with_stub((stub) => {
event = event_fixtures.update_display_settings__color_scheme_light;
page_params.color_scheme = 1;
override('night_mode.disable', stub.f); // automatically checks if called
@ -709,7 +707,7 @@ with_overrides(function (override) {
assert(page_params.color_scheme, 3);
});
global.with_stub(function (stub) {
global.with_stub((stub) => {
event = event_fixtures.update_display_settings__color_scheme_automatic;
page_params.color_scheme = 2;
override('night_mode.default_preference_checker', stub.f); // automatically checks if called
@ -718,7 +716,7 @@ with_overrides(function (override) {
assert(page_params.color_scheme, 1);
});
global.with_stub(function (stub) {
global.with_stub((stub) => {
event = event_fixtures.update_display_settings__emojiset;
called = false;
override('settings_display.report_emojiset_change', stub.f);
@ -740,7 +738,7 @@ with_overrides(function (override) {
dispatch(event);
assert_same(page_params.fluid_layout_width, true);
global.with_stub(function (stub) {
global.with_stub((stub) => {
event = event_fixtures.update_display_settings__demote_inactive_streams;
override('stream_data.set_filter_out_inactives', noop);
override('stream_list.update_streams_sidebar', stub.f);
@ -750,10 +748,10 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// update_global_notifications
const event = event_fixtures.update_global_notifications;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('notifications.handle_global_notification_updates', stub.f);
dispatch(event);
const args = stub.get_args('name', 'setting');
@ -762,11 +760,11 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// update_message_flags__read
const event = event_fixtures.update_message_flags__read;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('unread_ops.process_read_messages_event', stub.f);
dispatch(event);
const args = stub.get_args('message_ids');
@ -774,13 +772,13 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// update_message_flags__starred
override('starred_messages.rerender_ui', noop);
let event = event_fixtures.update_message_flags__starred_add;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('ui.update_starred_view', stub.f);
dispatch(event);
const args = stub.get_args('message_id', 'new_value');
@ -791,7 +789,7 @@ with_overrides(function (override) {
});
event = event_fixtures.update_message_flags__starred_remove;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('ui.update_starred_view', stub.f);
dispatch(event);
const args = stub.get_args('message_id', 'new_value');
@ -802,25 +800,25 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// delete_message
const event = event_fixtures.delete_message;
override('stream_list.update_streams_sidebar', noop);
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('unread_ops.process_read_messages_event', noop);
override('ui.remove_messages', stub.f);
dispatch(event);
const args = stub.get_args('message_ids');
assert_same(args.message_ids, [1337]);
});
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('unread_ops.process_read_messages_event', stub.f);
dispatch(event);
const args = stub.get_args('message_ids');
assert_same(args.message_ids, [1337]);
});
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('stream_topic_history.remove_messages', stub.f);
dispatch(event);
const args = stub.get_args('opts');
@ -830,10 +828,10 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
// attachments
let event = event_fixtures.user_status__set_away;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('activity.on_set_away', stub.f);
dispatch(event);
const args = stub.get_args('user_id');
@ -841,7 +839,7 @@ with_overrides(function (override) {
});
event = event_fixtures.user_status__revoke_away;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('activity.on_revoke_away', stub.f);
dispatch(event);
const args = stub.get_args('user_id');
@ -849,7 +847,7 @@ with_overrides(function (override) {
});
event = event_fixtures.user_status__set_status_text;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('activity.redraw_user', stub.f);
dispatch(event);
const args = stub.get_args('user_id');
@ -859,11 +857,11 @@ with_overrides(function (override) {
});
});
with_overrides(function (override) {
with_overrides((override) => {
const event = event_fixtures.realm_export;
override('settings_exports.populate_exports_table', noop);
dispatch(event);
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('settings_exports.populate_exports_table', stub.f);
dispatch(event);

View File

@ -32,7 +32,7 @@ test('add', (override) => {
name: sub.name,
});
global.with_stub(function (subscription_stub) {
global.with_stub((subscription_stub) => {
override('stream_events.mark_subscribed', subscription_stub.f);
dispatch(event);
const args = subscription_stub.get_args('sub', 'subscribers');
@ -77,7 +77,7 @@ test('remove', (override) => {
stream_data.add_sub(sub);
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('stream_events.mark_unsubscribed', stub.f);
dispatch(event);
const args = stub.get_args('sub');
@ -87,7 +87,7 @@ test('remove', (override) => {
test('update', (override) => {
const event = event_fixtures.subscription__update;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('stream_events.update_property', stub.f);
dispatch(event);
const args = stub.get_args('stream_id', 'property', 'value');
@ -100,7 +100,7 @@ test('update', (override) => {
test('add error handling', (override) => {
// test blueslip errors/warns
const event = event_fixtures.subscription__add;
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('blueslip.error', stub.f);
dispatch(event);
assert.deepEqual(stub.get_args('param').param, 'Subscribing to unknown stream with ID 42');

View File

@ -119,7 +119,7 @@ run_test('draft_model', () => {
localStorage.clear();
(function test_addDraft() {
stub_timestamp(1, function () {
stub_timestamp(1, () => {
const expected = { ...draft_1 };
expected.updatedAt = 1;
const id = draft_model.addDraft({ ...draft_1 });
@ -130,7 +130,7 @@ run_test('draft_model', () => {
localStorage.clear();
(function test_editDraft() {
stub_timestamp(2, function () {
stub_timestamp(2, () => {
ls.set("drafts", { id1: draft_1 });
const expected = { ...draft_2 };
expected.updatedAt = 2;
@ -313,7 +313,7 @@ run_test('format_drafts', () => {
return stub_render_now(time, new XDate(1549958107000));
};
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
assert.equal(template_name, 'draft_table_body');
// Tests formatting and sorting of drafts
assert.deepEqual(data.drafts, expected);

View File

@ -59,8 +59,8 @@ function return_true() { return true; }
function return_false() { return false; }
function stubbing(func_name_to_stub, test_function) {
global.with_overrides(function (override) {
global.with_stub(function (stub) {
global.with_overrides((override) => {
global.with_stub((stub) => {
override(func_name_to_stub, stub.f);
test_function(stub);
});
@ -165,7 +165,7 @@ run_test('basic_chars', () => {
}
function assert_mapping(c, func_name, shiftKey) {
stubbing(func_name, function () {
stubbing(func_name, () => {
assert(process(c, shiftKey));
});
}
@ -370,7 +370,7 @@ run_test('motion_keys', () => {
}
function assert_mapping(key_name, func_name, shiftKey, ctrlKey) {
stubbing(func_name, function () {
stubbing(func_name, () => {
assert(process(key_name, shiftKey, ctrlKey));
});
}

View File

@ -207,7 +207,7 @@ run_test('paste to input', () => {
]);
let entered = false;
widget.createPillonPaste(function () {
widget.createPillonPaste(() => {
entered = true;
});
@ -385,11 +385,11 @@ run_test('insert_remove', () => {
let created;
let removed;
widget.onPillCreate(function () {
widget.onPillCreate(() => {
created = true;
});
widget.onPillRemove(function () {
widget.onPillRemove(() => {
removed = true;
});

View File

@ -233,11 +233,11 @@ run_test('markdown_detection', () => {
"youtube url https://www.youtube.com/watch?v=HHZ8iqswiCw&feature=youtu.be&a",
];
no_markup.forEach(function (content) {
no_markup.forEach((content) => {
assert.equal(markdown.contains_backend_only_syntax(content), false);
});
markup.forEach(function (content) {
markup.forEach((content) => {
assert.equal(markdown.contains_backend_only_syntax(content), true);
});
});
@ -245,7 +245,7 @@ run_test('markdown_detection', () => {
run_test('marked_shared', () => {
const tests = markdown_data.regular_tests;
tests.forEach(function (test) {
tests.forEach((test) => {
// Ignore tests if specified
if (test.ignore === true) {
@ -423,7 +423,7 @@ run_test('marked', () => {
// isn't present in emoji_codes.codepoint_to_name.
delete emoji_codes.codepoint_to_name['1f6b2'];
test_cases.forEach(function (test_case) {
test_cases.forEach((test_case) => {
// Disable emoji conversion by default.
page_params.translate_emoticons = test_case.translate_emoticons || false;
@ -563,7 +563,7 @@ run_test('backend_only_realm_filters', () => {
'Here is the PR-#123.',
'Function abc() was introduced in (PR)#123.',
];
backend_only_realm_filters.forEach(function (content) {
backend_only_realm_filters.forEach((content) => {
assert.equal(markdown.contains_backend_only_syntax(content), true);
});
});

View File

@ -111,9 +111,7 @@ run_test('basics', () => {
list.view.clear_table = function () {};
list.remove_and_rerender([{id: 60}]);
const removed = list.all_messages().filter(function (msg) {
return msg.id !== 60;
});
const removed = list.all_messages().filter((msg) => msg.id !== 60);
assert.deepEqual(list.all_messages(), removed);
list.clear();
@ -312,20 +310,16 @@ run_test('local_echo', () => {
run_test('bookend', () => {
const list = new MessageList({});
with_overrides(function (override) {
with_overrides((override) => {
let expected = "translated: You subscribed to stream IceCream";
list.view.clear_trailing_bookend = noop;
list.narrowed = true;
override("narrow_state.stream", function () {
return "IceCream";
});
override("narrow_state.stream", () => "IceCream");
override("stream_data.is_subscribed", function () {
return true;
});
override("stream_data.is_subscribed", () => true);
global.with_stub(function (stub) {
global.with_stub((stub) => {
list.view.render_trailing_bookend = stub.f;
list.update_trailing_bookend();
const bookend = stub.get_args('content', 'subscribed', 'show_button');
@ -336,15 +330,11 @@ run_test('bookend', () => {
expected = "translated: You unsubscribed from stream IceCream";
list.last_message_historical = false;
override("stream_data.is_subscribed", function () {
return false;
});
override("stream_data.is_subscribed", () => false);
override("stream_data.get_sub", function () {
return {invite_only: false};
});
override("stream_data.get_sub", () => ({invite_only: false}));
global.with_stub(function (stub) {
global.with_stub((stub) => {
list.view.render_trailing_bookend = stub.f;
list.update_trailing_bookend();
const bookend = stub.get_args('content', 'subscribed', 'show_button');
@ -355,15 +345,11 @@ run_test('bookend', () => {
// Test when the stream is privates (invite only)
expected = "translated: You unsubscribed from stream IceCream";
override("stream_data.is_subscribed", function () {
return false;
});
override("stream_data.is_subscribed", () => false);
override("stream_data.get_sub", function () {
return {invite_only: true};
});
override("stream_data.get_sub", () => ({invite_only: true}));
global.with_stub(function (stub) {
global.with_stub((stub) => {
list.view.render_trailing_bookend = stub.f;
list.update_trailing_bookend();
const bookend = stub.get_args('content', 'subscribed', 'show_button');
@ -375,7 +361,7 @@ run_test('bookend', () => {
expected = "translated: You are not subscribed to stream IceCream";
list.last_message_historical = true;
global.with_stub(function (stub) {
global.with_stub((stub) => {
list.view.render_trailing_bookend = stub.f;
list.update_trailing_bookend();
const bookend = stub.get_args('content', 'subscribed', 'show_button');
@ -414,10 +400,8 @@ run_test('unmuted_messages', () => {
},
];
with_overrides(function (override) {
override('muting.is_topic_muted', function (stream_id) {
return stream_id === muted_stream_id;
});
with_overrides((override) => {
override('muting.is_topic_muted', (stream_id) => stream_id === muted_stream_id);
// Make sure unmuted_message filters out the "muted" entry,
// which we mark as having a muted topic, and not mentioned.
@ -437,7 +421,7 @@ run_test('add_remove_rerender', () => {
list.add_messages(messages);
assert.equal(list.num_items(), 3);
global.with_stub(function (stub) {
global.with_stub((stub) => {
list.rerender = stub.f;
list.remove_and_rerender(messages);
assert.equal(stub.num_calls, 1);

View File

@ -279,7 +279,7 @@ run_test('message_id_change', () => {
new_id: 402,
};
global.with_stub(function (stub) {
global.with_stub((stub) => {
home_msg_list.change_message_id = stub.f;
message_store.reify_message_id(opts);
const msg_id = stub.get_args('old', 'new');
@ -288,7 +288,7 @@ run_test('message_id_change', () => {
});
home_msg_list.view = {};
global.with_stub(function (stub) {
global.with_stub((stub) => {
home_msg_list.view.change_message_id = stub.f;
message_store.reify_message_id(opts);
const msg_id = stub.get_args('old', 'new');

View File

@ -2,9 +2,7 @@ zrequire('people');
set_global('message_store', {});
set_global('page_params', {});
set_global('settings_data', {});
set_global('md5', function (s) {
return 'md5-' + s;
});
set_global('md5', (s) => 'md5-' + s);
const settings_config = zrequire('settings_config');
const visibility = settings_config.email_address_visibility_values;
@ -401,7 +399,7 @@ run_test('user_timezone', () => {
assert.deepEqual(people.get_user_time_preferences(me.user_id), expected_pref);
const actual_moment = zrequire('actual_moment', 'moment-timezone');
set_global('moment', function () { return actual_moment('20130208T080910'); });
set_global('moment', () => actual_moment('20130208T080910'));
global.page_params.twenty_four_hour_time = true;
assert.equal(people.get_user_time(me.user_id), '0:09');
@ -1100,7 +1098,7 @@ run_test('is_valid_full_name_and_user_id', () => {
assert(people.is_valid_full_name_and_user_id(me.full_name, me.user_id));
});
run_test('emails_strings_to_user_ids_array', function () {
run_test('emails_strings_to_user_ids_array', () => {
people.add_active_user(steven);
people.add_active_user(maria);
@ -1112,7 +1110,7 @@ run_test('emails_strings_to_user_ids_array', function () {
assert.equal(user_ids, undefined);
});
run_test('get_visible_email', function () {
run_test('get_visible_email', () => {
people.add_active_user(steven);
people.add_active_user(maria);
@ -1123,7 +1121,7 @@ run_test('get_visible_email', function () {
assert.equal(email, maria.email);
});
run_test('get_active_message_people', function () {
run_test('get_active_message_people', () => {
message_store.user_ids = () => [
steven.user_id,
maria.user_id,

View File

@ -135,7 +135,7 @@ run_test('sender_hover', () => {
return {};
};
global.stub_templates(function (fn, opts) {
global.stub_templates((fn, opts) => {
switch (fn) {
case 'no_arrow_popover':
assert.deepEqual(opts, {
@ -229,7 +229,7 @@ run_test('actions_popover', () => {
};
};
global.stub_templates(function (fn, opts) {
global.stub_templates((fn, opts) => {
// TODO: Test all the properties of the popover
switch (fn) {
case 'actions_popover_content':

View File

@ -123,7 +123,7 @@ run_test('basics', () => {
assert(reactions.current_user_has_reacted_to_emoji(message, 'unicode_emoji,263a'));
assert(!reactions.current_user_has_reacted_to_emoji(message, 'bogus'));
result.sort(function (a, b) { return a.count - b.count; });
result.sort((a, b) => a.count - b.count);
const expected_result = [
{
@ -174,7 +174,7 @@ run_test('sending', () => {
reactions.remove_reaction = function () {};
reactions.add_reaction = function () {};
global.with_stub(function (stub) {
global.with_stub((stub) => {
global.channel.del = stub.f;
reactions.toggle_emoji_reaction(message_id, emoji_name);
const args = stub.get_args('args').args;
@ -194,7 +194,7 @@ run_test('sending', () => {
args.error();
});
emoji_name = 'alien'; // not set yet
global.with_stub(function (stub) {
global.with_stub((stub) => {
global.channel.post = stub.f;
reactions.toggle_emoji_reaction(message_id, emoji_name);
const args = stub.get_args('args').args;
@ -207,7 +207,7 @@ run_test('sending', () => {
});
emoji_name = 'inactive_realm_emoji';
global.with_stub(function (stub) {
global.with_stub((stub) => {
// Test removing a deactivated realm emoji. An user can interact with a
// deactivated realm emoji only by clicking on a reaction, hence, only
// `process_reaction_click()` codepath supports deleting/adding a deactivated
@ -224,7 +224,7 @@ run_test('sending', () => {
});
emoji_name = 'zulip'; // Test adding zulip emoji.
global.with_stub(function (stub) {
global.with_stub((stub) => {
global.channel.post = stub.f;
reactions.toggle_emoji_reaction(message_id, emoji_name);
const args = stub.get_args('args').args;
@ -298,7 +298,7 @@ run_test('add_and_remove_reaction', () => {
};
let template_called;
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
template_called = true;
assert.equal(template_name, 'message_reaction');
assert.equal(data.class, 'message_reaction reacted');
@ -386,7 +386,7 @@ run_test('add_and_remove_reaction', () => {
};
template_called = false;
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
assert.equal(data.class, 'message_reaction');
assert(data.is_realm_emoji);
template_called = true;
@ -674,7 +674,7 @@ run_test('process_reaction_click', () => {
emoji_name: 'smile',
emoji_code: '263a',
};
global.with_stub(function (stub) {
global.with_stub((stub) => {
global.channel.del = stub.f;
reactions.process_reaction_click(message_id, 'unicode_emoji,263a');
const args = stub.get_args('args').args;

View File

@ -297,7 +297,7 @@ run_test("test_recent_topics_launch", () => {
search_val: '',
};
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
if (template_name === 'recent_topics_table') {
assert.deepEqual(data, expected);
} else if (template_name === 'recent_topics_filters') {
@ -330,7 +330,7 @@ run_test('test_filter_all', () => {
};
let row_data;
let i;
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
if (template_name === 'recent_topic_row') {
// All the row will be processed.
i -= 1;
@ -386,14 +386,12 @@ run_test('test_filter_unread', () => {
const rt = zrequire('recent_topics');
global.stub_templates(function () {
return '<recent_topics table stub>';
});
global.stub_templates(() => '<recent_topics table stub>');
rt.process_messages(messages);
assert.equal(rt.inplace_rerender('1:topic-1'), true);
$('#recent_topics_filter_buttons').removeClass('btn-recent-selected');
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
assert.equal(template_name, 'recent_topics_filters');
assert.equal(data.filter_unread, expected.filter_unread);
assert.equal(data.filter_participated, expected.filter_participated);
@ -403,7 +401,7 @@ run_test('test_filter_unread', () => {
rt.set_filter('unread');
rt.update_filters_view();
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
if (template_name === 'recent_topic_row') {
// All the row will be processed.
assert.deepEqual(data, row_data[i]);
@ -452,9 +450,7 @@ run_test('test_filter_participated', () => {
const rt = zrequire('recent_topics');
global.stub_templates(function () {
return '<recent_topics table stub>';
});
global.stub_templates(() => '<recent_topics table stub>');
rt.process_messages(messages);
assert.equal(rt.inplace_rerender('1:topic-4'), true);
@ -466,7 +462,7 @@ run_test('test_filter_participated', () => {
rt.set_filter('muted');
$('#recent_topics_filter_buttons').removeClass('btn-recent-selected');
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
assert.equal(template_name, 'recent_topics_filters');
assert.equal(data.filter_unread, expected.filter_unread);
assert.equal(data.filter_participated, expected.filter_participated);
@ -476,7 +472,7 @@ run_test('test_filter_participated', () => {
rt.update_filters_view();
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
if (template_name === 'recent_topic_row') {
// All the row will be processed.
assert.deepEqual(data, row_data[i]);
@ -495,9 +491,7 @@ run_test('test_filter_participated', () => {
run_test('test_update_unread_count', () => {
const rt = zrequire('recent_topics');
rt.set_filter('all');
global.stub_templates(function () {
return '<recent_topics table stub>';
});
global.stub_templates(() => '<recent_topics table stub>');
rt.process_messages(messages);
// update a message
@ -506,9 +500,7 @@ run_test('test_update_unread_count', () => {
});
// template rendering is tested in test_recent_topics_launch.
global.stub_templates(function () {
return '<recent_topics table stub>';
});
global.stub_templates(() => '<recent_topics table stub>');
run_test('basic assertions', () => {
const rt = zrequire('recent_topics');

View File

@ -33,7 +33,7 @@ const _page_params = {
const _realm_icon = {};
const _channel = {};
global.stub_templates(function (name, data) {
global.stub_templates((name, data) => {
if (name === 'settings/admin_realm_domains_list') {
assert(data.realm_domain.domain);
return 'stub-domains-list';

View File

@ -126,7 +126,7 @@ run_test('populate_user_groups', () => {
let templates_render_called = false;
const fake_rendered_temp = $.create('fake_admin_user_group_list_template_rendered');
global.stub_templates(function (template, args) {
global.stub_templates((template, args) => {
assert.equal(template, 'admin_user_group_list');
assert.equal(args.user_group.id, 1);
assert.equal(args.user_group.name, 'Mobile');
@ -326,7 +326,7 @@ run_test('populate_user_groups', () => {
}
pills.onPillRemove = function (handler) {
global.patch_builtin('setTimeout', function (func) {
global.patch_builtin('setTimeout', (func) => {
func();
});
realm_user_group.members = new Set([2, 31]);
@ -364,9 +364,7 @@ run_test('with_external_user', () => {
return noop;
};
global.stub_templates(function () {
return noop;
});
global.stub_templates(() => noop);
people.get_by_user_id = function () {
return noop;
@ -791,7 +789,7 @@ run_test('on_events', () => {
assert.equal(opts.data.description, 'translated: All mobile members');
api_endpoint_called = true;
(function test_post_success() {
global.patch_builtin('setTimeout', function (func) {
global.patch_builtin('setTimeout', (func) => {
func();
});
opts.success();

View File

@ -4,7 +4,7 @@ set_global('page_params', {
is_guest: false,
});
set_global('$', function () {
set_global('$', () => {
});
set_global('document', null);
@ -954,7 +954,7 @@ run_test('filter inactives', () => {
stream_data.initialize(params);
assert(!stream_data.is_filtering_inactives());
_.times(30, function (i) {
_.times(30, (i) => {
const name = 'random' + i.toString();
const stream_id = 100 + i;

View File

@ -31,9 +31,9 @@ stream_data.add_sub(frontend);
run_test('update_property', () => {
// Invoke error for non-existent stream/property
with_overrides(function (override) {
with_overrides((override) => {
let errors = 0;
override('blueslip.warn', function () {
override('blueslip.warn', () => {
errors += 1;
});
@ -45,8 +45,8 @@ run_test('update_property', () => {
});
// Test update color
with_overrides(function (override) {
global.with_stub(function (stub) {
with_overrides((override) => {
global.with_stub((stub) => {
override('stream_color.update_stream_color', stub.f);
stream_events.update_property(1, 'color', 'blue');
const args = stub.get_args('sub', 'val');
@ -56,8 +56,8 @@ run_test('update_property', () => {
});
// Test in home view
with_overrides(function (override) {
global.with_stub(function (stub) {
with_overrides((override) => {
global.with_stub((stub) => {
override('stream_muting.update_is_muted', stub.f);
stream_events.update_property(1, 'in_home_view', false);
const args = stub.get_args('sub', 'val');
@ -97,8 +97,8 @@ run_test('update_property', () => {
assert.equal(checkbox.prop('checked'), true);
// Test name change
with_overrides(function (override) {
global.with_stub(function (stub) {
with_overrides((override) => {
global.with_stub((stub) => {
override('subs.update_stream_name', stub.f);
stream_events.update_property(1, 'name', 'the frontend');
const args = stub.get_args('sub', 'val');
@ -108,8 +108,8 @@ run_test('update_property', () => {
});
// Test description change
with_overrides(function (override) {
global.with_stub(function (stub) {
with_overrides((override) => {
global.with_stub((stub) => {
override('subs.update_stream_description', stub.f);
stream_events.update_property(1, 'description', 'we write code', {rendered_description: 'we write code'});
const args = stub.get_args('sub', 'val');
@ -123,7 +123,7 @@ run_test('update_property', () => {
assert.equal(frontend.email_address, 'zooly@zulip.com');
// Test pin to top
with_overrides(function (override) {
with_overrides((override) => {
override('stream_list.refresh_pinned_or_unpinned_stream', noop);
stream_events.update_property(1, 'pin_to_top', true);
checkbox = $("#pin_to_top_1");
@ -131,8 +131,8 @@ run_test('update_property', () => {
});
// Test stream privacy change event
with_overrides(function (override) {
global.with_stub(function (stub) {
with_overrides((override) => {
global.with_stub((stub) => {
override('subs.update_stream_privacy', stub.f);
stream_events.update_property(1, 'invite_only', true, {
history_public_to_subscribers: true,
@ -147,8 +147,8 @@ run_test('update_property', () => {
});
// Test stream stream_post_policy change event
with_overrides(function (override) {
global.with_stub(function (stub) {
with_overrides((override) => {
global.with_stub((stub) => {
override('subs.update_stream_post_policy', stub.f);
stream_events.update_property(1, 'stream_post_policy', stream_data.stream_post_policy_values.admins.code);
const args = stub.get_args('sub', 'val');
@ -158,8 +158,8 @@ run_test('update_property', () => {
});
// Test stream message_retention_days change event
with_overrides(function (override) {
global.with_stub(function (stub) {
with_overrides((override) => {
global.with_stub((stub) => {
override('subs.update_message_retention_setting', stub.f);
stream_events.update_property(1, 'message_retention_days', 20);
const args = stub.get_args('sub', 'val');
@ -171,10 +171,10 @@ run_test('update_property', () => {
run_test('marked_subscribed', () => {
// Test undefined error
with_overrides(function (override) {
with_overrides((override) => {
let errors = 0;
override('stream_color.update_stream_color', noop);
override('blueslip.error', function () {
override('blueslip.error', () => {
errors += 1;
});
stream_events.mark_subscribed(undefined, [], 'yellow');
@ -182,9 +182,9 @@ run_test('marked_subscribed', () => {
});
// Test early return if subscribed
with_overrides(function (override) {
with_overrides((override) => {
let completed = false;
override('message_util.do_unread_count_updates', function () {
override('message_util.do_unread_count_updates', () => {
completed = true; // This gets run if we continue and don't early return
});
const subscribed = {subscribed: true};
@ -208,7 +208,7 @@ run_test('marked_subscribed', () => {
set_global('overlays', { streams_open: return_true });
// Test basic dispatching and updating stream color
with_overrides(function (override) {
with_overrides((override) => {
let args;
let list_updated = false;
@ -218,10 +218,8 @@ run_test('marked_subscribed', () => {
override('stream_color.update_stream_color', noop);
override('stream_list.add_sidebar_row', stream_list_stub.f);
override('message_util.do_unread_count_updates', message_util_stub.f);
override('narrow_state.is_for_stream_id', function () {
return true;
});
override('current_msg_list.update_trailing_bookend', function () {
override('narrow_state.is_for_stream_id', () => true);
override('current_msg_list.update_trailing_bookend', () => {
list_updated = true;
});
@ -239,17 +237,15 @@ run_test('marked_subscribed', () => {
});
// Test assigning generated color
with_overrides(function (override) {
with_overrides((override) => {
frontend.color = undefined;
override('color_data.pick_color', function () {
return 'green';
});
override('color_data.pick_color', () => 'green');
let warnings = 0;
override('blueslip.warn', function () {
override('blueslip.warn', () => {
warnings += 1;
});
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('narrow_state.is_for_stream_id', noop);
override('message_util.do_unread_count_updates', noop);
override('stream_list.add_sidebar_row', noop);
@ -266,12 +262,12 @@ run_test('marked_subscribed', () => {
narrow_state.is_for_stream_id = () => false;
// Test assigning subscriber emails
with_overrides(function (override) {
with_overrides((override) => {
override('stream_color.update_stream_color', noop);
override('message_util.do_unread_count_updates', noop);
override('stream_list.add_sidebar_row', noop);
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('stream_data.set_subscribers', stub.f);
const user_ids = [15, 20, 25];
stream_events.mark_subscribed(frontend, user_ids, '');
@ -281,7 +277,7 @@ run_test('marked_subscribed', () => {
});
// assign self as well
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('stream_data.subscribe_myself', stub.f);
stream_events.mark_subscribed(frontend, [], '');
const args = stub.get_args('sub');
@ -289,7 +285,7 @@ run_test('marked_subscribed', () => {
});
// and finally update subscriber settings
global.with_stub(function (stub) {
global.with_stub((stub) => {
override('subs.update_settings_for_subscribed', stub.f);
stream_events.mark_subscribed(frontend, [], '');
const args = stub.get_args('sub');
@ -299,7 +295,7 @@ run_test('marked_subscribed', () => {
});
run_test('mark_unsubscribed', () => {
with_overrides(function (override) {
with_overrides((override) => {
let removed_sub = false;
override('stream_list.remove_sidebar_row', () => {
removed_sub = true;
@ -317,8 +313,8 @@ run_test('mark_unsubscribed', () => {
// Test unsubscribe
frontend.subscribed = true;
with_overrides(function (override) {
global.with_stub(function (stub) {
with_overrides((override) => {
global.with_stub((stub) => {
override('stream_data.unsubscribe_myself', stub.f);
override('subs.update_settings_for_unsubscribed', noop);
override('stream_list.remove_sidebar_row', noop);
@ -329,8 +325,8 @@ run_test('mark_unsubscribed', () => {
});
// Test update settings after unsubscribe
with_overrides(function (override) {
global.with_stub(function (stub) {
with_overrides((override) => {
global.with_stub((stub) => {
override('subs.update_settings_for_unsubscribed', stub.f);
override('stream_data.unsubscribe_myself', noop);
override('stream_list.remove_sidebar_row', noop);
@ -341,15 +337,13 @@ run_test('mark_unsubscribed', () => {
});
// Test update bookend and remove done event
with_overrides(function (override) {
with_overrides((override) => {
override('stream_data.unsubscribe_myself', noop);
override('subs.update_settings_for_unsubscribed', noop);
override('narrow_state.is_for_stream_id', function () {
return true;
});
override('narrow_state.is_for_stream_id', () => true);
let updated = false;
override('current_msg_list.update_trailing_bookend', function () {
override('current_msg_list.update_trailing_bookend', () => {
updated = true;
});

View File

@ -68,7 +68,7 @@ run_test('create_sidebar_row', () => {
devel_count.set_find_results('.value', devel_value);
devel_count.set_parent(sidebar_row);
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
assert.equal(template_name, 'stream_sidebar_row');
assert.equal(data.uri, '#narrow/stream/100-devel');
return '<devel sidebar row>';
@ -87,7 +87,7 @@ run_test('create_sidebar_row', () => {
social_count.set_find_results('.value', social_value);
social_count.set_parent(sidebar_row);
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
assert.equal(template_name, 'stream_sidebar_row');
assert.equal(data.uri, '#narrow/stream/200-social');
return '<social sidebar row>';
@ -133,7 +133,7 @@ run_test('create_sidebar_row', () => {
social.invite_only = true;
social.color = '#222222';
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
assert.equal(template_name, 'stream_privacy');
assert.equal(data.invite_only, true);
assert.equal(data.dark_background, 'dark_background');
@ -747,7 +747,7 @@ run_test('create_initial_sidebar_rows', () => {
stream_list.update_count_in_dom = noop;
global.stub_templates(function (template_name, data) {
global.stub_templates((template_name, data) => {
assert.equal(template_name, 'stream_sidebar_row');
return '<div>stub-html-' + data.name;
});

View File

@ -50,10 +50,8 @@ function sort_groups(query) {
return stream_sort.sort_groups(streams, query);
}
with_overrides(function (override) {
override('stream_data.is_active', function (sub) {
return sub.name !== "pneumonia";
});
with_overrides((override) => {
override('stream_data.is_active', (sub) => sub.name !== "pneumonia");
// Test sorting into categories/alphabetized
let sorted = sort_groups("");

View File

@ -225,49 +225,49 @@ run_test('last_seen_status_from_date', () => {
assert.equal(actual_status, expected_status);
}
assert_same(function (d) { return d.addSeconds(-20); },
assert_same((d) => d.addSeconds(-20),
i18n.t("Just now"));
assert_same(function (d) { return d.addMinutes(-1); },
assert_same((d) => d.addMinutes(-1),
i18n.t("Just now"));
assert_same(function (d) { return d.addMinutes(-2); },
assert_same((d) => d.addMinutes(-2),
i18n.t("Just now"));
assert_same(function (d) { return d.addMinutes(-30); },
assert_same((d) => d.addMinutes(-30),
i18n.t("30 minutes ago"));
assert_same(function (d) { return d.addHours(-1); },
assert_same((d) => d.addHours(-1),
i18n.t("An hour ago"));
assert_same(function (d) { return d.addHours(-2); },
assert_same((d) => d.addHours(-2),
i18n.t("2 hours ago"));
assert_same(function (d) { return d.addHours(-20); },
assert_same((d) => d.addHours(-20),
i18n.t("20 hours ago"));
assert_same(function (d) { return d.addDays(-1); },
assert_same((d) => d.addDays(-1),
i18n.t("Yesterday"));
assert_same(function (d) { return d.addDays(-2); },
assert_same((d) => d.addDays(-2),
i18n.t("2 days ago"));
assert_same(function (d) { return d.addDays(-61); },
assert_same((d) => d.addDays(-61),
i18n.t("61 days ago"));
assert_same(function (d) { return d.addDays(-300); },
assert_same((d) => d.addDays(-300),
i18n.t("May 06,\xa02015"));
assert_same(function (d) { return d.addDays(-366); },
assert_same((d) => d.addDays(-366),
i18n.t("Mar 01,\xa02015"));
assert_same(function (d) { return d.addYears(-3); },
assert_same((d) => d.addYears(-3),
i18n.t("Mar 01,\xa02013"));
// Set base_dateto to May 1 2016 12.30 AM (months are zero based)
base_date = new XDate(2016, 4, 1, 0, 30);
assert_same(function (d) { return d.addDays(-91); },
assert_same((d) => d.addDays(-91),
i18n.t("Jan\xa031"));
});

View File

@ -1,7 +1,5 @@
set_global('page_params', {realm_is_zephyr_mirror_realm: false});
set_global('md5', function (s) {
return 'md5-' + s;
});
set_global('md5', (s) => 'md5-' + s);
const settings_config = zrequire('settings_config');
page_params.realm_email_address_visibility =
@ -504,7 +502,7 @@ run_test('render_person when emails hidden', () => {
// Test render_person with regular person, under hidden email visibility case
page_params.is_admin = false;
let rendered = false;
global.stub_templates(function (template_name, args) {
global.stub_templates((template_name, args) => {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, b_user_1.full_name);
assert.equal(args.secondary, undefined);
@ -519,7 +517,7 @@ run_test('render_person', () => {
page_params.is_admin = true;
// Test render_person with regular person
let rendered = false;
global.stub_templates(function (template_name, args) {
global.stub_templates((template_name, args) => {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, a_user.full_name);
assert.equal(args.secondary, a_user.email);
@ -539,7 +537,7 @@ run_test('render_person', () => {
special_item_text: "special_text",
};
rendered = false;
global.stub_templates(function (template_name, args) {
global.stub_templates((template_name, args) => {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, special_person.special_item_text);
rendered = true;
@ -551,7 +549,7 @@ run_test('render_person', () => {
run_test('clear_rendered_person', () => {
let rendered = false;
global.stub_templates(function (template_name, args) {
global.stub_templates((template_name, args) => {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, b_bot.full_name);
assert.equal(args.secondary, b_bot.email);
@ -583,7 +581,7 @@ run_test('render_stream', () => {
stream_id: 42,
name: 'Short Description',
};
global.stub_templates(function (template_name, args) {
global.stub_templates((template_name, args) => {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, stream.name);
assert.equal(args.secondary, stream.description);
@ -600,7 +598,7 @@ run_test('render_stream', () => {
stream_id: 43,
name: 'Long Description',
};
global.stub_templates(function (template_name, args) {
global.stub_templates((template_name, args) => {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, stream.name);
const short_desc = stream.description.substring(0, 35);
@ -619,7 +617,7 @@ run_test('clear_rendered_stream', () => {
stream_id: 44,
name: 'Stream To Be Cleared',
};
global.stub_templates(function (template_name, args) {
global.stub_templates((template_name, args) => {
assert.equal(template_name, 'typeahead_list_item');
assert.equal(args.primary, stream.name);
assert.equal(args.secondary, stream.description);
@ -650,7 +648,7 @@ run_test('render_emoji', () => {
realm_emoji: 'TBD',
}));
global.stub_templates(function (template_name, args) {
global.stub_templates((template_name, args) => {
assert.equal(template_name, 'typeahead_list_item');
assert.deepEqual(args, {
primary: 'thumbs up',
@ -672,7 +670,7 @@ run_test('render_emoji', () => {
emoji_url: 'TBD',
};
global.stub_templates(function (template_name, args) {
global.stub_templates((template_name, args) => {
assert.equal(template_name, 'typeahead_list_item');
assert.deepEqual(args, {
primary: 'realm emoji',

View File

@ -268,7 +268,7 @@ run_test('basics', () => {
// stub functions to see how may time they are called
for (const method of Object.keys(call_count)) {
typing_status.__Rewire__(method, function () {
typing_status.__Rewire__(method, () => {
call_count[method] += 1;
});
}

View File

@ -1,7 +1,5 @@
zrequire('people');
set_global('md5', function (s) {
return 'md5-' + s;
});
set_global('md5', (s) => 'md5-' + s);
zrequire('user_pill');
set_global('page_params', {

View File

@ -101,7 +101,7 @@ run_test('robust_uri_decode', () => {
assert.equal(util.robust_uri_decode('xxx%3Ayyy'), 'xxx:yyy');
assert.equal(util.robust_uri_decode('xxx%3'), 'xxx');
set_global('decodeURIComponent', function () { throw 'foo'; });
set_global('decodeURIComponent', () => { throw 'foo'; });
try {
util.robust_uri_decode('%E0%A4%A');
} catch (e) {
@ -151,7 +151,7 @@ run_test('random_int', () => {
const min = 0;
const max = 100;
_.times(500, function () {
_.times(500, () => {
const val = util.random_int(min, max);
assert(min <= val);
assert(val <= max);

View File

@ -117,11 +117,11 @@ run_test('clicks', () => {
const state = {};
function set_up_click_handlers() {
$('#widget1').click(function () {
$('#widget1').click(() => {
state.clicked = true;
});
$('.some-class').keydown(function () {
$('.some-class').keydown(() => {
state.keydown = true;
});
}
@ -149,12 +149,12 @@ run_test('events', () => {
let value;
function initialize_handler() {
$('#my-parent').on('click', '.button-red', function (e) {
$('#my-parent').on('click', '.button-red', (e) => {
value = 'red'; // just a dummy side effect
e.stopPropagation();
});
$('#my-parent').on('click', '.button-blue', function (e) {
$('#my-parent').on('click', '.button-blue', (e) => {
value = 'blue';
e.stopPropagation();
});

View File

@ -8,8 +8,8 @@ exports.find_files_to_run = function () {
if (process.argv[2]) {
oneFileFilter = process.argv
.slice(2)
.filter(function (filename) {return (/[.]js$/).test(filename);})
.map(function (filename) {return filename.replace(/\.js$/i, '');});
.filter((filename) => (/[.]js$/).test(filename))
.map((filename) => filename.replace(/\.js$/i, ''));
}
// tests_dir is where we find our specific unit tests (as opposed
@ -17,24 +17,22 @@ exports.find_files_to_run = function () {
const tests_dir = __dirname.replace(/zjsunit/, 'node_tests');
let tests = fs.readdirSync(tests_dir)
.filter(function (filename) {return !(/^\./i).test(filename);})
.filter(function (filename) {return (/\.js$/i).test(filename);})
.map(function (filename) {return filename.replace(/\.js$/i, '');});
.filter((filename) => !(/^\./i).test(filename))
.filter((filename) => (/\.js$/i).test(filename))
.map((filename) => filename.replace(/\.js$/i, ''));
if (oneFileFilter.length > 0) {
tests = tests.filter(function (filename) {
return oneFileFilter.includes(filename);
});
tests = tests.filter((filename) => oneFileFilter.includes(filename));
testsDifference = _.difference(oneFileFilter, tests);
}
testsDifference.forEach(function (filename) {
testsDifference.forEach((filename) => {
throw filename + ".js does not exist";
});
tests.sort();
const files = tests.map(function (fn) {
const files = tests.map((fn) => {
const obj = {};
obj.name = fn;
obj.full_name = path.join(tests_dir, fn);

View File

@ -104,7 +104,7 @@ global.run_test = (label, f) => {
};
try {
files.forEach(function (file) {
files.forEach((file) => {
set_global('location', {
hash: '#',
});

View File

@ -45,7 +45,7 @@ exports.clear_zulip_refs = function () {
};
exports.restore = function () {
requires.forEach(function (fn) {
requires.forEach((fn) => {
delete require.cache[require.resolve(fn)];
});
Object.assign(global, old_globals);
@ -57,14 +57,12 @@ exports.restore = function () {
};
exports.stub_out_jquery = function () {
set_global('$', function () {
return {
set_global('$', () => ({
on: function () {},
trigger: function () {},
hide: function () {},
removeClass: function () {},
};
});
}));
$.fn = {};
$.now = function () {};
};
@ -86,7 +84,7 @@ exports.with_overrides = function (test_function) {
global[module][func_name] = f;
clobber_callbacks.push(function () {
clobber_callbacks.push(() => {
// If you get a failure from this, you probably just
// need to have your test do its own overrides and
// not cherry-pick off of the prior test's setup.

View File

@ -33,7 +33,7 @@ exports.with_stub = function (f) {
};
(function test_ourselves() {
exports.with_stub(function (stub) {
exports.with_stub((stub) => {
stub.f('blue', 42);
const args = stub.get_args('color', 'n');
assert.equal(args.color, 'blue');

View File

@ -305,7 +305,7 @@ exports.make_new_elem = function (selector, opts) {
},
removeClass: function (class_names) {
class_names = class_names.split(' ');
class_names.forEach(function (class_name) {
class_names.forEach((class_name) => {
classes.delete(class_name);
});
return self;

View File

@ -202,7 +202,7 @@ function mark_client_active() {
}
exports.initialize = function () {
$("html").on("mousemove", function () {
$("html").on("mousemove", () => {
exports.new_user_input = true;
});

View File

@ -41,8 +41,8 @@ exports.process_message = function (message) {
const regex = new RegExp('(' + before_punctuation + ')' +
'(' + clean + ')' +
'(' + after_punctuation + ')', 'ig');
message.content = message.content.replace(regex, function (match, before, word,
after, offset, content) {
message.content = message.content.replace(regex, (match, before, word,
after, offset, content) => {
// Logic for ensuring that we don't muck up rendered HTML.
const pre_match = content.substring(0, offset);
// We want to find the position of the `<` and `>` only in the

View File

@ -76,17 +76,17 @@ exports.set_up_alert_words = function () {
exports.render_alert_words_ui();
$('#create_alert_word_form').on('click', '#create_alert_word_button', function () {
$('#create_alert_word_form').on('click', '#create_alert_word_button', () => {
const word = $('#create_alert_word_name').val();
add_alert_word(word);
});
$('#alert_words_list').on('click', '.remove-alert-word', function (event) {
$('#alert_words_list').on('click', '.remove-alert-word', (event) => {
const word = $(event.currentTarget).parents('li').find('.value').text();
remove_alert_word(word);
});
$('#create_alert_word_form').on('keypress', '#create_alert_word_name', function (event) {
$('#create_alert_word_form').on('keypress', '#create_alert_word_name', (event) => {
const key = event.which;
// Handle enter (13) as "add".
if (key === 13) {
@ -97,7 +97,7 @@ exports.set_up_alert_words = function () {
}
});
$('#alert-word-settings').on('click', '.close-alert-word-status', function (event) {
$('#alert-word-settings').on('click', '.close-alert-word-status', (event) => {
event.preventDefault();
const alert = $(event.currentTarget).parents('.alert');
alert.hide();

View File

@ -1,4 +1,4 @@
$(function () {
$(() => {
$('a.envelope-link').click(function () {
common.copy_data_attribute_value($(this), "admin-emails");
});

View File

@ -1,4 +1,4 @@
$(function () {
$(() => {
$("body").on("click", ".scrub-realm-button", function (e) {
e.preventDefault();
const string_id = $(this).data("string-id");

View File

@ -117,14 +117,14 @@ function scroll_finish() {
scroll_timer = setTimeout(floating_recipient_bar.update, 100);
}
$(function () {
$(() => {
$.fn.safeOuterHeight = function (...args) {
return this.outerHeight(...args) || 0;
};
$.fn.safeOuterWidth = function (...args) {
return this.outerWidth(...args) || 0;
};
$('.app').scroll(_.throttle(function () {
$('.app').scroll(_.throttle(() => {
scroll_finish();
}, 50));
exports.initialize();

View File

@ -115,9 +115,7 @@ exports.update_attachments = function (event) {
return;
}
if (event.op === 'remove' || event.op === 'update') {
attachments = attachments.filter(function (a) {
return a.id !== event.attachment.id;
});
attachments = attachments.filter((a) => a.id !== event.attachment.id);
}
if (event.op === 'add' || event.op === 'update') {
format_attachment_data([event.attachment]);
@ -135,7 +133,7 @@ exports.set_up_attachments = function () {
const status = $('#delete-upload-status');
loading.make_indicator($('#attachments_loading_indicator'), {text: 'Loading...'});
$('#uploaded_files_table').on('click', '.remove-attachment', function (e) {
$('#uploaded_files_table').on('click', '.remove-attachment', (e) => {
delete_attachments($(e.target).closest(".uploaded_file_row").attr('data-attachment-id'));
});

View File

@ -52,7 +52,7 @@ exports.build_user_avatar_widget = function (upload_function) {
$("#user-avatar-source").hide();
}
$("#user-avatar-upload-widget .settings-page-delete-button").on('click keydown', function (e) {
$("#user-avatar-upload-widget .settings-page-delete-button").on('click keydown', (e) => {
e.preventDefault();
e.stopPropagation();
channel.del({

View File

@ -11,7 +11,7 @@ exports.initialize = function () {
},
});
$('#update-card-button').on('click', function (e) {
$('#update-card-button').on('click', (e) => {
const email = $("#payment-method").data("email");
card_change_handler.open({
name: 'Zulip',
@ -25,7 +25,7 @@ exports.initialize = function () {
e.preventDefault();
});
$("#change-plan-status").on('click', function (e) {
$("#change-plan-status").on('click', (e) => {
helpers.create_ajax_request("/json/billing/plan/change", "planchange", undefined, ["status"]);
e.preventDefault();
});
@ -33,6 +33,6 @@ exports.initialize = function () {
window.billing = exports;
$(function () {
$(() => {
exports.initialize();
});

View File

@ -22,7 +22,7 @@ exports.create_ajax_request = function (url, form_name, stripe_token = null, num
data.stripe_token = JSON.stringify(stripe_token.id);
}
form.serializeArray().forEach(function (item) {
form.serializeArray().forEach((item) => {
if (numeric_inputs.includes(item.name)) {
data[item.name] = item.value;
} else {

View File

@ -10,7 +10,7 @@ exports.initialize = () => {
},
});
$('#add-card-button').on('click', function (e) {
$('#add-card-button').on('click', (e) => {
const license_management = $('input[type=radio][name=license_management]:checked').val();
if (helpers.is_valid_input($("#" + license_management + "_license_count")) === false) {
return;
@ -28,7 +28,7 @@ exports.initialize = () => {
e.preventDefault();
});
$("#invoice-button").on("click", function (e) {
$("#invoice-button").on("click", (e) => {
if (helpers.is_valid_input($("#invoiced_licenses")) === false) {
return;
}
@ -36,7 +36,7 @@ exports.initialize = () => {
helpers.create_ajax_request("/json/billing/upgrade", "invoice", undefined, ["licenses"]);
});
$("#sponsorship-button").on("click", function (e) {
$("#sponsorship-button").on("click", (e) => {
e.preventDefault();
helpers.create_ajax_request("/json/billing/sponsorship", "sponsorship", undefined, undefined, "/");
});
@ -69,6 +69,6 @@ exports.initialize = () => {
window.upgrade = exports;
$(function () {
$(() => {
exports.initialize();
});

View File

@ -200,7 +200,7 @@ exports.exception_msg = function blueslip_exception_msg(ex) {
return message;
};
$(window).on('error', function (event) {
$(window).on('error', (event) => {
const ex = event.originalEvent.error;
if (!ex || ex instanceof BlueslipError) {
return;

View File

@ -19,7 +19,7 @@ const services = new Map();
const services_fields = ['base_url', 'interface',
'config_data', 'service_name', 'token'];
const send_change_event = _.debounce(function () {
const send_change_event = _.debounce(() => {
settings_bots.render_bots();
}, 50);

View File

@ -123,9 +123,7 @@ function buddy_list_create() {
self.get_items = function () {
const obj = self.container.find(self.item_sel);
return obj.map(function (i, elem) {
return $(elem);
});
return obj.map((i, elem) => $(elem));
};
self.first_key = function () {
@ -317,7 +315,7 @@ function buddy_list_create() {
// sure everything's in place.
const scroll_container = ui.get_scroll_element($(self.scroll_container_sel));
scroll_container.scroll(function () {
scroll_container.scroll(() => {
self.fill_screen_with_content();
});
};

View File

@ -77,7 +77,7 @@ function call(args, idempotent) {
if (!data && idempotent) {
// If idempotent, retry
blueslip.log("Retrying idempotent" + args);
setTimeout(function () {
setTimeout(() => {
const jqXHR = $.ajax(args);
add_pending_request(jqXHR);
}, 0);

View File

@ -32,7 +32,7 @@ exports.initialize = function () {
return;
}
current_msg_list.select_id(id);
setTimeout(function () {
setTimeout(() => {
// The algorithm to trigger long tap is that first, we check
// whether the message is still touched after MS_DELAY ms and
// the user isn't scrolling the messages(see other touch event
@ -45,18 +45,18 @@ exports.initialize = function () {
$(this).trigger("longtap");
}
}
}.bind(this), MS_DELAY);
}, MS_DELAY);
});
$("#main_div").on("touchend", ".messagebox", function () {
$("#main_div").on("touchend", ".messagebox", () => {
meta.touchdown = false;
});
$("#main_div").on("touchmove", ".messagebox", function () {
$("#main_div").on("touchmove", ".messagebox", () => {
meta.invalid = true;
});
$("#main_div").on("contextmenu", ".messagebox", function (e) {
$("#main_div").on("contextmenu", ".messagebox", (e) => {
e.preventDefault();
});
}
@ -178,19 +178,19 @@ exports.initialize = function () {
$(".tooltip").remove();
});
$('body').on('mouseenter', '.message_edit_notice', function (e) {
$('body').on('mouseenter', '.message_edit_notice', (e) => {
if (page_params.realm_allow_edit_history) {
$(e.currentTarget).addClass("message_edit_notice_hover");
}
});
$('body').on('mouseleave', '.message_edit_notice', function (e) {
$('body').on('mouseleave', '.message_edit_notice', (e) => {
if (page_params.realm_allow_edit_history) {
$(e.currentTarget).removeClass("message_edit_notice_hover");
}
});
$('body').on('click', '.message_edit_notice', function (e) {
$('body').on('click', '.message_edit_notice', (e) => {
popovers.hide_all();
const message_id = rows.id($(e.currentTarget).closest(".message_row"));
const row = current_msg_list.get_row(message_id);
@ -207,7 +207,7 @@ exports.initialize = function () {
// TOOLTIP FOR MESSAGE REACTIONS
$('#main_div').on('mouseenter', '.message_reaction', function (e) {
$('#main_div').on('mouseenter', '.message_reaction', (e) => {
e.stopPropagation();
const elem = $(e.currentTarget);
const local_id = elem.attr('data-reaction-id');
@ -226,14 +226,14 @@ exports.initialize = function () {
$(".tooltip-arrow").remove();
});
$('#main_div').on('mouseleave', '.message_reaction', function (e) {
$('#main_div').on('mouseleave', '.message_reaction', (e) => {
e.stopPropagation();
$(e.currentTarget).tooltip('destroy');
});
// DESTROY PERSISTING TOOLTIPS ON HOVER
$("body").on('mouseenter', '.tooltip', function (e) {
$("body").on('mouseenter', '.tooltip', (e) => {
e.stopPropagation();
$(e.currentTarget).remove();
});
@ -252,7 +252,7 @@ exports.initialize = function () {
// USER STATUS MODAL
$(".user-status-value").on("click", function (e) {
$(".user-status-value").on("click", (e) => {
e.stopPropagation();
const user_status_value = $(e.currentTarget).attr("data-user-status-value");
$("input.user_status").val(user_status_value);
@ -373,7 +373,7 @@ exports.initialize = function () {
// MUTING
$('body').on('click', '.on_hover_topic_mute', function (e) {
$('body').on('click', '.on_hover_topic_mute', (e) => {
e.stopPropagation();
const stream_id = parseInt($(e.currentTarget).attr('data-stream-id'), 10);
const topic = $(e.currentTarget).attr('data-topic-name');
@ -382,7 +382,7 @@ exports.initialize = function () {
$('body').on('keydown', '.on_hover_topic_mute', convert_enter_to_click);
$('body').on('click', '.on_hover_topic_unmute', function (e) {
$('body').on('click', '.on_hover_topic_unmute', (e) => {
e.stopPropagation();
const stream_id = parseInt($(e.currentTarget).attr('data-stream-id'), 10);
const topic = $(e.currentTarget).attr('data-topic-name');
@ -393,12 +393,12 @@ exports.initialize = function () {
// RECENT TOPICS
$('body').on('click', '#recent_topics_search', function (e) {
$('body').on('click', '#recent_topics_search', (e) => {
e.stopPropagation();
recent_topics.change_focused_element(e, 'click');
});
$('body').on('click', '.on_hover_topic_read', function (e) {
$('body').on('click', '.on_hover_topic_read', (e) => {
e.stopPropagation();
const stream_id = parseInt($(e.currentTarget).attr('data-stream-id'), 10);
const topic = $(e.currentTarget).attr('data-topic-name');
@ -407,19 +407,19 @@ exports.initialize = function () {
$('body').on('keydown', '.on_hover_topic_read', convert_enter_to_click);
$('body').on('click', '.btn-recent-filters', function (e) {
$('body').on('click', '.btn-recent-filters', (e) => {
e.stopPropagation();
recent_topics.set_filter(e.currentTarget.dataset.filter);
recent_topics.update_filters_view();
});
// Search for all table rows (this combines stream & topic names)
$('body').on('keyup', '#recent_topics_search', _.debounce(function () {
$('body').on('keyup', '#recent_topics_search', _.debounce(() => {
recent_topics.update_filters_view();
// Wait for user to go idle before initiating search.
}, 300));
$('body').on('click', '#recent_topics_search_clear', function (e) {
$('body').on('click', '#recent_topics_search_clear', (e) => {
e.stopPropagation();
$('#recent_topics_search').val("");
recent_topics.update_filters_view();
@ -459,7 +459,7 @@ exports.initialize = function () {
// SIDEBARS
$("#userlist-toggle-button").on("click", function (e) {
$("#userlist-toggle-button").on("click", (e) => {
e.preventDefault();
e.stopPropagation();
@ -470,7 +470,7 @@ exports.initialize = function () {
}
});
$("#streamlist-toggle-button").on("click", function (e) {
$("#streamlist-toggle-button").on("click", (e) => {
e.preventDefault();
e.stopPropagation();
@ -481,7 +481,7 @@ exports.initialize = function () {
}
});
$('#user_presences').expectOne().on('click', '.selectable_sidebar_block', function (e) {
$('#user_presences').expectOne().on('click', '.selectable_sidebar_block', (e) => {
const li = $(e.target).parents('li');
activity.narrow_for_user({li: li});
@ -508,7 +508,7 @@ exports.initialize = function () {
}
// BUDDY LIST TOOLTIPS
$('#user_presences').on('mouseenter', '.user-presence-link, .user_sidebar_entry .user_circle, .user_sidebar_entry .selectable_sidebar_block', function (e) {
$('#user_presences').on('mouseenter', '.user-presence-link, .user_sidebar_entry .user_circle, .user_sidebar_entry .selectable_sidebar_block', (e) => {
e.stopPropagation();
const elem = $(e.currentTarget).closest(".user_sidebar_entry").find(".user-presence-link");
const user_id_string = elem.attr('data-user-id');
@ -516,14 +516,14 @@ exports.initialize = function () {
do_render_buddy_list_tooltip(elem, title_data);
});
$('#user_presences').on('mouseleave click', '.user-presence-link, .user_sidebar_entry .user_circle, .user_sidebar_entry .selectable_sidebar_block', function (e) {
$('#user_presences').on('mouseleave click', '.user-presence-link, .user_sidebar_entry .user_circle, .user_sidebar_entry .selectable_sidebar_block', (e) => {
e.stopPropagation();
const elem = $(e.currentTarget).closest(".user_sidebar_entry").find(".user-presence-link");
$(elem).tooltip('destroy');
});
// PM LIST TOOLTIPS
$("body").on('mouseenter', '#pm_user_status', function (e) {
$("body").on('mouseenter', '#pm_user_status', (e) => {
$(".tooltip").remove();
e.stopPropagation();
const elem = $(e.currentTarget);
@ -535,14 +535,14 @@ exports.initialize = function () {
do_render_buddy_list_tooltip(elem, title_data);
});
$("body").on('mouseleave', '#pm_user_status', function (e) {
$("body").on('mouseleave', '#pm_user_status', (e) => {
e.stopPropagation();
$(e.currentTarget).tooltip('destroy');
});
// HOME
$(document).on('click', ".top_left_all_messages", function (e) {
$(document).on('click', ".top_left_all_messages", (e) => {
ui_util.change_tab_to('#home');
narrow.deactivate();
search.update_button_visibility();
@ -552,7 +552,7 @@ exports.initialize = function () {
e.preventDefault();
});
$(".brand").on('click', function (e) {
$(".brand").on('click', (e) => {
if (overlays.is_active()) {
overlays.close_active();
} else {
@ -577,11 +577,11 @@ exports.initialize = function () {
stream_popover.register_click_handlers();
notifications.register_click_handlers();
$('body').on('click', '.logout_button', function () {
$('body').on('click', '.logout_button', () => {
$('#logout_form').submit();
});
$('.restart_get_events_button').click(function () {
$('.restart_get_events_button').click(() => {
server_events.restart_get_events({dont_block: true});
});
@ -589,12 +589,12 @@ exports.initialize = function () {
$("body").on("click", ".alert-box > div .exit", function () {
const $alert = $(this).closest(".alert-box > div");
$alert.addClass("fade-out");
setTimeout(function () {
setTimeout(() => {
$alert.removeClass("fade-out show");
}, 300);
});
$("#settings_page").on("click", ".collapse-settings-btn", function () {
$("#settings_page").on("click", ".collapse-settings-btn", () => {
settings_toggle.toggle_org_setting_collapse();
});
@ -607,40 +607,40 @@ exports.initialize = function () {
// NB: This just binds to current elements, and won't bind to elements
// created after ready() is called.
$('#compose-send-status .compose-send-status-close').click(
function () { $('#compose-send-status').stop(true).fadeOut(500); }
() => { $('#compose-send-status').stop(true).fadeOut(500); }
);
$('#nonexistent_stream_reply_error .compose-send-status-close').click(
function () { $('#nonexistent_stream_reply_error').stop(true).fadeOut(500); }
() => { $('#nonexistent_stream_reply_error').stop(true).fadeOut(500); }
);
$('.compose_stream_button').click(function () {
$('.compose_stream_button').click(() => {
popovers.hide_mobile_message_buttons_popover();
compose_actions.start('stream', {trigger: 'new topic button'});
});
$('.compose_private_button').click(function () {
$('.compose_private_button').click(() => {
popovers.hide_mobile_message_buttons_popover();
compose_actions.start('private');
});
$('body').on('click', '.compose_mobile_stream_button', function () {
$('body').on('click', '.compose_mobile_stream_button', () => {
popovers.hide_mobile_message_buttons_popover();
compose_actions.start('stream', {trigger: 'new topic button'});
});
$('body').on('click', '.compose_mobile_private_button', function () {
$('body').on('click', '.compose_mobile_private_button', () => {
popovers.hide_mobile_message_buttons_popover();
compose_actions.start('private');
});
$('.compose_reply_button').click(function () {
$('.compose_reply_button').click(() => {
compose_actions.respond_to_message({trigger: 'reply button'});
});
$('.empty_feed_compose_stream').click(function (e) {
$('.empty_feed_compose_stream').click((e) => {
compose_actions.start('stream', {trigger: 'empty feed message'});
e.preventDefault();
});
$('.empty_feed_compose_private').click(function (e) {
$('.empty_feed_compose_private').click((e) => {
compose_actions.start('private', {trigger: 'empty feed message'});
e.preventDefault();
});
@ -677,23 +677,23 @@ exports.initialize = function () {
$("#compose_buttons").click(handle_compose_click);
$(".compose-content").click(handle_compose_click);
$("#compose_close").click(function () {
$("#compose_close").click(() => {
compose_actions.cancel();
});
$("#streams_inline_cog").click(function (e) {
$("#streams_inline_cog").click((e) => {
e.stopPropagation();
hashchange.go_to_location('streams/subscribed');
});
$("#streams_filter_icon").click(function (e) {
$("#streams_filter_icon").click((e) => {
e.stopPropagation();
stream_list.toggle_filter_displayed(e);
});
// WEBATHENA
$('body').on('click', '.webathena_login', function (e) {
$('body').on('click', '.webathena_login', (e) => {
$("#zephyr-mirror-error").removeClass("show");
const principal = ["zephyr", "zephyr"];
WinChan.open({
@ -703,7 +703,7 @@ exports.initialize = function () {
realm: "ATHENA.MIT.EDU",
principal: principal,
},
}, function (err, r) {
}, (err, r) => {
if (err) {
blueslip.warn(err);
return;
@ -731,9 +731,7 @@ exports.initialize = function () {
// End Webathena code
// disable the draggability for left-sidebar components
$('#stream_filters, #global_filters').on('dragstart', function () {
return false;
});
$('#stream_filters, #global_filters').on('dragstart', () => false);
(function () {
const map = {
@ -760,9 +758,7 @@ exports.initialize = function () {
}
});
$(document).on("drop", ".editable-section", function () {
return false;
});
$(document).on("drop", ".editable-section", () => false);
$(document).on("input", ".editable-section", function () {
// if there are any child nodes, inclusive of <br> which means you
@ -863,7 +859,7 @@ exports.initialize = function () {
$('#hotspot_' + hotspot_name + '_icon').remove();
});
$('body').on('click', '.hotspot-button', function (e) {
$('body').on('click', '.hotspot-button', (e) => {
e.preventDefault();
e.stopPropagation();
@ -872,14 +868,14 @@ exports.initialize = function () {
});
// stop propagation
$('body').on('click', '.hotspot.overlay .hotspot-popover', function (e) {
$('body').on('click', '.hotspot.overlay .hotspot-popover', (e) => {
e.stopPropagation();
});
// MAIN CLICK HANDLER
$(document).on('click', function (e) {
$(document).on('click', (e) => {
if (e.button !== 0 || $(e.target).is(".drag")) {
// Firefox emits right click events on the document, but not on
// the child nodes, so the #compose stopPropagation doesn't get a
@ -925,11 +921,11 @@ exports.initialize = function () {
// Workaround for Bootstrap issue #5900, which basically makes dropdowns
// unclickable on mobile devices.
// https://github.com/twitter/bootstrap/issues/5900
$('a.dropdown-toggle, .dropdown-menu a').on('touchstart', function (e) {
$('a.dropdown-toggle, .dropdown-menu a').on('touchstart', (e) => {
e.stopPropagation();
});
$(".settings-header.mobile .fa-chevron-left").on("click", function () {
$(".settings-header.mobile .fa-chevron-left").on("click", () => {
settings_panel_menu.mobile_deactivate_section();
});
};

View File

@ -6,7 +6,7 @@ if (module.hot) {
exports.status_classes = 'alert-error alert-success alert-info alert-warning';
exports.autofocus = function (selector) {
$(function () {
$(() => {
$(selector).focus();
});
};

View File

@ -18,7 +18,7 @@ exports.toggle = function (opts) {
// classes need to be added for correct alignment or other purposes
_component.addClass(opts.html_class);
}
opts.values.forEach(function (value, i) {
opts.values.forEach((value, i) => {
// create a tab with a tab-id so they don't have to be referenced
// by text value which can be inconsistent.
const tab = $("<div class='ind-tab' data-tab-key='" + value.key + "' data-tab-id='" + i + "' tabindex='0'>" + value.label + "</div>");

View File

@ -259,7 +259,7 @@ exports.compose_error = compose_error;
function nonexistent_stream_reply_error() {
$("#nonexistent_stream_reply_error").show();
$("#compose-reply-error-msg").html("There are no messages to reply to yet.");
setTimeout(function () {
setTimeout(() => {
$("#nonexistent_stream_reply_error").hide();
}, 5000);
}
@ -936,14 +936,14 @@ exports.initialize = function () {
$("#below-compose-content .video_link").toggle(exports.compute_show_video_chat_button());
$('#stream_message_recipient_stream,#stream_message_recipient_topic,#private_message_recipient').on('keyup', update_fade);
$('#stream_message_recipient_stream,#stream_message_recipient_topic,#private_message_recipient').on('change', update_fade);
$('#compose-textarea').on('keydown', function (event) {
$('#compose-textarea').on('keydown', (event) => {
exports.handle_keydown(event, $("#compose-textarea").expectOne());
});
$('#compose-textarea').on('keyup', function (event) {
$('#compose-textarea').on('keyup', (event) => {
exports.handle_keyup(event, $("#compose-textarea").expectOne());
});
$("#compose form").on("submit", function (e) {
$("#compose form").on("submit", (e) => {
e.preventDefault();
exports.finish();
});
@ -952,7 +952,7 @@ exports.initialize = function () {
upload.feature_check($("#compose #attach_files"));
$("#compose-all-everyone").on('click', '.compose-all-everyone-confirm', function (event) {
$("#compose-all-everyone").on('click', '.compose-all-everyone-confirm', (event) => {
event.preventDefault();
$(event.target).parents('.compose-all-everyone').remove();
@ -961,7 +961,7 @@ exports.initialize = function () {
exports.finish();
});
$("#compose-announce").on('click', '.compose-announce-confirm', function (event) {
$("#compose-announce").on('click', '.compose-announce-confirm', (event) => {
event.preventDefault();
$(event.target).parents('.compose-announce').remove();
@ -970,7 +970,7 @@ exports.initialize = function () {
exports.finish();
});
$("#compose-send-status").on('click', '.sub_unsub_button', function (event) {
$("#compose-send-status").on('click', '.sub_unsub_button', (event) => {
event.preventDefault();
const stream_name = $('#stream_message_recipient_stream').val();
@ -982,13 +982,13 @@ exports.initialize = function () {
$("#compose-send-status").hide();
});
$("#compose-send-status").on('click', '#compose_not_subscribed_close', function (event) {
$("#compose-send-status").on('click', '#compose_not_subscribed_close', (event) => {
event.preventDefault();
$("#compose-send-status").hide();
});
$("#compose_invite_users").on('click', '.compose_invite_link', function (event) {
$("#compose_invite_users").on('click', '.compose_invite_link', (event) => {
event.preventDefault();
const invite_row = $(event.target).parents('.compose_invite_user');
@ -1030,7 +1030,7 @@ exports.initialize = function () {
stream_edit.invite_user_to_stream([user_id], sub, success, xhr_failure);
});
$("#compose_invite_users").on('click', '.compose_invite_close', function (event) {
$("#compose_invite_users").on('click', '.compose_invite_close', (event) => {
const invite_row = $(event.target).parents('.compose_invite_user');
const all_invites = $("#compose_invite_users");
@ -1041,7 +1041,7 @@ exports.initialize = function () {
}
});
$("#compose_private_stream_alert").on('click', '.compose_private_stream_alert_close', function (event) {
$("#compose_private_stream_alert").on('click', '.compose_private_stream_alert_close', (event) => {
const stream_alert_row = $(event.target).parents('.compose_private_stream_alert');
const stream_alert = $("#compose_private_stream_alert");
@ -1055,12 +1055,12 @@ exports.initialize = function () {
// Click event binding for "Attach files" button
// Triggers a click on a hidden file input field
$("#compose").on("click", "#attach_files", function (e) {
$("#compose").on("click", "#attach_files", (e) => {
e.preventDefault();
$("#compose #file_input").trigger("click");
});
$('body').on('click', '.video_link', function (e) {
$('body').on('click', '.video_link', (e) => {
e.preventDefault();
let target_textarea;
@ -1138,7 +1138,7 @@ exports.initialize = function () {
}
});
$("#compose").on("click", "#markdown_preview", function (e) {
$("#compose").on("click", "#markdown_preview", (e) => {
e.preventDefault();
const content = $("#compose-textarea").val();
$("#compose-textarea").hide();
@ -1149,7 +1149,7 @@ exports.initialize = function () {
exports.render_and_show_preview($("#markdown_preview_spinner"), $("#preview_content"), content);
});
$("#compose").on("click", "#undo_markdown_preview", function (e) {
$("#compose").on("click", "#undo_markdown_preview", (e) => {
e.preventDefault();
exports.clear_preview_area();
});
@ -1158,7 +1158,7 @@ exports.initialize = function () {
mode: "compose",
});
$("#compose-textarea").focus(function () {
$("#compose-textarea").focus(() => {
const opts = {
message_type: compose_state.get_message_type(),
stream: $('#stream_message_recipient_stream').val(),

View File

@ -69,7 +69,7 @@ function fade_messages() {
}
// Defer updating all message groups so that the compose box can open sooner
setTimeout(function (expected_msg_list, expected_recipient) {
setTimeout((expected_msg_list, expected_recipient) => {
const all_groups = rows.get_table(current_msg_list.table_name).find(".recipient_row");
if (current_msg_list !== expected_msg_list ||

View File

@ -51,9 +51,7 @@ exports.get_user_ids_string = function () {
exports.get_emails = function () {
// return something like "alice@example.com,bob@example.com"
const user_ids = exports.get_user_ids();
const emails = user_ids.map(function (id) {
return people.get_by_user_id(id).email;
}).join(",");
const emails = user_ids.map((id) => people.get_by_user_id(id).email).join(",");
return emails;
};

View File

@ -63,13 +63,13 @@ exports.replace_syntax = function (old_syntax, new_syntax, textarea) {
textarea = $('#compose-textarea');
}
textarea.val(textarea.val().replace(old_syntax, function () {
textarea.val(textarea.val().replace(old_syntax, () =>
// We need this anonymous function to avoid JavaScript's
// replace() function treating `$`s in new_syntax as special syntax. See
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Description
// for details.
return new_syntax;
}));
new_syntax
));
};
exports.compute_placeholder_text = function (opts) {

View File

@ -257,12 +257,12 @@ function select_on_focus(field_id) {
// conditions in Chrome so we need to protect against infinite
// recursion.
let in_handler = false;
$("#" + field_id).focus(function () {
$("#" + field_id).focus(() => {
if (in_handler) {
return;
}
in_handler = true;
$("#" + field_id).select().one('mouseup', function (e) {
$("#" + field_id).select().one('mouseup', (e) => {
e.preventDefault();
});
in_handler = false;
@ -907,7 +907,7 @@ exports.content_typeahead_selected = function (item, event) {
// Keep the cursor after the newly inserted text, as Bootstrap will call textbox.change() to
// overwrite the text in the textbox.
setTimeout(function () {
setTimeout(() => {
textbox.caret(beginning.length, beginning.length);
// Also, trigger autosize to check if compose box needs to be resized.
compose_ui.autosize_textarea();
@ -954,7 +954,7 @@ exports.sort_results = function (completing, matches, token) {
// topic_jump doesn't actually have a typeahead popover, so we return quickly here.
return matches;
case 'topic_list':
return typeahead_helper.sorter(token, matches, function (x) {return x;});
return typeahead_helper.sorter(token, matches, (x) => x);
}
};
@ -1044,7 +1044,7 @@ exports.initialize = function () {
$("form#send_message_form").keydown(handle_keydown);
$("form#send_message_form").keyup(handle_keyup);
$("#enter_sends").click(function () {
$("#enter_sends").click(() => {
const send_button = $("#compose-send-button");
page_params.enter_sends = $("#enter_sends").is(":checked");
if (page_params.enter_sends) {
@ -1097,7 +1097,7 @@ exports.initialize = function () {
return typeahead_helper.render_typeahead_item({ primary: item });
},
sorter: function (items) {
const sorted = typeahead_helper.sorter(this.query, items, function (x) {return x;});
const sorted = typeahead_helper.sorter(this.query, items, (x) => x);
if (sorted.length > 0 && !sorted.includes(this.query)) {
sorted.unshift(this.query);
}

View File

@ -62,12 +62,12 @@ exports.launch = function (conf) {
yes_button.html(conf.html_yes_button);
// Set up handlers.
yes_button.on('click', function () {
yes_button.on('click', () => {
overlays.close_modal('#confirm_dialog_modal');
conf.on_click();
});
confirm_dialog.on('hide', function () {
confirm_dialog.on('hide', () => {
confirm_dialog.remove();
});

View File

@ -108,7 +108,7 @@ function select_div(div, selection) {
}
function remove_div(div, ranges, selection) {
window.setTimeout(function () {
window.setTimeout(() => {
selection = window.getSelection();
selection.removeAllRanges();
@ -210,9 +210,7 @@ exports.analyze_selection = function (selection) {
ranges.push(range);
startc = $(range.startContainer);
start_data = find_boundary_tr($(startc.parents('.selectable_row, .message_header')[0]), function (row) {
return row.next();
});
start_data = find_boundary_tr($(startc.parents('.selectable_row, .message_header')[0]), (row) => row.next());
if (start_data === undefined) {
// Skip any selection sections that don't intersect a message.
continue;
@ -237,9 +235,7 @@ exports.analyze_selection = function (selection) {
} else {
initial_end_tr = $(endc.parents('.selectable_row')[0]);
}
end_data = find_boundary_tr(initial_end_tr, function (row) {
return row.prev();
});
end_data = find_boundary_tr(initial_end_tr, (row) => row.prev());
if (end_data === undefined) {
// Skip any selection sections that don't intersect a message.

View File

@ -1,5 +1,5 @@
let csrf_token;
$(function () {
$(() => {
// This requires that we used Jinja2's {% csrf_input %} somewhere on the page.
const csrf_input = $('input[name="csrfmiddlewaretoken"]');
if (csrf_input.length > 0) {

View File

@ -30,11 +30,9 @@ export function check_duplicate_ids() {
const collisions = [];
let total_collisions = 0;
Array.prototype.slice.call(document.querySelectorAll("*")).forEach(function (o) {
Array.prototype.slice.call(document.querySelectorAll("*")).forEach((o) => {
if (o.id && ids.has(o.id)) {
const el = collisions.find(function (c) {
return c.id === o.id;
});
const el = collisions.find((c) => c.id === o.id);
ids.add(o.id);
total_collisions += 1;

View File

@ -318,9 +318,9 @@ exports.launch = function () {
const unsorted_raw_drafts = Object.values(data);
const sorted_raw_drafts = unsorted_raw_drafts.sort(function (draft_a, draft_b) {
return draft_b.updatedAt - draft_a.updatedAt;
});
const sorted_raw_drafts = unsorted_raw_drafts.sort(
(draft_a, draft_b) => draft_b.updatedAt - draft_a.updatedAt
);
const sorted_formatted_drafts = sorted_raw_drafts.map(exports.format_draft).filter(Boolean);
@ -514,7 +514,7 @@ exports.set_initial_element = function (drafts) {
};
exports.initialize = function () {
window.addEventListener("beforeunload", function () {
window.addEventListener("beforeunload", () => {
exports.update_draft();
});
@ -522,7 +522,7 @@ exports.initialize = function () {
$("#compose-textarea").focusout(exports.update_draft);
$('body').on('focus', '.draft-info-box', function (e) {
$('body').on('focus', '.draft-info-box', (e) => {
activate_element(e.target);
});
};

View File

@ -55,7 +55,7 @@ const DropdownListWidget = function (opts) {
const value = $(this).attr('data-value');
update(value);
});
$(`#${opts.container_id} .dropdown_list_reset_button`).click(function (e) {
$(`#${opts.container_id} .dropdown_list_reset_button`).click((e) => {
update(opts.null_value);
e.preventDefault();
});
@ -79,22 +79,22 @@ const DropdownListWidget = function (opts) {
},
},
});
$(`#${opts.container_id} .dropdown-search`).click(function (e) {
$(`#${opts.container_id} .dropdown-search`).click((e) => {
e.stopPropagation();
});
dropdown_toggle.click(function () {
dropdown_toggle.click(() => {
search_input.val("").trigger("input");
});
dropdown_toggle.focus(function (e) {
dropdown_toggle.focus((e) => {
// On opening a Bootstrap Dropdown, the parent element recieves focus.
// Here, we want our search input to have focus instead.
e.preventDefault();
search_input.focus();
});
search_input.keydown(function (e) {
search_input.keydown((e) => {
if (!/(38|40|27)/.test(e.keyCode)) {
return;
}

View File

@ -30,7 +30,7 @@ function resend_message(message, row) {
function on_error(response) {
exports.message_send_error(message.id, response);
setTimeout(function () {
setTimeout(() => {
retry_spinner.toggleClass('rotating', false);
}, 300);
blueslip.log("Manual resend of message failed");

View File

@ -505,7 +505,7 @@ exports.emoji_select_tab = function (elt) {
const scrollheight = elt.prop('scrollHeight');
const elt_height = elt.height();
let currently_selected = "";
section_head_offsets.forEach(function (o) {
section_head_offsets.forEach((o) => {
if (scrolltop + elt_height / 2 >= o.position_y) {
currently_selected = o.section;
}
@ -528,14 +528,14 @@ exports.emoji_select_tab = function (elt) {
function register_popover_events(popover) {
const $emoji_map = popover.find('.emoji-popover-emoji-map');
ui.get_scroll_element($emoji_map).on("scroll", function () {
ui.get_scroll_element($emoji_map).on("scroll", () => {
exports.emoji_select_tab(ui.get_scroll_element($emoji_map));
});
$('.emoji-popover-filter').on('input', filter_emojis);
$('.emoji-popover-filter').keydown(maybe_select_emoji);
$('.emoji-popover').keypress(process_keypress);
$('.emoji-popover').keydown(function (e) {
$('.emoji-popover').keydown((e) => {
// Because of cross-browser issues we need to handle backspace
// key separately. Firefox fires `keypress` event for backspace
// key but chrome doesn't so we need to trigger the logic for
@ -670,7 +670,7 @@ exports.register_click_handlers = function () {
exports.toggle_emoji_popover(this, message_id);
});
$("#main_div").on("mouseenter", ".reaction_button", function (e) {
$("#main_div").on("mouseenter", ".reaction_button", (e) => {
e.stopPropagation();
const elem = $(e.currentTarget);
@ -685,12 +685,12 @@ exports.register_click_handlers = function () {
$(".tooltip-arrow").remove();
});
$('#main_div').on('mouseleave', '.reaction_button', function (e) {
$('#main_div').on('mouseleave', '.reaction_button', (e) => {
e.stopPropagation();
$(e.currentTarget).tooltip('hide');
});
$("body").on("click", ".actions_popover .reaction_button", function (e) {
$("body").on("click", ".actions_popover .reaction_button", (e) => {
const message_id = $(e.currentTarget).data('message-id');
e.preventDefault();
e.stopPropagation();
@ -710,20 +710,18 @@ exports.register_click_handlers = function () {
const $popover = $(e.currentTarget).closest('.emoji-info-popover').expectOne();
const $emoji_map = $popover.find(".emoji-popover-emoji-map");
const offset = section_head_offsets.find(function (o) {
return o.section === $(this).attr("data-tab-name");
}.bind(this));
const offset = section_head_offsets.find((o) => o.section === $(this).attr("data-tab-name"));
if (offset) {
ui.get_scroll_element($emoji_map).scrollTop(offset.position_y);
}
});
$("body").on("click", ".emoji-popover-filter", function () {
$("body").on("click", ".emoji-popover-filter", () => {
reset_emoji_showcase();
});
$("body").on("mouseenter", ".emoji-popover-emoji", function (e) {
$("body").on("mouseenter", ".emoji-popover-emoji", (e) => {
const emoji_id = $(e.currentTarget).data("emoji-id");
const emoji_coordinates = get_emoji_coordinates(emoji_id);

View File

@ -71,7 +71,7 @@ function set_up_handlers() {
meta.handlers_set = true;
// if the user mouses over the notification, don't hide it.
meta.$container.mouseenter(function () {
meta.$container.mouseenter(() => {
if (!meta.opened) {
return;
}
@ -80,7 +80,7 @@ function set_up_handlers() {
});
// once the user's mouse leaves the notification, restart the countdown.
meta.$container.mouseleave(function () {
meta.$container.mouseleave(() => {
if (!meta.opened) {
return;
}
@ -91,11 +91,11 @@ function set_up_handlers() {
meta.hide_me_time = Math.max(meta.hide_me_time, new Date().getTime() + 2000);
});
meta.$container.on('click', '.exit-me', function () {
meta.$container.on('click', '.exit-me', () => {
animate.fadeOut();
});
meta.$container.on('click', '.feedback_undo', function () {
meta.$container.on('click', '.feedback_undo', () => {
if (meta.undo) {
meta.undo();
}

View File

@ -369,8 +369,8 @@ Filter.prototype = {
operands: function (operator) {
return _.chain(this._operators)
.filter(function (elem) { return !elem.negated && elem.operator === operator; })
.map(function (elem) { return elem.operand; })
.filter((elem) => !elem.negated && elem.operator === operator)
.map((elem) => elem.operand)
.value();
},

View File

@ -86,12 +86,12 @@ exports.update_org_settings_menu_item = function () {
exports.initialize = function () {
exports.update_org_settings_menu_item();
$('#gear-menu a[data-toggle="tab"]').on('show', function (e) {
$('#gear-menu a[data-toggle="tab"]').on('show', (e) => {
// Save the position of our old tab away, before we switch
const old_tab = $(e.relatedTarget).attr('href');
scroll_positions.set(old_tab, message_viewport.scrollTop());
});
$('#gear-menu a[data-toggle="tab"]').on('shown', function (e) {
$('#gear-menu a[data-toggle="tab"]').on('shown', (e) => {
const target_tab = $(e.target).attr('href');
// Hide all our error messages when switching tabs
$('.alert').removeClass("show");

View File

@ -281,7 +281,7 @@ exports.go_to_location = function (hash) {
};
exports.initialize = function () {
$(window).on('hashchange', function (e) {
$(window).on('hashchange', (e) => {
hashchanged(false, e.originalEvent);
});
hashchanged(true);

View File

@ -634,7 +634,7 @@ exports.process_hotkey = function (e, hotkey) {
compose_actions.start('private', {trigger: "compose_hotkey"});
return true;
case 'narrow_private':
return do_narrow_action(function (target, opts) {
return do_narrow_action((target, opts) => {
narrow.by('is', 'private', opts);
});
case 'query_streams':
@ -792,7 +792,7 @@ exports.process_keydown = function (e) {
return exports.process_hotkey(e, hotkey);
};
$(document).keydown(function (e) {
$(document).keydown((e) => {
if (exports.process_keydown(e)) {
e.preventDefault();
}
@ -806,7 +806,7 @@ exports.process_keypress = function (e) {
return exports.process_hotkey(e, hotkey);
};
$(document).keypress(function (e) {
$(document).keypress((e) => {
if (exports.process_keypress(e)) {
e.preventDefault();
}

View File

@ -203,7 +203,7 @@ function insert_hotspot_into_DOM(hotspot) {
'<div class="bounce"><span class="bounce-icon">?</span></div>' +
'</div>';
setTimeout(function () {
setTimeout(() => {
$('body').prepend(hotspot_icon_HTML);
$('body').prepend(hotspot_overlay_HTML);
if (place_icon(hotspot)) {
@ -211,8 +211,8 @@ function insert_hotspot_into_DOM(hotspot) {
}
// reposition on any event that might update the UI
['resize', 'scroll', 'onkeydown', 'click'].forEach(function (event_name) {
window.addEventListener(event_name, _.debounce(function () {
['resize', 'scroll', 'onkeydown', 'click'].forEach((event_name) => {
window.addEventListener(event_name, _.debounce(() => {
if (place_icon(hotspot)) {
place_popover(hotspot);
}
@ -247,7 +247,7 @@ function close_read_hotspots(new_hotspots) {
exports.load_new = function (new_hotspots) {
close_read_hotspots(new_hotspots);
new_hotspots.forEach(function (hotspot) {
new_hotspots.forEach((hotspot) => {
hotspot.location = HOTSPOT_LOCATIONS.get(hotspot.name);
});
new_hotspots.forEach(insert_hotspot_into_DOM);

View File

@ -16,9 +16,7 @@ exports.process_loaded_messages = function (messages) {
exports.get_huddles = function () {
let huddles = Array.from(huddle_timestamps.keys());
huddles = _.sortBy(huddles, function (huddle) {
return huddle_timestamps.get(huddle);
});
huddles = _.sortBy(huddles, (huddle) => huddle_timestamps.get(huddle));
return huddles.reverse();
};

View File

@ -187,16 +187,14 @@ exports.create = function (opts) {
insertManyPills: function (pills) {
if (typeof pills === "string") {
pills = pills.split(/,/g).map(function (pill) {
return pill.trim();
});
pills = pills.split(/,/g).map((pill) => pill.trim());
}
// this is an array to push all the errored values to, so it's drafts
// of pills for the user to fix.
const drafts = [];
pills.forEach(function (pill) {
pills.forEach((pill) => {
// if this returns `false`, it erroed and we should push it to
// the draft pills.
if (funcs.appendPill(pill) === false) {
@ -235,7 +233,7 @@ exports.create = function (opts) {
};
(function events() {
store.$parent.on("keydown", ".input", function (e) {
store.$parent.on("keydown", ".input", (e) => {
const char = e.keyCode || e.charCode;
if (char === KEY.ENTER) {
@ -300,7 +298,7 @@ exports.create = function (opts) {
// handle events while hovering on ".pill" elements.
// the three primary events are next, previous, and delete.
store.$parent.on("keydown", ".pill", function (e) {
store.$parent.on("keydown", ".pill", (e) => {
const char = e.keyCode || e.charCode;
const $pill = store.$parent.find(".pill:focus");
@ -328,7 +326,7 @@ exports.create = function (opts) {
// replace formatted input with plaintext to allow for sane copy-paste
// actions.
store.$parent.on("paste", ".input", function (e) {
store.$parent.on("paste", ".input", (e) => {
e.preventDefault();
// get text representation of clipboard
@ -360,7 +358,7 @@ exports.create = function (opts) {
}
});
store.$parent.on("copy", ".pill", function (e) {
store.$parent.on("copy", ".pill", (e) => {
const id = store.$parent.find(":focus").data("id");
const data = funcs.getByID(id);
e.originalEvent.clipboardData.setData("text/plain", store.get_text_from_item(data.item));

View File

@ -73,7 +73,7 @@ function submit_invitation_form() {
const invitee_emails_errored = [];
const error_list = [];
let is_invitee_deactivated = false;
arr.errors.forEach(function (value) {
arr.errors.forEach((value) => {
const [email, error_message, deactivated] = value;
error_list.push(`${email}: ${error_message}`);
if (deactivated) {
@ -161,17 +161,17 @@ exports.launch = function () {
};
exports.initialize = function () {
$(document).on('click', '.invite_check_all_button', function (e) {
$(document).on('click', '.invite_check_all_button', (e) => {
$('#streams_to_add :checkbox').prop('checked', true);
e.preventDefault();
});
$(document).on('click', '.invite_uncheck_all_button', function (e) {
$(document).on('click', '.invite_uncheck_all_button', (e) => {
$('#streams_to_add :checkbox').prop('checked', false);
e.preventDefault();
});
$("#submit-invitation").on("click", function () {
$("#submit-invitation").on("click", () => {
const is_generate_invite_link = $('#generate_multiuse_invite_radio').prop('checked');
if (is_generate_invite_link) {
generate_multiuse_invite();
@ -180,7 +180,7 @@ exports.initialize = function () {
}
});
$("#generate_multiuse_invite_button").on("click", function () {
$("#generate_multiuse_invite_button").on("click", () => {
$("#generate_multiuse_invite_radio").prop("checked", true);
$("#multiuse_radio_section").show();
$("#invite-method-choice").hide();
@ -190,7 +190,7 @@ exports.initialize = function () {
reset_error_messages();
});
$('#invite-user').on('change', '#generate_multiuse_invite_radio', function () {
$('#invite-user').on('change', '#generate_multiuse_invite_radio', () => {
$('#invitee_emails').prop('disabled', false);
$('#submit-invitation').text(i18n.t('Invite'));
$('#submit-invitation').data('loading-text', i18n.t('Inviting...'));

View File

@ -11,7 +11,7 @@ const keys = {
};
exports.handle = function (opts) {
opts.elem.keydown(function (e) {
opts.elem.keydown((e) => {
const key = e.which || e.keyCode;
if (e.altKey || e.ctrlKey || e.shiftKey) {

View File

@ -8,7 +8,7 @@ function render_lightbox_list_images(preview_source) {
const images = Array.prototype.slice.call($(".focused_table .message_inline_image img"));
const $image_list = $("#lightbox_overlay .image-list").html("");
images.forEach(function (img) {
images.forEach((img) => {
const src = img.getAttribute("src");
const className = preview_source === src ? "image selected" : "image";
@ -321,7 +321,7 @@ exports.initialize = function () {
}
});
$("#lightbox_overlay .image-preview").on("dblclick", "img, canvas", function (e) {
$("#lightbox_overlay .image-preview").on("dblclick", "img, canvas", (e) => {
$("#lightbox_overlay .lightbox-canvas-trigger").click();
e.preventDefault();
});
@ -332,7 +332,7 @@ exports.initialize = function () {
}
});
$("#lightbox_overlay").on("click", ".image-info-wrapper, .center", function (e) {
$("#lightbox_overlay").on("click", ".image-info-wrapper, .center", (e) => {
if ($(e.target).is(".image-info-wrapper, .center")) {
overlays.close_overlay("lightbox");
}

View File

@ -4,7 +4,7 @@ const events = {
};
window.onload = function () {
document.body.addEventListener("mouseup", function (e) {
document.body.addEventListener("mouseup", (e) => {
events.documentMouseup = events.documentMouseup.filter(function (event) {
// go through automatic cleanup when running events.
if (!document.body.contains(event.canvas)) {
@ -17,7 +17,7 @@ window.onload = function () {
});
window.addEventListener("resize", function (e) {
events.windowResize = events.windowResize.filter(function (event) {
events.windowResize = events.windowResize.filter((event) => {
if (!document.body.contains(event.canvas)) {
return false;
}
@ -25,7 +25,7 @@ window.onload = function () {
event.callback.call(this, e);
return true;
}.bind(this));
});
});
};
@ -76,7 +76,7 @@ const funcs = {
// actually an element that can scroll. The wheel event will
// detect the *gesture* of scrolling over an element, without actually
// worrying about scrollable content.
canvas.addEventListener("wheel", function (e) {
canvas.addEventListener("wheel", (e) => {
e.preventDefault();
// this is to reverse scrolling directions for the image.
@ -111,12 +111,12 @@ const funcs = {
// the only valid mousedown events should originate inside of the
// canvas.
canvas.addEventListener("mousedown", function () {
canvas.addEventListener("mousedown", () => {
mousedown = true;
});
// on mousemove, actually run the pan events.
canvas.addEventListener("mousemove", function (e) {
canvas.addEventListener("mousemove", (e) => {
// to pan, there must be mousedown and mousemove, check if valid.
if (mousedown === true) {
polyfillMouseMovement(e);
@ -145,7 +145,7 @@ const funcs = {
// that the LightboxCanvas instance created in lightbox.js can be
// accessed from hotkey.js. Major code refactoring is required in lightbox.js
// to implement these keyboard shortcuts in hotkey.js
document.addEventListener('keydown', function (e) {
document.addEventListener('keydown', (e) => {
if (!overlays.lightbox_open()) {
return;
}
@ -165,7 +165,7 @@ const funcs = {
// make sure that when the mousedown is lifted on <canvas>to prevent
// panning events.
canvas.addEventListener("mouseup", function () {
canvas.addEventListener("mouseup", () => {
mousedown = false;
// reset this to be empty so that the values will `NaN` on first
// mousemove and default to a change of (0, 0).

View File

@ -62,11 +62,9 @@ const ls = {
// Remove keys which match a regex.
removeDataRegex: function (version, regex) {
const key_regex = new RegExp(this.formGetter(version, regex));
const keys = Object.keys(localStorage).filter(function (key) {
return key_regex.test(key);
});
const keys = Object.keys(localStorage).filter((key) => key_regex.test(key));
keys.forEach(function (key) {
keys.forEach((key) => {
localStorage.removeItem(key);
});
},

View File

@ -176,7 +176,7 @@ exports.apply_markdown = function (message) {
silencedMentionHandler: function (quote) {
// Silence quoted mentions.
const user_mention_re = /<span.*user-mention.*data-user-id="(\d+|\*)"[^>]*>@/gm;
quote = quote.replace(user_mention_re, function (match) {
quote = quote.replace(user_mention_re, (match) => {
match = match.replace(/"user-mention"/g, '"user-mention silent"');
match = match.replace(/>@/g, '>');
return match;
@ -502,9 +502,7 @@ exports.initialize = function (realm_filters, helper_config) {
// Tell our fenced code preprocessor how to insert arbitrary
// HTML into the output. This generated HTML is safe to not escape
fenced_code.set_stash_func(function (html) {
return marked.stashHtml(html, true);
});
fenced_code.set_stash_func((html) => marked.stashHtml(html, true));
marked.setOptions({
gfm: true,

View File

@ -380,7 +380,7 @@ function edit_message(row, raw_content) {
// Do this right away, rather than waiting for the timer to do its first update,
// since otherwise there is a noticeable lag
message_edit_countdown_timer.text(timer_text(seconds_left));
const countdown_timer = setInterval(function () {
const countdown_timer = setInterval(() => {
seconds_left -= 1;
if (seconds_left <= 0) {
clearInterval(countdown_timer);
@ -437,11 +437,11 @@ function edit_message(row, raw_content) {
}
if (!message.locally_echoed) {
message_edit_topic.keyup(function () {
message_edit_topic.keyup(() => {
set_propagate_selector_display();
});
message_edit_stream.on('change', function () {
message_edit_stream.on('change', () => {
set_propagate_selector_display();
});
}
@ -781,7 +781,7 @@ exports.edit_last_sent_message = function () {
// Finally do the real work!
compose_actions.cancel();
exports.start(msg_row, function () {
exports.start(msg_row, () => {
$('#message_edit_content').focus();
});
};
@ -807,7 +807,7 @@ exports.delete_message = function (msg_id) {
} else {
hide_delete_btn_show_spinner(false);
}
$('#do_delete_message_button').off().on('click', function (e) {
$('#do_delete_message_button').off().on('click', (e) => {
e.stopPropagation();
e.preventDefault();
currently_deleting_messages.push(msg_id);

View File

@ -45,7 +45,7 @@ function maybe_add_narrowed_messages(messages, msg_list) {
},
error: function () {
// We might want to be more clever here
setTimeout(function () {
setTimeout(() => {
if (msg_list === current_msg_list) {
// Don't actually try again if we unnarrowed
// while waiting

View File

@ -109,7 +109,7 @@ function get_messages_success(data, opts) {
if (!data) {
// The server occasionally returns no data during a
// restart. Ignore those responses and try again
setTimeout(function () {
setTimeout(() => {
exports.load_messages(opts);
}, 0);
return;
@ -239,7 +239,7 @@ exports.load_messages = function (opts) {
// We might want to be more clever here
$('#connection-error').addClass("show");
setTimeout(function () {
setTimeout(() => {
exports.load_messages(opts);
}, consts.error_retry_time);
},

View File

@ -445,7 +445,7 @@ exports.all = new exports.MessageList({
// doing something. Be careful, though, if you try to capture
// mousemove, then you will have to contend with the autoscroll
// itself generating mousemove events.
$(document).on('message_selected.zulip wheel', function () {
$(document).on('message_selected.zulip wheel', () => {
message_viewport.stop_auto_scrolling();
});

View File

@ -282,7 +282,7 @@ MessageListData.prototype = {
let viewable_messages;
if (this.muting_enabled) {
this._all_items = messages.concat(this._all_items);
this._all_items.sort(function (a, b) {return a.id - b.id;});
this._all_items.sort((a, b) => a.id - b.id);
viewable_messages = this.unmuted_messages(messages);
this._items = viewable_messages.concat(this._items);
@ -292,7 +292,7 @@ MessageListData.prototype = {
this._items = messages.concat(this._items);
}
this._items.sort(function (a, b) {return a.id - b.id;});
this._items.sort((a, b) => a.id - b.id);
this._add_to_hash(messages);
return viewable_messages;
},
@ -371,7 +371,7 @@ MessageListData.prototype = {
if (self._is_localonly_id(msg.id)) {
// First non-local message before this one
const effective = self._next_nonlocal_message(self._items, a_idx,
function (idx) { return idx - 1; });
(idx) => idx - 1);
if (effective) {
// Turn the 10.02 in [11, 10.02, 12] into 11.02
const decimal = parseFloat((msg.id % 1).toFixed(0.02));
@ -472,7 +472,7 @@ MessageListData.prototype = {
_add_to_hash: function (messages) {
const self = this;
messages.forEach(function (elem) {
messages.forEach((elem) => {
const id = parseFloat(elem.id);
if (isNaN(id)) {
blueslip.fatal("Bad message id");
@ -525,7 +525,7 @@ MessageListData.prototype = {
// If this message is now out of order, re-order and re-render
const self = this;
setTimeout(function () {
setTimeout(() => {
const current_message = self._hash.get(new_id);
const index = self._items.indexOf(current_message);
@ -537,9 +537,9 @@ MessageListData.prototype = {
}
const next = self._next_nonlocal_message(self._items, index,
function (idx) { return idx + 1; });
(idx) => idx + 1);
const prev = self._next_nonlocal_message(self._items, index,
function (idx) { return idx - 1; });
(idx) => idx - 1);
if (next !== undefined && current_message.id > next.id ||
prev !== undefined && current_message.id < prev.id) {

View File

@ -153,13 +153,13 @@ function scroll_finish() {
}
exports.initialize = function () {
message_viewport.message_pane.scroll(_.throttle(function () {
message_viewport.message_pane.scroll(_.throttle(() => {
unread_ops.process_visible();
scroll_finish();
}, 50));
// Scroll handler that marks messages as read when you scroll past them.
$(document).on('message_selected.zulip', function (event) {
$(document).on('message_selected.zulip', (event) => {
if (event.id === -1) {
return;
}

View File

@ -419,14 +419,14 @@ exports.initialize = function () {
jwindow = $(window);
exports.message_pane = $(".app");
// This handler must be placed before all resize handlers in our application
jwindow.resize(function () {
jwindow.resize(() => {
dimensions.height.reset();
dimensions.width.reset();
top_of_feed.reset();
bottom_of_feed.reset();
});
$(document).on('compose_started compose_canceled compose_finished', function () {
$(document).on('compose_started compose_canceled compose_finished', () => {
bottom_of_feed.reset();
});
};

View File

@ -334,7 +334,7 @@ exports.activate = function (raw_operators, opts) {
tab_bar.initialize();
msg_list.initial_core_time = new Date();
setTimeout(function () {
setTimeout(() => {
resize.resize_stream_filters_container();
msg_list.initial_free_time = new Date();
maybe_report_narrow_time(msg_list);
@ -840,7 +840,7 @@ exports.deactivate = function () {
handle_post_narrow_deactivate_processes();
unnarrow_times.initial_core_time = new Date();
setTimeout(function () {
setTimeout(() => {
resize.resize_stream_filters_container();
unnarrow_times.initial_free_time = new Date();
report_unnarrow_time();

View File

@ -63,7 +63,7 @@ function get_audio_file_path(audio_element, audio_file_without_extension) {
}
exports.initialize = function () {
$(window).focus(function () {
$(window).focus(() => {
window_has_focus = true;
for (const notice_mem_entry of notice_memory.values()) {
@ -75,7 +75,7 @@ exports.initialize = function () {
// counts.
unread_ops.process_visible();
}).blur(function () {
}).blur(() => {
window_has_focus = false;
});
@ -250,7 +250,7 @@ if (window.electron_bridge !== undefined) {
if (window.electron_bridge.set_send_notification_reply_message_supported !== undefined) {
window.electron_bridge.set_send_notification_reply_message_supported(true);
}
window.electron_bridge.on_event('send_notification_reply_message', function (message_id, reply) {
window.electron_bridge.on_event('send_notification_reply_message', (message_id, reply) => {
const message = message_store.get(message_id);
const data = {
type: message.type,
@ -658,7 +658,7 @@ exports.notify_local_mixes = function (messages, need_user_to_scroll) {
if (need_user_to_scroll) {
reason = i18n.t("Sent! Scroll down to view your message.");
exports.notify_above_composebox(reason, "", null, "");
setTimeout(function () {
setTimeout(() => {
$('#out-of-view-notification').hide();
}, 3000);
}
@ -716,20 +716,20 @@ exports.reify_message_id = function (opts) {
};
exports.register_click_handlers = function () {
$('#out-of-view-notification').on('click', '.compose_notification_narrow_by_topic', function (e) {
$('#out-of-view-notification').on('click', '.compose_notification_narrow_by_topic', (e) => {
const message_id = $(e.currentTarget).data('message-id');
narrow.by_topic(message_id, {trigger: 'compose_notification'});
e.stopPropagation();
e.preventDefault();
});
$('#out-of-view-notification').on('click', '.compose_notification_scroll_to_message', function (e) {
$('#out-of-view-notification').on('click', '.compose_notification_scroll_to_message', (e) => {
const message_id = $(e.currentTarget).data('message-id');
current_msg_list.select_id(message_id);
navigate.scroll_to_selected();
e.stopPropagation();
e.preventDefault();
});
$('#out-of-view-notification').on('click', '.out-of-view-notification-close', function (e) {
$('#out-of-view-notification').on('click', '.out-of-view-notification-close', (e) => {
exports.clear_compose_notifications();
e.stopPropagation();
e.preventDefault();

View File

@ -221,7 +221,7 @@ exports.open_settings = function () {
};
exports.initialize = function () {
$("body").on("click", ".overlay, .overlay .exit", function (e) {
$("body").on("click", ".overlay, .overlay .exit", (e) => {
let $target = $(e.target);
// if the target is not the .overlay element, search up the node tree

View File

@ -139,9 +139,7 @@ exports.is_known_user_id = function (user_id) {
};
function sort_numerically(user_ids) {
user_ids.sort(function (a, b) {
return a - b;
});
user_ids.sort((a, b) => a - b);
return user_ids;
}
@ -859,9 +857,9 @@ exports.get_message_people = function () {
exports.get_active_message_people = function () {
const message_people = exports.get_message_people();
const active_message_people = message_people.filter(function (item) {
return active_user_dict.has(item.user_id);
});
const active_message_people = message_people.filter((item) =>
active_user_dict.has(item.user_id)
);
return active_message_people;
};

View File

@ -53,9 +53,7 @@ exports.recent = (function () {
conversation.max_message_id = message_id;
}
recent_private_messages.sort(function (a, b) {
return b.max_message_id - a.max_message_id;
});
recent_private_messages.sort((a, b) => b.max_message_id - a.max_message_id);
};
self.get = function () {

View File

@ -284,12 +284,12 @@ exports.activate = function (opts) {
const html = render_widgets_poll_widget();
elem.html(html);
elem.find('input.poll-question').on('keyup', function (e) {
elem.find('input.poll-question').on('keyup', (e) => {
e.stopPropagation();
update_edit_controls();
});
elem.find('input.poll-question').on('keydown', function (e) {
elem.find('input.poll-question').on('keydown', (e) => {
e.stopPropagation();
if (e.keyCode === 13) {
@ -303,27 +303,27 @@ exports.activate = function (opts) {
}
});
elem.find('.poll-edit-question').on('click', function (e) {
elem.find('.poll-edit-question').on('click', (e) => {
e.stopPropagation();
start_editing();
});
elem.find("button.poll-question-check").on('click', function (e) {
elem.find("button.poll-question-check").on('click', (e) => {
e.stopPropagation();
submit_question();
});
elem.find("button.poll-question-remove").on('click', function (e) {
elem.find("button.poll-question-remove").on('click', (e) => {
e.stopPropagation();
abort_edit();
});
elem.find("button.poll-option").on('click', function (e) {
elem.find("button.poll-option").on('click', (e) => {
e.stopPropagation();
submit_option();
});
elem.find('input.poll-option').on('keydown', function (e) {
elem.find('input.poll-option').on('keydown', (e) => {
e.stopPropagation();
if (e.keyCode === 13) {
@ -345,7 +345,7 @@ exports.activate = function (opts) {
const html = render_widgets_poll_widget_results(widget_data);
elem.find('ul.poll-widget').html(html);
elem.find("button.poll-vote").off('click').on('click', function (e) {
elem.find("button.poll-vote").off('click').on('click', (e) => {
e.stopPropagation();
const key = $(e.target).attr('data-key');
submit_vote(key);

View File

@ -56,7 +56,7 @@ function copy_email_handler(e) {
email_el.addClass('email_copied');
email_textnode.nodeValue = i18n.t('Email copied');
setTimeout(function () {
setTimeout(() => {
email_el.removeClass('email_copied');
email_textnode.nodeValue = copy_icon.attr('data-clipboard-text');
}, 1500);
@ -306,8 +306,8 @@ exports.show_user_profile = function (user) {
const dateFormat = moment.localeData().longDateFormat('LL');
const field_types = page_params.custom_profile_field_types;
const profile_data = page_params.custom_profile_fields
.map(function (f) {return get_custom_profile_field_data(user, f, field_types, dateFormat);})
.filter(function (f) {return f.name !== undefined;});
.map((f) => get_custom_profile_field_data(user, f, field_types, dateFormat))
.filter((f) => f.name !== undefined);
const args = {
full_name: user.full_name,
@ -346,26 +346,18 @@ function get_user_info_popover_items() {
function fetch_group_members(member_ids) {
return member_ids
.map(function (m) {
return people.get_by_user_id(m);
})
.filter(function (m) {
return m !== undefined;
})
.map(function (p) {
return Object.assign({}, p, {
.map((m) => people.get_by_user_id(m))
.filter((m) => m !== undefined)
.map((p) => Object.assign({}, p, {
user_circle_class: buddy_data.get_user_circle_class(p.user_id),
is_active: people.is_active_user_for_popover(p.user_id),
user_last_seen_time_status: buddy_data.user_last_seen_time_status(p.user_id),
});
});
}));
}
function sort_group_members(members) {
return members
.sort(function (a, b) {
return a.full_name.localeCompare(b.full_name);
});
.sort((a, b) => a.full_name.localeCompare(b.full_name));
}
// exporting these functions for testing purposes
@ -762,7 +754,7 @@ exports.register_click_handlers = function () {
});
$('body').on('click', '.info_popover_actions .narrow_to_private_messages', function (e) {
$('body').on('click', '.info_popover_actions .narrow_to_private_messages', (e) => {
const user_id = elem_to_user_id($(e.target).parents('ul'));
const email = people.get_by_user_id(user_id).email;
exports.hide_message_info_popover();
@ -771,7 +763,7 @@ exports.register_click_handlers = function () {
e.preventDefault();
});
$('body').on('click', '.info_popover_actions .narrow_to_messages_sent', function (e) {
$('body').on('click', '.info_popover_actions .narrow_to_messages_sent', (e) => {
const user_id = elem_to_user_id($(e.target).parents('ul'));
const email = people.get_by_user_id(user_id).email;
exports.hide_message_info_popover();
@ -780,7 +772,7 @@ exports.register_click_handlers = function () {
e.preventDefault();
});
$('body').on('click', '.user_popover .mention_user', function (e) {
$('body').on('click', '.user_popover .mention_user', (e) => {
if (!compose_state.composing()) {
compose_actions.start('stream', {trigger: 'sidebar user actions'});
}
@ -794,7 +786,7 @@ exports.register_click_handlers = function () {
e.preventDefault();
});
$('body').on('click', '.message-info-popover .mention_user', function (e) {
$('body').on('click', '.message-info-popover .mention_user', (e) => {
if (!compose_state.composing()) {
compose_actions.respond_to_message({trigger: 'user sidebar popover'});
}
@ -807,7 +799,7 @@ exports.register_click_handlers = function () {
e.preventDefault();
});
$('body').on('click', '.info_popover_actions .view_user_profile', function (e) {
$('body').on('click', '.info_popover_actions .view_user_profile', (e) => {
const user_id = elem_to_user_id($(e.target).parents('ul'));
const user = people.get_by_user_id(user_id);
exports.show_user_profile(user);
@ -815,7 +807,7 @@ exports.register_click_handlers = function () {
e.preventDefault();
});
$('body').on('click', '.info_popover_actions .clear_status', function (e) {
$('body').on('click', '.info_popover_actions .clear_status', (e) => {
e.preventDefault();
const me = elem_to_user_id($(e.target).parents('ul'));
user_status.server_update({
@ -827,13 +819,13 @@ exports.register_click_handlers = function () {
});
});
$('body').on('click', '.bot-owner-name', function (e) {
$('body').on('click', '.bot-owner-name', (e) => {
const user_id = parseInt($(e.target).attr('data-bot-owner-id'), 10);
const user = people.get_by_user_id(user_id);
exports.show_user_profile(user);
});
$('body').on('click', '#user-profile-modal #name #edit-button', function () {
$('body').on('click', '#user-profile-modal #name #edit-button', () => {
exports.hide_user_profile();
});
@ -843,21 +835,21 @@ exports.register_click_handlers = function () {
e.preventDefault();
});
$('body').on('click', '.set_away_status', function (e) {
$('body').on('click', '.set_away_status', (e) => {
exports.hide_all();
user_status.server_set_away();
e.stopPropagation();
e.preventDefault();
});
$('body').on('click', '.revoke_away_status', function (e) {
$('body').on('click', '.revoke_away_status', (e) => {
exports.hide_all();
user_status.server_revoke_away();
e.stopPropagation();
e.preventDefault();
});
$('body').on('click', '.update_status_text', function (e) {
$('body').on('click', '.update_status_text', (e) => {
exports.hide_all();
user_status_ui.open_overlay();
@ -909,7 +901,7 @@ exports.register_click_handlers = function () {
}
});
$('body').on('click', '.respond_button', function (e) {
$('body').on('click', '.respond_button', (e) => {
// Arguably, we should fetch the message ID to respond to from
// e.target, but that should always be the current selected
// message in the current message list (and
@ -921,14 +913,14 @@ exports.register_click_handlers = function () {
e.preventDefault();
});
$('body').on('click', '.reminder_button', function (e) {
$('body').on('click', '.reminder_button', (e) => {
const message_id = $(e.currentTarget).data('message-id');
exports.render_actions_remind_popover($(".selected_message .actions_hover")[0], message_id);
e.stopPropagation();
e.preventDefault();
});
$('body').on('click', '.remind.custom', function (e) {
$('body').on('click', '.remind.custom', (e) => {
$(e.currentTarget)[0]._flatpickr.toggle();
e.stopPropagation();
e.preventDefault();
@ -942,42 +934,42 @@ exports.register_click_handlers = function () {
e.preventDefault();
}
$('body').on('click', '.remind.in_20m', function (e) {
$('body').on('click', '.remind.in_20m', (e) => {
const datestr = moment().add(20, 'm').format();
reminder_click_handler(datestr, e);
});
$('body').on('click', '.remind.in_1h', function (e) {
$('body').on('click', '.remind.in_1h', (e) => {
const datestr = moment().add(1, 'h').format();
reminder_click_handler(datestr, e);
});
$('body').on('click', '.remind.in_3h', function (e) {
$('body').on('click', '.remind.in_3h', (e) => {
const datestr = moment().add(3, 'h').format();
reminder_click_handler(datestr, e);
});
$('body').on('click', '.remind.tomo', function (e) {
$('body').on('click', '.remind.tomo', (e) => {
const datestr = moment().add(1, 'd').hour(9).minute(0).seconds(0).format();
reminder_click_handler(datestr, e);
});
$('body').on('click', '.remind.nxtw', function (e) {
$('body').on('click', '.remind.nxtw', (e) => {
const datestr = moment().add(1, 'w').day('monday').hour(9).minute(0).seconds(0).format();
reminder_click_handler(datestr, e);
});
$('body').on('click', '.flatpickr-calendar', function (e) {
$('body').on('click', '.flatpickr-calendar', (e) => {
e.stopPropagation();
e.preventDefault();
});
$('body').on('click', '.flatpickr-confirm', function (e) {
$('body').on('click', '.flatpickr-confirm', (e) => {
const datestr = $(".remind.custom")[0].value;
reminder_click_handler(datestr, e);
});
$('body').on('click', '.respond_personal_button, .compose_private_message', function (e) {
$('body').on('click', '.respond_personal_button, .compose_private_message', (e) => {
const user_id = elem_to_user_id($(e.target).parents('ul'));
const email = people.get_by_user_id(user_id).email;
compose_actions.start('private', {
@ -987,7 +979,7 @@ exports.register_click_handlers = function () {
e.stopPropagation();
e.preventDefault();
});
$('body').on('click', '.popover_toggle_collapse', function (e) {
$('body').on('click', '.popover_toggle_collapse', (e) => {
const message_id = $(e.currentTarget).data('message-id');
const row = current_msg_list.get_row(message_id);
const message = current_msg_list.get(rows.id(row));
@ -1005,7 +997,7 @@ exports.register_click_handlers = function () {
e.stopPropagation();
e.preventDefault();
});
$('body').on('click', '.popover_edit_message', function (e) {
$('body').on('click', '.popover_edit_message', (e) => {
const message_id = $(e.currentTarget).data('message-id');
const row = current_msg_list.get_row(message_id);
exports.hide_actions_popover();
@ -1013,7 +1005,7 @@ exports.register_click_handlers = function () {
e.stopPropagation();
e.preventDefault();
});
$('body').on('click', '.view_edit_history', function (e) {
$('body').on('click', '.view_edit_history', (e) => {
const message_id = $(e.currentTarget).data('message-id');
const row = current_msg_list.get_row(message_id);
const message = current_msg_list.get(rows.id(row));
@ -1026,7 +1018,7 @@ exports.register_click_handlers = function () {
e.preventDefault();
});
$('body').on('click', '.popover_mute_topic', function (e) {
$('body').on('click', '.popover_mute_topic', (e) => {
const stream_id = parseInt($(e.currentTarget).attr('data-msg-stream-id'), 10);
const topic = $(e.currentTarget).attr('data-msg-topic');
@ -1036,7 +1028,7 @@ exports.register_click_handlers = function () {
e.preventDefault();
});
$('body').on('click', '.popover_unmute_topic', function (e) {
$('body').on('click', '.popover_unmute_topic', (e) => {
const stream_id = parseInt($(e.currentTarget).attr('data-msg-stream-id'), 10);
const topic = $(e.currentTarget).attr('data-msg-topic');
@ -1046,7 +1038,7 @@ exports.register_click_handlers = function () {
e.preventDefault();
});
$('body').on('click', '.delete_message', function (e) {
$('body').on('click', '.delete_message', (e) => {
const message_id = $(e.currentTarget).data('message-id');
exports.hide_actions_popover();
message_edit.delete_message(message_id);
@ -1065,7 +1057,7 @@ exports.register_click_handlers = function () {
.css("display", "block")
.delay(1000).fadeOut(300);
setTimeout(function () {
setTimeout(() => {
// The Cliboard library works by focusing to a hidden textarea.
// We unfocus this so keyboard shortcuts, etc., will work again.
$(":focus").blur();
@ -1078,7 +1070,7 @@ exports.register_click_handlers = function () {
(function () {
let last_scroll = 0;
$('.app').on('scroll', function () {
$('.app').on('scroll', () => {
if (suppress_scroll_hide) {
suppress_scroll_hide = false;
return;
@ -1125,7 +1117,7 @@ exports.hide_all_except_sidebars = function () {
exports.hide_user_profile();
// look through all the popovers that have been added and removed.
list_of_popovers.forEach(function ($o) {
list_of_popovers.forEach(($o) => {
if (!document.body.contains($o.$element[0]) && $o.$tip) {
$o.$tip.remove();
}

View File

@ -1,3 +1,3 @@
$(function () {
$(() => {
$("#register").submit();
});

View File

@ -1,4 +1,4 @@
$(function () {
$(() => {
// This code will be executed when the user visits /login and
// dev_login.html is rendered.
if ($("[data-page-id='dev-login']").length > 0) {

View File

@ -1,7 +1,7 @@
$(function () {
$(() => {
// This code will be executed when the user visits /emails in
// development mode and email_log.html is rendered.
$('#toggle').change(function () {
$('#toggle').change(() => {
if ($('.email-text').css('display') === 'none') {
$(".email-text").each(function () {
$(this).css("display", "block");
@ -25,7 +25,7 @@ $(function () {
$("#forward_address_sections").hide();
}
});
$("#save_smptp_details").on("click", function () {
$("#save_smptp_details").on("click", () => {
const address = $('input[name=forward]:checked').val() === "enabled" ? $("#address").val() : "";
const csrf_token = $('input[name="csrfmiddlewaretoken"]').attr('value');
const data = {forward_address: address, csrfmiddlewaretoken: csrf_token};
@ -35,7 +35,7 @@ $(function () {
data: data,
success: function () {
$("#smtp_form_status").show();
setTimeout(function () {
setTimeout(() => {
$("#smtp_form_status").hide();
}, 3000);
},

View File

@ -1,10 +1,10 @@
$(function () {
$('.portico-header li.logout').on('click', function () {
$(() => {
$('.portico-header li.logout').on('click', () => {
$('#logout_form').submit();
return false;
});
$("body").click(function (e) {
$("body").click((e) => {
const $this = $(e.target);
if ($this.closest(".dropdown .dropdown-pill").length > 0 && !$(".dropdown").hasClass("show")) {

View File

@ -72,7 +72,7 @@ const loading = {
const markdownSB = new SimpleBar($(".markdown")[0]);
const fetch_page = function (path, callback) {
$.get(path, function (res) {
$.get(path, (res) => {
const $html = $(res).find(".markdown .content");
callback($html.html().trim());
@ -87,7 +87,7 @@ const update_page = function (html_map, path) {
scrollToHash(markdownSB);
} else {
loading.name = path;
fetch_page(path, function (res) {
fetch_page(path, (res) => {
html_map.set(path, res);
$(".markdown .content").html(res);
loading.name = null;
@ -99,7 +99,7 @@ const update_page = function (html_map, path) {
new SimpleBar($(".sidebar")[0]);
$(".sidebar.slide h2").click(function (e) {
$(".sidebar.slide h2").click((e) => {
const $next = $(e.target).next();
if ($next.is("ul")) {
@ -146,11 +146,11 @@ $(document).on('click', '.markdown .content h1, .markdown .content h2, .markdown
scrollToHash(markdownSB);
});
$(".hamburger").click(function () {
$(".hamburger").click(() => {
$(".sidebar").toggleClass("show");
});
$(".markdown").click(function () {
$(".markdown").click(() => {
if ($(".sidebar.show").length) {
$(".sidebar.show").toggleClass("show");
}
@ -162,7 +162,7 @@ render_code_sections();
// to the right place.
scrollToHash(markdownSB);
window.addEventListener("popstate", function () {
window.addEventListener("popstate", () => {
const path = window.location.pathname;
update_page(html_map, path);
});

View File

@ -10,7 +10,7 @@ const INTEGRATIONS = new Map();
const CATEGORIES = new Map();
function load_data() {
$('.integration-lozenge').toArray().forEach(function (integration) {
$('.integration-lozenge').toArray().forEach((integration) => {
const name = $(integration).data('name');
const display_name = $(integration).find('.integration-name').text().trim();
@ -19,7 +19,7 @@ function load_data() {
}
});
$('.integration-category').toArray().forEach(function (category) {
$('.integration-category').toArray().forEach((category) => {
const name = $(category).data('category');
const display_name = $(category).text().trim();
@ -39,7 +39,7 @@ let state = Object.assign({}, INITIAL_STATE);
function adjust_font_sizing() {
$('.integration-lozenge').toArray().forEach(function (integration) {
$('.integration-lozenge').toArray().forEach((integration) => {
const $integration_name = $(integration).find('.integration-name');
const $integration_category = $(integration).find('.integration-category');
@ -97,11 +97,11 @@ function update_categories() {
adjust_font_sizing();
}
const update_integrations = _.debounce(function () {
const update_integrations = _.debounce(() => {
const max_scrollY = window.scrollY;
const integrations = $('.integration-lozenges').children().toArray();
integrations.forEach(function (integration) {
integrations.forEach((integration) => {
const $integration = $(integration).find('.integration-lozenge');
const $integration_category = $integration.find('.integration-category');
@ -140,14 +140,12 @@ function hide_catalog_show_integration() {
const categories = $('.integration-' + state.integration).data('categories')
.slice(1, -1)
.split(',')
.map(function (category) {
return category.trim().slice(1, -1);
});
.map((category) => category.trim().slice(1, -1));
function show_integration(doc) {
$('#integration-instructions-group .name').text(INTEGRATIONS.get(state.integration));
$('#integration-instructions-group .categories .integration-category').remove();
categories.forEach(function (category) {
categories.forEach((category) => {
let link;
for (const [name, display_name] of CATEGORIES) {
if (display_name === category) {
@ -323,7 +321,7 @@ function toggle_categories_dropdown() {
}
function integration_events() {
$('#integration-search input[type="text"]').keypress(function (e) {
$('#integration-search input[type="text"]').keypress((e) => {
const integrations = $('.integration-lozenges').children().toArray();
if (e.which === 13 && e.target.value !== '') {
for (let i = 0; i < integrations.length; i += 1) {
@ -337,24 +335,24 @@ function integration_events() {
}
});
$('.integration-categories-dropdown .dropdown-toggle').click(function () {
$('.integration-categories-dropdown .dropdown-toggle').click(() => {
toggle_categories_dropdown();
});
$('.integration-instruction-block').on('click', 'a .integration-category', function (e) {
$('.integration-instruction-block').on('click', 'a .integration-category', (e) => {
const category = $(e.target).data('category');
dispatch('SHOW_CATEGORY', { category: category });
return false;
});
$('.integrations a .integration-category').on('click', function (e) {
$('.integrations a .integration-category').on('click', (e) => {
const category = $(e.target).data('category');
dispatch('CHANGE_CATEGORY', { category: category });
toggle_categories_dropdown();
return false;
});
$('.integrations a .integration-lozenge').on('click', function (e) {
$('.integrations a .integration-lozenge').on('click', (e) => {
if (!$(e.target).closest('.integration-lozenge').hasClass('integration-create-your-own')) {
const integration = $(e.target).closest('.integration-lozenge').data('name');
dispatch('SHOW_INTEGRATION', { integration: integration });
@ -362,7 +360,7 @@ function integration_events() {
}
});
$('a#integration-list-link span, a#integration-list-link i').on('click', function () {
$('a#integration-list-link span, a#integration-list-link i').on('click', () => {
dispatch('HIDE_INTEGRATION');
return false;
});
@ -371,11 +369,11 @@ function integration_events() {
// the input event.
$(".integrations .searchbar input[type='text']")
.focus()
.on('input', function (e) {
.on('input', (e) => {
dispatch('UPDATE_QUERY', { query: e.target.value.toLowerCase() });
});
$(window).scroll(function () {
$(window).scroll(() => {
if (document.body.scrollTop > 330) {
$('.integration-categories-sidebar').addClass('sticky');
} else {
@ -383,11 +381,11 @@ function integration_events() {
}
});
$(window).on('resize', function () {
$(window).on('resize', () => {
adjust_font_sizing();
});
$(window).on('popstate', function () {
$(window).on('popstate', () => {
if (window.location.pathname.startsWith('/integrations')) {
dispatch('LOAD_PATH');
} else {
@ -397,7 +395,7 @@ function integration_events() {
}
// init
$(function () {
$(() => {
integration_events();
load_data();
dispatch('LOAD_PATH');

Some files were not shown because too many files have changed in this diff Show More