From 8c9488a9040016520f8e5797ecbe834bf7251fc6 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sat, 29 Oct 2016 11:19:25 -0700 Subject: [PATCH] Add topic_list.build_widget(). This gets us closer to a component model for topic lists. --- frontend_tests/node_tests/stream_list.js | 7 +- static/js/topic_list.js | 93 +++++++++++++----------- 2 files changed, 56 insertions(+), 44 deletions(-) diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js index 3fae028190..67e45ce07b 100644 --- a/frontend_tests/node_tests/stream_list.js +++ b/frontend_tests/node_tests/stream_list.js @@ -34,7 +34,7 @@ global.use_template('stream_sidebar_row'); global.use_template('stream_privacy'); global.use_template('topic_list_item'); -(function test_topic_list_build_list() { +(function test_topic_list_build_widget() { var stream = "devel"; var active_topic = "testing"; var max_topics = 5; @@ -47,8 +47,9 @@ global.use_template('topic_list_item'); return 1; }; - var topic_html = topic_list.build_list(stream, active_topic, max_topics); - global.write_test_output("test_topic_list_build_list", topic_html); + var widget = topic_list.build_widget(stream, active_topic, max_topics); + var topic_html = widget.get_dom(); + global.write_test_output("test_topic_list_build_widget", topic_html); var topic = $(topic_html).find('a').text().trim(); assert.equal(topic, 'coding'); diff --git a/static/js/topic_list.js b/static/js/topic_list.js index 22bd5292dd..1d396d18dd 100644 --- a/static/js/topic_list.js +++ b/static/js/topic_list.js @@ -55,52 +55,63 @@ exports.set_count = function (stream_li, topic, count) { update_count_in_dom(count_span, value_span, count); }; -exports.build_list = function (stream, active_topic, max_topics) { - var topics = stream_data.get_recent_topics(stream) || []; +exports.build_widget = function (stream, active_topic, max_topics) { + var self = {}; - if (active_topic) { - active_topic = active_topic.toLowerCase(); - } + function build_list(stream, active_topic, max_topics) { + var topics = stream_data.get_recent_topics(stream) || []; - var hiding_topics = false; - - var ul = $('