Skip to content

A platform for community discussion. Free, open, simple.

Add extensibility endpoints for clicking on topic list item rows

Robin Wardea9c1e5cf899
diff --git a/app/assets/javascripts/discourse/components/latest-topic-list-item.js.es6 b/app/assets/javascripts/discourse/components/latest-topic-list-item.js.es6
index d8fd285316e..6a78bf877d6 100644
--- a/app/assets/javascripts/discourse/components/latest-topic-list-item.js.es6
+++ b/app/assets/javascripts/discourse/components/latest-topic-list-item.js.es6
@@ -1,7 +1,21 @@
-import { showEntrance } from "discourse/components/topic-list-item";
+import { showEntrance, navigateToTopic } from "discourse/components/topic-list-item";
export default Ember.Component.extend({
- click: showEntrance,
attributeBindings: ['topic.id:data-topic-id'],
- classNameBindings: [':latest-topic-list-item', 'topic.archived', 'topic.visited']
+ classNameBindings: [':latest-topic-list-item', 'topic.archived', 'topic.visited'],
+
+ showEntrance,
+ navigateToTopic,
+
+ click(e) {
+ // for events undefined has a different meaning than false
+ if (this.showEntrance(e) === false) {
+ return false;
+ }
+
+ return this.unhandledRowClick(e, this.get('topic'));
+ },
+
+ // Can be overwritten by plugins to handle clicks on other parts of the row
+ unhandledRowClick() { },
});
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 7793fbd1b9f..f9b3cd38b76 100644
--- a/app/assets/javascripts/discourse/components/topic-list-item.js.es6
+++ b/app/assets/javascripts/discourse/components/topic-list-item.js.es6
@@ -20,6 +20,12 @@ export function showEntrance(e) {
}
}
+export function navigateToTopic(topic, href) {
+ this.appEvents.trigger('header:update-topic', topic);
+ DiscourseURL.routeTo(href || topic.get('url'));
+ return false;
+}
+
export default Ember.Component.extend(bufferedRender({
rerenderTriggers: ['bulkSelectEnabled', 'topic.pinned'],
tagName: 'tr',
@@ -107,8 +113,10 @@ export default Ember.Component.extend(bufferedRender({
return false;
}.property(),
+ showEntrance,
+
click(e) {
- const result = showEntrance.call(this, e);
+ const result = this.showEntrance(e);
if (result === false) { return result; }
const topic = this.get('topic');
@@ -124,19 +132,23 @@ export default Ember.Component.extend(bufferedRender({
}
if (target.hasClass('raw-topic-link')) {
- if (wantsNewWindow(e)) { return true; }
-
- this.appEvents.trigger('header:update-topic', topic);
- DiscourseURL.routeTo(target.attr('href'));
- return false;
+ if (wantsNewWindow(e)) { return true; }
+ return this.navigateToTopic(topic, target.attr('href'));
}
if (target.closest('a.topic-status').length === 1) {
this.get('topic').togglePinnedForUser();
return false;
}
+
+ return this.unhandledRowClick(e, topic);
},
+ navigateToTopic,
+
+ // Can be overwritten by plugins to handle clicks on other parts of the row
+ unhandledRowClick() { },
+
highlight(opts = { isLastViewedTopic: false }) {
const $topic = this.$();
$topic