From 1f9f00a629f2f013cf358bd6a9683dd701f2acb1 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Sun, 4 Nov 2018 11:23:45 +0200 Subject: [PATCH] DEV: Add data-topic-id to more elements containing titles. --- .../discourse/components/composer-action-title.js.es6 | 6 +++--- .../javascripts/discourse/helpers/topic-link.js.es6 | 2 +- app/assets/javascripts/discourse/templates/topic.hbs | 2 +- .../discourse/widgets/header-topic-info.js.es6 | 1 + app/assets/javascripts/discourse/widgets/link.js.es6 | 8 +++++++- app/assets/javascripts/discourse/widgets/post.js.es6 | 6 +++++- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/components/composer-action-title.js.es6 b/app/assets/javascripts/discourse/components/composer-action-title.js.es6 index 55a437ffa38..25fc7f4ddbc 100644 --- a/app/assets/javascripts/discourse/components/composer-action-title.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-action-title.js.es6 @@ -66,9 +66,9 @@ export default Ember.Component.extend({ }, _formatReplyToTopic(link) { - return `${ - link.anchor - }`.htmlSafe(); + return `${link.anchor}`.htmlSafe(); }, _formatReplyToUserPost(avatar, link) { diff --git a/app/assets/javascripts/discourse/helpers/topic-link.js.es6 b/app/assets/javascripts/discourse/helpers/topic-link.js.es6 index 32a55cf9891..31e6a6af5aa 100644 --- a/app/assets/javascripts/discourse/helpers/topic-link.js.es6 +++ b/app/assets/javascripts/discourse/helpers/topic-link.js.es6 @@ -11,6 +11,6 @@ registerUnbound("topic-link", (topic, args) => { args.class.split(" ").forEach(c => classes.push(c)); } - const result = `${title}`; + const result = `${title}`; return new Handlebars.SafeString(result); }); diff --git a/app/assets/javascripts/discourse/templates/topic.hbs b/app/assets/javascripts/discourse/templates/topic.hbs index 400a7efb4de..b87bf86c34a 100644 --- a/app/assets/javascripts/discourse/templates/topic.hbs +++ b/app/assets/javascripts/discourse/templates/topic.hbs @@ -44,7 +44,7 @@ {{else}} -

+

{{#unless model.is_warning}} {{#if siteSettings.enable_personal_messages}} diff --git a/app/assets/javascripts/discourse/widgets/header-topic-info.js.es6 b/app/assets/javascripts/discourse/widgets/header-topic-info.js.es6 index 6f79883cae6..def37089aa6 100644 --- a/app/assets/javascripts/discourse/widgets/header-topic-info.js.es6 +++ b/app/assets/javascripts/discourse/widgets/header-topic-info.js.es6 @@ -40,6 +40,7 @@ export default createWidget("header-topic-info", { className: "topic-link", action: "jumpToTopPost", href, + attributes: { "data-topic-id": topic.get("id") }, contents: () => titleHTML }) ); diff --git a/app/assets/javascripts/discourse/widgets/link.js.es6 b/app/assets/javascripts/discourse/widgets/link.js.es6 index 24d62c3eeb8..841fda069f5 100644 --- a/app/assets/javascripts/discourse/widgets/link.js.es6 +++ b/app/assets/javascripts/discourse/widgets/link.js.es6 @@ -35,12 +35,18 @@ export default createWidget("link", { }, buildAttributes(attrs) { - return { + const ret = { href: this.href(attrs), title: attrs.title ? I18n.t(attrs.title, attrs.titleOptions) : this.label(attrs) }; + if (attrs.attributes) { + Object.keys(attrs.attributes).forEach( + k => (ret[k] = attrs.attributes[k]) + ); + } + return ret; }, label(attrs) { diff --git a/app/assets/javascripts/discourse/widgets/post.js.es6 b/app/assets/javascripts/discourse/widgets/post.js.es6 index 0c646963de4..51a46c97fb5 100644 --- a/app/assets/javascripts/discourse/widgets/post.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post.js.es6 @@ -464,7 +464,11 @@ createWidget("post-article", { }, buildAttributes(attrs) { - return { "data-post-id": attrs.id, "data-user-id": attrs.user_id }; + return { + "data-post-id": attrs.id, + "data-topic-id": attrs.topicId, + "data-user-id": attrs.user_id + }; }, html(attrs, state) {