From 6f230945c2fe05036ee9d4d4e129bdb6105f64b4 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 23 Mar 2017 13:14:19 -0400 Subject: [PATCH] UX: Clear the header when navigating to a new topic --- .../components/topic-list-item.js.es6 | 9 +++++++- .../discourse/helpers/topic-link.js.es6 | 21 +++++++++++++------ .../discourse/lib/intercept-click.js.es6 | 2 ++ .../templates/list/topic-list-item.raw.hbs | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/discourse/components/topic-list-item.js.es6 b/app/assets/javascripts/discourse/components/topic-list-item.js.es6 index 9fdd978cd6c..34dfadf0f8b 100644 --- a/app/assets/javascripts/discourse/components/topic-list-item.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-list-item.js.es6 @@ -1,3 +1,4 @@ +import DiscourseURL from 'discourse/lib/url'; import computed from 'ember-addons/ember-computed-decorators'; import { bufferedRender } from 'discourse-common/lib/buffered-render'; import { findRawTemplate } from 'discourse/lib/raw-templates'; @@ -111,8 +112,8 @@ export default Ember.Component.extend(bufferedRender({ const target = $(e.target); if (target.hasClass('bulk-select')) { const selected = this.get('selected'); - const topic = this.get('topic'); + const topic = this.get('topic'); if (target.is(':checked')) { selected.addObject(topic); } else { @@ -120,6 +121,12 @@ export default Ember.Component.extend(bufferedRender({ } } + if (target.hasClass('raw-topic-link')) { + this.appEvents.trigger('header:hide-topic'); + DiscourseURL.routeTo(target.attr('href')); + return false; + } + if (target.closest('a.topic-status').length === 1) { this.get('topic').togglePinnedForUser(); return false; diff --git a/app/assets/javascripts/discourse/helpers/topic-link.js.es6 b/app/assets/javascripts/discourse/helpers/topic-link.js.es6 index 2c1d61606f6..b71649495bc 100644 --- a/app/assets/javascripts/discourse/helpers/topic-link.js.es6 +++ b/app/assets/javascripts/discourse/helpers/topic-link.js.es6 @@ -1,11 +1,20 @@ import { registerUnbound } from 'discourse-common/lib/helpers'; -registerUnbound('topic-link', function(topic) { - var title = topic.get('fancyTitle'); - var url = topic.linked_post_number ? topic.urlForPostNumber(topic.linked_post_number) : topic.get('lastUnreadUrl'); +registerUnbound('topic-link', (topic, args) => { + const title = topic.get('fancyTitle'); + const url = topic.linked_post_number ? + topic.urlForPostNumber(topic.linked_post_number) : + topic.get('lastUnreadUrl'); - var extraClass = topic.get('last_read_post_number') === topic.get('highest_post_number') ? " visited" : ""; - var string = "" + title + ""; + const classes = ['title']; + if (topic.get('last_read_post_number') === topic.get('highest_post_number')) { + classes.push('visited'); + } - return new Handlebars.SafeString(string); + if (args.class) { + args.class.split(" ").forEach(c => classes.push(c)); + } + + const result = `${title}`; + return new Handlebars.SafeString(result); }); diff --git a/app/assets/javascripts/discourse/lib/intercept-click.js.es6 b/app/assets/javascripts/discourse/lib/intercept-click.js.es6 index 758164e784d..c7ee4b63330 100644 --- a/app/assets/javascripts/discourse/lib/intercept-click.js.es6 +++ b/app/assets/javascripts/discourse/lib/intercept-click.js.es6 @@ -22,6 +22,7 @@ export default function interceptClick(e) { $currentTarget.data('auto-route') || $currentTarget.data('share-url') || $currentTarget.hasClass('widget-link') || + $currentTarget.hasClass('raw-link') || $currentTarget.hasClass('mention') || (!$currentTarget.hasClass('d-link') && !$currentTarget.data('user-card') && @@ -29,6 +30,7 @@ export default function interceptClick(e) { $currentTarget.hasClass('lightbox') || href.indexOf("mailto:") === 0 || (href.match(/^http[s]?:\/\//i) && !href.match(new RegExp("^https?:\\/\\/" + window.location.hostname, "i")))) { + return; } diff --git a/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs b/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs index b88602c0a08..d38f958ab30 100644 --- a/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs +++ b/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs @@ -8,7 +8,7 @@ {{raw-plugin-outlet name="topic-list-before-status"}} {{raw "topic-status" topic=topic}} - {{topic-link topic}} + {{topic-link topic class="raw-link raw-topic-link"}} {{#if topic.featured_link}} {{topic-featured-link topic}} {{/if}}