activity.js: Consolidate initialization code.

We now intialize user-list-filter within activity.initialize(),
which gives us more control to set the module variable
`meta.$user_list_filter` before we build the user sidebar,
while setting up its handlers after we build the sidebar.
This commit is contained in:
Steve Howell 2017-10-07 09:57:44 -07:00 committed by Tim Abbott
parent 662b5ffbba
commit 3ef2df363b
2 changed files with 12 additions and 7 deletions

View File

@ -240,6 +240,8 @@ presence.presence_info[mark.user_id] = { status: activity.IDLE };
presence.presence_info[norbert.user_id] = { status: activity.ACTIVE };
presence.presence_info[zoe.user_id] = { status: activity.ACTIVE };
activity.set_user_list_filter();
(function test_presence_list_full_update() {
var users = activity.build_user_sidebar();
assert.deepEqual(users, [{
@ -369,6 +371,7 @@ $('.user-list-filter').is = function (sel) {
};
compose_actions.start = function () {};
activity.set_user_list_filter_handlers();
var keydown_handler = $('.user-list-filter').get_on_handler('keydown');
keydown_handler(e);
}());
@ -504,7 +507,7 @@ presence.presence_info[zoe.user_id] = { status: activity.ACTIVE };
// Reset jquery here.
set_global('$', global.make_zjquery());
activity.initialize_filter_state();
activity.set_user_list_filter();
(function test_insert_unfiltered_user_with_filter() {
// This test only tests that we do not explode when

View File

@ -488,9 +488,14 @@ exports.initialize = function () {
page_params.initial_servertime);
delete page_params.presences;
exports.set_user_list_filter();
exports.build_user_sidebar();
exports.update_huddles();
exports.set_user_list_filter_handlers();
$('#clear_search_people_button').on('click', exports.clear_search);
// Let the server know we're here, but pass "false" for
// want_redraw, since we just got all this info in page_params.
focus_ping(false);
@ -598,21 +603,18 @@ function focus_user_filter(e) {
update_clear_search_button();
}
exports.initialize_filter_state = function () {
exports.set_user_list_filter = function () {
meta.$user_list_filter = $(".user-list-filter");
};
exports.set_user_list_filter_handlers = function () {
meta.$user_list_filter.expectOne()
.on('click', focus_user_filter)
.on('input', update_users_for_search)
.on('keydown', maybe_select_person)
.on('blur', update_clear_search_button);
$('#clear_search_people_button').on('click', exports.clear_search);
};
$(function () {
exports.initialize_filter_state();
});
return exports;
}());