From 8429105c2413e891baaa0f51e2b278272f768ac0 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 17 Sep 2013 17:04:44 -0400 Subject: [PATCH] Add chevron menu for topics in left sidebar. The first menu option supported is to narrow to the topic. The chevron only shows up if you turn on feature_flags.muting. (imported from commit 17482f538a6d3e4ff96a36c042bad972d34f4b11) --- static/js/popovers.js | 64 ++++++++++++++++++- static/js/stream_list.js | 1 + static/js/ui.js | 3 + .../templates/sidebar_subject_list.handlebars | 5 ++ .../topic_sidebar_actions.handlebars | 8 +++ 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 static/templates/topic_sidebar_actions.handlebars diff --git a/static/js/popovers.js b/static/js/popovers.js index 5c2b54ce5d..e4efcb43b8 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -145,6 +145,7 @@ exports.show_streamlist_sidebar = function () { }; var current_stream_sidebar_elem; +var current_topic_sidebar_elem; var current_user_sidebar_elem; function user_sidebar_popped() { @@ -155,6 +156,10 @@ function stream_sidebar_popped() { return current_stream_sidebar_elem !== undefined; } +function topic_sidebar_popped() { + return current_topic_sidebar_elem !== undefined; +} + exports.hide_stream_sidebar_popover = function () { if (stream_sidebar_popped()) { $(current_stream_sidebar_elem).popover("destroy"); @@ -162,6 +167,13 @@ exports.hide_stream_sidebar_popover = function () { } }; +exports.hide_topic_sidebar_popover = function () { + if (topic_sidebar_popped()) { + $(current_topic_sidebar_elem).popover("destroy"); + current_topic_sidebar_elem = undefined; + } +}; + exports.hide_user_sidebar_popover = function () { if (user_sidebar_popped()) { $(current_user_sidebar_elem).closest("li").popover("destroy"); @@ -253,6 +265,55 @@ exports.register_click_handlers = function () { e.preventDefault(); }); + + $('#stream_filters').on('click', '.topic-sidebar-arrow', function (e) { + var elt = e.target; + + if (topic_sidebar_popped() + && current_topic_sidebar_elem === elt) { + // If the popover is already shown, clicking again should toggle it. + popovers.hide_topic_sidebar_popover(); + e.stopPropagation(); + return; + } + + popovers.hide_all(); + popovers.show_streamlist_sidebar(); + + var stream_name = $(elt).closest('.expanded_subjects').expectOne().attr('data-stream'); + var topic_name = $(elt).closest('li').expectOne().attr('data-name'); + + var content = templates.render('topic_sidebar_actions', { + 'stream_name': stream_name, + 'topic_name': topic_name + }); + + $(elt).popover({ + content: content, + trigger: "manual", + fixed: true + }); + + $(elt).popover("show"); + + current_topic_sidebar_elem = elt; + e.stopPropagation(); + }); + + $('body').on('click', '.narrow_to_topic', function (e) { + popovers.hide_topic_sidebar_popover(); + + var row = $(e.currentTarget).closest('.narrow_to_topic').expectOne(); + var stream_name = row.attr('data-stream-name'); + var topic_name = row.attr('data-topic-name'); + + var operators = [['stream', stream_name], ['topic', topic_name]]; + var opts = {select_first_unread: true, trigger: 'sidebar'}; + narrow.activate(operators, opts); + + e.stopPropagation(); + }); + $('#stream_filters').on('click', '.stream-sidebar-arrow', function (e) { var elt = e.target; if (stream_sidebar_popped() @@ -441,13 +502,14 @@ exports.register_click_handlers = function () { exports.any_active = function () { // True if any popover (that this module manages) is currently shown. - return popovers.actions_popped() || user_sidebar_popped() || stream_sidebar_popped() || message_info_popped(); + return popovers.actions_popped() || user_sidebar_popped() || stream_sidebar_popped() || topic_sidebar_popped() || message_info_popped(); }; exports.hide_all = function () { popovers.hide_actions_popover(); popovers.hide_message_info_popover(); popovers.hide_stream_sidebar_popover(); + popovers.hide_topic_sidebar_popover(); popovers.hide_user_sidebar_popover(); popovers.hide_userlist_sidebar(); popovers.hide_streamlist_sidebar(); diff --git a/static/js/stream_list.js b/static/js/stream_list.js index e1c7ee35b6..040c74b6d6 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -198,6 +198,7 @@ function rebuild_recent_subjects(stream, subject) { stream_li.append(templates.render('sidebar_subject_list', {subjects: display_subjects, + topic_sidebar_arrow: feature_flags.muting, stream: stream})); if (active_orig_subject !== undefined) { diff --git a/static/js/ui.js b/static/js/ui.js index be1ca98f3b..70b65a1f39 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -1275,6 +1275,9 @@ $(function () { if (exports.home_tab_obscured()) { ui.change_tab_to('#home'); } + + popovers.hide_all(); + var stream = $(e.target).parents('ul').attr('data-stream'); var subject = $(e.target).parents('li').attr('data-name'); diff --git a/static/templates/sidebar_subject_list.handlebars b/static/templates/sidebar_subject_list.handlebars index f8faa4fe7a..015eab57fc 100644 --- a/static/templates/sidebar_subject_list.handlebars +++ b/static/templates/sidebar_subject_list.handlebars @@ -9,6 +9,11 @@
{{unread}}
+ {{#if ../topic_sidebar_arrow}} + + + + {{/if}} {{/each}} diff --git a/static/templates/topic_sidebar_actions.handlebars b/static/templates/topic_sidebar_actions.handlebars new file mode 100644 index 0000000000..d75f9d501f --- /dev/null +++ b/static/templates/topic_sidebar_actions.handlebars @@ -0,0 +1,8 @@ +