mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
This introduces a generic class called list_cursor to handle the main details of navigating the buddy list and wires it into activity.js. It replaces some fairly complicated code that was coupled to stream_list and used lots of jQuery. The new code interacts with the buddy_list API instead of jQuery directly. It also persists the key across redraws, so we don't lose our place when a focus ping happens or we type more characters. Note that we no longer cycle to the top when we hit the bottom, or vice versa. Cycling can be kind of an anti-feature when you want to just lay on the arrow keys until they hit the end. The changes to stream_list.js here do not affect the left sidebar; they only remove code that was used for the right sidebar.
117 lines
2.7 KiB
JavaScript
117 lines
2.7 KiB
JavaScript
var user_search = function (opts) {
|
|
// This is mostly view code to manage the user search widget
|
|
// above the buddy list. We rely on other code to manage the
|
|
// details of populating the list when we change.
|
|
|
|
var self = {};
|
|
|
|
var $widget = $('#user-list .input-append').expectOne();
|
|
var $input = $('.user-list-filter').expectOne();
|
|
|
|
self.input_field = function () {
|
|
return $input;
|
|
};
|
|
|
|
self.text = function () {
|
|
return $input.val().trim();
|
|
};
|
|
|
|
self.searching = function () {
|
|
return $input.is(':focus');
|
|
};
|
|
|
|
self.empty = function () {
|
|
return self.text() === '';
|
|
};
|
|
|
|
self.clear_search = function () {
|
|
if (self.empty()) {
|
|
self.close_widget();
|
|
return;
|
|
}
|
|
|
|
$input.val('');
|
|
$input.blur();
|
|
opts.reset_items();
|
|
};
|
|
|
|
self.escape_search = function () {
|
|
if (self.empty()) {
|
|
self.close_widget();
|
|
return;
|
|
}
|
|
|
|
$input.val('');
|
|
opts.update_list();
|
|
};
|
|
|
|
self.hide_widget = function () {
|
|
$widget.addClass('notdisplayed');
|
|
};
|
|
|
|
self.show_widget = function () {
|
|
$widget.removeClass('notdisplayed');
|
|
};
|
|
|
|
self.widget_shown = function () {
|
|
return $widget.hasClass('notdisplayed');
|
|
};
|
|
|
|
self.clear_and_hide_search = function () {
|
|
if (!self.empty()) {
|
|
$input.val('');
|
|
opts.update_list();
|
|
}
|
|
self.close_widget();
|
|
};
|
|
|
|
self.close_widget = function () {
|
|
$input.blur();
|
|
self.hide_widget();
|
|
opts.reset_items();
|
|
};
|
|
|
|
self.expand_column = function () {
|
|
var column = $input.closest(".app-main [class^='column-']");
|
|
if (!column.hasClass("expanded")) {
|
|
popovers.hide_all();
|
|
if (column.hasClass('column-left')) {
|
|
stream_popover.show_streamlist_sidebar();
|
|
} else if (column.hasClass('column-right')) {
|
|
popovers.show_userlist_sidebar();
|
|
}
|
|
}
|
|
};
|
|
|
|
self.initiate_search = function () {
|
|
self.expand_column();
|
|
self.show_widget();
|
|
$input.focus();
|
|
};
|
|
|
|
self.toggle_filter_displayed = function () {
|
|
if (self.widget_shown()) {
|
|
self.initiate_search();
|
|
} else {
|
|
self.clear_and_hide_search();
|
|
}
|
|
};
|
|
|
|
function on_focus(e) {
|
|
opts.on_focus();
|
|
e.stopPropagation();
|
|
}
|
|
|
|
$('#clear_search_people_button').on('click', self.clear_search);
|
|
$('#userlist-header').on('click', self.toggle_filter_displayed);
|
|
|
|
$input.on('input', opts.update_list);
|
|
$input.on('focus', on_focus);
|
|
|
|
return self;
|
|
};
|
|
|
|
if (typeof module !== 'undefined') {
|
|
module.exports = user_search;
|
|
}
|