mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
Move get_topic_filter_li to topic_list.js.
This also brought along:
iterate_to_find (copied, see large comment explaining why)
activate_topic (extracted from a one-liner)
set_count (formerly stream_list.set_subject_count)
For get_topic_filter_li, we now pass in stream_li instead of
stream to decouple parent/child responsibilities between the
components.
Also, I made some s/subject/topic/ fixes.
This commit is contained in:
@@ -2,6 +2,31 @@ var topic_list = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
function iterate_to_find(selector, name_to_find, context) {
|
||||
// This code is duplicated with stream_list.js, but we should
|
||||
// not try to de-dup this; instead, we should try to make it sane
|
||||
// for topics and avoid O(N) iteration.
|
||||
//
|
||||
// We could start by using canonical lowercase values for the
|
||||
// data-name attributes (and eventually use topic ids when the
|
||||
// back end allows). Either that, or we should have a data
|
||||
// structure that links topic names to list items, so that we
|
||||
// don't have to search the DOM at all.
|
||||
var lowercase_name = name_to_find.toLowerCase();
|
||||
var found = _.find($(selector, context), function (elem) {
|
||||
return $(elem).attr('data-name').toLowerCase() === lowercase_name;
|
||||
});
|
||||
return found ? $(found) : $();
|
||||
}
|
||||
|
||||
function get_topic_filter_li(stream_li, topic) {
|
||||
return iterate_to_find(".expanded_subjects li.expanded_subject", topic, stream_li);
|
||||
}
|
||||
|
||||
exports.activate_topic = function (stream_li, active_topic) {
|
||||
get_topic_filter_li(stream_li, active_topic).addClass('active-sub-filter');
|
||||
};
|
||||
|
||||
exports.update_count_in_dom = function (count_span, value_span, count) {
|
||||
if (count === 0) {
|
||||
count_span.hide();
|
||||
@@ -13,6 +38,19 @@ exports.update_count_in_dom = function (count_span, value_span, count) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.set_count = function (stream_li, topic, count) {
|
||||
var topic_li = get_topic_filter_li(stream_li, topic);
|
||||
var count_span = topic_li.find('.subject_count');
|
||||
var value_span = count_span.find('.value');
|
||||
|
||||
if (count_span.length === 0 || value_span.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
exports.update_count_in_dom(count_span, value_span, count);
|
||||
};
|
||||
|
||||
|
||||
return exports;
|
||||
}());
|
||||
if (typeof module !== 'undefined') {
|
||||
|
||||
Reference in New Issue
Block a user