js: Automatically convert var to let and const in more files.

This commit was automatically generated by `tools/lint --only=eslint
--fix`, after an `.eslintrc.json` change.

A half dozen files were removed from the changes by tabbott pending
further work to ensure we avoid breaking valuable PRs with merge
conflicts.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2019-11-01 16:06:25 -07:00
parent 329d0126bd
commit f9f104a4f8
18 changed files with 904 additions and 904 deletions

View File

@ -128,9 +128,9 @@ run_test('buddy_status', () => {
run_test('title_data', () => {
// Groups
var is_group = true;
var user_ids_string = "9999,1000";
var expected_group_data = {
let is_group = true;
const user_ids_string = "9999,1000";
let expected_group_data = {
is_group: is_group,
recipients: "Human Selma, Old User",
is_bot: false,
@ -140,7 +140,7 @@ run_test('title_data', () => {
is_group = '';
// Bots with owners.
var bot_owner_exists = true;
let bot_owner_exists = true;
expected_group_data = {
is_group: '',
name: 'Blue Herring Bot',
@ -168,7 +168,7 @@ run_test('title_data', () => {
status_text: 'out to lunch',
});
var expected_data = {
let expected_data = {
is_group: is_group,
status_text: 'out to lunch',
last_seen: 'translated: Active now',

View File

@ -9,19 +9,19 @@ set_global('message_store', {});
set_global('page_params', {});
set_global('feature_flags', {});
var me = {
const me = {
email: 'me@example.com',
user_id: 30,
full_name: 'Me Myself',
};
var joe = {
const joe = {
email: 'joe@example.com',
user_id: 31,
full_name: 'joe',
};
var steve = {
const steve = {
email: 'STEVE@foo.com',
user_id: 32,
full_name: 'steve',
@ -36,7 +36,7 @@ function assert_same_operators(result, terms) {
terms = _.map(terms, function (term) {
// If negated flag is undefined, we explicitly
// set it to false.
var negated = term.negated;
let negated = term.negated;
if (!negated) {
negated = false;
}
@ -50,12 +50,12 @@ function assert_same_operators(result, terms) {
}
run_test('basics', () => {
var operators = [
let operators = [
{operator: 'stream', operand: 'foo'},
{operator: 'stream', operand: 'exclude_stream', negated: true},
{operator: 'topic', operand: 'bar'},
];
var filter = new Filter(operators);
let filter = new Filter(operators);
assert_same_operators(filter.operators(), operators);
assert.deepEqual(filter.operands('stream'), ['foo']);
@ -162,10 +162,10 @@ run_test('basics', () => {
assert(filter.can_apply_locally());
});
run_test('show_first_unread', () => {
var operators = [
let operators = [
{operator: 'is', operand: 'any'},
];
var filter = new Filter(operators);
let filter = new Filter(operators);
assert(filter.allow_use_first_unread_when_narrowing());
operators = [
@ -188,42 +188,42 @@ run_test('show_first_unread', () => {
});
run_test('topic_stuff', () => {
var operators = [
const operators = [
{operator: 'stream', operand: 'foo'},
{operator: 'topic', operand: 'old topic'},
];
var filter = new Filter(operators);
const filter = new Filter(operators);
assert(filter.has_topic('foo', 'old topic'));
assert(!filter.has_topic('wrong', 'old topic'));
assert(!filter.has_topic('foo', 'wrong'));
var new_filter = filter.filter_with_new_topic('new topic');
const new_filter = filter.filter_with_new_topic('new topic');
assert.deepEqual(new_filter.operands('stream'), ['foo']);
assert.deepEqual(new_filter.operands('topic'), ['new topic']);
});
run_test('new_style_operators', () => {
var term = {
const term = {
operator: 'stream',
operand: 'foo',
};
var operators = [term];
var filter = new Filter(operators);
const operators = [term];
const filter = new Filter(operators);
assert.deepEqual(filter.operands('stream'), ['foo']);
assert(filter.is_exactly('stream'));
});
run_test('public_operators', () => {
var operators = [
let operators = [
{operator: 'stream', operand: 'foo'},
{operator: 'in', operand: 'all'},
{operator: 'topic', operand: 'bar'},
];
var filter = new Filter(operators);
let filter = new Filter(operators);
assert_same_operators(filter.public_operators(), operators);
assert(!filter.is_exactly('stream'));
@ -241,7 +241,7 @@ run_test('canonicalizations', () => {
assert.equal(Filter.canonicalize_operator('Subject'), 'topic');
assert.equal(Filter.canonicalize_operator('FROM'), 'sender');
var term;
let term;
term = Filter.canonicalize_term({operator: 'Stream', operand: 'Denmark'});
assert.equal(term.operator, 'stream');
assert.equal(term.operand, 'Denmark');
@ -292,7 +292,7 @@ function get_predicate(operators) {
}
function make_sub(name, stream_id) {
var sub = {
const sub = {
name: name,
stream_id: stream_id,
};
@ -308,9 +308,9 @@ run_test('predicate_basics', () => {
// To keep these tests simple, we only pass objects with a few relevant attributes
// rather than full-fledged message objects.
var stream_id = 42;
const stream_id = 42;
make_sub('Foo', stream_id);
var predicate = get_predicate([['stream', 'Foo'], ['topic', 'Bar']]);
let predicate = get_predicate([['stream', 'Foo'], ['topic', 'Bar']]);
assert(predicate({type: 'stream', stream_id: stream_id, topic: 'bar'}));
assert(!predicate({type: 'stream', stream_id: stream_id, topic: 'whatever'}));
@ -356,7 +356,7 @@ run_test('predicate_basics', () => {
predicate = get_predicate([['in', 'all']]);
assert(predicate({}));
var unknown_stream_id = 999;
const unknown_stream_id = 999;
predicate = get_predicate([['in', 'home']]);
assert(!predicate({stream_id: unknown_stream_id, stream: 'unknown'}));
assert(predicate({type: 'private'}));
@ -435,10 +435,10 @@ run_test('predicate_basics', () => {
});
run_test('negated_predicates', () => {
var predicate;
var narrow;
let predicate;
let narrow;
var social_stream_id = 555;
const social_stream_id = 555;
make_sub('social', social_stream_id);
narrow = [
@ -459,7 +459,7 @@ run_test('negated_predicates', () => {
run_test('mit_exceptions', () => {
global.page_params.realm_is_zephyr_mirror_realm = true;
var predicate = get_predicate([['stream', 'Foo'], ['topic', 'personal']]);
let predicate = get_predicate([['stream', 'Foo'], ['topic', 'personal']]);
assert(predicate({type: 'stream', stream: 'foo', topic: 'personal'}));
assert(predicate({type: 'stream', stream: 'foo.d', topic: 'personal'}));
assert(predicate({type: 'stream', stream: 'foo.d', topic: ''}));
@ -471,7 +471,7 @@ run_test('mit_exceptions', () => {
assert(predicate({type: 'stream', stream: 'foo', topic: 'bar.d'}));
// Try to get the MIT regex to explode for an empty stream.
var terms = [
let terms = [
{operator: 'stream', operand: ''},
{operator: 'topic', operand: 'bar'},
];
@ -488,7 +488,7 @@ run_test('mit_exceptions', () => {
});
run_test('predicate_edge_cases', () => {
var predicate;
let predicate;
// The code supports undefined as an operator to Filter, which results
// in a predicate that accepts any message.
predicate = new Filter().predicate();
@ -507,11 +507,11 @@ run_test('predicate_edge_cases', () => {
assert(predicate({}));
// Exercise caching feature.
var terms = [
const terms = [
{operator: 'stream', operand: 'Foo'},
{operator: 'topic', operand: 'bar'},
];
var filter = new Filter(terms);
const filter = new Filter(terms);
filter.predicate();
predicate = filter.predicate(); // get cached version
assert(predicate({type: 'stream', stream: 'foo', topic: 'bar'}));
@ -519,11 +519,11 @@ run_test('predicate_edge_cases', () => {
});
run_test('parse', () => {
var string;
var operators;
let string;
let operators;
function _test() {
var result = Filter.parse(string);
const result = Filter.parse(string);
assert_same_operators(result, operators);
}
@ -646,8 +646,8 @@ run_test('parse', () => {
});
run_test('unparse', () => {
var string;
var operators;
let string;
let operators;
operators = [
{operator: 'stream', operand: 'Foo'},
@ -697,8 +697,8 @@ run_test('unparse', () => {
});
run_test('describe', () => {
var narrow;
var string;
let narrow;
let string;
narrow = [
{operator: 'streams', operand: 'public'},
@ -825,10 +825,10 @@ run_test('describe', () => {
});
run_test('is_functions', () => {
var terms = [
let terms = [
{operator: 'stream', operand: 'My Stream'},
];
var filter = new Filter(terms);
let filter = new Filter(terms);
assert.equal(filter.is_exactly('stream'), true);
assert.equal(filter.is_exactly('stream', 'topic'), false);
assert.equal(filter.is_exactly('pm-with'), false);
@ -995,12 +995,12 @@ run_test('first_valid_id_from', () => {
});
run_test('update_email', () => {
var terms = [
const terms = [
{operator: 'pm-with', operand: 'steve@foo.com'},
{operator: 'sender', operand: 'steve@foo.com'},
{operator: 'stream', operand: 'steve@foo.com'}, // try to be tricky
];
var filter = new Filter(terms);
const filter = new Filter(terms);
filter.update_email(steve.user_id, 'showell@foo.com');
assert.deepEqual(filter.operands('pm-with'), ['showell@foo.com']);
assert.deepEqual(filter.operands('sender'), ['showell@foo.com']);
@ -1013,6 +1013,6 @@ run_test('error_cases', () => {
// should not be reached unless we break other code.
people.pm_with_user_ids = function () {};
var predicate = get_predicate([['pm-with', 'Joe@example.com']]);
const predicate = get_predicate([['pm-with', 'Joe@example.com']]);
assert(!predicate({type: 'private'}));
});

View File

@ -48,16 +48,16 @@ set_global('Image', function () {
});
emoji.initialize();
var doc = "";
const doc = "";
set_global('document', doc);
set_global('$', global.make_zjquery());
set_global('feature_flags', {local_echo: true});
var people = global.people;
const people = global.people;
var cordelia = {
const cordelia = {
full_name: 'Cordelia Lear',
user_id: 101,
email: 'cordelia@zulip.com',
@ -96,21 +96,21 @@ people.add({
people.initialize_current_user(cordelia.user_id);
var hamletcharacters = {
const hamletcharacters = {
name: "hamletcharacters",
id: 1,
description: "Characters of Hamlet",
members: [cordelia.user_id],
};
var backend = {
const backend = {
name: "Backend",
id: 2,
description: "Backend team",
members: [],
};
var edgecase_group = {
const edgecase_group = {
name: "Bobby <h1>Tables</h1>",
id: 3,
description: "HTML Syntax to check for Markdown edge cases.",
@ -121,15 +121,15 @@ global.user_groups.add(hamletcharacters);
global.user_groups.add(backend);
global.user_groups.add(edgecase_group);
var stream_data = global.stream_data;
var denmark = {
const stream_data = global.stream_data;
const denmark = {
subscribed: false,
color: 'blue',
name: 'Denmark',
stream_id: 1,
is_muted: true,
};
var social = {
const social = {
subscribed: true,
color: 'red',
name: 'social',
@ -137,14 +137,14 @@ var social = {
is_muted: false,
invite_only: true,
};
var edgecase_stream = {
const edgecase_stream = {
subscribed: true,
color: 'green',
name: 'Bobby <h1>Tables</h1>',
stream_id: 3,
is_muted: false,
};
var edgecase_stream_2 = {
const edgecase_stream_2 = {
subscribed: true,
color: 'yellow',
name: 'Bobby <h1',
@ -161,18 +161,18 @@ stream_data.add_sub('Bobby <h1', edgecase_stream_2);
// Check the default behavior of fenced code blocks
// works properly before markdown is initialized.
run_test('fenced_block_defaults', () => {
var input = '\n```\nfenced code\n```\n\nand then after\n';
var expected = '\n\n<div class="codehilite"><pre><span></span>fenced code\n</pre></div>\n\n\n\nand then after\n\n';
var output = fenced_code.process_fenced_code(input);
const input = '\n```\nfenced code\n```\n\nand then after\n';
const expected = '\n\n<div class="codehilite"><pre><span></span>fenced code\n</pre></div>\n\n\n\nand then after\n\n';
const output = fenced_code.process_fenced_code(input);
assert.equal(output, expected);
});
markdown.initialize();
var bugdown_data = global.read_fixture_data('markdown_test_cases.json');
const bugdown_data = global.read_fixture_data('markdown_test_cases.json');
run_test('bugdown_detection', () => {
var no_markup = [
const no_markup = [
"This is a plaintext message",
"This is a plaintext: message",
"This is a :plaintext message",
@ -195,7 +195,7 @@ run_test('bugdown_detection', () => {
"And an avatar !avatar(leo@zulip.com) is here",
];
var markup = [
const markup = [
"Contains a https://zulip.com/image.png file",
"Contains a https://zulip.com/image.jpg file",
"https://zulip.com/image.jpg",
@ -220,7 +220,7 @@ run_test('bugdown_detection', () => {
});
run_test('marked_shared', () => {
var tests = bugdown_data.regular_tests;
const tests = bugdown_data.regular_tests;
tests.forEach(function (test) {
@ -229,11 +229,11 @@ run_test('marked_shared', () => {
return;
}
var message = {raw_content: test.input};
const message = {raw_content: test.input};
page_params.translate_emoticons = test.translate_emoticons || false;
markdown.apply_markdown(message);
var output = message.content;
var error_message = `Failure in test: ${test.name}`;
const output = message.content;
const error_message = `Failure in test: ${test.name}`;
if (test.marked_expected_output) {
global.bugdown_assert.notEqual(test.expected_output, output, error_message);
global.bugdown_assert.equal(test.marked_expected_output, output, error_message);
@ -246,7 +246,7 @@ run_test('marked_shared', () => {
});
run_test('message_flags', () => {
var message = {raw_content: '@**Leo**'};
let message = {raw_content: '@**Leo**'};
markdown.apply_markdown(message);
assert(!message.mentioned);
assert(!message.mentioned_me_directly);
@ -263,7 +263,7 @@ run_test('message_flags', () => {
});
run_test('marked', () => {
var test_cases = [
const test_cases = [
{input: 'hello', expected: '<p>hello</p>'},
{input: 'hello there', expected: '<p>hello there</p>'},
{input: 'hello **bold** for you', expected: '<p>hello <strong>bold</strong> for you</p>'},
@ -396,18 +396,18 @@ run_test('marked', () => {
// Disable emoji conversion by default.
page_params.translate_emoticons = test_case.translate_emoticons || false;
var input = test_case.input;
var expected = test_case.expected;
const input = test_case.input;
const expected = test_case.expected;
var message = {raw_content: input};
const message = {raw_content: input};
markdown.apply_markdown(message);
var output = message.content;
const output = message.content;
assert.equal(expected, output);
});
});
run_test('topic_links', () => {
var message = {type: 'stream', topic: "No links here"};
let message = {type: 'stream', topic: "No links here"};
markdown.add_topic_links(message);
assert.equal(util.get_topic_links(message).length, []);
@ -456,8 +456,8 @@ run_test('topic_links', () => {
});
run_test('message_flags', () => {
var input = "/me is testing this";
var message = {topic: "No links here", raw_content: input};
let input = "/me is testing this";
let message = {topic: "No links here", raw_content: input};
markdown.apply_markdown(message);
assert.equal(message.is_me_message, true);
@ -528,7 +528,7 @@ run_test('message_flags', () => {
});
run_test('backend_only_realm_filters', () => {
var backend_only_realm_filters = [
const backend_only_realm_filters = [
'Here is the PR-#123.',
'Function abc() was introduced in (PR)#123.',
];
@ -541,8 +541,8 @@ run_test('python_to_js_filter', () => {
// The only way to reach python_to_js_filter is indirectly, hence the call
// to set_realm_filters.
markdown.set_realm_filters([['/a(?im)a/g'], ['/a(?L)a/g']]);
var actual_value = marked.InlineLexer.rules.zulip.realm_filters;
var expected_value = [/\/aa\/g(?![\w])/gim, /\/aa\/g(?![\w])/g];
let actual_value = marked.InlineLexer.rules.zulip.realm_filters;
let expected_value = [/\/aa\/g(?![\w])/gim, /\/aa\/g(?![\w])/g];
assert.deepEqual(actual_value, expected_value);
// Test case with multiple replacements.
markdown.set_realm_filters([['#cf(?P<contest>[0-9]+)(?P<problem>[A-Z][0-9A-Z]*)', 'http://google.com']]);
@ -562,7 +562,7 @@ run_test('python_to_js_filter', () => {
run_test('katex_throws_unexpected_exceptions', () => {
katex.renderToString = function () { throw new Error('some-exception'); };
blueslip.set_test_data('error', 'Error: some-exception');
var message = { raw_content: '$$a$$' };
const message = { raw_content: '$$a$$' };
markdown.apply_markdown(message);
assert.equal(blueslip.get_test_logs('error').length, 1);
blueslip.clear_test_data();

View File

@ -5,13 +5,13 @@ set_global('$', global.make_zjquery());
set_global('i18n', global.stub_i18n);
set_global('confirm_dialog', {});
var noop = function () {};
const noop = function () {};
var pills = {
const pills = {
pill: {},
};
var create_item_handler;
let create_item_handler;
set_global('channel', {});
set_global('blueslip', global.make_zblueslip());
@ -83,31 +83,31 @@ run_test('can_edit', () => {
});
var user_group_selector = "#user-groups #1";
var cancel_selector = "#user-groups #1 .save-status.btn-danger";
var saved_selector = "#user-groups #1 .save-status.sea-green";
var name_selector = "#user-groups #1 .name";
var description_selector = "#user-groups #1 .description";
var instructions_selector = "#user-groups #1 .save-instructions";
const user_group_selector = "#user-groups #1";
const cancel_selector = "#user-groups #1 .save-status.btn-danger";
const saved_selector = "#user-groups #1 .save-status.sea-green";
const name_selector = "#user-groups #1 .name";
const description_selector = "#user-groups #1 .description";
const instructions_selector = "#user-groups #1 .save-instructions";
run_test('populate_user_groups', () => {
var realm_user_group = {
const realm_user_group = {
id: 1,
name: 'Mobile',
description: 'All mobile people',
members: Dict.from_array([2, 4]),
};
var iago = {
const iago = {
email: 'iago@zulip.com',
user_id: 2,
full_name: 'Iago',
};
var alice = {
const alice = {
email: 'alice@example.com',
user_id: 31,
full_name: 'Alice',
};
var bob = {
const bob = {
email: 'bob@example.com',
user_id: 32,
full_name: 'Bob',
@ -121,8 +121,8 @@ run_test('populate_user_groups', () => {
return [realm_user_group];
};
var templates_render_called = false;
var fake_rendered_temp = $.create('fake_admin_user_group_list_template_rendered');
let templates_render_called = false;
const fake_rendered_temp = $.create('fake_admin_user_group_list_template_rendered');
global.stub_templates(function (template, args) {
assert.equal(template, 'admin_user_group_list');
assert.equal(args.user_group.id, 1);
@ -132,13 +132,13 @@ run_test('populate_user_groups', () => {
return fake_rendered_temp;
});
var user_groups_list_append_called = false;
let user_groups_list_append_called = false;
$('#user-groups').append = function (rendered_temp) {
assert.equal(rendered_temp, fake_rendered_temp);
user_groups_list_append_called = true;
};
var get_person_from_user_id_called = false;
let get_person_from_user_id_called = false;
people.get_person_from_user_id = function (user_id) {
if (user_id === iago.user_id) {
return iago;
@ -155,11 +155,11 @@ run_test('populate_user_groups', () => {
return true;
};
var all_pills = {};
const all_pills = {};
var pill_container_stub = $('.pill-container[data-group-pills="1"]');
const pill_container_stub = $('.pill-container[data-group-pills="1"]');
pills.appendValidatedData = function (item) {
var id = item.user_id;
const id = item.user_id;
assert.equal(all_pills[id], undefined);
all_pills[id] = item;
};
@ -167,17 +167,17 @@ run_test('populate_user_groups', () => {
return _.values(all_pills);
};
var text_cleared;
let text_cleared;
pills.clear_text = function () {
text_cleared = true;
};
var input_field_stub = $.create('fake-input-field');
const input_field_stub = $.create('fake-input-field');
pill_container_stub.children = function () {
return input_field_stub;
};
var input_typeahead_called = false;
let input_typeahead_called = false;
input_field_stub.typeahead = function (config) {
assert.equal(config.items, 5);
assert(config.fixed);
@ -190,27 +190,27 @@ run_test('populate_user_groups', () => {
assert.equal(typeof config.updater, 'function');
(function test_highlighter() {
var fake_person = $.create('fake-person');
const fake_person = $.create('fake-person');
typeahead_helper.render_person = function () {
return fake_person;
};
assert.equal(config.highlighter(), fake_person);
}());
var fake_context = {
const fake_context = {
query: 'ali',
};
(function test_source() {
var result = config.source.call(fake_context, iago);
var emails = _.pluck(result, 'email').sort();
const result = config.source.call(fake_context, iago);
const emails = _.pluck(result, 'email').sort();
assert.deepEqual(emails, [alice.email, bob.email]);
}());
(function test_matcher() {
/* Here the query doesn't begin with an '@' because typeahead is triggered
by the '@' sign and thus removed in the query. */
var result = config.matcher.call(fake_context, iago);
let result = config.matcher.call(fake_context, iago);
assert(!result);
result = config.matcher.call(fake_context, alice);
@ -218,7 +218,7 @@ run_test('populate_user_groups', () => {
}());
(function test_sorter() {
var sort_recipientbox_typeahead_called = false;
let sort_recipientbox_typeahead_called = false;
typeahead_helper.sort_recipientbox_typeahead = function () {
sort_recipientbox_typeahead_called = true;
};
@ -232,9 +232,9 @@ run_test('populate_user_groups', () => {
return realm_user_group;
};
var saved_fade_out_called = false;
var cancel_fade_to_called = false;
var instructions_fade_to_called = false;
let saved_fade_out_called = false;
let cancel_fade_to_called = false;
let instructions_fade_to_called = false;
$(saved_selector).fadeOut = function () {
saved_fade_out_called = true;
};
@ -274,7 +274,7 @@ run_test('populate_user_groups', () => {
input_typeahead_called = true;
};
var get_by_email_called = false;
let get_by_email_called = false;
people.get_by_email = function (user_email) {
get_by_email_called = true;
if (user_email === iago.email) {
@ -293,14 +293,14 @@ run_test('populate_user_groups', () => {
function test_create_item(handler) {
(function test_rejection_path() {
var item = handler(iago.email, pills.items());
const item = handler(iago.email, pills.items());
assert(get_by_email_called);
assert.equal(item, undefined);
}());
(function test_success_path() {
get_by_email_called = false;
var res = handler(bob.email, pills.items());
const res = handler(bob.email, pills.items());
assert(get_by_email_called);
assert.equal(typeof res, 'object');
assert.equal(res.user_id, bob.user_id);
@ -333,7 +333,7 @@ run_test('populate_user_groups', () => {
});
run_test('with_external_user', () => {
var realm_user_group = {
const realm_user_group = {
id: 1,
name: 'Mobile',
description: 'All mobile people',
@ -361,7 +361,7 @@ run_test('with_external_user', () => {
return noop;
};
var can_edit_called = 0;
let can_edit_called = 0;
settings_user_groups.can_edit = function () {
can_edit_called += 1;
return false;
@ -370,11 +370,11 @@ run_test('with_external_user', () => {
// Reset zjquery to test stuff with user who cannot edit
set_global('$', global.make_zjquery());
var user_group_find_called = 0;
var user_group_stub = $('div.user-group[id="1"]');
var name_field_stub = $.create('fake-name-field');
var description_field_stub = $.create('fake-description-field');
var input_stub = $.create('fake-input');
let user_group_find_called = 0;
const user_group_stub = $('div.user-group[id="1"]');
const name_field_stub = $.create('fake-name-field');
const description_field_stub = $.create('fake-description-field');
const input_stub = $.create('fake-input');
user_group_stub.find = function (elem) {
if (elem === '.name') {
user_group_find_called += 1;
@ -386,9 +386,9 @@ run_test('with_external_user', () => {
}
};
var pill_container_stub = $('.pill-container[data-group-pills="1"]');
var pill_stub = $.create('fake-pill');
var pill_container_find_called = 0;
const pill_container_stub = $('.pill-container[data-group-pills="1"]');
const pill_stub = $.create('fake-pill');
let pill_container_find_called = 0;
pill_container_stub.find = function (elem) {
if (elem === '.input') {
pill_container_find_called += 1;
@ -406,7 +406,7 @@ run_test('with_external_user', () => {
};
// Test the 'off' handlers on the pill-container
var turned_off = {};
const turned_off = {};
pill_container_stub.off = function (event_name, sel) {
if (sel === undefined) {
sel = 'whole';
@ -414,9 +414,9 @@ run_test('with_external_user', () => {
turned_off[event_name + '/' + sel] = true;
};
var pill_hover_called = false;
var callback;
var empty_fn;
let pill_hover_called = false;
let callback;
let empty_fn;
pill_stub.hover = function (one, two) {
callback = one;
empty_fn = two;
@ -425,9 +425,9 @@ run_test('with_external_user', () => {
assert.equal(typeof two, 'function');
};
var exit_button = $.create('fake-pill-exit');
const exit_button = $.create('fake-pill-exit');
pill_stub.set_find_results('.exit', exit_button);
var exit_button_called = false;
let exit_button_called = false;
exit_button.css = function (property, value) {
exit_button_called = true;
assert.equal(property, 'opacity');
@ -447,32 +447,32 @@ run_test('with_external_user', () => {
settings_user_groups.set_up();
var set_parents_result_called = 0;
var set_attributes_called = 0;
let set_parents_result_called = 0;
let set_attributes_called = 0;
// Test different handlers with an external user
var delete_handler = $('#user-groups').get_on_handler('click', '.delete');
var fake_delete = $.create('fk-#user-groups.delete_btn');
const delete_handler = $('#user-groups').get_on_handler('click', '.delete');
const fake_delete = $.create('fk-#user-groups.delete_btn');
fake_delete.set_parents_result('.user-group', $('.user-group'));
set_parents_result_called += 1;
$('.user-group').attr('id', '1');
set_attributes_called += 1;
var name_update_handler = $(user_group_selector).get_on_handler("input", ".name");
const name_update_handler = $(user_group_selector).get_on_handler("input", ".name");
var des_update_handler = $(user_group_selector).get_on_handler("input", ".description");
const des_update_handler = $(user_group_selector).get_on_handler("input", ".description");
var member_change_handler = $(user_group_selector).get_on_handler("blur", ".input");
const member_change_handler = $(user_group_selector).get_on_handler("blur", ".input");
var name_change_handler = $(user_group_selector).get_on_handler("blur", ".name");
const name_change_handler = $(user_group_selector).get_on_handler("blur", ".name");
var des_change_handler = $(user_group_selector).get_on_handler("blur", ".description");
const des_change_handler = $(user_group_selector).get_on_handler("blur", ".description");
var event = {
const event = {
stopPropagation: noop,
};
var pill_click_called = false;
var pill_click_handler = pill_container_stub.get_on_handler('click');
let pill_click_called = false;
const pill_click_handler = pill_container_stub.get_on_handler('click');
pill_click_called = true;
assert(callback);
@ -501,7 +501,7 @@ run_test('with_external_user', () => {
run_test('reload', () => {
$('#user-groups').html('Some text');
var populate_user_groups_called = false;
let populate_user_groups_called = false;
settings_user_groups.populate_user_groups = function () {
populate_user_groups_called = true;
};
@ -512,7 +512,7 @@ run_test('reload', () => {
run_test('reset', () => {
settings_user_groups.reset();
var result = settings_user_groups.reload();
const result = settings_user_groups.reload();
assert.equal(result, undefined);
});
@ -523,13 +523,13 @@ run_test('on_events', () => {
};
(function test_admin_user_group_form_submit_triggered() {
var handler = $('.organization form.admin-user-group-form').get_on_handler("submit");
var event = {
const handler = $('.organization form.admin-user-group-form').get_on_handler("submit");
const event = {
stopPropagation: noop,
preventDefault: noop,
};
var fake_this = $.create('fake-form.admin-user-group-form');
var fake_object_array = [{
const fake_this = $.create('fake-form.admin-user-group-form');
const fake_object_array = [{
name: 'fake-name',
value: '',
}, {
@ -540,7 +540,7 @@ run_test('on_events', () => {
return fake_object_array;
};
channel.post = function (opts) {
var data = {
const data = {
members: '[null]',
};
data[fake_object_array[1].name] = fake_object_array[1].value;
@ -564,14 +564,14 @@ run_test('on_events', () => {
(function test_post_error() {
$('#admin-user-group-status').show();
ui_report.error = function (error_msg, error_obj, ele) {
var xhr = {
const xhr = {
responseText: '{"msg":"fake-msg"}',
};
assert.equal(error_msg, 'translated: Failed');
assert.deepEqual(error_obj, xhr);
assert.equal(ele, $('#admin-user-group-status'));
};
var xhr = {
const xhr = {
responseText: '{"msg":"fake-msg", "attrib":"val"}',
};
opts.error(xhr);
@ -584,16 +584,16 @@ run_test('on_events', () => {
}());
(function test_user_groups_delete_click_triggered() {
var handler = $('#user-groups').get_on_handler("click", ".delete");
var fake_this = $.create('fake-#user-groups.delete_btn');
const handler = $('#user-groups').get_on_handler("click", ".delete");
const fake_this = $.create('fake-#user-groups.delete_btn');
fake_this.set_parents_result('.user-group', $('.user-group'));
$('.user-group').attr('id', '1');
channel.del = function (opts) {
var data = {
const data = {
id: 1,
};
var settings_user_groups_reload_called = false;
let settings_user_groups_reload_called = false;
assert.equal(opts.url, "/json/user_groups/1");
assert.deepEqual(opts.data, data);
@ -616,9 +616,9 @@ run_test('on_events', () => {
}());
(function test_user_groups_keypress_enter_triggered() {
var handler = $('#user-groups').get_on_handler("keypress", ".user-group h4 > span");
var default_action_for_enter_stopped = false;
var event = {
const handler = $('#user-groups').get_on_handler("keypress", ".user-group h4 > span");
let default_action_for_enter_stopped = false;
const event = {
which: 13,
preventDefault: function () {
default_action_for_enter_stopped = true;
@ -629,21 +629,21 @@ run_test('on_events', () => {
}());
(function test_do_not_blur() {
var blur_event_classes = [".name", ".description", ".input"];
var api_endpoint_called = false;
const blur_event_classes = [".name", ".description", ".input"];
let api_endpoint_called = false;
channel.post = function () {
api_endpoint_called = true;
};
channel.patch = noop;
var fake_this = $.create('fake-#user-groups_do_not_blur');
var event = {
const fake_this = $.create('fake-#user-groups_do_not_blur');
const event = {
relatedTarget: fake_this,
};
// Any of the blur_exceptions trigger blur event.
_.each(blur_event_classes, function (class_name) {
var handler = $(user_group_selector).get_on_handler("blur", class_name);
var blur_exceptions = _.without([".pill-container", ".name", ".description", ".input", ".delete"],
const handler = $(user_group_selector).get_on_handler("blur", class_name);
const blur_exceptions = _.without([".pill-container", ".name", ".description", ".input", ".delete"],
class_name);
_.each(blur_exceptions, function (blur_exception) {
api_endpoint_called = false;
@ -668,7 +668,7 @@ run_test('on_events', () => {
assert(!api_endpoint_called);
// Cancel button triggers blur event.
var settings_user_groups_reload_called = false;
let settings_user_groups_reload_called = false;
settings_user_groups.reload = function () {
settings_user_groups_reload_called = true;
};
@ -687,14 +687,14 @@ run_test('on_events', () => {
}());
(function test_update_cancel_button() {
var handler_name = $(user_group_selector).get_on_handler("input", ".name");
var handler_desc = $(user_group_selector).get_on_handler("input", ".description");
var sib_des = $(description_selector);
var sib_name = $(name_selector);
const handler_name = $(user_group_selector).get_on_handler("input", ".name");
const handler_desc = $(user_group_selector).get_on_handler("input", ".description");
const sib_des = $(description_selector);
const sib_name = $(name_selector);
sib_name.text(i18n.t('mobile'));
sib_des.text(i18n.t('All mobile members'));
var group_data = {
const group_data = {
name: 'translated: mobile',
description: 'translated: All mobile members',
members: Dict.from_array([2, 31])};
@ -702,8 +702,8 @@ run_test('on_events', () => {
return group_data;
};
var cancel_fade_out_called = false;
var instructions_fade_out_called = false;
let cancel_fade_out_called = false;
let instructions_fade_out_called = false;
$(cancel_selector).show();
$(cancel_selector).fadeOut = function () {
cancel_fade_out_called = true;
@ -713,7 +713,7 @@ run_test('on_events', () => {
};
// Cancel button removed if user group if user group has no changes.
var fake_this = $.create('fake-#update_cancel_button');
const fake_this = $.create('fake-#update_cancel_button');
handler_name.call(fake_this);
assert(cancel_fade_out_called);
assert(instructions_fade_out_called);
@ -735,21 +735,21 @@ run_test('on_events', () => {
}());
(function test_user_groups_save_group_changes_triggered() {
var handler_name = $(user_group_selector).get_on_handler("blur", ".name");
var handler_desc = $(user_group_selector).get_on_handler("blur", ".description");
var sib_des = $(description_selector);
var sib_name = $(name_selector);
const handler_name = $(user_group_selector).get_on_handler("blur", ".name");
const handler_desc = $(user_group_selector).get_on_handler("blur", ".description");
const sib_des = $(description_selector);
const sib_name = $(name_selector);
sib_name.text(i18n.t('mobile'));
sib_des.text(i18n.t('All mobile members'));
var group_data = {members: Dict.from_array([2, 31])};
const group_data = {members: Dict.from_array([2, 31])};
user_groups.get_user_group_from_id = function () {
return group_data;
};
var api_endpoint_called = false;
var cancel_fade_out_called = false;
var saved_fade_to_called = false;
var instructions_fade_out_called = false;
let api_endpoint_called = false;
let cancel_fade_out_called = false;
let saved_fade_to_called = false;
let instructions_fade_out_called = false;
$(instructions_selector).fadeOut = function () {
instructions_fade_out_called = true;
};
@ -785,17 +785,17 @@ run_test('on_events', () => {
assert(saved_fade_to_called);
}());
(function test_post_error() {
var user_group_error = $(user_group_selector + ' .user-group-status');
const user_group_error = $(user_group_selector + ' .user-group-status');
user_group_error.show();
ui_report.error = function (error_msg, error_obj, ele) {
var xhr = {
const xhr = {
responseText: '{"msg":"fake-msg"}',
};
assert.equal(error_msg, 'translated: Failed');
assert.deepEqual(error_obj, xhr);
assert.equal(ele, user_group_error);
};
var xhr = {
const xhr = {
responseText: '{"msg":"fake-msg", "attrib":"val"}',
};
opts.error(xhr);
@ -804,12 +804,12 @@ run_test('on_events', () => {
}());
};
var fake_this = $.create('fake-#user-groups_blur_name');
const fake_this = $.create('fake-#user-groups_blur_name');
fake_this.closest = function () {
return [];
};
fake_this.set_parents_result(user_group_selector, $(user_group_selector));
var event = {
const event = {
relatedTarget: fake_this,
};
@ -831,8 +831,8 @@ run_test('on_events', () => {
}());
(function test_user_groups_save_member_changes_triggered() {
var handler = $(user_group_selector).get_on_handler("blur", ".input");
var realm_user_group = {
const handler = $(user_group_selector).get_on_handler("blur", ".input");
const realm_user_group = {
id: 1,
name: 'Mobile',
description: 'All mobile people',
@ -844,9 +844,9 @@ run_test('on_events', () => {
return realm_user_group;
};
var cancel_fade_out_called = false;
var saved_fade_to_called = false;
var instructions_fade_out_called = false;
let cancel_fade_out_called = false;
let saved_fade_to_called = false;
let instructions_fade_out_called = false;
$(instructions_selector).fadeOut = function () {
instructions_fade_out_called = true;
};
@ -861,7 +861,7 @@ run_test('on_events', () => {
return $(saved_selector);
};
var api_endpoint_called = false;
let api_endpoint_called = false;
channel.post = function (opts) {
assert.equal(opts.url, "/json/user_groups/1/members");
assert.equal(opts.data.add, '[31]');
@ -876,12 +876,12 @@ run_test('on_events', () => {
}());
};
var fake_this = $.create('fake-#user-groups_blur_input');
const fake_this = $.create('fake-#user-groups_blur_input');
fake_this.set_parents_result(user_group_selector, $(user_group_selector));
fake_this.closest = function () {
return [];
};
var event = {
const event = {
relatedTarget: fake_this,
};

View File

@ -1590,7 +1590,7 @@ run_test('user_presence_rows', () => {
});
run_test('buddy_list_tooltip_content', () => {
var args = {
const args = {
status_text: 'out to lunch',
last_seen: 'Active now',
is_away: false,
@ -1598,8 +1598,8 @@ run_test('buddy_list_tooltip_content', () => {
online_now: true,
};
var html = render('buddy_list_tooltip_content', args);
var tooltip_content = $(html).find(".tooltip_inner_content");
const html = render('buddy_list_tooltip_content', args);
const tooltip_content = $(html).find(".tooltip_inner_content");
assert.equal(tooltip_content.text().trim(), 'Iagoout to lunchActive now');
});

View File

@ -9,7 +9,7 @@
exports.max_size_before_shrinking = 600;
var fade_config = {
const fade_config = {
get_user_id: function (item) {
return item.user_id;
},
@ -22,7 +22,7 @@ var fade_config = {
};
exports.get_user_circle_class = function (user_id) {
var status = exports.buddy_status(user_id);
const status = exports.buddy_status(user_id);
switch (status) {
case 'active':
@ -38,7 +38,7 @@ exports.get_user_circle_class = function (user_id) {
};
exports.status_description = function (user_id) {
var status = exports.buddy_status(user_id);
const status = exports.buddy_status(user_id);
switch (status) {
case 'active':
@ -59,7 +59,7 @@ exports.level = function (user_id) {
return 0;
}
var status = exports.buddy_status(user_id);
const status = exports.buddy_status(user_id);
switch (status) {
case 'active':
@ -87,19 +87,19 @@ exports.buddy_status = function (user_id) {
};
exports.compare_function = function (a, b) {
var level_a = exports.level(a);
var level_b = exports.level(b);
var diff = level_a - level_b;
const level_a = exports.level(a);
const level_b = exports.level(b);
const diff = level_a - level_b;
if (diff !== 0) {
return diff;
}
// Sort equivalent PM names alphabetically
var person_a = people.get_person_from_user_id(a);
var person_b = people.get_person_from_user_id(b);
const person_a = people.get_person_from_user_id(a);
const person_b = people.get_person_from_user_id(b);
var full_name_a = person_a ? person_a.full_name : '';
var full_name_b = person_b ? person_b.full_name : '';
const full_name_a = person_a ? person_a.full_name : '';
const full_name_b = person_b ? person_b.full_name : '';
return util.strcmp(full_name_a, full_name_b);
};
@ -117,16 +117,16 @@ function filter_user_ids(filter_text, user_ids) {
user_ids = _.reject(user_ids, people.is_my_user_id);
var search_terms = filter_text.toLowerCase().split(/[|,]+/);
let search_terms = filter_text.toLowerCase().split(/[|,]+/);
search_terms = _.map(search_terms, function (s) {
return s.trim();
});
var persons = _.map(user_ids, function (user_id) {
const persons = _.map(user_ids, function (user_id) {
return people.get_person_from_user_id(user_id);
});
var user_id_dict = people.filter_people_by_search_terms(persons, search_terms);
const user_id_dict = people.filter_people_by_search_terms(persons, search_terms);
return user_id_dict.keys();
}
@ -156,7 +156,7 @@ exports.my_user_status = function (user_id) {
};
exports.user_last_seen_time_status = function (user_id) {
var status = presence.get_status(user_id);
const status = presence.get_status(user_id);
if (status === "active") {
return i18n.t("Active now");
}
@ -172,7 +172,7 @@ exports.user_last_seen_time_status = function (user_id) {
// may have queries on presence that go back only N weeks).
//
// We give the somewhat vague status of "Unknown" for these users.
var last_active_date = presence.last_active_date(user_id);
const last_active_date = presence.last_active_date(user_id);
if (last_active_date === undefined) {
return i18n.t("More than 2 weeks ago");
}
@ -180,10 +180,10 @@ exports.user_last_seen_time_status = function (user_id) {
};
exports.info_for = function (user_id) {
var user_circle_class = exports.get_user_circle_class(user_id);
var person = people.get_person_from_user_id(user_id);
var my_user_status = exports.my_user_status(user_id);
var user_circle_status = exports.status_description(user_id);
const user_circle_class = exports.get_user_circle_class(user_id);
const person = people.get_person_from_user_id(user_id);
const my_user_status = exports.my_user_status(user_id);
const user_circle_status = exports.status_description(user_id);
return {
href: hash_util.pm_with_uri(person.email),
@ -208,9 +208,9 @@ exports.get_title_data = function (user_ids_string, is_group) {
}
// Since it's not a group, user_ids_string is a single user ID.
var user_id = user_ids_string;
var person = people.get_person_from_user_id(user_id);
var bot_owner_exists = false;
const user_id = user_ids_string;
const person = people.get_person_from_user_id(user_id);
let bot_owner_exists = false;
if (person.is_bot) {
if (person.bot_owner_id !== null) {
@ -231,9 +231,9 @@ exports.get_title_data = function (user_ids_string, is_group) {
// For buddy list and individual PMS. Since is_group=False, it's
// a single, human, user.
var active_status = presence.get_status(user_id);
var last_seen = exports.user_last_seen_time_status(user_id);
var online_now = active_status === 'active';
const active_status = presence.get_status(user_id);
const last_seen = exports.user_last_seen_time_status(user_id);
const online_now = active_status === 'active';
return {
is_group: '',
@ -247,7 +247,7 @@ exports.get_title_data = function (user_ids_string, is_group) {
};
exports.get_item = function (user_id) {
var info = exports.info_for(user_id);
const info = exports.info_for(user_id);
compose_fade.update_user_info([info], fade_config);
return info;
};
@ -278,7 +278,7 @@ function maybe_shrink_list(user_ids, filter_text) {
}
exports.get_filtered_and_sorted_user_ids = function (filter_text) {
var user_ids;
let user_ids;
if (filter_text) {
// If there's a filter, select from all users, not just those
@ -292,7 +292,7 @@ exports.get_filtered_and_sorted_user_ids = function (filter_text) {
}
user_ids = _.filter(user_ids, function (user_id) {
var person = people.get_person_from_user_id(user_id);
const person = people.get_person_from_user_id(user_id);
if (person) {
// if the user is bot, do not show in presence data.
@ -310,7 +310,7 @@ exports.get_filtered_and_sorted_user_ids = function (filter_text) {
};
exports.get_items_for_users = function (user_ids) {
var user_info = _.map(user_ids, exports.info_for).filter(function (person) {
const user_info = _.map(user_ids, exports.info_for).filter(function (person) {
// filtered bots and yourself are set to "undefined" in the `info_for`
// function.
return typeof person !== "undefined";
@ -322,9 +322,9 @@ exports.get_items_for_users = function (user_ids) {
};
exports.huddle_fraction_present = function (huddle) {
var user_ids = huddle.split(',');
const user_ids = huddle.split(',');
var num_present = 0;
let num_present = 0;
_.each(user_ids, function (user_id) {
if (presence.is_active(user_id)) {
num_present += 1;

View File

@ -1,15 +1,15 @@
// You won't find every click handler here, but it's a good place to start!
var render_buddy_list_tooltip = require('../templates/buddy_list_tooltip.hbs');
var render_buddy_list_tooltip_content = require('../templates/buddy_list_tooltip_content.hbs');
const render_buddy_list_tooltip = require('../templates/buddy_list_tooltip.hbs');
const render_buddy_list_tooltip_content = require('../templates/buddy_list_tooltip_content.hbs');
exports.initialize = function () {
// MOUSE MOVING VS DRAGGING FOR SELECTION DATA TRACKING
var drag = (function () {
var start;
var time;
const drag = (function () {
let start;
let time;
return {
start: function (e) {
@ -18,9 +18,9 @@ exports.initialize = function () {
},
end: function (e) {
var end = { x: e.offsetX, y: e.offsetY };
const end = { x: e.offsetX, y: e.offsetY };
var dist;
let dist;
if (start) {
// get the linear difference between two coordinates on the screen.
dist = Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
@ -60,8 +60,8 @@ exports.initialize = function () {
}
function initialize_long_tap() {
var MS_DELAY = 750;
var meta = {
const MS_DELAY = 750;
const meta = {
touchdown: false,
current_target: undefined,
};
@ -69,7 +69,7 @@ exports.initialize = function () {
$("#main_div").on("touchstart", ".messagebox", function () {
meta.touchdown = true;
meta.invalid = false;
var id = rows.id($(this).closest(".message_row"));
const id = rows.id($(this).closest(".message_row"));
meta.current_target = id;
if (!id) {
return;
@ -111,7 +111,7 @@ exports.initialize = function () {
initialize_long_tap();
}
var select_message_function = function (e) {
const select_message_function = function (e) {
if (is_clickable_message_element($(e.target))) {
// If this click came from a hyperlink, don't trigger the
// reply action. The simple way of doing this is simply
@ -139,8 +139,8 @@ exports.initialize = function () {
// older browsers, we may be able to use the window.selection
// API instead.
if (drag.val < 5 && drag.time < 150 || drag.val < 2) {
var row = $(this).closest(".message_row");
var id = rows.id(row);
const row = $(this).closest(".message_row");
const id = rows.id(row);
if (message_edit.is_editing(id)) {
// Clicks on a message being edited shouldn't trigger a reply.
@ -162,7 +162,7 @@ exports.initialize = function () {
} else {
$("#main_div").on("longtap", ".messagebox", function (e) {
// find the correct selection API for the browser.
var sel = window.getSelection ? window.getSelection() : document.selection;
const sel = window.getSelection ? window.getSelection() : document.selection;
// if one matches, remove the current selections.
// after a longtap that is valid, there should be no text selected.
if (sel) {
@ -181,15 +181,15 @@ exports.initialize = function () {
e.stopPropagation();
popovers.hide_all();
var message_id = rows.id($(this).closest(".message_row"));
var message = message_store.get(message_id);
const message_id = rows.id($(this).closest(".message_row"));
const message = message_store.get(message_id);
message_flags.toggle_starred_and_update_server(message);
});
$("#main_div").on("click", ".message_reaction", function (e) {
e.stopPropagation();
var local_id = $(this).attr('data-reaction-id');
var message_id = rows.get_message_id(this);
const local_id = $(this).attr('data-reaction-id');
const message_id = rows.get_message_id(this);
reactions.process_reaction_click(message_id, local_id);
$(".tooltip").remove();
});
@ -208,10 +208,10 @@ exports.initialize = function () {
$('body').on('click', '.message_edit_notice', function (e) {
popovers.hide_all();
var message_id = rows.id($(e.currentTarget).closest(".message_row"));
var row = current_msg_list.get_row(message_id);
var message = current_msg_list.get(rows.id(row));
var message_history_cancel_btn = $('#message-history-cancel');
const message_id = rows.id($(e.currentTarget).closest(".message_row"));
const row = current_msg_list.get_row(message_id);
const message = current_msg_list.get(rows.id(row));
const message_history_cancel_btn = $('#message-history-cancel');
if (page_params.realm_allow_edit_history) {
message_edit.show_history(message);
@ -225,10 +225,10 @@ exports.initialize = function () {
$('#main_div').on('mouseenter', '.message_reaction', function (e) {
e.stopPropagation();
var elem = $(e.currentTarget);
var local_id = elem.attr('data-reaction-id');
var message_id = rows.get_message_id(e.currentTarget);
var title = reactions.get_reaction_title_data(message_id, local_id);
const elem = $(e.currentTarget);
const local_id = elem.attr('data-reaction-id');
const message_id = rows.get_message_id(e.currentTarget);
const title = reactions.get_reaction_title_data(message_id, local_id);
elem.tooltip({
title: title,
@ -258,7 +258,7 @@ exports.initialize = function () {
e.preventDefault();
// Note that we may have an href here, but we trust the stream id more,
// so we re-encode the hash.
var stream_id = $(this).attr('data-stream-id');
const stream_id = $(this).attr('data-stream-id');
if (stream_id) {
hashchange.go_to_location(hash_util.by_stream_uri(stream_id));
return;
@ -270,7 +270,7 @@ exports.initialize = function () {
$(".user-status-value").on("click", function (e) {
e.stopPropagation();
var user_status_value = $(e.currentTarget).attr("data-user-status-value");
const user_status_value = $(e.currentTarget).attr("data-user-status-value");
$("input.user_status").val(user_status_value);
user_status_ui.toggle_clear_message_button();
user_status_ui.update_button();
@ -279,7 +279,7 @@ exports.initialize = function () {
// NOTIFICATION CLICK
$('body').on('click', '.notification', function () {
var payload = $(this).data("narrow");
const payload = $(this).data("narrow");
ui_util.change_tab_to('#home');
narrow.activate(payload.raw_operators, payload.opts_notif);
});
@ -287,51 +287,51 @@ exports.initialize = function () {
// MESSAGE EDITING
$('body').on('click', '.edit_content_button', function (e) {
var row = current_msg_list.get_row(rows.id($(this).closest(".message_row")));
const row = current_msg_list.get_row(rows.id($(this).closest(".message_row")));
current_msg_list.select_id(rows.id(row));
message_edit.start(row);
e.stopPropagation();
popovers.hide_all();
});
$('body').on('click', '.always_visible_topic_edit,.on_hover_topic_edit', function (e) {
var recipient_row = $(this).closest(".recipient_row");
const recipient_row = $(this).closest(".recipient_row");
message_edit.start_topic_edit(recipient_row);
e.stopPropagation();
popovers.hide_all();
});
$("body").on("click", ".topic_edit_save", function (e) {
var recipient_row = $(this).closest(".recipient_row");
const recipient_row = $(this).closest(".recipient_row");
message_edit.show_topic_edit_spinner(recipient_row);
message_edit.save(recipient_row, true);
e.stopPropagation();
popovers.hide_all();
});
$("body").on("click", ".topic_edit_cancel", function (e) {
var recipient_row = $(this).closest(".recipient_row");
const recipient_row = $(this).closest(".recipient_row");
current_msg_list.hide_edit_topic(recipient_row);
e.stopPropagation();
popovers.hide_all();
});
$("body").on("click", ".message_edit_save", function (e) {
var row = $(this).closest(".message_row");
const row = $(this).closest(".message_row");
message_edit.save(row, false);
e.stopPropagation();
popovers.hide_all();
});
$("body").on("click", ".message_edit_cancel", function (e) {
var row = $(this).closest(".message_row");
const row = $(this).closest(".message_row");
message_edit.end(row);
e.stopPropagation();
popovers.hide_all();
});
$("body").on("click", ".message_edit_close", function (e) {
var row = $(this).closest(".message_row");
const row = $(this).closest(".message_row");
message_edit.end(row);
e.stopPropagation();
popovers.hide_all();
});
$("body").on("click", ".copy_message", function (e) {
var row = $(this).closest(".message_row");
const row = $(this).closest(".message_row");
message_edit.end(row);
row.find(".alert-msg").text(i18n.t("Copied!"));
row.find(".alert-msg").css("display", "block");
@ -345,26 +345,26 @@ exports.initialize = function () {
}
});
$('#message_edit_form .send-status-close').click(function () {
var row_id = rows.id($(this).closest(".message_row"));
var send_status = $('#message-edit-send-status-' + row_id);
const row_id = rows.id($(this).closest(".message_row"));
const send_status = $('#message-edit-send-status-' + row_id);
$(send_status).stop(true).fadeOut(200);
});
$("body").on("click", "#message_edit_form [id^='attach_files_']", function (e) {
e.preventDefault();
var row_id = rows.id($(this).closest(".message_row"));
const row_id = rows.id($(this).closest(".message_row"));
$("#message_edit_file_input_" + row_id).trigger("click");
});
$("body").on("click", "#message_edit_form [id^='markdown_preview_']", function (e) {
e.preventDefault();
var row_id = rows.id($(this).closest(".message_row"));
const row_id = rows.id($(this).closest(".message_row"));
function $_(selector) {
return $(selector + "_" + row_id);
}
var content = $_("#message_edit_content").val();
const content = $_("#message_edit_content").val();
$_("#message_edit_content").hide();
$_("#markdown_preview").hide();
$_("#undo_markdown_preview").show();
@ -376,7 +376,7 @@ exports.initialize = function () {
$("body").on("click", "#message_edit_form [id^='undo_markdown_preview_']", function (e) {
e.preventDefault();
var row_id = rows.id($(this).closest(".message_row"));
const row_id = rows.id($(this).closest(".message_row"));
function $_(selector) {
return $(selector + "_" + row_id);
}
@ -392,19 +392,19 @@ exports.initialize = function () {
$('body').on('click', '.on_hover_topic_mute', function (e) {
e.stopPropagation();
var stream_id = $(e.currentTarget).attr('data-stream-id');
var topic = $(e.currentTarget).attr('data-topic-name');
const stream_id = $(e.currentTarget).attr('data-stream-id');
const topic = $(e.currentTarget).attr('data-topic-name');
muting_ui.mute(stream_id, topic);
});
// RECIPIENT BARS
function get_row_id_for_narrowing(narrow_link_elem) {
var group = rows.get_closest_group(narrow_link_elem);
var msg_id = rows.id_for_recipient_row(group);
const group = rows.get_closest_group(narrow_link_elem);
const msg_id = rows.id_for_recipient_row(group);
var nearest = current_msg_list.get(msg_id);
var selected = current_msg_list.selected_message();
const nearest = current_msg_list.get(msg_id);
const selected = current_msg_list.selected_message();
if (util.same_recipient(nearest, selected)) {
return selected.id;
}
@ -416,7 +416,7 @@ exports.initialize = function () {
return;
}
e.preventDefault();
var row_id = get_row_id_for_narrowing(this);
const row_id = get_row_id_for_narrowing(this);
narrow.by_recipient(row_id, {trigger: 'message header'});
});
@ -425,7 +425,7 @@ exports.initialize = function () {
return;
}
e.preventDefault();
var row_id = get_row_id_for_narrowing(this);
const row_id = get_row_id_for_narrowing(this);
narrow.by_topic(row_id, {trigger: 'message header'});
});
@ -435,7 +435,7 @@ exports.initialize = function () {
e.preventDefault();
e.stopPropagation();
var sidebarHidden = !$(".app-main .column-right").hasClass("expanded");
const sidebarHidden = !$(".app-main .column-right").hasClass("expanded");
popovers.hide_all();
if (sidebarHidden) {
popovers.show_userlist_sidebar();
@ -446,7 +446,7 @@ exports.initialize = function () {
e.preventDefault();
e.stopPropagation();
var sidebarHidden = !$(".app-main .column-left").hasClass("expanded");
const sidebarHidden = !$(".app-main .column-left").hasClass("expanded");
popovers.hide_all();
if (sidebarHidden) {
stream_popover.show_streamlist_sidebar();
@ -454,7 +454,7 @@ exports.initialize = function () {
});
$('#user_presences').expectOne().on('click', '.selectable_sidebar_block', function (e) {
var li = $(e.target).parents('li');
const li = $(e.target).parents('li');
activity.narrow_for_user({li: li});
@ -465,8 +465,8 @@ exports.initialize = function () {
});
$('#group-pms').expectOne().on('click', '.selectable_sidebar_block', function (e) {
var user_ids_string = $(e.target).parents('li').attr('data-user-ids');
var emails = people.user_ids_string_to_emails_string(user_ids_string);
const user_ids_string = $(e.target).parents('li').attr('data-user-ids');
const emails = people.user_ids_string_to_emails_string(user_ids_string);
narrow.by('pm-with', emails, {trigger: 'sidebar'});
e.preventDefault();
e.stopPropagation();
@ -498,15 +498,15 @@ 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) {
e.stopPropagation();
var elem = $(e.currentTarget).closest(".user_sidebar_entry").find(".user-presence-link");
var user_id = elem.attr('data-user-id');
var title_data = buddy_data.get_title_data(user_id, false);
const elem = $(e.currentTarget).closest(".user_sidebar_entry").find(".user-presence-link");
const user_id = elem.attr('data-user-id');
const title_data = buddy_data.get_title_data(user_id, false);
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) {
e.stopPropagation();
var elem = $(e.currentTarget).closest(".user_sidebar_entry").find(".user-presence-link");
const elem = $(e.currentTarget).closest(".user_sidebar_entry").find(".user-presence-link");
$(elem).tooltip('destroy');
});
@ -514,12 +514,12 @@ exports.initialize = function () {
$("body").on('mouseenter', '#pm_user_status, #group_pms_right_sidebar', function (e) {
$(".tooltip").remove();
e.stopPropagation();
var elem = $(e.currentTarget);
var user_ids_string = elem.attr('data-user-ids-string');
const elem = $(e.currentTarget);
const user_ids_string = elem.attr('data-user-ids-string');
// This converts from 'true' in the DOM to true.
var is_group = JSON.parse(elem.attr('data-is-group'));
const is_group = JSON.parse(elem.attr('data-is-group'));
var title_data = buddy_data.get_title_data(user_ids_string, is_group);
const title_data = buddy_data.get_title_data(user_ids_string, is_group);
do_render_buddy_list_tooltip(elem, title_data);
});
@ -553,7 +553,7 @@ exports.initialize = function () {
// MISC
(function () {
var sel = ["#group-pm-list", "#stream_filters", "#global_filters", "#user_presences"].join(", ");
const sel = ["#group-pm-list", "#stream_filters", "#global_filters", "#user_presences"].join(", ");
$(sel).on("click", "a", function () {
this.blur();
@ -575,7 +575,7 @@ exports.initialize = function () {
// this will hide the alerts that you click "x" on.
$("body").on("click", ".alert-box > div .exit", function () {
var $alert = $(this).closest(".alert-box > div");
const $alert = $(this).closest(".alert-box > div");
$alert.addClass("fade-out");
setTimeout(function () {
$alert.removeClass("fade-out show");
@ -634,7 +634,7 @@ exports.initialize = function () {
});
$("body").on("click", "[data-overlay-trigger]", function () {
var target = $(this).attr("data-overlay-trigger");
const target = $(this).attr("data-overlay-trigger");
info_overlay.show(target);
});
@ -704,7 +704,7 @@ exports.initialize = function () {
$('body').on('click', '.webathena_login', function (e) {
$("#zephyr-mirror-error").removeClass("show");
var principal = ["zephyr", "zephyr"];
const principal = ["zephyr", "zephyr"];
WinChan.open({
url: "https://webathena.mit.edu/#!request_ticket_v1",
relay_url: "https://webathena.mit.edu/relay.html",
@ -745,7 +745,7 @@ exports.initialize = function () {
});
(function () {
var map = {
const map = {
".stream-description-editable": {
on_start: stream_edit.set_raw_description,
on_save: stream_edit.change_stream_description,
@ -777,7 +777,7 @@ exports.initialize = function () {
// if there are any child nodes, inclusive of <br> which means you
// have lines in your description or title, you're doing something
// wrong.
for (var x = 0; x < this.childNodes.length; x += 1) {
for (let x = 0; x < this.childNodes.length; x += 1) {
if (this.childNodes[x].nodeType !== 3) {
this.innerText = this.innerText.replace(/\n/, "");
break;
@ -786,8 +786,8 @@ exports.initialize = function () {
});
$("body").on("click", "[data-make-editable]", function () {
var selector = $(this).attr("data-make-editable");
var edit_area = $(this).parent().find(selector);
const selector = $(this).attr("data-make-editable");
const edit_area = $(this).parent().find(selector);
if (edit_area.attr("contenteditable") === "true") {
$("[data-finish-editing='" + selector + "']").hide();
edit_area.attr("contenteditable", false);
@ -810,7 +810,7 @@ exports.initialize = function () {
});
$("body").on("click", "[data-finish-editing]", function (e) {
var selector = $(this).attr("data-finish-editing");
const selector = $(this).attr("data-finish-editing");
if (map[selector].on_save) {
map[selector].on_save(e);
$(this).hide();
@ -829,11 +829,11 @@ exports.initialize = function () {
hotspots.close_hotspot_icon(this);
// show popover
var hotspot_name = $(e.target).closest('.hotspot-icon')
const hotspot_name = $(e.target).closest('.hotspot-icon')
.attr('id')
.replace('hotspot_', '')
.replace('_icon', '');
var overlay_name = 'hotspot_' + hotspot_name + '_overlay';
const overlay_name = 'hotspot_' + hotspot_name + '_overlay';
overlays.open_overlay({
name: overlay_name,
@ -856,9 +856,9 @@ exports.initialize = function () {
e.preventDefault();
e.stopPropagation();
var overlay_name = $(this).closest('.hotspot.overlay').attr('id');
const overlay_name = $(this).closest('.hotspot.overlay').attr('id');
var hotspot_name = overlay_name
const hotspot_name = overlay_name
.replace('hotspot_', '')
.replace('_overlay', '');

View File

@ -1,9 +1,9 @@
const TurndownService = require("turndown/lib/turndown.cjs.js");
function find_boundary_tr(initial_tr, iterate_row) {
var j;
var skip_same_td_check = false;
var tr = initial_tr;
let j;
let skip_same_td_check = false;
let tr = initial_tr;
// If the selection boundary is somewhere that does not have a
// parent tr, we should let the browser handle the copy-paste
@ -34,7 +34,7 @@ function find_boundary_tr(initial_tr, iterate_row) {
}
function construct_recipient_header(message_row) {
var message_header_content = rows.get_message_recipient_header(message_row)
const message_header_content = rows.get_message_recipient_header(message_row)
.text()
.replace(/\s+/g, " ")
.replace(/^\s/, "").replace(/\s$/, "");
@ -57,14 +57,14 @@ how modern browsers deal with copy/paste. Just test
your changes carefully.
*/
function construct_copy_div(div, start_id, end_id) {
var start_row = current_msg_list.get_row(start_id);
var start_recipient_row = rows.get_message_recipient_row(start_row);
var start_recipient_row_id = rows.id_for_recipient_row(start_recipient_row);
var should_include_start_recipient_header = false;
const start_row = current_msg_list.get_row(start_id);
const start_recipient_row = rows.get_message_recipient_row(start_row);
const start_recipient_row_id = rows.id_for_recipient_row(start_recipient_row);
let should_include_start_recipient_header = false;
var last_recipient_row_id = start_recipient_row_id;
for (var row = start_row; rows.id(row) <= end_id; row = rows.next_visible(row)) {
var recipient_row_id = rows.id_for_recipient_row(rows.get_message_recipient_row(row));
let last_recipient_row_id = start_recipient_row_id;
for (let row = start_row; rows.id(row) <= end_id; row = rows.next_visible(row)) {
const recipient_row_id = rows.id_for_recipient_row(rows.get_message_recipient_row(row));
// if we found a message from another recipient,
// it means that we have messages from several recipients,
// so we have to add new recipient's bar to final copied message
@ -74,8 +74,8 @@ function construct_copy_div(div, start_id, end_id) {
last_recipient_row_id = recipient_row_id;
should_include_start_recipient_header = true;
}
var message = current_msg_list.get(rows.id(row));
var message_firstp = $(message.content).slice(0, 1);
const message = current_msg_list.get(rows.id(row));
const message_firstp = $(message.content).slice(0, 1);
message_firstp.prepend(message.sender_full_name + ": ");
div.append(message_firstp);
div.append($(message.content).slice(1));
@ -132,13 +132,13 @@ exports.copy_handler = function () {
// * Otherwise, we want to copy the bodies of all messages that
// were partially covered by the selection.
var selection = window.getSelection();
var analysis = exports.analyze_selection(selection);
var ranges = analysis.ranges;
var start_id = analysis.start_id;
var end_id = analysis.end_id;
var skip_same_td_check = analysis.skip_same_td_check;
var div = $('<div>');
const selection = window.getSelection();
const analysis = exports.analyze_selection(selection);
const ranges = analysis.ranges;
const start_id = analysis.start_id;
const end_id = analysis.end_id;
const skip_same_td_check = analysis.skip_same_td_check;
const div = $('<div>');
if (start_id === undefined || end_id === undefined) {
// In this case either the starting message or the ending
@ -186,20 +186,20 @@ exports.analyze_selection = function (selection) {
// analyze the combined range of the selections, and copy their
// full content.
var i;
var range;
var ranges = [];
var startc;
var endc;
var initial_end_tr;
var start_id;
var end_id;
var start_data;
var end_data;
let i;
let range;
const ranges = [];
let startc;
let endc;
let initial_end_tr;
let start_id;
let end_id;
let start_data;
let end_data;
// skip_same_td_check is true whenever we know for a fact that the
// selection covers multiple messages (and thus we should no
// longer consider letting the browser handle the copy event).
var skip_same_td_check = false;
let skip_same_td_check = false;
for (i = 0; i < selection.rangeCount; i += 1) {
range = selection.getRangeAt(i);
@ -297,7 +297,7 @@ exports.paste_handler_converter = function (paste_html) {
};
exports.paste_handler = function (event) {
var clipboardData = event.originalEvent.clipboardData;
const clipboardData = event.originalEvent.clipboardData;
if (!clipboardData) {
// On IE11, ClipboardData isn't defined. One can instead
// access it with `window.clipboardData`, but even that
@ -308,10 +308,10 @@ exports.paste_handler = function (event) {
}
if (clipboardData.getData) {
var paste_html = clipboardData.getData('text/html');
const paste_html = clipboardData.getData('text/html');
if (paste_html && page_params.development_environment) {
var text = exports.paste_handler_converter(paste_html);
var mdImageRegex = /^!\[.*\]\(.*\)$/;
const text = exports.paste_handler_converter(paste_html);
const mdImageRegex = /^!\[.*\]\(.*\)$/;
if (text.match(mdImageRegex)) {
// This block catches cases where we are pasting an
// image into Zulip, which should be handled by the

View File

@ -10,7 +10,7 @@ exports.get_hash_section = function (hash) {
return '';
}
var parts = hash.replace(/\/$/, "").split(/\//);
const parts = hash.replace(/\/$/, "").split(/\//);
return parts[1] || '';
};
@ -26,7 +26,7 @@ exports.encodeHashComponent = function (str) {
exports.encode_operand = function (operator, operand) {
if (operator === 'group-pm-with' || operator === 'pm-with' || operator === 'sender') {
var slug = people.emails_to_slug(operand);
const slug = people.emails_to_slug(operand);
if (slug) {
return slug;
}
@ -42,7 +42,7 @@ exports.encode_operand = function (operator, operand) {
exports.encode_stream_id = function (stream_id) {
// stream_data appends the stream name, but it does not do the
// URI encoding piece
var slug = stream_data.id_to_slug(stream_id);
const slug = stream_data.id_to_slug(stream_id);
return exports.encodeHashComponent(slug);
};
@ -61,7 +61,7 @@ exports.decodeHashComponent = function (str) {
exports.decode_operand = function (operator, operand) {
if (operator === 'group-pm-with' || operator === 'pm-with' || operator === 'sender') {
var emails = people.slug_to_emails(operand);
const emails = people.slug_to_emails(operand);
if (emails) {
return emails;
}
@ -89,16 +89,16 @@ exports.by_stream_topic_uri = function (stream_id, topic) {
// corresponding hash: the # component
// of the narrow URL
exports.operators_to_hash = function (operators) {
var hash = '#';
let hash = '#';
if (operators !== undefined) {
hash = '#narrow';
_.each(operators, function (elem) {
// Support legacy tuples.
var operator = elem.operator;
var operand = elem.operand;
const operator = elem.operator;
const operand = elem.operand;
var sign = elem.negated ? '-' : '';
const sign = elem.negated ? '-' : '';
hash += '/' + sign + exports.encodeHashComponent(operator)
+ '/' + exports.encode_operand(operator, operand);
});
@ -128,11 +128,11 @@ exports.huddle_with_uri = function (user_ids_string) {
};
exports.by_conversation_and_time_uri = function (message) {
var absolute_url = window.location.protocol + "//" +
const absolute_url = window.location.protocol + "//" +
window.location.host + "/" +
window.location.pathname.split('/')[1];
var suffix = "/near/" + exports.encodeHashComponent(message.id);
const suffix = "/near/" + exports.encodeHashComponent(message.id);
if (message.type === "stream") {
return absolute_url +
@ -144,30 +144,30 @@ exports.by_conversation_and_time_uri = function (message) {
};
exports.stream_edit_uri = function (sub) {
var hash = "#streams" + "/" + sub.stream_id + "/" + exports.encodeHashComponent(sub.name);
const hash = "#streams" + "/" + sub.stream_id + "/" + exports.encodeHashComponent(sub.name);
return hash;
};
exports.parse_narrow = function (hash) {
var i;
var operators = [];
let i;
const operators = [];
for (i = 1; i < hash.length; i += 2) {
// We don't construct URLs with an odd number of components,
// but the user might write one.
var operator = exports.decodeHashComponent(hash[i]);
let operator = exports.decodeHashComponent(hash[i]);
// Do not parse further if empty operator encountered.
if (operator === '') {
break;
}
var raw_operand = hash[i + 1];
const raw_operand = hash[i + 1];
if (!raw_operand) {
return;
}
var operand = exports.decode_operand(operator, raw_operand);
var negated = false;
const operand = exports.decode_operand(operator, raw_operand);
let negated = false;
if (operator[0] === '-') {
negated = true;
operator = operator.slice(1);

View File

@ -1,7 +1,7 @@
var render_bookend = require('../templates/bookend.hbs');
var render_message_group = require('../templates/message_group.hbs');
var render_recipient_row = require('../templates/recipient_row.hbs');
var render_single_message = require('../templates/single_message.hbs');
const render_bookend = require('../templates/bookend.hbs');
const render_message_group = require('../templates/message_group.hbs');
const render_recipient_row = require('../templates/recipient_row.hbs');
const render_single_message = require('../templates/single_message.hbs');
function MessageListView(list, table_name, collapse_messages) {
this.list = list;
@ -20,10 +20,10 @@ function MessageListView(list, table_name, collapse_messages) {
}
function get_user_id_for_mention_button(elem) {
var user_id = $(elem).attr('data-user-id');
const user_id = $(elem).attr('data-user-id');
// Handle legacy markdown that was rendered before we cut
// over to using data-user-id.
var email = $(elem).attr('data-user-email');
const email = $(elem).attr('data-user-email');
if (user_id === "*" || email === "*") {
return "*";
@ -35,7 +35,7 @@ function get_user_id_for_mention_button(elem) {
if (email) {
// Will return undefined if there's no match
var user = people.get_by_email(email);
const user = people.get_by_email(email);
if (user) {
return user.user_id;
}
@ -45,7 +45,7 @@ function get_user_id_for_mention_button(elem) {
}
function get_user_group_id_for_mention_button(elem) {
var user_group_id = $(elem).attr('data-user-group-id');
const user_group_id = $(elem).attr('data-user-group-id');
if (user_group_id) {
return user_group_id;
@ -58,8 +58,8 @@ function same_day(earlier_msg, later_msg) {
if (earlier_msg === undefined || later_msg === undefined) {
return false;
}
var earlier_time = new XDate(earlier_msg.msg.timestamp * 1000);
var later_time = new XDate(later_msg.msg.timestamp * 1000);
const earlier_time = new XDate(earlier_msg.msg.timestamp * 1000);
const later_time = new XDate(later_msg.msg.timestamp * 1000);
return earlier_time.toDateString() === later_time.toDateString();
}
@ -79,19 +79,19 @@ function same_recipient(a, b) {
}
function render_group_display_date(group, message_container) {
var time = new XDate(message_container.msg.timestamp * 1000);
var today = new XDate();
var date_element = timerender.render_date(time, undefined, today)[0];
const time = new XDate(message_container.msg.timestamp * 1000);
const today = new XDate();
const date_element = timerender.render_date(time, undefined, today)[0];
group.date = date_element.outerHTML;
}
function update_group_date_divider(group, message_container, prev) {
var time = new XDate(message_container.msg.timestamp * 1000);
var today = new XDate();
const time = new XDate(message_container.msg.timestamp * 1000);
const today = new XDate();
if (prev !== undefined) {
var prev_time = new XDate(prev.msg.timestamp * 1000);
const prev_time = new XDate(prev.msg.timestamp * 1000);
if (time.toDateString() !== prev_time.toDateString()) {
// NB: group_date_divider_html is HTML, inserted into the document without escaping.
group.group_date_divider_html = timerender.render_date(time, prev_time,
@ -118,17 +118,17 @@ function clear_message_date_divider(msg) {
}
function update_message_date_divider(opts) {
var prev_msg_container = opts.prev_msg_container;
var curr_msg_container = opts.curr_msg_container;
const prev_msg_container = opts.prev_msg_container;
const curr_msg_container = opts.curr_msg_container;
if (!prev_msg_container || same_day(curr_msg_container, prev_msg_container)) {
clear_message_date_divider(curr_msg_container);
return;
}
var prev_time = new XDate(prev_msg_container.msg.timestamp * 1000);
var curr_time = new XDate(curr_msg_container.msg.timestamp * 1000);
var today = new XDate();
const prev_time = new XDate(prev_msg_container.msg.timestamp * 1000);
const curr_time = new XDate(curr_msg_container.msg.timestamp * 1000);
const today = new XDate();
curr_msg_container.want_date_divider = true;
curr_msg_container.date_divider_html =
@ -136,7 +136,7 @@ function update_message_date_divider(opts) {
}
function set_timestr(message_container) {
var time = new XDate(message_container.msg.timestamp * 1000);
const time = new XDate(message_container.msg.timestamp * 1000);
message_container.timestr = timerender.stringify_time(time);
}
@ -166,7 +166,7 @@ function populate_group_from_message_container(group, message_container) {
group.match_topic = util.get_match_topic(message_container.msg);
group.stream_url = message_container.stream_url;
group.topic_url = message_container.topic_url;
var sub = stream_data.get_sub(message_container.msg.stream);
const sub = stream_data.get_sub(message_container.msg.stream);
if (sub === undefined) {
// Hack to handle unusual cases like the tutorial where
// the streams used don't actually exist in the subs
@ -196,8 +196,8 @@ MessageListView.prototype = {
_get_msg_timestring: function (message_container) {
if (message_container.msg.last_edit_timestamp !== undefined) {
var last_edit_time = new XDate(message_container.msg.last_edit_timestamp * 1000);
var today = new XDate();
const last_edit_time = new XDate(message_container.msg.last_edit_timestamp * 1000);
const today = new XDate();
return timerender.render_date(last_edit_time, undefined, today)[0].textContent +
" at " + timerender.stringify_time(last_edit_time);
}
@ -211,9 +211,9 @@ MessageListView.prototype = {
// * `edited_in_left_col` -- when label appears in left column.
// * `edited_alongside_sender` -- when label appears alongside sender info.
// * `edited_status_msg` -- when label appears for a "/me" message.
var last_edit_timestr = this._get_msg_timestring(message_container);
var include_sender = message_container.include_sender;
var status_message = Boolean(message_container.status_message);
const last_edit_timestr = this._get_msg_timestring(message_container);
const include_sender = message_container.include_sender;
const status_message = Boolean(message_container.status_message);
if (last_edit_timestr !== undefined) {
message_container.last_edit_timestr = last_edit_timestr;
message_container.edited_in_left_col = !include_sender;
@ -227,9 +227,9 @@ MessageListView.prototype = {
return;
}
var last_subscribed = !last_msg_container.msg.historical;
var first_subscribed = !first_msg_container.msg.historical;
var stream = first_msg_container.msg.stream;
const last_subscribed = !last_msg_container.msg.historical;
const first_subscribed = !first_msg_container.msg.historical;
const stream = first_msg_container.msg.stream;
if (!last_subscribed && first_subscribed) {
group.bookend_top = true;
@ -254,10 +254,10 @@ MessageListView.prototype = {
};
}
var self = this;
var current_group = start_group();
var new_message_groups = [];
var prev;
const self = this;
let current_group = start_group();
const new_message_groups = [];
let prev;
function add_message_container_to_group(message_container) {
if (same_sender(prev, message_container)) {
@ -278,7 +278,7 @@ MessageListView.prototype = {
}
_.each(message_containers, function (message_container) {
var message_reactions = reactions.get_message_reactions(message_container.msg);
const message_reactions = reactions.get_message_reactions(message_container.msg);
message_container.msg.message_reactions = message_reactions;
message_container.include_recipient = false;
message_container.include_footer = false;
@ -364,8 +364,8 @@ MessageListView.prototype = {
if (first_group === undefined || second_group === undefined) {
return false;
}
var last_msg_container = _.last(first_group.message_containers);
var first_msg_container = _.first(second_group.message_containers);
const last_msg_container = _.last(first_group.message_containers);
const first_msg_container = _.first(second_group.message_containers);
// Join two groups into one.
if (this.collapse_messages && same_recipient(last_msg_container, first_msg_container) &&
@ -403,17 +403,17 @@ MessageListView.prototype = {
// append_messages are messages which should be added to the last group in the DOM
// rerender_messages are messages which should be updated in place in the DOM
var message_actions = {
const message_actions = {
append_groups: [],
prepend_groups: [],
rerender_groups: [],
append_messages: [],
rerender_messages_next_same_sender: [],
};
var first_group;
var second_group;
var curr_msg_container;
var prev_msg_container;
let first_group;
let second_group;
let curr_msg_container;
let prev_msg_container;
if (where === 'top') {
first_group = _.last(new_message_groups);
@ -431,7 +431,7 @@ MessageListView.prototype = {
curr_msg_container = _.first(second_group.message_containers);
}
var was_joined = this.join_message_groups(first_group, second_group);
const was_joined = this.join_message_groups(first_group, second_group);
if (was_joined) {
update_message_date_divider({
prev_msg_container: prev_msg_container,
@ -501,9 +501,9 @@ MessageListView.prototype = {
blueslip.error('programming error--pass in jQuery objects');
}
var self = this;
const self = this;
_.each($message_rows, function (dom_row) {
var row = $(dom_row);
const row = $(dom_row);
self._put_row(row);
self._post_process_single_row(row);
});
@ -521,7 +521,7 @@ MessageListView.prototype = {
blueslip.error('programming error--expected single element');
}
var content = row.find('.message_content');
const content = row.find('.message_content');
// Set the rtl class if the text has an rtl direction
if (rtl.get_direction(content.text()) === 'rtl') {
@ -529,7 +529,7 @@ MessageListView.prototype = {
}
content.find('.user-mention').each(function () {
var user_id = get_user_id_for_mention_button(this);
const user_id = get_user_id_for_mention_button(this);
// We give special highlights to the mention buttons
// that refer to the current user.
if (user_id === "*" || people.is_my_user_id(user_id)) {
@ -541,7 +541,7 @@ MessageListView.prototype = {
// mention text to show the user's current name,
// assuming that you're not searching for text
// inside the highlight.
var person = people.get_person_from_user_id(user_id);
const person = people.get_person_from_user_id(user_id);
if (person !== undefined) {
// Note that person might be undefined in some
// unpleasant corner cases involving data import.
@ -551,8 +551,8 @@ MessageListView.prototype = {
});
content.find('.user-group-mention').each(function () {
var user_group_id = get_user_group_id_for_mention_button(this);
var user_group = user_groups.get_user_group_from_id(user_group_id, true);
const user_group_id = get_user_group_id_for_mention_button(this);
const user_group = user_groups.get_user_group_from_id(user_group_id, true);
if (user_group === undefined) {
// This is a user group the current user doesn't have
// data on. This can happen when user groups are
@ -561,7 +561,7 @@ MessageListView.prototype = {
return;
}
var my_user_id = people.my_current_user_id();
const my_user_id = people.my_current_user_id();
// Mark user group you're a member of.
if (user_groups.is_member_of(user_group_id, my_user_id)) {
$(this).addClass('user-mention-me');
@ -575,7 +575,7 @@ MessageListView.prototype = {
});
content.find('a.stream').each(function () {
var stream_id = $(this).attr('data-stream-id');
const stream_id = $(this).attr('data-stream-id');
if (stream_id && !$(this).find(".highlight").length) {
// Display the current name for stream if it is not
// being displayed in search highlight.
@ -584,12 +584,12 @@ MessageListView.prototype = {
});
content.find('a.stream-topic').each(function () {
var stream_id = $(this).attr('data-stream-id');
const stream_id = $(this).attr('data-stream-id');
if (stream_id && !$(this).find(".highlight").length) {
// Display the current name for stream if it is not
// being displayed in search highlight.
var text = $(this).text();
var topic = text.split('>', 2)[1];
const text = $(this).text();
const topic = text.split('>', 2)[1];
$(this).text("#" + stream_data.maybe_get_stream_name(stream_id) + ' > ' + topic);
}
});
@ -598,12 +598,12 @@ MessageListView.prototype = {
// page_params.emojiset is 'text'.
if (page_params.emojiset === 'text') {
content.find(".emoji").replaceWith(function () {
var text = $(this).attr("title");
const text = $(this).attr("title");
return ":" + text + ":";
});
}
var id = rows.id(row);
const id = rows.id(row);
message_edit.maybe_show_edit(row, id);
submessage.process_submessages({
@ -613,18 +613,18 @@ MessageListView.prototype = {
},
_get_message_template: function (message_container) {
var msg_reactions = reactions.get_message_reactions(message_container.msg);
const msg_reactions = reactions.get_message_reactions(message_container.msg);
message_container.msg.message_reactions = msg_reactions;
var msg_to_render = _.extend(message_container, {
const msg_to_render = _.extend(message_container, {
table_name: this.table_name,
});
return render_single_message(msg_to_render);
},
_render_group: function (opts) {
var message_groups = opts.message_groups;
var use_match_properties = opts.use_match_properties;
var table_name = opts.table_name;
const message_groups = opts.message_groups;
const use_match_properties = opts.use_match_properties;
const table_name = opts.table_name;
return $(render_message_group({
message_groups: message_groups,
@ -639,22 +639,22 @@ MessageListView.prototype = {
// Store this in a separate variable so it doesn't get
// confusingly masked in upcoming loops.
var self = this;
const self = this;
if (messages.length === 0 || self.table_name === undefined) {
return;
}
var list = self.list; // for convenience
var table_name = self.table_name;
var table = rows.get_table(table_name);
var orig_scrolltop_offset;
const list = self.list; // for convenience
const table_name = self.table_name;
const table = rows.get_table(table_name);
let orig_scrolltop_offset;
// If we start with the message feed scrolled up (i.e.
// the bottom message is not visible), then we will respect
// the user's current position after rendering, rather
// than auto-scrolling.
var started_scrolled_up = message_viewport.is_scrolled_up();
const started_scrolled_up = message_viewport.is_scrolled_up();
// The messages we are being asked to render are shared with between
// all messages lists. To prevent having both list views overwriting
@ -690,13 +690,13 @@ MessageListView.prototype = {
return;
}
var new_message_groups = self.build_message_groups(message_containers, self.table_name);
var message_actions = self.merge_message_groups(new_message_groups, where);
var new_dom_elements = [];
var rendered_groups;
var dom_messages;
var last_message_row;
var last_group_row;
const new_message_groups = self.build_message_groups(message_containers, self.table_name);
const message_actions = self.merge_message_groups(new_message_groups, where);
let new_dom_elements = [];
let rendered_groups;
let dom_messages;
let last_message_row;
let last_group_row;
_.each(message_containers, function (message_container) {
self.message_containers[message_container.msg.id] = message_container;
@ -729,7 +729,7 @@ MessageListView.prototype = {
save_scroll_position();
_.each(message_actions.rerender_groups, function (message_group) {
var old_message_group = $('#' + message_group.message_group_id);
const old_message_group = $('#' + message_group.message_group_id);
// Remove the top date_row, we'll re-add it after rendering
old_message_group.prev('.date_row').remove();
@ -756,9 +756,9 @@ MessageListView.prototype = {
// entirely, since it appears the next_is_same_sender CSS
// class doesn't do anything.
if (message_actions.rerender_messages_next_same_sender.length > 0) {
var targets = message_actions.rerender_messages_next_same_sender;
const targets = message_actions.rerender_messages_next_same_sender;
_.each(targets, function (message_container) {
var row = self.get_row(message_container.msg.id);
const row = self.get_row(message_container.msg.id);
$(row).find("div.messagebox").toggleClass("next_is_same_sender",
message_container.next_is_same_sender);
});
@ -815,17 +815,17 @@ MessageListView.prototype = {
restore_scroll_position();
var last_message_group = _.last(self._message_groups);
const last_message_group = _.last(self._message_groups);
if (last_message_group !== undefined) {
list.last_message_historical =
_.last(last_message_group.message_containers).msg.historical;
}
var stream_name = narrow_state.stream();
const stream_name = narrow_state.stream();
if (stream_name !== undefined) {
// If user narrows to a stream, doesn't update
// trailing bookend if user is subscribed.
var sub = stream_data.get_sub(stream_name);
const sub = stream_data.get_sub(stream_name);
if (sub === undefined || !sub.subscribed) {
list.update_trailing_bookend();
}
@ -834,12 +834,12 @@ MessageListView.prototype = {
if (list === current_msg_list) {
// Update the fade.
var get_element = function (message_group) {
const get_element = function (message_group) {
// We don't have a MessageGroup class, but we can at least hide the messy details
// of rows.js from compose_fade. We provide a callback function to be lazy--
// compose_fade may not actually need the elements depending on its internal
// state.
var message_row = self.get_row(message_group.message_containers[0].msg.id);
const message_row = self.get_row(message_group.message_containers[0].msg.id);
return rows.get_message_recipient_row(message_row);
};
@ -850,8 +850,8 @@ MessageListView.prototype = {
// First, in single-recipient narrows, potentially
// auto-scroll to the latest message if it was sent by us.
if (narrow_state.narrowed_by_reply()) {
var selected_id = list.selected_id();
var i;
const selected_id = list.selected_id();
let i;
// Iterate backwards to find the last message
// sent_by_me, stopping at the pointer position.
@ -859,7 +859,7 @@ MessageListView.prototype = {
// should be limited in how far offscreen it's willing
// to go.
for (i = messages.length - 1; i >= 0; i -= 1) {
var id = messages[i].id;
const id = messages[i].id;
if (id <= selected_id) {
break;
}
@ -878,8 +878,8 @@ MessageListView.prototype = {
need_user_to_scroll: true,
};
}
var new_messages_height = self._new_messages_height(new_dom_elements);
var need_user_to_scroll = self._maybe_autoscroll(new_messages_height);
const new_messages_height = self._new_messages_height(new_dom_elements);
const need_user_to_scroll = self._maybe_autoscroll(new_messages_height);
if (need_user_to_scroll) {
return {
@ -890,8 +890,8 @@ MessageListView.prototype = {
},
_new_messages_height: function (rendered_elems) {
var new_messages_height = 0;
var id_of_last_message_sent_by_us = -1;
let new_messages_height = 0;
let id_of_last_message_sent_by_us = -1;
// C++ iterators would have made this less painful
_.each(rendered_elems.reverse(), function (elem) {
@ -903,7 +903,7 @@ MessageListView.prototype = {
if (id_of_last_message_sent_by_us > -1) {
return;
}
var row_id = rows.id(elem);
const row_id = rows.id(elem);
// check for `row_id` NaN in case we're looking at a date row or bookend row
if (row_id > -1 &&
people.is_current_user(this.get_message(row_id).sender_email)) {
@ -920,8 +920,8 @@ MessageListView.prototype = {
// it's the max amount that we can scroll down (or "skooch
// up" the messages) before knocking the selected message
// out of the feed.
var selected_row_top = selected_row.offset().top;
var scroll_limit = selected_row_top - viewport_info.visible_top;
const selected_row_top = selected_row.offset().top;
let scroll_limit = selected_row_top - viewport_info.visible_top;
if (scroll_limit < 0) {
// This shouldn't happen, but if we're off by a pixel or
@ -940,8 +940,8 @@ MessageListView.prototype = {
//
// returns `true` if we need the user to scroll
var selected_row = this.selected_row();
var last_visible = rows.last_visible();
const selected_row = this.selected_row();
const last_visible = rows.last_visible();
// Make sure we have a selected row and last visible row. (defensive)
if (!(selected_row && selected_row.length > 0 && last_visible)) {
@ -971,8 +971,8 @@ MessageListView.prototype = {
return false;
}
var info = message_viewport.message_viewport_info();
var scroll_limit = this._scroll_limit(selected_row, info);
const info = message_viewport.message_viewport_info();
const scroll_limit = this._scroll_limit(selected_row, info);
// This next decision is fairly debatable. For a big message that
// would push the pointer off the screen, we do a partial autoscroll,
@ -982,8 +982,8 @@ MessageListView.prototype = {
// c) scroll amount isn't really tied to size of new messages (bad)
// d) all the bad things about scrolling for users who want messages
// to stay on the screen
var scroll_amount;
var need_user_to_scroll;
let scroll_amount;
let need_user_to_scroll;
if (new_messages_height <= scroll_limit) {
// This is the happy path where we can just scroll
@ -997,7 +997,7 @@ MessageListView.prototype = {
// (Even if we are somewhat constrained here, the message may
// still end up being visible, so we do some arithmetic.)
scroll_amount = scroll_limit;
var offset = message_viewport.offset_from_bottom(last_visible);
const offset = message_viewport.offset_from_bottom(last_visible);
// For determining whether we need to show the user a "you
// need to scroll down" notification, the obvious check
@ -1011,11 +1011,11 @@ MessageListView.prototype = {
// this notification, we need to adjust by the amount that
// the current compose is bigger than the empty, open
// compose box.
var compose_textarea_default_height = 42;
var compose_textarea_current_height = $("#compose-textarea").height();
var expected_change =
const compose_textarea_default_height = 42;
const compose_textarea_current_height = $("#compose-textarea").height();
const expected_change =
compose_textarea_current_height - compose_textarea_default_height;
var expected_offset = offset - expected_change;
const expected_offset = offset - expected_change;
need_user_to_scroll = expected_offset > scroll_amount;
}
@ -1039,7 +1039,7 @@ MessageListView.prototype = {
},
update_render_window: function (selected_idx, check_for_changed) {
var new_start = Math.max(selected_idx - this._RENDER_WINDOW_SIZE / 2, 0);
const new_start = Math.max(selected_idx - this._RENDER_WINDOW_SIZE / 2, 0);
if (check_for_changed && new_start === this._render_win_start) {
return false;
}
@ -1056,7 +1056,7 @@ MessageListView.prototype = {
return false;
}
var selected_idx = this.list.selected_idx();
const selected_idx = this.list.selected_idx();
// We rerender under the following conditions:
// * The selected message is within this._RENDER_THRESHOLD messages
@ -1085,9 +1085,9 @@ MessageListView.prototype = {
rerender_preserving_scrolltop: function (discard_rendering_state) {
// old_offset is the number of pixels between the top of the
// viewable window and the selected message
var old_offset;
var selected_row = this.selected_row();
var selected_in_view = selected_row.length > 0;
let old_offset;
const selected_row = this.selected_row();
const selected_in_view = selected_row.length > 0;
if (selected_in_view) {
old_offset = selected_row.offset().top;
}
@ -1102,7 +1102,7 @@ MessageListView.prototype = {
},
set_message_offset: function (offset) {
var msg = this.selected_row();
const msg = this.selected_row();
message_viewport.scrollTop(message_viewport.scrollTop() + msg.offset().top - offset);
},
@ -1148,23 +1148,23 @@ MessageListView.prototype = {
return;
}
var first_row = this.get_row(message_containers[0].msg.id);
const first_row = this.get_row(message_containers[0].msg.id);
// We may not have the row if the stream or topic was muted
if (first_row.length === 0) {
return;
}
var recipient_row = rows.get_message_recipient_row(first_row);
var header = recipient_row.find('.message_header');
var message_group_id = recipient_row.attr("id");
const recipient_row = rows.get_message_recipient_row(first_row);
const header = recipient_row.find('.message_header');
const message_group_id = recipient_row.attr("id");
// Since there might be multiple dates within the message
// group, it's important to lookup the original/full message
// group rather than doing an artificial rerendering of the
// message header from the set of message containers passed in
// here.
var group = this._find_message_group(message_group_id);
const group = this._find_message_group(message_group_id);
if (group === undefined) {
blueslip.error("Could not find message group for rerendering headers");
return;
@ -1176,14 +1176,14 @@ MessageListView.prototype = {
// rerendering rather than looking up the original version.
populate_group_from_message_container(group, group.message_containers[0]);
var rendered_recipient_row = $(render_recipient_row(group));
const rendered_recipient_row = $(render_recipient_row(group));
header.replaceWith(rendered_recipient_row);
},
_rerender_message: function (message_container, message_content_edited) {
var row = this.get_row(message_container.msg.id);
var was_selected = this.list.selected_message() === message_container.msg;
const row = this.get_row(message_container.msg.id);
const was_selected = this.list.selected_message() === message_container.msg;
// Re-render just this one message
this._maybe_format_me_message(message_container);
@ -1192,7 +1192,7 @@ MessageListView.prototype = {
// Make sure the right thing happens if the message was edited to mention us.
message_container.contains_mention = message_container.msg.mentioned;
var rendered_msg = $(this._get_message_template(message_container));
const rendered_msg = $(this._get_message_template(message_container));
if (message_content_edited) {
rendered_msg.addClass("fade-in-message");
}
@ -1205,10 +1205,10 @@ MessageListView.prototype = {
},
rerender_messages: function (messages, message_content_edited) {
var self = this;
const self = this;
// Convert messages to list messages
var message_containers = _.map(messages, function (message) {
let message_containers = _.map(messages, function (message) {
return self.message_containers[message.id];
});
// We may not have the message_container if the stream or topic was muted
@ -1216,8 +1216,8 @@ MessageListView.prototype = {
return message_container === undefined;
});
var message_groups = [];
var current_group = [];
const message_groups = [];
let current_group = [];
_.each(message_containers, function (message_container) {
if (current_group.length === 0 ||
same_recipient(current_group[current_group.length - 1], message_container)) {
@ -1237,11 +1237,11 @@ MessageListView.prototype = {
},
append: function (messages, messages_are_new) {
var cur_window_size = this._render_win_end - this._render_win_start;
var render_info;
const cur_window_size = this._render_win_end - this._render_win_start;
let render_info;
if (cur_window_size < this._RENDER_WINDOW_SIZE) {
var slice_to_render = messages.slice(0, this._RENDER_WINDOW_SIZE - cur_window_size);
const slice_to_render = messages.slice(0, this._RENDER_WINDOW_SIZE - cur_window_size);
render_info = this.render(slice_to_render, 'bottom', messages_are_new);
this._render_win_end += slice_to_render.length;
}
@ -1251,7 +1251,7 @@ MessageListView.prototype = {
// newly received message should trigger a rerender so that
// the new message, which will appear in the viewable area,
// is rendered.
var needed_rerender = this.maybe_rerender();
const needed_rerender = this.maybe_rerender();
if (needed_rerender) {
render_info = {need_user_to_scroll: true};
@ -1264,10 +1264,10 @@ MessageListView.prototype = {
this._render_win_start += messages.length;
this._render_win_end += messages.length;
var cur_window_size = this._render_win_end - this._render_win_start;
const cur_window_size = this._render_win_end - this._render_win_start;
if (cur_window_size < this._RENDER_WINDOW_SIZE) {
var msgs_to_render_count = this._RENDER_WINDOW_SIZE - cur_window_size;
var slice_to_render = messages.slice(messages.length - msgs_to_render_count);
const msgs_to_render_count = this._RENDER_WINDOW_SIZE - cur_window_size;
const slice_to_render = messages.slice(messages.length - msgs_to_render_count);
this.render(slice_to_render, 'top', false);
this._render_win_start -= slice_to_render.length;
}
@ -1287,7 +1287,7 @@ MessageListView.prototype = {
},
get_row: function (id) {
var row = this._rows[id];
const row = this._rows[id];
if (row === undefined) {
// For legacy reasons we need to return an empty
@ -1299,12 +1299,12 @@ MessageListView.prototype = {
},
clear_trailing_bookend: function () {
var trailing_bookend = rows.get_table(this.table_name).find('.trailing_bookend');
const trailing_bookend = rows.get_table(this.table_name).find('.trailing_bookend');
trailing_bookend.remove();
},
render_trailing_bookend: function (trailing_bookend_content, subscribed, show_button) {
var rendered_trailing_bookend = $(render_bookend({
const rendered_trailing_bookend = $(render_bookend({
bookend_content: trailing_bookend_content,
trailing: show_button,
subscribed: subscribed,
@ -1322,7 +1322,7 @@ MessageListView.prototype = {
change_message_id: function (old_id, new_id) {
if (this._rows[old_id] !== undefined) {
var row = this._rows[old_id];
const row = this._rows[old_id];
delete this._rows[old_id];
row.attr('zid', new_id);
@ -1332,7 +1332,7 @@ MessageListView.prototype = {
}
if (this.message_containers[old_id] !== undefined) {
var message_container = this.message_containers[old_id];
const message_container = this.message_containers[old_id];
delete this.message_containers[old_id];
this.message_containers[new_id] = message_container;
}
@ -1344,8 +1344,8 @@ MessageListView.prototype = {
// Slice the '<p>/me ' off the front, and '</p>' off the first line
// 'p' tag is sliced off to get sender in the same line as the
// first line of the message
var msg_content = message_container.msg.content;
var p_index = msg_content.indexOf('</p>');
const msg_content = message_container.msg.content;
const p_index = msg_content.indexOf('</p>');
message_container.status_message = msg_content.slice('<p>/me '.length, p_index) +
msg_content.slice(p_index + '</p>'.length);
message_container.include_sender = true;

View File

@ -1,4 +1,4 @@
var unnarrow_times;
let unnarrow_times;
function report_narrow_time(initial_core_time, initial_free_time, network_time) {
channel.post({
@ -28,8 +28,8 @@ function report_unnarrow_time() {
return;
}
var initial_core_time = unnarrow_times.initial_core_time - unnarrow_times.start_time;
var initial_free_time = unnarrow_times.initial_free_time - unnarrow_times.start_time;
const initial_core_time = unnarrow_times.initial_core_time - unnarrow_times.start_time;
const initial_free_time = unnarrow_times.initial_free_time - unnarrow_times.start_time;
channel.post({
url: '/json/report/unnarrow_times',
@ -58,8 +58,8 @@ exports.save_pre_narrow_offset_for_reload = function () {
exports.narrow_title = "home";
exports.activate = function (raw_operators, opts) {
var start_time = new Date();
var was_narrowed_already = narrow_state.active();
const start_time = new Date();
const was_narrowed_already = narrow_state.active();
// most users aren't going to send a bunch of a out-of-narrow messages
// and expect to visit a list of narrows, so let's get these out of the way.
notifications.clear_compose_notifications();
@ -71,8 +71,8 @@ exports.activate = function (raw_operators, opts) {
if (raw_operators.length === 0) {
return exports.deactivate();
}
var filter = new Filter(raw_operators);
var operators = filter.operators();
const filter = new Filter(raw_operators);
const operators = filter.operators();
// Take the most detailed part of the narrow to use as the title.
// If the operator is something other than "stream", "topic", or
@ -84,14 +84,14 @@ exports.activate = function (raw_operators, opts) {
exports.narrow_title = filter.operands("stream")[0];
}
} else if (filter.has_operator("is")) {
var title = filter.operands("is")[0];
let title = filter.operands("is")[0];
title = title.charAt(0).toUpperCase() + title.slice(1) + " messages";
exports.narrow_title = title;
} else if (filter.has_operator("pm-with") || filter.has_operator("group-pm-with")) {
var emails = filter.public_operators()[0].operand;
var user_ids = people.emails_strings_to_user_ids_string(emails);
const emails = filter.public_operators()[0].operand;
const user_ids = people.emails_strings_to_user_ids_string(emails);
if (user_ids !== undefined) {
var names = people.get_recipients(user_ids);
const names = people.get_recipients(user_ids);
if (filter.has_operator("pm-with")) {
exports.narrow_title = names;
} else {
@ -120,7 +120,7 @@ exports.activate = function (raw_operators, opts) {
trigger: 'unknown',
});
var id_info = {
const id_info = {
target_id: undefined,
local_select_id: undefined,
final_select_id: undefined,
@ -140,7 +140,7 @@ exports.activate = function (raw_operators, opts) {
// having a near: narrow auto-reloaded.
id_info.target_id = opts.then_select_id;
if (opts.then_select_offset === undefined) {
var row = current_msg_list.get_row(opts.then_select_id);
const row = current_msg_list.get_row(opts.then_select_id);
if (row.length > 0) {
opts.then_select_offset = row.offset().top;
}
@ -157,12 +157,12 @@ exports.activate = function (raw_operators, opts) {
// reflect the upcoming narrow.
narrow_state.set_current_filter(filter);
var muting_enabled = narrow_state.muting_enabled();
const muting_enabled = narrow_state.muting_enabled();
// Save how far from the pointer the top of the message list was.
exports.save_pre_narrow_offset_for_reload();
var msg_data = new MessageListData({
let msg_data = new MessageListData({
filter: narrow_state.filter(),
muting_enabled: muting_enabled,
});
@ -189,7 +189,7 @@ exports.activate = function (raw_operators, opts) {
});
}
var msg_list = new message_list.MessageList({
const msg_list = new message_list.MessageList({
data: msg_data,
table_name: 'zfilt',
collapse_messages: !narrow_state.filter().is_search(),
@ -208,16 +208,16 @@ exports.activate = function (raw_operators, opts) {
message_list.set_narrowed(msg_list);
current_msg_list = message_list.narrowed;
var then_select_offset;
let then_select_offset;
if (id_info.target_id === id_info.final_select_id) {
then_select_offset = opts.then_select_offset;
}
var select_immediately = id_info.local_select_id !== undefined;
const select_immediately = id_info.local_select_id !== undefined;
(function fetch_messages() {
var anchor;
var use_first_unread;
let anchor;
let use_first_unread;
if (id_info.final_select_id !== undefined) {
anchor = id_info.final_select_id;
@ -266,7 +266,7 @@ exports.activate = function (raw_operators, opts) {
if (page_params.search_pills_enabled && opts.trigger !== 'search') {
search_pill_widget.widget.clear(true);
_.each(operators, function (operator) {
var search_string = Filter.unparse([operator]);
const search_string = Filter.unparse([operator]);
search_pill.append_search_string(search_string, search_pill_widget.widget);
});
}
@ -295,7 +295,7 @@ exports.activate = function (raw_operators, opts) {
compose_actions.on_narrow(opts);
var current_filter = narrow_state.filter();
const current_filter = narrow_state.filter();
top_left_corner.handle_narrow_activated(current_filter);
stream_list.handle_narrow_activated(current_filter);
@ -325,7 +325,7 @@ function load_local_messages(msg_data) {
// cases when our local cache (message_list.all) has at least
// one message the user will expect to see in the new narrow.
var in_msgs = message_list.all.all_messages();
const in_msgs = message_list.all.all_messages();
msg_data.add_messages(in_msgs);
return !msg_data.empty();
@ -337,9 +337,9 @@ exports.maybe_add_local_messages = function (opts) {
//
// - update id_info with more complete values
// - add messages into our message list from our local cache
var id_info = opts.id_info;
var msg_data = opts.msg_data;
var unread_info = narrow_state.get_first_unread_info();
const id_info = opts.id_info;
const msg_data = opts.msg_data;
const unread_info = narrow_state.get_first_unread_info();
if (unread_info.flavor === 'cannot_compute') {
if (id_info.target_id) {
@ -405,7 +405,7 @@ exports.maybe_add_local_messages = function (opts) {
// is caught up, so the last message in our now-populated
// msg_data object must be the last message matching the
// narrow the server could give us, so we can render locally.
var last_msg = msg_data.last();
const last_msg = msg_data.last();
id_info.final_select_id = last_msg.id;
id_info.local_select_id = id_info.final_select_id;
return;
@ -445,19 +445,19 @@ exports.update_selection = function (opts) {
return;
}
var id_info = opts.id_info;
var select_offset = opts.select_offset;
const id_info = opts.id_info;
const select_offset = opts.select_offset;
var msg_id = id_info.final_select_id;
let msg_id = id_info.final_select_id;
if (msg_id === undefined) {
msg_id = message_list.narrowed.first_unread_message_id();
}
var preserve_pre_narrowing_screen_position =
const preserve_pre_narrowing_screen_position =
message_list.narrowed.get(msg_id) !== undefined &&
select_offset !== undefined;
var then_scroll = !preserve_pre_narrowing_screen_position;
const then_scroll = !preserve_pre_narrowing_screen_position;
message_list.narrowed.select_id(msg_id, {
then_scroll: then_scroll,
@ -478,7 +478,7 @@ exports.stream_topic = function () {
// This function returns the stream/topic that we most
// specifically care about, according (mostly) to the
// currently selected message.
var msg = current_msg_list.selected_message();
const msg = current_msg_list.selected_message();
if (msg) {
return {
@ -497,7 +497,7 @@ exports.stream_topic = function () {
exports.activate_stream_for_cycle_hotkey = function (stream_name) {
// This is the common code for A/D hotkeys.
var filter_expr = [
const filter_expr = [
{operator: 'stream', operand: stream_name},
];
exports.activate(filter_expr, {});
@ -505,13 +505,13 @@ exports.activate_stream_for_cycle_hotkey = function (stream_name) {
exports.stream_cycle_backward = function () {
var curr_stream = narrow_state.stream();
const curr_stream = narrow_state.stream();
if (!curr_stream) {
return;
}
var stream_name = topic_generator.get_prev_stream(curr_stream);
const stream_name = topic_generator.get_prev_stream(curr_stream);
if (!stream_name) {
return;
@ -521,13 +521,13 @@ exports.stream_cycle_backward = function () {
};
exports.stream_cycle_forward = function () {
var curr_stream = narrow_state.stream();
const curr_stream = narrow_state.stream();
if (!curr_stream) {
return;
}
var stream_name = topic_generator.get_next_stream(curr_stream);
const stream_name = topic_generator.get_next_stream(curr_stream);
if (!stream_name) {
return;
@ -537,13 +537,13 @@ exports.stream_cycle_forward = function () {
};
exports.narrow_to_next_topic = function () {
var curr_info = exports.stream_topic();
const curr_info = exports.stream_topic();
if (!curr_info) {
return;
}
var next_narrow = topic_generator.get_next_topic(
const next_narrow = topic_generator.get_next_topic(
curr_info.stream,
curr_info.topic
);
@ -552,7 +552,7 @@ exports.narrow_to_next_topic = function () {
return;
}
var filter_expr = [
const filter_expr = [
{operator: 'stream', operand: next_narrow.stream},
{operator: 'topic', operand: next_narrow.topic},
];
@ -562,9 +562,9 @@ exports.narrow_to_next_topic = function () {
exports.narrow_to_next_pm_string = function () {
var curr_pm = narrow_state.pm_string();
const curr_pm = narrow_state.pm_string();
var next_pm = topic_generator.get_next_unread_pm_string(curr_pm);
const next_pm = topic_generator.get_next_unread_pm_string(curr_pm);
if (!next_pm) {
return;
@ -572,14 +572,14 @@ exports.narrow_to_next_pm_string = function () {
// Hopefully someday we can narrow by user_ids_string instead of
// mapping back to emails.
var pm_with = people.user_ids_string_to_emails_string(next_pm);
const pm_with = people.user_ids_string_to_emails_string(next_pm);
var filter_expr = [
const filter_expr = [
{operator: 'pm-with', operand: pm_with},
];
// force_close parameter is true to not auto open compose_box
var opts = {
const opts = {
force_close: true,
};
@ -595,7 +595,7 @@ exports.by = function (operator, operand, opts) {
exports.by_topic = function (target_id, opts) {
// don't use current_msg_list as it won't work for muted messages or for out-of-narrow links
var original = message_store.get(target_id);
const original = message_store.get(target_id);
if (original.type !== 'stream') {
// Only stream messages have topics, but the
// user wants us to narrow in some way.
@ -608,7 +608,7 @@ exports.by_topic = function (target_id, opts) {
// message is about to be marked read in the new view.
unread_ops.notify_server_message_read(original);
var search_terms = [
const search_terms = [
{operator: 'stream', operand: original.stream},
{operator: 'topic', operand: util.get_message_topic(original)},
];
@ -620,7 +620,7 @@ exports.by_topic = function (target_id, opts) {
exports.by_recipient = function (target_id, opts) {
opts = _.defaults({}, opts, {then_select_id: target_id});
// don't use current_msg_list as it won't work for muted messages or for out-of-narrow links
var message = message_store.get(target_id);
const message = message_store.get(target_id);
// We don't check msg_list.can_mark_messages_read here only because
// the target msg_list isn't initialized yet; in any case, the
@ -644,21 +644,21 @@ exports.to_compose_target = function () {
return;
}
var opts = {
const opts = {
trigger: 'narrow_to_compose_target',
};
if (compose_state.get_message_type() === 'stream') {
var stream_name = compose_state.stream_name();
var stream_id = stream_data.get_stream_id(stream_name);
const stream_name = compose_state.stream_name();
const stream_id = stream_data.get_stream_id(stream_name);
if (!stream_id) {
return;
}
// If we are composing to a new topic, we narrow to the stream but
// grey-out the message view instead of narrowing to an empty view.
var topics = topic_data.get_recent_names(stream_id);
var operators = [{operator: 'stream', operand: stream_name}];
var topic = compose_state.topic();
const topics = topic_data.get_recent_names(stream_id);
const operators = [{operator: 'stream', operand: stream_name}];
const topic = compose_state.topic();
if (topics.indexOf(topic) !== -1) {
operators.push({operator: 'topic', operand: topic});
}
@ -667,9 +667,9 @@ exports.to_compose_target = function () {
}
if (compose_state.get_message_type() === 'private') {
var recipient_string = compose_state.recipient();
var emails = util.extract_pm_recipients(recipient_string);
var invalid = _.reject(emails, people.is_valid_email_for_compose);
const recipient_string = compose_state.recipient();
const emails = util.extract_pm_recipients(recipient_string);
const invalid = _.reject(emails, people.is_valid_email_for_compose);
// If there are no recipients or any recipient is
// invalid, narrow to all PMs.
if (emails.length === 0 || invalid.length > 0) {
@ -735,11 +735,11 @@ exports.deactivate = function () {
hashchange.save_narrow();
if (current_msg_list.selected_id() !== -1) {
var preserve_pre_narrowing_screen_position =
const preserve_pre_narrowing_screen_position =
current_msg_list.selected_row().length > 0 &&
current_msg_list.pre_narrow_offset !== undefined;
var message_id_to_select;
var select_opts = {
let message_id_to_select;
const select_opts = {
then_scroll: true,
use_closest: true,
empty_ok: true,
@ -790,27 +790,27 @@ exports.restore_home_state = function () {
};
function set_invalid_narrow_message(invalid_narrow_message) {
var search_string_display = $("#empty_search_stop_words_string");
const search_string_display = $("#empty_search_stop_words_string");
search_string_display.text(invalid_narrow_message);
}
function show_search_query() {
// when search bar contains multiple filters, only show search queries
var current_filter = narrow_state.filter();
var search_query = current_filter.operands("search")[0];
var query_words = search_query.split(" ");
const current_filter = narrow_state.filter();
const search_query = current_filter.operands("search")[0];
const query_words = search_query.split(" ");
var search_string_display = $("#empty_search_stop_words_string");
var query_contains_stop_words = false;
const search_string_display = $("#empty_search_stop_words_string");
let query_contains_stop_words = false;
// Also removes previous search_string if any
search_string_display.text(i18n.t("You searched for:"));
// Add in stream:foo and topic:bar if present
if (current_filter.has_operator("stream") || current_filter.has_operator("topic")) {
var stream_topic_string = "";
var stream = current_filter.operands('stream')[0];
var topic = current_filter.operands('topic')[0];
let stream_topic_string = "";
const stream = current_filter.operands('stream')[0];
const topic = current_filter.operands('topic')[0];
if (stream) {
stream_topic_string = "stream: " + stream;
}
@ -843,24 +843,24 @@ function show_search_query() {
}
function pick_empty_narrow_banner() {
var default_banner = $('#empty_narrow_message');
const default_banner = $('#empty_narrow_message');
var current_filter = narrow_state.filter();
const current_filter = narrow_state.filter();
if (current_filter === undefined) {
return default_banner;
}
var first_term = current_filter.operators()[0];
var first_operator = first_term.operator;
var first_operand = first_term.operand;
var num_operators = current_filter.operators().length;
const first_term = current_filter.operators()[0];
const first_operator = first_term.operator;
const first_operand = first_term.operand;
const num_operators = current_filter.operators().length;
if (num_operators !== 1) {
// For invalid-multi-operator narrows, we display an invalid narrow message
var streams = current_filter.operands("stream");
const streams = current_filter.operands("stream");
var invalid_narrow_message = "";
let invalid_narrow_message = "";
// No message can have multiple streams
if (streams.length > 1) {
invalid_narrow_message = i18n.t("You are searching for messages that belong to more than one stream, which is not possible.");
@ -901,7 +901,7 @@ function pick_empty_narrow_banner() {
} else if (first_operator === "stream" && !stream_data.is_subscribed(first_operand)) {
// You are narrowed to a stream which does not exist or is a private stream
// in which you were never subscribed.
var stream_sub = stream_data.get_sub(narrow_state.stream());
const stream_sub = stream_data.get_sub(narrow_state.stream());
if (!stream_sub || !stream_sub.should_display_subscription_button) {
return $("#nonsubbed_private_nonexistent_stream_narrow_message");
}

View File

@ -1,22 +1,22 @@
var confirmDatePlugin = require("flatpickr/dist/plugins/confirmDate/confirmDate.js");
var render_actions_popover_content = require('../templates/actions_popover_content.hbs');
var render_mobile_message_buttons_popover = require('../templates/mobile_message_buttons_popover.hbs');
var render_mobile_message_buttons_popover_content = require('../templates/mobile_message_buttons_popover_content.hbs');
var render_no_arrow_popover = require('../templates/no_arrow_popover.hbs');
var render_remind_me_popover_content = require('../templates/remind_me_popover_content.hbs');
var render_user_group_info_popover = require('../templates/user_group_info_popover.hbs');
var render_user_group_info_popover_content = require('../templates/user_group_info_popover_content.hbs');
var render_user_info_popover_content = require('../templates/user_info_popover_content.hbs');
var render_user_info_popover_title = require('../templates/user_info_popover_title.hbs');
var render_user_profile_modal = require("../templates/user_profile_modal.hbs");
const confirmDatePlugin = require("flatpickr/dist/plugins/confirmDate/confirmDate.js");
const render_actions_popover_content = require('../templates/actions_popover_content.hbs');
const render_mobile_message_buttons_popover = require('../templates/mobile_message_buttons_popover.hbs');
const render_mobile_message_buttons_popover_content = require('../templates/mobile_message_buttons_popover_content.hbs');
const render_no_arrow_popover = require('../templates/no_arrow_popover.hbs');
const render_remind_me_popover_content = require('../templates/remind_me_popover_content.hbs');
const render_user_group_info_popover = require('../templates/user_group_info_popover.hbs');
const render_user_group_info_popover_content = require('../templates/user_group_info_popover_content.hbs');
const render_user_info_popover_content = require('../templates/user_info_popover_content.hbs');
const render_user_info_popover_title = require('../templates/user_info_popover_title.hbs');
const render_user_profile_modal = require("../templates/user_profile_modal.hbs");
var current_actions_popover_elem;
var current_flatpickr_instance;
var current_message_info_popover_elem;
var current_mobile_message_buttons_popover_elem;
var userlist_placement = "right";
let current_actions_popover_elem;
let current_flatpickr_instance;
let current_message_info_popover_elem;
let current_mobile_message_buttons_popover_elem;
let userlist_placement = "right";
var list_of_popovers = [];
let list_of_popovers = [];
// this utilizes the proxy pattern to intercept all calls to $.fn.popover
// and push the $.fn.data($o, "popover") results to an array.
@ -36,7 +36,7 @@ var list_of_popovers = [];
};
// add back all shallow properties of $.fn.popover to the new proxied version.
for (var x in popover) {
for (const x in popover) {
if (popover.hasOwnProperty(x)) {
$.fn.popover[x] = popover[x];
}
@ -44,12 +44,12 @@ var list_of_popovers = [];
}($.fn.popover));
function copy_email_handler(e) {
var email_el = $(e.trigger.parentElement);
var copy_icon = email_el.find('i');
const email_el = $(e.trigger.parentElement);
const copy_icon = email_el.find('i');
// only change the parent element's text back to email
// and not overwrite the tooltip.
var email_textnode = email_el[0].childNodes[2];
const email_textnode = email_el[0].childNodes[2];
email_el.addClass('email_copied');
email_textnode.nodeValue = i18n.t('Email copied');
@ -64,19 +64,19 @@ function copy_email_handler(e) {
function init_email_clipboard() {
$('.user_popover_email').each(function () {
if (this.clientWidth < this.scrollWidth) {
var email_el = $(this);
var copy_email_icon = email_el.find('i');
const email_el = $(this);
const copy_email_icon = email_el.find('i');
copy_email_icon.removeClass('hide_copy_icon');
var copy_email_clipboard = new ClipboardJS(copy_email_icon[0]);
const copy_email_clipboard = new ClipboardJS(copy_email_icon[0]);
copy_email_clipboard.on('success', copy_email_handler);
}
});
}
function load_medium_avatar(user, elt) {
var user_avatar_url = "avatar/" + user.user_id + "/medium";
var sender_avatar_medium = new Image();
const user_avatar_url = "avatar/" + user.user_id + "/medium";
const sender_avatar_medium = new Image();
sender_avatar_medium.src = user_avatar_url;
$(sender_avatar_medium).on("load", function () {
elt.css("background-image", "url(" + $(this).attr("src") + ")");
@ -84,7 +84,7 @@ function load_medium_avatar(user, elt) {
}
function calculate_info_popover_placement(size, elt) {
var ypos = elt.offset().top;
const ypos = elt.offset().top;
if (!(ypos + size / 2 < message_viewport.height() &&
ypos > size / 2)) {
@ -97,9 +97,9 @@ function calculate_info_popover_placement(size, elt) {
}
function get_custom_profile_field_data(user, field, field_types, dateFormat) {
var field_value = people.get_custom_profile_data(user.user_id, field.id);
var field_type = field.type;
var profile_field = {};
const field_value = people.get_custom_profile_data(user.user_id, field.id);
const field_type = field.type;
const profile_field = {};
if (!field_value) {
return profile_field;
@ -123,7 +123,7 @@ function get_custom_profile_field_data(user, field, field_types, dateFormat) {
profile_field.value = field_value.value;
break;
case field_types.CHOICE.id: {
var field_choice_dict = JSON.parse(field.field_data);
const field_choice_dict = JSON.parse(field.field_data);
profile_field.value = field_choice_dict[field_value.value].text;
break;
}
@ -152,10 +152,10 @@ function get_visible_email(user) {
function render_user_info_popover(user, popover_element, is_sender_popover, private_msg_class,
template_class, popover_placement) {
var is_me = people.is_my_user_id(user.user_id);
const is_me = people.is_my_user_id(user.user_id);
var can_set_away = false;
var can_revoke_away = false;
let can_set_away = false;
let can_revoke_away = false;
if (is_me) {
if (user_status.is_away(user.user_id)) {
@ -165,7 +165,7 @@ function render_user_info_popover(user, popover_element, is_sender_popover, priv
}
}
var args = {
const args = {
can_revoke_away: can_revoke_away,
can_set_away: can_set_away,
is_active: people.is_active_user_for_popover(user.user_id),
@ -188,12 +188,12 @@ function render_user_info_popover(user, popover_element, is_sender_popover, priv
};
if (user.is_bot) {
var is_cross_realm_bot = user.is_cross_realm_bot;
var bot_owner_id = user.bot_owner_id;
const is_cross_realm_bot = user.is_cross_realm_bot;
const bot_owner_id = user.bot_owner_id;
if (is_cross_realm_bot) {
args.is_cross_realm_bot = is_cross_realm_bot;
} else if (bot_owner_id) {
var bot_owner = people.get_person_from_user_id(bot_owner_id);
const bot_owner = people.get_person_from_user_id(bot_owner_id);
args.bot_owner = bot_owner;
}
}
@ -228,7 +228,7 @@ exports._test_calculate_info_popover_placement = calculate_info_popover_placemen
// user is the user whose profile to show
// message is the message containing it, which should be selected
function show_user_info_popover(element, user, message) {
var last_popover_elem = current_message_info_popover_elem;
const last_popover_elem = current_message_info_popover_elem;
exports.hide_all();
if (last_popover_elem !== undefined
&& last_popover_elem.get()[0] === element) {
@ -237,7 +237,7 @@ function show_user_info_popover(element, user, message) {
return;
}
current_msg_list.select_id(message.id);
var elt = $(element);
const elt = $(element);
if (elt.data('popover') === undefined) {
if (user === undefined) {
// This is never supposed to happen, not even for deactivated
@ -246,7 +246,7 @@ function show_user_info_popover(element, user, message) {
return;
}
var is_sender_popover = message.sender_id === user.user_id;
const is_sender_popover = message.sender_id === user.user_id;
render_user_info_popover(user, elt, is_sender_popover, "respond_personal_button",
"message-info-popover", "right");
@ -255,7 +255,7 @@ function show_user_info_popover(element, user, message) {
}
function show_mobile_message_buttons_popover(element) {
var last_popover_elem = current_mobile_message_buttons_popover_elem;
const last_popover_elem = current_mobile_message_buttons_popover_elem;
exports.hide_all();
if (last_popover_elem !== undefined
&& last_popover_elem.get()[0] === element) {
@ -264,7 +264,7 @@ function show_mobile_message_buttons_popover(element) {
return;
}
var $element = $(element);
const $element = $(element);
$element.popover({
placement: "left",
template: render_mobile_message_buttons_popover(),
@ -293,13 +293,13 @@ exports.hide_user_profile = function () {
exports.show_user_profile = function (user) {
exports.hide_all();
var dateFormat = moment.localeData().longDateFormat('LL');
var field_types = page_params.custom_profile_field_types;
var profile_data = page_params.custom_profile_fields
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;});
var args = {
const args = {
full_name: user.full_name,
email: get_visible_email(user),
profile_data: profile_data,
@ -325,7 +325,7 @@ function get_user_info_popover_items() {
return;
}
var popover_data = current_message_info_popover_elem.data('popover');
const popover_data = current_message_info_popover_elem.data('popover');
if (!popover_data) {
blueslip.error('Cannot find popover data for actions menu.');
return;
@ -366,10 +366,10 @@ exports._test_sort_group_members = sort_group_members;
// user is the user whose profile to show
// message is the message containing it, which should be selected
function show_user_group_info_popover(element, group, message) {
var last_popover_elem = current_message_info_popover_elem;
const last_popover_elem = current_message_info_popover_elem;
// hardcoded pixel height of the popover
// note that the actual size varies (in group size), but this is about as big as it gets
var popover_size = 390;
const popover_size = 390;
exports.hide_all();
if (last_popover_elem !== undefined
&& last_popover_elem.get()[0] === element) {
@ -378,9 +378,9 @@ function show_user_group_info_popover(element, group, message) {
return;
}
current_msg_list.select_id(message.id);
var elt = $(element);
const elt = $(element);
if (elt.data('popover') === undefined) {
var args = {
const args = {
group_name: group.name,
group_description: group.description,
members: sort_group_members(fetch_group_members(group.members.keys())),
@ -398,7 +398,7 @@ function show_user_group_info_popover(element, group, message) {
}
exports.toggle_actions_popover = function (element, id) {
var last_popover_elem = current_actions_popover_elem;
const last_popover_elem = current_actions_popover_elem;
exports.hide_all();
if (last_popover_elem !== undefined
&& last_popover_elem.get()[0] === element) {
@ -409,12 +409,12 @@ exports.toggle_actions_popover = function (element, id) {
$(element).closest('.message_row').toggleClass('has_popover has_actions_popover');
current_msg_list.select_id(id);
var elt = $(element);
const elt = $(element);
if (elt.data('popover') === undefined) {
var message = current_msg_list.get(id);
var editability = message_edit.get_editability(message);
var use_edit_icon;
var editability_menu_item;
const message = current_msg_list.get(id);
const editability = message_edit.get_editability(message);
let use_edit_icon;
let editability_menu_item;
if (editability === message_edit.editability_types.FULL) {
use_edit_icon = true;
editability_menu_item = i18n.t("Edit");
@ -425,43 +425,43 @@ exports.toggle_actions_popover = function (element, id) {
use_edit_icon = false;
editability_menu_item = i18n.t("View source");
}
var topic = util.get_message_topic(message);
var can_mute_topic =
const topic = util.get_message_topic(message);
const can_mute_topic =
message.stream &&
topic &&
!muting.is_topic_muted(message.stream_id, topic);
var can_unmute_topic =
const can_unmute_topic =
message.stream &&
topic &&
muting.is_topic_muted(message.stream_id, topic);
var should_display_edit_history_option = _.any(message.edit_history, function (entry) {
var prev_topic = util.get_edit_event_prev_topic(entry);
const should_display_edit_history_option = _.any(message.edit_history, function (entry) {
const prev_topic = util.get_edit_event_prev_topic(entry);
return entry.prev_content !== undefined || prev_topic !== undefined;
}) && page_params.realm_allow_edit_history;
// Disabling this for /me messages is a temporary workaround
// for the fact that we don't have a styling for how that
// should look. See also condense.js.
var should_display_collapse = !message.locally_echoed &&
const should_display_collapse = !message.locally_echoed &&
!message.is_me_message &&
!message.collapsed;
var should_display_uncollapse = !message.locally_echoed &&
const should_display_uncollapse = !message.locally_echoed &&
!message.is_me_message &&
message.collapsed;
var should_display_edit_and_view_source =
const should_display_edit_and_view_source =
message.content !== '<p>(deleted)</p>' ||
editability === message_edit.editability_types.FULL ||
editability === message_edit.editability_types.TOPIC_ONLY;
var should_display_quote_and_reply = message.content !== '<p>(deleted)</p>';
const should_display_quote_and_reply = message.content !== '<p>(deleted)</p>';
var conversation_time_uri = hash_util.by_conversation_and_time_uri(message)
const conversation_time_uri = hash_util.by_conversation_and_time_uri(message)
.replace(/\(/g, '%28')
.replace(/\)/g, '%29');
var should_display_delete_option = message_edit.get_deletability(message);
var args = {
const should_display_delete_option = message_edit.get_deletability(message);
const args = {
message_id: message.id,
historical: message.historical,
stream_id: message.stream_id,
@ -482,7 +482,7 @@ exports.toggle_actions_popover = function (element, id) {
should_display_quote_and_reply: should_display_quote_and_reply,
};
var ypos = elt.offset().top;
const ypos = elt.offset().top;
elt.popover({
// Popover height with 7 items in it is ~190 px
placement: message_viewport.height() - ypos < 220 ? 'top' : 'bottom',
@ -500,13 +500,13 @@ exports.render_actions_remind_popover = function (element, id) {
exports.hide_all();
$(element).closest('.message_row').toggleClass('has_popover has_actions_popover');
current_msg_list.select_id(id);
var elt = $(element);
const elt = $(element);
if (elt.data('popover') === undefined) {
var message = current_msg_list.get(id);
var args = {
const message = current_msg_list.get(id);
const args = {
message: message,
};
var ypos = elt.offset().top;
const ypos = elt.offset().top;
elt.popover({
// Popover height with 7 items in it is ~190 px
placement: message_viewport.height() - ypos < 220 ? 'top' : 'bottom',
@ -533,7 +533,7 @@ function get_action_menu_menu_items() {
return;
}
var popover_data = current_actions_popover_elem.data('popover');
const popover_data = current_actions_popover_elem.data('popover');
if (!popover_data) {
blueslip.error('Cannot find popover data for actions menu.');
return;
@ -555,7 +555,7 @@ function popover_items_handle_keyboard(key, items) {
return;
}
var index = items.index(items.filter(':focus'));
let index = items.index(items.filter(':focus'));
if (key === "enter" && index >= 0 && index < items.length) {
return items[index].click();
@ -573,7 +573,7 @@ function popover_items_handle_keyboard(key, items) {
function focus_first_action_popover_item() {
// For now I recommend only calling this when the user opens the menu with a hotkey.
// Our popup menus act kind of funny when you mix keyboard and mouse.
var items = get_action_menu_menu_items();
const items = get_action_menu_menu_items();
focus_first_popover_item(items);
}
@ -585,7 +585,7 @@ exports.open_message_menu = function (message) {
return true;
}
var id = message.id;
const id = message.id;
exports.toggle_actions_popover($(".selected_message .actions_hover")[0], id);
if (current_actions_popover_elem) {
focus_first_action_popover_item();
@ -594,7 +594,7 @@ exports.open_message_menu = function (message) {
};
exports.actions_menu_handle_keyboard = function (key) {
var items = get_action_menu_menu_items();
const items = get_action_menu_menu_items();
popover_items_handle_keyboard(key, items);
};
@ -643,8 +643,8 @@ exports.show_pm_list_sidebar = function () {
resize.resize_page_components();
};
var current_user_sidebar_user_id;
var current_user_sidebar_popover;
let current_user_sidebar_user_id;
let current_user_sidebar_popover;
function user_sidebar_popped() {
return current_user_sidebar_popover !== undefined;
@ -667,21 +667,21 @@ exports.hide_user_sidebar_popover = function () {
function focus_user_info_popover_item() {
// For now I recommend only calling this when the user opens the menu with a hotkey.
// Our popup menus act kind of funny when you mix keyboard and mouse.
var items = get_user_info_popover_items();
const items = get_user_info_popover_items();
focus_first_popover_item(items);
}
exports.user_info_popover_handle_keyboard = function (key) {
var items = get_user_info_popover_items();
const items = get_user_info_popover_items();
popover_items_handle_keyboard(key, items);
};
exports.show_sender_info = function () {
var $message = $(".selected_message");
var $sender = $message.find('.sender_info_hover');
const $message = $(".selected_message");
const $sender = $message.find('.sender_info_hover');
var message = current_msg_list.get(rows.id($message));
var user = people.get_person_from_user_id(message.sender_id);
const message = current_msg_list.get(rows.id($message));
const user = people.get_person_from_user_id(message.sender_id);
show_user_info_popover($sender[0], user, message);
if (current_message_info_popover_elem) {
focus_user_info_popover_item();
@ -693,7 +693,7 @@ exports.show_sender_info = function () {
// side effect of closing popovers, which we don't want. So we
// suppress the first hide from scrolling after a resize using this
// variable.
var suppress_scroll_hide = false;
let suppress_scroll_hide = false;
exports.set_suppress_scroll_hide = function () {
suppress_scroll_hide = true;
@ -701,32 +701,32 @@ exports.set_suppress_scroll_hide = function () {
exports.register_click_handlers = function () {
$("#main_div").on("click", ".actions_hover", function (e) {
var row = $(this).closest(".message_row");
const row = $(this).closest(".message_row");
e.stopPropagation();
exports.toggle_actions_popover(this, rows.id(row));
});
$("#main_div").on("click", ".sender_name, .sender_name-in-status, .inline_profile_picture", function (e) {
var row = $(this).closest(".message_row");
const row = $(this).closest(".message_row");
e.stopPropagation();
var message = current_msg_list.get(rows.id(row));
var user = people.get_person_from_user_id(message.sender_id);
const message = current_msg_list.get(rows.id(row));
const user = people.get_person_from_user_id(message.sender_id);
show_user_info_popover(this, user, message);
});
$("#main_div").on("click", ".user-mention", function (e) {
var id = $(this).attr('data-user-id');
const id = $(this).attr('data-user-id');
// We fallback to email to handle legacy markdown that was rendered
// before we cut over to using data-user-id
var email = $(this).attr('data-user-email');
const email = $(this).attr('data-user-email');
if (id === '*' || email === '*') {
return;
}
var row = $(this).closest(".message_row");
const row = $(this).closest(".message_row");
e.stopPropagation();
var message = current_msg_list.get(rows.id(row));
var user;
const message = current_msg_list.get(rows.id(row));
let user;
if (id) {
user = people.get_person_from_user_id(id);
} else {
@ -736,11 +736,11 @@ exports.register_click_handlers = function () {
});
$("#main_div").on("click", ".user-group-mention", function (e) {
var id = $(this).attr('data-user-group-id');
var row = $(this).closest(".message_row");
const id = $(this).attr('data-user-group-id');
const row = $(this).closest(".message_row");
e.stopPropagation();
var message = current_msg_list.get(rows.id(row));
var group = user_groups.get_user_group_from_id(id, true);
const message = current_msg_list.get(rows.id(row));
const group = user_groups.get_user_group_from_id(id, true);
if (group === undefined) {
// This user group has likely been deleted.
blueslip.info('Unable to find user group in message' + message.sender_id);
@ -751,8 +751,8 @@ exports.register_click_handlers = function () {
$('body').on('click', '.info_popover_actions .narrow_to_private_messages', function (e) {
var user_id = $(e.target).parents('ul').attr('data-user-id');
var email = people.get_person_from_user_id(user_id).email;
const user_id = $(e.target).parents('ul').attr('data-user-id');
const email = people.get_person_from_user_id(user_id).email;
exports.hide_message_info_popover();
narrow.by('pm-with', email, {trigger: 'user sidebar popover'});
e.stopPropagation();
@ -760,8 +760,8 @@ exports.register_click_handlers = function () {
});
$('body').on('click', '.info_popover_actions .narrow_to_messages_sent', function (e) {
var user_id = $(e.target).parents('ul').attr('data-user-id');
var email = people.get_person_from_user_id(user_id).email;
const user_id = $(e.target).parents('ul').attr('data-user-id');
const email = people.get_person_from_user_id(user_id).email;
exports.hide_message_info_popover();
narrow.by('sender', email, {trigger: 'user sidebar popover'});
e.stopPropagation();
@ -772,9 +772,9 @@ exports.register_click_handlers = function () {
if (!compose_state.composing()) {
compose_actions.start('stream', {trigger: 'sidebar user actions'});
}
var user_id = $(e.target).parents('ul').attr('data-user-id');
var name = people.get_person_from_user_id(user_id).full_name;
var mention = people.get_mention_syntax(name, user_id);
const user_id = $(e.target).parents('ul').attr('data-user-id');
const name = people.get_person_from_user_id(user_id).full_name;
const mention = people.get_mention_syntax(name, user_id);
compose_ui.insert_syntax_and_focus(mention);
exports.hide_user_sidebar_popover();
exports.hide_userlist_sidebar();
@ -786,9 +786,9 @@ exports.register_click_handlers = function () {
if (!compose_state.composing()) {
compose_actions.respond_to_message({trigger: 'user sidebar popover'});
}
var user_id = $(e.target).parents('ul').attr('data-user-id');
var name = people.get_person_from_user_id(user_id).full_name;
var mention = people.get_mention_syntax(name, user_id);
const user_id = $(e.target).parents('ul').attr('data-user-id');
const name = people.get_person_from_user_id(user_id).full_name;
const mention = people.get_mention_syntax(name, user_id);
compose_ui.insert_syntax_and_focus(mention);
exports.hide_message_info_popover();
e.stopPropagation();
@ -796,8 +796,8 @@ exports.register_click_handlers = function () {
});
$('body').on('click', '.info_popover_actions .view_user_profile', function (e) {
var user_id = $(e.target).parents('ul').attr('data-user-id');
var user = people.get_person_from_user_id(user_id);
const user_id = $(e.target).parents('ul').attr('data-user-id');
const user = people.get_person_from_user_id(user_id);
exports.show_user_profile(user);
e.stopPropagation();
e.preventDefault();
@ -805,7 +805,7 @@ exports.register_click_handlers = function () {
$('body').on('click', '.info_popover_actions .clear_status', function (e) {
e.preventDefault();
var me = $(e.target).parents('ul').attr('data-user-id');
const me = $(e.target).parents('ul').attr('data-user-id');
user_status.server_update({
user_id: me,
status_text: '',
@ -816,8 +816,8 @@ exports.register_click_handlers = function () {
});
$('body').on('click', '.bot-owner-name', function (e) {
var user_id = $(e.target).attr('data-bot-owner-id');
var user = people.get_person_from_user_id(user_id);
const user_id = $(e.target).attr('data-bot-owner-id');
const user = people.get_person_from_user_id(user_id);
exports.show_user_profile(user);
});
@ -859,8 +859,8 @@ exports.register_click_handlers = function () {
// use email of currently selected user, rather than some elem comparison,
// as the presence list may be redrawn with new elements.
var target = $(this).closest('li');
var user_id = target.find('a').attr('data-user-id');
const target = $(this).closest('li');
const user_id = target.find('a').attr('data-user-id');
if (String(current_user_sidebar_user_id) === user_id) {
// If the popover is already shown, clicking again should toggle it.
@ -877,8 +877,8 @@ exports.register_click_handlers = function () {
stream_popover.show_streamlist_sidebar();
}
var user = people.get_person_from_user_id(user_id);
var popover_placement = userlist_placement === "left" ? "right" : "left";
const user = people.get_person_from_user_id(user_id);
const popover_placement = userlist_placement === "left" ? "right" : "left";
render_user_info_popover(user, target, false, "compose_private_message",
"user_popover", popover_placement);
@ -888,7 +888,7 @@ exports.register_click_handlers = function () {
});
$('body').on("mouseenter", ".user_popover_email", function () {
var tooltip_holder = $(this).find('div');
const tooltip_holder = $(this).find('div');
if (this.offsetWidth < this.scrollWidth) {
tooltip_holder.addClass('display-tooltip');
@ -910,7 +910,7 @@ exports.register_click_handlers = function () {
});
$('body').on('click', '.reminder_button', function (e) {
var message_id = $(e.currentTarget).data('message-id');
const message_id = $(e.currentTarget).data('message-id');
exports.render_actions_remind_popover($(".selected_message .actions_hover")[0], message_id);
e.stopPropagation();
e.preventDefault();
@ -923,7 +923,7 @@ exports.register_click_handlers = function () {
});
function reminder_click_handler(datestr, e) {
var id = $(".remind.custom").data('message-id');
const id = $(".remind.custom").data('message-id');
reminder.do_set_reminder_for_message(id, datestr);
exports.hide_all();
e.stopPropagation();
@ -931,27 +931,27 @@ exports.register_click_handlers = function () {
}
$('body').on('click', '.remind.in_20m', function (e) {
var datestr = moment().add(20, 'm').format();
const datestr = moment().add(20, 'm').format();
reminder_click_handler(datestr, e);
});
$('body').on('click', '.remind.in_1h', function (e) {
var datestr = moment().add(1, 'h').format();
const datestr = moment().add(1, 'h').format();
reminder_click_handler(datestr, e);
});
$('body').on('click', '.remind.in_3h', function (e) {
var datestr = moment().add(3, 'h').format();
const datestr = moment().add(3, 'h').format();
reminder_click_handler(datestr, e);
});
$('body').on('click', '.remind.tomo', function (e) {
var datestr = moment().add(1, 'd').hour(9).minute(0).seconds(0).format();
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) {
var datestr = moment().add(1, 'w').day('monday').hour(9).minute(0).seconds(0).format();
const datestr = moment().add(1, 'w').day('monday').hour(9).minute(0).seconds(0).format();
reminder_click_handler(datestr, e);
});
@ -961,13 +961,13 @@ exports.register_click_handlers = function () {
});
$('body').on('click', '.flatpickr-confirm', function (e) {
var datestr = $(".remind.custom")[0].value;
const datestr = $(".remind.custom")[0].value;
reminder_click_handler(datestr, e);
});
$('body').on('click', '.respond_personal_button, .compose_private_message', function (e) {
var user_id = $(e.target).parents('ul').attr('data-user-id');
var email = people.get_person_from_user_id(user_id).email;
const user_id = $(e.target).parents('ul').attr('data-user-id');
const email = people.get_person_from_user_id(user_id).email;
compose_actions.start('private', {
trigger: 'popover send private',
private_message_recipient: email});
@ -976,9 +976,9 @@ exports.register_click_handlers = function () {
e.preventDefault();
});
$('body').on('click', '.popover_toggle_collapse', function (e) {
var message_id = $(e.currentTarget).data('message-id');
var row = current_msg_list.get_row(message_id);
var message = current_msg_list.get(rows.id(row));
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));
exports.hide_actions_popover();
@ -994,18 +994,18 @@ exports.register_click_handlers = function () {
e.preventDefault();
});
$('body').on('click', '.popover_edit_message', function (e) {
var message_id = $(e.currentTarget).data('message-id');
var row = current_msg_list.get_row(message_id);
const message_id = $(e.currentTarget).data('message-id');
const row = current_msg_list.get_row(message_id);
exports.hide_actions_popover();
message_edit.start(row);
e.stopPropagation();
e.preventDefault();
});
$('body').on('click', '.view_edit_history', function (e) {
var message_id = $(e.currentTarget).data('message-id');
var row = current_msg_list.get_row(message_id);
var message = current_msg_list.get(rows.id(row));
var message_history_cancel_btn = $('#message-history-cancel');
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));
const message_history_cancel_btn = $('#message-history-cancel');
exports.hide_actions_popover();
message_edit.show_history(message);
@ -1015,8 +1015,8 @@ exports.register_click_handlers = function () {
});
$('body').on('click', '.popover_mute_topic', function (e) {
var stream_id = $(e.currentTarget).attr('data-msg-stream-id');
var topic = $(e.currentTarget).attr('data-msg-topic');
const stream_id = $(e.currentTarget).attr('data-msg-stream-id');
const topic = $(e.currentTarget).attr('data-msg-topic');
exports.hide_actions_popover();
muting_ui.mute(stream_id, topic);
@ -1025,8 +1025,8 @@ exports.register_click_handlers = function () {
});
$('body').on('click', '.popover_unmute_topic', function (e) {
var stream_id = $(e.currentTarget).attr('data-msg-stream-id');
var topic = $(e.currentTarget).attr('data-msg-topic');
const stream_id = $(e.currentTarget).attr('data-msg-stream-id');
const topic = $(e.currentTarget).attr('data-msg-topic');
exports.hide_actions_popover();
muting_ui.unmute(stream_id, topic);
@ -1035,7 +1035,7 @@ exports.register_click_handlers = function () {
});
$('body').on('click', '.delete_message', function (e) {
var message_id = $(e.currentTarget).data('message-id');
const message_id = $(e.currentTarget).data('message-id');
exports.hide_actions_popover();
message_edit.delete_message(message_id);
e.stopPropagation();
@ -1046,8 +1046,8 @@ exports.register_click_handlers = function () {
$('body').on('click', '.copy_link', function (e) {
exports.hide_actions_popover();
var id = $(this).attr("data-message-id");
var row = $("[zid='" + id + "']");
const id = $(this).attr("data-message-id");
const row = $("[zid='" + id + "']");
row.find(".alert-msg")
.text(i18n.t("Copied!"))
.css("display", "block")
@ -1064,7 +1064,7 @@ exports.register_click_handlers = function () {
});
(function () {
var last_scroll = 0;
let last_scroll = 0;
$('.app').on('scroll', function () {
if (suppress_scroll_hide) {
@ -1072,7 +1072,7 @@ exports.register_click_handlers = function () {
return;
}
var date = new Date().getTime();
const date = new Date().getTime();
// only run `popovers.hide_all()` if the last scroll was more
// than 250ms ago.
@ -1135,22 +1135,22 @@ exports.set_userlist_placement = function (placement) {
exports.compute_placement = function (elt, popover_height, popover_width,
prefer_vertical_positioning) {
var client_rect = elt.get(0).getBoundingClientRect();
var distance_from_top = client_rect.top;
var distance_from_bottom = message_viewport.height() - client_rect.bottom;
var distance_from_left = client_rect.left;
var distance_from_right = message_viewport.width() - client_rect.right;
const client_rect = elt.get(0).getBoundingClientRect();
const distance_from_top = client_rect.top;
const distance_from_bottom = message_viewport.height() - client_rect.bottom;
const distance_from_left = client_rect.left;
const distance_from_right = message_viewport.width() - client_rect.right;
var elt_will_fit_horizontally =
const elt_will_fit_horizontally =
distance_from_left + elt.width() / 2 > popover_width / 2 &&
distance_from_right + elt.width() / 2 > popover_width / 2;
var elt_will_fit_vertically =
const elt_will_fit_vertically =
distance_from_bottom + elt.height() / 2 > popover_height / 2 &&
distance_from_top + elt.height() / 2 > popover_height / 2;
// default to placing the popover in the center of the screen
var placement = 'viewport_center';
let placement = 'viewport_center';
// prioritize left/right over top/bottom
if (distance_from_top > popover_height && elt_will_fit_horizontally) {

View File

@ -216,7 +216,7 @@ function set_invite_to_stream_policy_dropdown() {
}
function set_user_group_edit_policy_dropdown() {
var value = get_property_value("realm_user_group_edit_policy");
const value = get_property_value("realm_user_group_edit_policy");
$("#id_realm_user_group_edit_policy").val(value);
}
@ -839,7 +839,7 @@ exports.build_page = function () {
data = {};
data.authentication_methods = JSON.stringify(get_auth_method_table_data());
} else if (subsection === 'user_defaults') {
var realm_default_twenty_four_hour_time = $('#id_realm_default_twenty_four_hour_time').val();
const realm_default_twenty_four_hour_time = $('#id_realm_default_twenty_four_hour_time').val();
data.default_twenty_four_hour_time = realm_default_twenty_four_hour_time;
}
return data;

View File

@ -1,7 +1,7 @@
var render_admin_user_group_list = require('../templates/admin_user_group_list.hbs');
var render_confirm_delete_user = require('../templates/confirm_delete_user.hbs');
const render_admin_user_group_list = require('../templates/admin_user_group_list.hbs');
const render_confirm_delete_user = require('../templates/confirm_delete_user.hbs');
var meta = {
const meta = {
loaded: false,
};
@ -14,7 +14,7 @@ exports.reload = function () {
return;
}
var user_groups_section = $('#user-groups').expectOne();
const user_groups_section = $('#user-groups').expectOne();
user_groups_section.html('');
exports.populate_user_groups();
};
@ -39,8 +39,8 @@ exports.can_edit = function (group_id) {
exports.populate_user_groups = function () {
var user_groups_section = $('#user-groups').expectOne();
var user_groups_array = user_groups.get_realm_user_groups();
const user_groups_section = $('#user-groups').expectOne();
const user_groups_array = user_groups.get_realm_user_groups();
_.each(user_groups_array, function (data) {
user_groups_section.append(render_admin_user_group_list({
user_group: {
@ -49,16 +49,16 @@ exports.populate_user_groups = function () {
description: data.description,
},
}));
var pill_container = $('.pill-container[data-group-pills="' + data.id + '"]');
var pills = user_pill.create_pills(pill_container);
const pill_container = $('.pill-container[data-group-pills="' + data.id + '"]');
const pills = user_pill.create_pills(pill_container);
function get_pill_user_ids() {
return user_pill.get_user_ids(pills);
}
var userg = $('div.user-group[id="' + data.id + '"]');
const userg = $('div.user-group[id="' + data.id + '"]');
data.members.keys().forEach(function (user_id) {
var user = people.get_person_from_user_id(user_id);
const user = people.get_person_from_user_id(user_id);
user_pill.append_user(user, pills);
});
@ -85,13 +85,13 @@ exports.populate_user_groups = function () {
update_membership(data.id);
function is_user_group_changed() {
var draft_group = get_pill_user_ids();
var group_data = user_groups.get_user_group_from_id(data.id);
var original_group = group_data.members.keys();
var same_groups = _.isEqual(_.sortBy(draft_group), _.sortBy(original_group));
var description = $('#user-groups #' + data.id + ' .description').text().trim();
var name = $('#user-groups #' + data.id + ' .name').text().trim();
var user_group_status = $('#user-groups #' + data.id + ' .user-group-status');
const draft_group = get_pill_user_ids();
const group_data = user_groups.get_user_group_from_id(data.id);
const original_group = group_data.members.keys();
const same_groups = _.isEqual(_.sortBy(draft_group), _.sortBy(original_group));
const description = $('#user-groups #' + data.id + ' .description').text().trim();
const name = $('#user-groups #' + data.id + ' .name').text().trim();
const user_group_status = $('#user-groups #' + data.id + ' .user-group-status');
if (user_group_status.is(':visible')) {
return false;
@ -108,9 +108,9 @@ exports.populate_user_groups = function () {
if (!exports.can_edit(data.id)) {
return;
}
var cancel_button = $('#user-groups #' + data.id + ' .save-status.btn-danger');
var saved_button = $('#user-groups #' + data.id + ' .save-status.sea-green');
var save_instructions = $('#user-groups #' + data.id + ' .save-instructions');
const cancel_button = $('#user-groups #' + data.id + ' .save-status.btn-danger');
const saved_button = $('#user-groups #' + data.id + ' .save-status.sea-green');
const save_instructions = $('#user-groups #' + data.id + ' .save-instructions');
if (is_user_group_changed() &&
!cancel_button.is(':visible')) {
@ -125,9 +125,9 @@ exports.populate_user_groups = function () {
}
function show_saved_button() {
var cancel_button = $('#user-groups #' + data.id + ' .save-status.btn-danger');
var saved_button = $('#user-groups #' + data.id + ' .save-status.sea-green');
var save_instructions = $('#user-groups #' + data.id + ' .save-instructions');
const cancel_button = $('#user-groups #' + data.id + ' .save-status.btn-danger');
const saved_button = $('#user-groups #' + data.id + ' .save-status.sea-green');
const save_instructions = $('#user-groups #' + data.id + ' .save-instructions');
if (!saved_button.is(':visible')) {
cancel_button.fadeOut(0);
save_instructions.fadeOut(0);
@ -136,15 +136,15 @@ exports.populate_user_groups = function () {
}
function save_members() {
var draft_group = get_pill_user_ids();
var group_data = user_groups.get_user_group_from_id(data.id);
var original_group = group_data.members.keys();
var same_groups = _.isEqual(_.sortBy(draft_group), _.sortBy(original_group));
const draft_group = get_pill_user_ids();
const group_data = user_groups.get_user_group_from_id(data.id);
const original_group = group_data.members.keys();
const same_groups = _.isEqual(_.sortBy(draft_group), _.sortBy(original_group));
if (!draft_group.length || same_groups) {
return;
}
var added = _.difference(draft_group, original_group);
var removed = _.difference(original_group, draft_group);
const added = _.difference(draft_group, original_group);
const removed = _.difference(original_group, draft_group);
channel.post({
url: "/json/user_groups/" + data.id + '/members',
data: {
@ -158,10 +158,10 @@ exports.populate_user_groups = function () {
}
function save_name_desc() {
var user_group_status = $('#user-groups #' + data.id + ' .user-group-status');
var group_data = user_groups.get_user_group_from_id(data.id);
var description = $('#user-groups #' + data.id + ' .description').text().trim();
var name = $('#user-groups #' + data.id + ' .name').text().trim();
const user_group_status = $('#user-groups #' + data.id + ' .user-group-status');
const group_data = user_groups.get_user_group_from_id(data.id);
const description = $('#user-groups #' + data.id + ' .description').text().trim();
const name = $('#user-groups #' + data.id + ' .name').text().trim();
if (group_data.description === description && group_data.name === name) {
return;
@ -178,7 +178,7 @@ exports.populate_user_groups = function () {
setTimeout(show_saved_button, 200);
},
error: function (xhr) {
var errors = JSON.parse(xhr.responseText).msg;
const errors = JSON.parse(xhr.responseText).msg;
xhr.responseText = JSON.stringify({msg: errors});
ui_report.error(i18n.t("Failed"), xhr, user_group_status);
update_cancel_button();
@ -194,7 +194,7 @@ exports.populate_user_groups = function () {
return true;
}
var blur_exceptions = _.without([".pill-container", ".name", ".description", ".input", ".delete"],
const blur_exceptions = _.without([".pill-container", ".name", ".description", ".input", ".delete"],
except_class);
if ($(event.relatedTarget).closest('#user-groups #' + data.id).length) {
return _.some(blur_exceptions, function (class_name) {
@ -239,7 +239,7 @@ exports.populate_user_groups = function () {
update_cancel_button();
});
var input = pill_container.children('.input');
const input = pill_container.children('.input');
if (exports.can_edit(data.id)) {
user_pill.set_up_typeahead_on_pills(input, pills, update_cancel_button);
}
@ -268,9 +268,9 @@ exports.set_up = function () {
e.preventDefault();
e.stopPropagation();
var user_group_status = $('#admin-user-group-status');
const user_group_status = $('#admin-user-group-status');
var group = {
const group = {
members: JSON.stringify([people.my_current_user_id()]),
};
_.each($(this).serializeArray(), function (obj) {
@ -290,7 +290,7 @@ exports.set_up = function () {
},
error: function (xhr) {
user_group_status.hide();
var errors = JSON.parse(xhr.responseText).msg;
const errors = JSON.parse(xhr.responseText).msg;
xhr.responseText = JSON.stringify({msg: errors});
ui_report.error(i18n.t("Failed"), xhr, user_group_status);
},
@ -298,12 +298,12 @@ exports.set_up = function () {
});
$('#user-groups').on('click', '.delete', function () {
var group_id = $(this).parents('.user-group').attr('id');
const group_id = $(this).parents('.user-group').attr('id');
if (!exports.can_edit(group_id)) {
return;
}
var user_group = user_groups.get_user_group_from_id(group_id);
var btn = $(this);
const user_group = user_groups.get_user_group_from_id(group_id);
const btn = $(this);
function delete_user_group() {
channel.del({
@ -322,9 +322,9 @@ exports.set_up = function () {
}
// This is mostly important for styling concerns.
var modal_parent = $('#settings_content');
const modal_parent = $('#settings_content');
var html_body = render_confirm_delete_user({
const html_body = render_confirm_delete_user({
group_name: user_group.name,
});

View File

@ -1,8 +1,8 @@
var render_announce_stream_docs = require('../templates/announce_stream_docs.hbs');
var render_new_stream_users = require('../templates/new_stream_users.hbs');
var render_subscription_invites_warning_modal = require('../templates/subscription_invites_warning_modal.hbs');
const render_announce_stream_docs = require('../templates/announce_stream_docs.hbs');
const render_new_stream_users = require('../templates/new_stream_users.hbs');
const render_subscription_invites_warning_modal = require('../templates/subscription_invites_warning_modal.hbs');
var created_stream;
let created_stream;
exports.reset_created_stream = function () {
created_stream = undefined;
@ -16,8 +16,8 @@ exports.get_name = function () {
return created_stream;
};
var stream_subscription_error = (function () {
var self = {};
const stream_subscription_error = (function () {
const self = {};
self.report_no_subs_to_stream = function () {
$("#stream_subscription_error").text(i18n.t("You cannot create a stream with no subscribers!"));
@ -37,8 +37,8 @@ var stream_subscription_error = (function () {
}());
var stream_name_error = (function () {
var self = {};
const stream_name_error = (function () {
const self = {};
self.report_already_exists = function () {
$("#stream_name_error").text(i18n.t("A stream with this name already exists"));
@ -118,7 +118,7 @@ function ajaxSubscribeForCreation(stream_name, description, principals, invite_o
// The rest of the work is done via the subscribe event we will get
},
error: function (xhr) {
var msg = JSON.parse(xhr.responseText).msg;
const msg = JSON.parse(xhr.responseText).msg;
if (msg.indexOf('access') >= 0) {
// If we can't access the stream, we can safely assume it's
// a duplicate stream that we are not invited to.
@ -143,11 +143,11 @@ function update_announce_stream_state() {
// If the stream is invite only, disable the "Announce stream" option.
// Otherwise enable it.
var announce_stream_checkbox = $('#announce-new-stream input');
var announce_stream_label = $('#announce-new-stream');
var disable_it = false;
var privacy_type = $('input:radio[name=privacy]:checked').val();
var is_invite_only = privacy_type === "invite-only" || privacy_type === "invite-only-public-history";
const announce_stream_checkbox = $('#announce-new-stream input');
const announce_stream_label = $('#announce-new-stream');
let disable_it = false;
const privacy_type = $('input:radio[name=privacy]:checked').val();
const is_invite_only = privacy_type === "invite-only" || privacy_type === "invite-only-public-history";
announce_stream_label.removeClass("control-label-disabled");
if (is_invite_only) {
@ -170,14 +170,14 @@ function get_principals() {
}
function create_stream() {
var stream_name = $.trim($("#create_stream_name").val());
var description = $.trim($("#create_stream_description").val());
var privacy_setting = $('#stream_creation_form input[name=privacy]:checked').val();
var is_announcement_only = $('#stream_creation_form input[name=is-announcement-only]').prop('checked');
var principals = get_principals();
const stream_name = $.trim($("#create_stream_name").val());
const description = $.trim($("#create_stream_description").val());
const privacy_setting = $('#stream_creation_form input[name=privacy]:checked').val();
const is_announcement_only = $('#stream_creation_form input[name=is-announcement-only]').prop('checked');
const principals = get_principals();
var invite_only;
var history_public_to_subscribers;
let invite_only;
let history_public_to_subscribers;
if (privacy_setting === 'invite-only') {
invite_only = true;
@ -192,7 +192,7 @@ function create_stream() {
created_stream = stream_name;
var announce = !!page_params.notifications_stream &&
const announce = !!page_params.notifications_stream &&
$('#announce-new-stream input').prop('checked');
// Even though we already check to make sure that while typing the user cannot enter
@ -254,16 +254,16 @@ exports.show_new_stream_modal = function () {
$("#stream-creation").removeClass("hide");
$(".right .settings").hide();
var all_users = people.get_rest_of_realm();
const all_users = people.get_rest_of_realm();
// Add current user on top of list
all_users.unshift(people.get_person_from_user_id(page_params.user_id));
var html = render_new_stream_users({
const html = render_new_stream_users({
users: all_users,
streams: stream_data.get_streams_for_settings_page(),
is_admin: page_params.is_admin,
});
var container = $('#people_to_add');
const container = $('#people_to_add');
container.html(html);
exports.create_handlers_for_users(container);
@ -281,14 +281,14 @@ exports.show_new_stream_modal = function () {
clear_error_display();
$("#stream-checkboxes label.checkbox").on('change', function (e) {
var elem = $(this);
var stream_id = elem.attr('data-stream-id');
var checked = elem.find('input').prop('checked');
var subscriber_ids = stream_data.get_sub_by_id(stream_id).subscribers;
const elem = $(this);
const stream_id = elem.attr('data-stream-id');
const checked = elem.find('input').prop('checked');
const subscriber_ids = stream_data.get_sub_by_id(stream_id).subscribers;
$('#user-checkboxes label.checkbox').each(function () {
var user_elem = $(this);
var user_id = user_elem.attr('data-user-id');
const user_elem = $(this);
const user_id = user_elem.attr('data-user-id');
if (subscriber_ids.has(user_id)) {
user_elem.find('input').prop('checked', checked);
@ -337,23 +337,23 @@ exports.create_handlers_for_users = function (container) {
// Search People or Streams
container.on('input', '.add-user-list-filter', function (e) {
var user_list = $(".add-user-list-filter");
const user_list = $(".add-user-list-filter");
if (user_list === 0) {
return;
}
var search_term = user_list.expectOne().val().trim();
var search_terms = search_term.toLowerCase().split(",");
const search_term = user_list.expectOne().val().trim();
const search_terms = search_term.toLowerCase().split(",");
(function filter_user_checkboxes() {
var user_labels = $("#user-checkboxes label.add-user-label");
const user_labels = $("#user-checkboxes label.add-user-label");
if (search_term === '') {
user_labels.css({display: 'block'});
return;
}
var users = people.get_rest_of_realm();
var filtered_users = people.filter_people_by_search_terms(users, search_terms);
const users = people.get_rest_of_realm();
const filtered_users = people.filter_people_by_search_terms(users, search_terms);
// Be careful about modifying the follow code. A naive implementation
// will work very poorly with a large user population (~1000 users).
@ -363,10 +363,10 @@ exports.create_handlers_for_users = function (container) {
// This would break the previous implementation, whereas the new
// implementation is merely sluggish.
user_labels.each(function () {
var elem = $(this);
var user_id = elem.attr('data-user-id');
var user_checked = filtered_users.has(user_id);
var display = user_checked ? "block" : "none";
const elem = $(this);
const user_id = elem.attr('data-user-id');
const user_checked = filtered_users.has(user_id);
const display = user_checked ? "block" : "none";
elem.css({display: display});
});
}());
@ -377,7 +377,7 @@ exports.create_handlers_for_users = function (container) {
exports.set_up_handlers = function () {
var container = $('#stream-creation').expectOne();
const container = $('#stream-creation').expectOne();
container.on('change', '#make-invite-only input', update_announce_stream_state);
@ -385,14 +385,14 @@ exports.set_up_handlers = function () {
e.preventDefault();
clear_error_display();
var stream_name = $.trim($("#create_stream_name").val());
var name_ok = stream_name_error.validate_for_submit(stream_name);
const stream_name = $.trim($("#create_stream_name").val());
const name_ok = stream_name_error.validate_for_submit(stream_name);
if (!name_ok) {
return;
}
var principals = get_principals();
const principals = get_principals();
if (principals.length === 0) {
stream_subscription_error.report_no_subs_to_stream();
return;
@ -403,7 +403,7 @@ exports.set_up_handlers = function () {
}
if (principals.length >= 50) {
var invites_warning_modal = render_subscription_invites_warning_modal({
const invites_warning_modal = render_subscription_invites_warning_modal({
stream_name: stream_name,
count: principals.length,
});
@ -423,14 +423,14 @@ exports.set_up_handlers = function () {
});
container.on("input", "#create_stream_name", function () {
var stream_name = $.trim($("#create_stream_name").val());
const stream_name = $.trim($("#create_stream_name").val());
// This is an inexpensive check.
stream_name_error.pre_validate(stream_name);
});
container.on("mouseover", "#announce-stream-docs", function (e) {
var announce_stream_docs = $("#announce-stream-docs");
const announce_stream_docs = $("#announce-stream-docs");
announce_stream_docs.popover({
placement: "right",
content: render_announce_stream_docs({

View File

@ -1,7 +1,7 @@
var render_subscription = require('../templates/subscription.hbs');
var render_subscription_settings = require('../templates/subscription_settings.hbs');
var render_subscription_table_body = require('../templates/subscription_table_body.hbs');
var render_subscriptions = require('../templates/subscriptions.hbs');
const render_subscription = require('../templates/subscription.hbs');
const render_subscription_settings = require('../templates/subscription_settings.hbs');
const render_subscription_table_body = require('../templates/subscription_table_body.hbs');
const render_subscriptions = require('../templates/subscriptions.hbs');
exports.show_subs_pane = {
nothing_selected: function () {
@ -15,7 +15,7 @@ exports.show_subs_pane = {
};
exports.check_button_for_sub = function (sub) {
var id = parseInt(sub.stream_id, 10);
const id = parseInt(sub.stream_id, 10);
return $(".stream-row[data-stream-id='" + id + "'] .check");
};
@ -26,14 +26,14 @@ exports.row_for_stream_id = function (stream_id) {
exports.settings_button_for_sub = function (sub) {
// We don't do expectOne() here, because this button is only
// visible if the user has that stream selected in the streams UI.
var id = parseInt(sub.stream_id, 10);
const id = parseInt(sub.stream_id, 10);
return $(".subscription_settings[data-stream-id='" + id + "'] .subscribe-button");
};
function get_row_data(row) {
var row_id = row.attr('data-stream-id');
const row_id = row.attr('data-stream-id');
if (row_id) {
var row_object = stream_data.get_sub_by_id(row_id);
const row_object = stream_data.get_sub_by_id(row_id);
return {
id: row_id,
object: row_object,
@ -42,9 +42,9 @@ function get_row_data(row) {
}
exports.get_active_data = function () {
var active_row = $('div.stream-row.active');
var valid_active_id = active_row.attr('data-stream-id');
var active_tab = $('.subscriptions-container').find('div.ind-tab.selected');
const active_row = $('div.stream-row.active');
const valid_active_id = active_row.attr('data-stream-id');
const active_tab = $('.subscriptions-container').find('div.ind-tab.selected');
return {
row: active_row,
id: valid_active_id,
@ -61,8 +61,8 @@ function get_hash_safe() {
}
function selectText(element) {
var range;
var sel;
let range;
let sel;
if (window.getSelection) {
sel = window.getSelection();
range = document.createRange();
@ -84,7 +84,7 @@ function should_list_all_streams() {
// this finds the stream that is actively open in the settings and focused in
// the left side.
exports.active_stream = function () {
var hash_components = window.location.hash.substr(1).split(/\//);
const hash_components = window.location.hash.substr(1).split(/\//);
// if the string casted to a number is valid, and another component
// after exists then it's a stream name/id pair.
@ -106,7 +106,7 @@ exports.toggle_pin_to_top_stream = function (sub) {
};
exports.maybe_update_realm_default_stream_name = function (stream_id, new_name) {
var idx = _.findIndex(page_params.realm_default_streams, function (stream) {
const idx = _.findIndex(page_params.realm_default_streams, function (stream) {
return stream.stream_id === stream_id;
});
if (idx === -1) {
@ -125,11 +125,11 @@ exports.is_subscribed_stream_tab_active = function () {
};
exports.update_stream_name = function (sub, new_name) {
var old_name = sub.name;
const old_name = sub.name;
// Rename the stream internally.
stream_data.rename_sub(sub, new_name);
var stream_id = sub.stream_id;
const stream_id = sub.stream_id;
// Update the left sidebar.
stream_list.rename_stream(sub, new_name);
@ -141,7 +141,7 @@ exports.update_stream_name = function (sub, new_name) {
stream_edit.update_stream_name(sub, new_name);
// Update the subscriptions page
var sub_row = exports.row_for_stream_id(stream_id);
const sub_row = exports.row_for_stream_id(stream_id);
sub_row.find(".stream-name").text(new_name);
// Update the message feed.
@ -161,7 +161,7 @@ exports.update_stream_description = function (sub, description, rendered_descrip
sub.rendered_description = rendered_description.replace('<p>', '').replace('</p>', '');
// Update stream row
var sub_row = exports.row_for_stream_id(sub.stream_id);
const sub_row = exports.row_for_stream_id(sub.stream_id);
sub_row.find(".description").html(sub.rendered_description);
// Update stream settings
@ -190,7 +190,7 @@ exports.update_stream_announcement_only = function (sub, new_value) {
};
exports.set_color = function (stream_id, color) {
var sub = stream_data.get_sub_by_id(stream_id);
const sub = stream_data.get_sub_by_id(stream_id);
stream_edit.set_stream_property(sub, 'color', color);
};
@ -218,8 +218,8 @@ exports.add_sub_to_table = function (sub) {
return;
}
var html = render_subscription(sub);
var settings_html = render_subscription_settings(sub);
const html = render_subscription(sub);
const settings_html = render_subscription_settings(sub);
if (stream_create.get_name() === sub.name) {
ui.get_content_element($(".streams-list")).prepend(html);
ui.reset_scrollbar($(".streams-list"));
@ -243,7 +243,7 @@ exports.add_sub_to_table = function (sub) {
exports.is_sub_already_present = function (sub) {
// This checks if a stream is already listed the "Manage streams"
// UI, by checking for its subscribe/unsubscribe checkmark button.
var button = exports.check_button_for_sub(sub);
const button = exports.check_button_for_sub(sub);
if (button.length !== 0) {
return true;
}
@ -253,9 +253,9 @@ exports.is_sub_already_present = function (sub) {
exports.remove_stream = function (stream_id) {
// It is possible that row is empty when we deactivate a
// stream, but we let jQuery silently handle that.
var row = exports.row_for_stream_id(stream_id);
const row = exports.row_for_stream_id(stream_id);
row.remove();
var sub = stream_data.get_sub_by_id(stream_id);
const sub = stream_data.get_sub_by_id(stream_id);
if (stream_edit.is_sub_settings_active(sub)) {
exports.show_subs_pane.nothing_selected();
}
@ -283,10 +283,10 @@ exports.update_settings_for_subscribed = function (sub) {
};
exports.show_active_stream_in_left_panel = function () {
var selected_row = get_hash_safe().split(/\//)[1];
const selected_row = get_hash_safe().split(/\//)[1];
if (parseFloat(selected_row)) {
var sub_row = exports.row_for_stream_id(selected_row);
const sub_row = exports.row_for_stream_id(selected_row);
sub_row.addClass("active");
}
};
@ -328,10 +328,10 @@ function triage_stream(query, sub) {
}
}
var search_terms = search_util.get_search_terms(query.input);
const search_terms = search_util.get_search_terms(query.input);
function match(attr) {
var val = sub[attr];
const val = sub[attr];
return search_util.vanilla_match({
val: val,
@ -354,15 +354,15 @@ function get_stream_id_buckets(stream_ids, query) {
// When we simplify the settings UI, we can get
// rid of the "others" bucket.
var buckets = {
const buckets = {
name: [],
desc: [],
other: [],
};
_.each(stream_ids, function (stream_id) {
var sub = stream_data.get_sub_by_id(stream_id);
var match_status = triage_stream(query, sub);
const sub = stream_data.get_sub_by_id(stream_id);
const match_status = triage_stream(query, sub);
if (match_status === 'name_match') {
buckets.name.push(stream_id);
@ -380,11 +380,11 @@ function get_stream_id_buckets(stream_ids, query) {
}
exports.populate_stream_settings_left_panel = function () {
var sub_rows = stream_data.get_updated_unsorted_subs();
var template_data = {
const sub_rows = stream_data.get_updated_unsorted_subs();
const template_data = {
subscriptions: sub_rows,
};
var html = render_subscriptions(template_data);
const html = render_subscriptions(template_data);
ui.get_content_element($('#subscriptions_table .streams-list')).html(html);
};
@ -393,26 +393,26 @@ exports.populate_stream_settings_left_panel = function () {
exports.filter_table = function (query) {
exports.show_active_stream_in_left_panel();
var widgets = {};
var streams_list_scrolltop = ui.get_scroll_element($(".streams-list")).scrollTop();
const widgets = {};
const streams_list_scrolltop = ui.get_scroll_element($(".streams-list")).scrollTop();
var stream_ids = [];
const stream_ids = [];
_.each($("#subscriptions_table .stream-row"), function (row) {
var stream_id = $(row).attr('data-stream-id');
const stream_id = $(row).attr('data-stream-id');
stream_ids.push(stream_id);
});
var buckets = get_stream_id_buckets(stream_ids, query);
const buckets = get_stream_id_buckets(stream_ids, query);
// If we just re-built the DOM from scratch we wouldn't need
// all this hidden/notdisplayed logic.
var hidden_ids = {};
const hidden_ids = {};
_.each(buckets.other, function (stream_id) {
hidden_ids[stream_id] = true;
});
_.each($("#subscriptions_table .stream-row"), function (row) {
var stream_id = $(row).attr('data-stream-id');
const stream_id = $(row).attr('data-stream-id');
// Below code goes away if we don't do sort-DOM-in-place.
if (hidden_ids[stream_id]) {
@ -428,7 +428,7 @@ exports.filter_table = function (query) {
ui.reset_scrollbar($("#subscription_overlay .streams-list"));
var all_stream_ids = [].concat(
const all_stream_ids = [].concat(
buckets.name,
buckets.desc,
buckets.other
@ -444,12 +444,12 @@ exports.filter_table = function (query) {
ui.get_scroll_element($(".streams-list")).scrollTop(streams_list_scrolltop);
};
var subscribed_only = true;
let subscribed_only = true;
exports.get_search_params = function () {
var search_box = $("#add_new_subscription input[type='text']");
var input = search_box.expectOne().val().trim();
var params = {
const search_box = $("#add_new_subscription input[type='text']");
const input = search_box.expectOne().val().trim();
const params = {
input: input,
subscribed_only: subscribed_only,
};
@ -465,11 +465,11 @@ exports.maybe_reset_right_panel = function () {
};
exports.actually_filter_streams = function () {
var search_params = exports.get_search_params();
const search_params = exports.get_search_params();
exports.filter_table(search_params);
};
var filter_streams = _.throttle(exports.actually_filter_streams, 50);
const filter_streams = _.throttle(exports.actually_filter_streams, 50);
// Make it explicit that our toggler is not created right away.
exports.toggler = undefined;
@ -518,7 +518,7 @@ exports.setup_page = function (callback) {
});
if (should_list_all_streams()) {
var toggler_elem = exports.toggler.get();
const toggler_elem = exports.toggler.get();
$("#subscriptions_table .search-container").prepend(toggler_elem);
}
if (page_params.is_guest) {
@ -533,7 +533,7 @@ exports.setup_page = function (callback) {
$('#subscriptions_table').empty();
var template_data = {
const template_data = {
can_create_streams: page_params.can_create_streams,
hide_all_streams: !should_list_all_streams(),
max_name_length: page_params.stream_name_max_length,
@ -541,7 +541,7 @@ exports.setup_page = function (callback) {
is_admin: page_params.is_admin,
};
var rendered = render_subscription_table_body(template_data);
const rendered = render_subscription_table_body(template_data);
$('#subscriptions_table').append(rendered);
exports.populate_stream_settings_left_panel();
@ -567,7 +567,7 @@ exports.setup_page = function (callback) {
};
exports.switch_to_stream_row = function (stream_id) {
var stream_row = exports.row_for_stream_id(stream_id);
const stream_row = exports.row_for_stream_id(stream_id);
exports.get_active_data().row.removeClass("active");
stream_row.addClass("active");
@ -605,7 +605,7 @@ exports.change_state = function (section) {
// if the section is a valid number.
if (/\d+/.test(section)) {
var stream_id = section;
const stream_id = section;
// Guest users can not access unsubscribed streams
// So redirect guest users to 'subscribed' tab
// for any unsubscribed stream settings hash
@ -640,8 +640,8 @@ exports.close = function () {
};
exports.switch_rows = function (event) {
var active_data = exports.get_active_data();
var switch_row;
const active_data = exports.get_active_data();
let switch_row;
if (window.location.hash === '#streams/new') {
// Prevent switching stream rows when creating a new stream
return false;
@ -663,9 +663,9 @@ exports.switch_rows = function (event) {
}
}
var row_data = get_row_data(switch_row);
const row_data = get_row_data(switch_row);
if (row_data) {
var stream_id = row_data.id;
const stream_id = row_data.id;
exports.switch_to_stream_row(stream_id);
} else if (event === 'up_arrow' && !row_data) {
$('#search_stream_name').focus();
@ -674,8 +674,8 @@ exports.switch_rows = function (event) {
};
exports.keyboard_sub = function () {
var active_data = exports.get_active_data();
var row_data = get_row_data(active_data.row);
const active_data = exports.get_active_data();
const row_data = get_row_data(active_data.row);
if (row_data) {
exports.sub_or_unsub(row_data.object);
if (row_data.object.subscribed && active_data.tab.text() === 'Subscribed') {
@ -686,7 +686,7 @@ exports.keyboard_sub = function () {
};
exports.toggle_view = function (event) {
var active_data = exports.get_active_data();
const active_data = exports.get_active_data();
if (event === 'right_arrow' && active_data.tab.text() === 'Subscribed') {
exports.toggler.goto('all-streams');
@ -696,17 +696,17 @@ exports.toggle_view = function (event) {
};
exports.view_stream = function () {
var active_data = exports.get_active_data();
var row_data = get_row_data(active_data.row);
const active_data = exports.get_active_data();
const row_data = get_row_data(active_data.row);
if (row_data) {
var stream_narrow_hash = '#narrow/stream/' + hash_util.encode_stream_name(row_data.object.name);
const stream_narrow_hash = '#narrow/stream/' + hash_util.encode_stream_name(row_data.object.name);
hashchange.go_to_location(stream_narrow_hash);
}
};
function ajaxSubscribe(stream, color) {
// Subscribe yourself to a single stream.
var true_stream_name;
let true_stream_name;
return channel.post({
url: "/json/users/me/subscriptions",
@ -716,7 +716,7 @@ function ajaxSubscribe(stream, color) {
$("#create_stream_name").val("");
}
var res = JSON.parse(xhr.responseText);
const res = JSON.parse(xhr.responseText);
if (!$.isEmptyObject(res.already_subscribed)) {
// Display the canonical stream capitalization.
true_stream_name = res.already_subscribed[people.my_current_email()][0];
@ -752,7 +752,7 @@ exports.do_open_create_stream = function () {
// Only call this directly for hash changes.
// Prefer open_create_stream().
var stream = $.trim($("#search_stream_name").val());
const stream = $.trim($("#search_stream_name").val());
if (!should_list_all_streams()) {
// Realms that don't allow listing streams should simply be subscribed to.
@ -809,11 +809,11 @@ exports.initialize = function () {
e.preventDefault();
$('#subscription-status').hide();
var stream_name = narrow_state.stream();
const stream_name = narrow_state.stream();
if (stream_name === undefined) {
return;
}
var sub = stream_data.get_sub(stream_name);
const sub = stream_data.get_sub(stream_name);
exports.sub_or_unsub(sub);
$('.empty_feed_notice').hide();
@ -831,7 +831,7 @@ exports.initialize = function () {
});
(function defocus_sub_settings() {
var sel = ".search-container, .streams-list, .subscriptions-header";
const sel = ".search-container, .streams-list, .subscriptions-header";
$("#subscriptions_table").on("click", sel, function (e) {
if ($(e.target).is(sel)) {

View File

@ -27,7 +27,7 @@ interface ExportLoaderOptions {
}
function getExposeLoaders(optionsArr: ExportLoaderOptions[]): RuleSetRule[] {
const exposeLoaders = [];
for (var loaderEntry of optionsArr) {
for (const loaderEntry of optionsArr) {
const path = loaderEntry.path;
let name = "";
const useArr = [cacheLoader];
@ -38,7 +38,7 @@ function getExposeLoaders(optionsArr: ExportLoaderOptions[]): RuleSetRule[] {
} else {
// If name is an array
if (Array.isArray(loaderEntry.name)) {
for (var exposeName of loaderEntry.name) {
for (const exposeName of loaderEntry.name) {
useArr.push({loader: 'expose-loader', options: exposeName});
}
// If name is a string

View File

@ -216,7 +216,7 @@ export default (env?: string): webpack.Configuration[] => {
// Expose Global variables for third party libraries to webpack modules
// Use the unminified versions of jquery and underscore so that
// Good error messages show up in production and development in the source maps
var exposeOptions = [
const exposeOptions = [
{ path: "blueimp-md5/js/md5.js" },
{ path: "clipboard/dist/clipboard.js", name: "ClipboardJS" },
{ path: "xdate/src/xdate.js", name: "XDate" },