mirror of https://github.com/zulip/zulip.git
topic lists: Refactor handling of parent element.
The widget that gets built in topic_list.build_widget() now knows how to add itself to its parent element and expose an interface to retrieve the parent.
This commit is contained in:
parent
3b7430ba82
commit
d8b5558699
|
@ -30,13 +30,15 @@ global.compile_template('topic_list_item');
|
||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
var widget = topic_list.build_widget(stream, active_topic, max_topics);
|
var parent_elem = $('<div>');
|
||||||
|
var widget = topic_list.build_widget(parent_elem, stream, active_topic, max_topics);
|
||||||
var topic_html = widget.get_dom();
|
var topic_html = widget.get_dom();
|
||||||
|
|
||||||
|
assert.equal(widget.get_parent(), parent_elem);
|
||||||
|
|
||||||
var topic = $(topic_html).find('a').text().trim();
|
var topic = $(topic_html).find('a').text().trim();
|
||||||
assert.equal(topic, 'coding');
|
assert.equal(topic, 'coding');
|
||||||
|
|
||||||
var output_html = '<div>' + topic_html.html() + '</div>';
|
global.write_test_output("test_topic_list_build_widget", parent_elem.html());
|
||||||
global.write_test_output("test_topic_list_build_widget", topic_html.html());
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ exports.set_count = function (stream_name, topic, count) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.build_widget = function (stream, active_topic, max_topics) {
|
exports.build_widget = function (parent_elem, stream, active_topic, max_topics) {
|
||||||
var self = {};
|
var self = {};
|
||||||
self.topic_items = new Dict({fold_case: true});
|
self.topic_items = new Dict({fold_case: true});
|
||||||
|
|
||||||
|
@ -86,6 +86,10 @@ exports.build_widget = function (stream, active_topic, max_topics) {
|
||||||
return ul;
|
return ul;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.get_parent = function () {
|
||||||
|
return parent_elem;
|
||||||
|
};
|
||||||
|
|
||||||
self.is_for_stream = function (stream_name) {
|
self.is_for_stream = function (stream_name) {
|
||||||
return stream === stream_name;
|
return stream === stream_name;
|
||||||
};
|
};
|
||||||
|
@ -124,6 +128,13 @@ exports.build_widget = function (stream, active_topic, max_topics) {
|
||||||
|
|
||||||
self.dom = build_list(stream, active_topic, max_topics);
|
self.dom = build_list(stream, active_topic, max_topics);
|
||||||
|
|
||||||
|
parent_elem.append(self.dom);
|
||||||
|
|
||||||
|
if (active_topic) {
|
||||||
|
self.activate_topic(active_topic);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -131,18 +142,8 @@ exports.rebuild = function (stream_li, stream) {
|
||||||
var max_topics = 5;
|
var max_topics = 5;
|
||||||
|
|
||||||
var active_topic = narrow.topic();
|
var active_topic = narrow.topic();
|
||||||
|
|
||||||
exports.remove_expanded_topics();
|
exports.remove_expanded_topics();
|
||||||
|
active_widget = exports.build_widget(stream_li, stream, active_topic, max_topics);
|
||||||
var widget = exports.build_widget(stream, active_topic, max_topics);
|
|
||||||
|
|
||||||
stream_li.append(widget.get_dom());
|
|
||||||
|
|
||||||
if (active_topic) {
|
|
||||||
widget.activate_topic(active_topic);
|
|
||||||
}
|
|
||||||
|
|
||||||
active_widget = widget; // set our global
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// For zooming, we only do topic-list stuff here...let stream_list
|
// For zooming, we only do topic-list stuff here...let stream_list
|
||||||
|
|
Loading…
Reference in New Issue