From 71f808dea9c66cb7f6e6fe7905642a825bd2fa2a Mon Sep 17 00:00:00 2001 From: Keegan George Date: Fri, 1 Nov 2024 04:44:08 +0900 Subject: [PATCH] DEV: Improve method of presenting link clicks (#29453) Currently the tracking for clicked links are injected into the HTML in a span tag. This leads to the link counter value being highlighted when copying and pasting. Additionally, any means for using CSS to hide link counters result in a gap due to it occupying a specific width. With this change, we make link counters appear in a data attribute on the link element and visually shown with CSS `::after` element. --- .../components/topic-map/topic-map-link.gjs | 3 +++ .../topic-map/topic-map-summary.gjs | 8 +------ .../discourse/app/templates/user/summary.hbs | 10 ++------ .../discourse/app/widgets/post-cooked.js | 19 +++++++-------- .../discourse/app/widgets/post-links.js | 10 ++++---- .../tests/acceptance/composer-test.js | 2 +- .../discourse/tests/acceptance/topic-test.js | 6 ++++- .../components/widgets/post-test.js | 23 +++++++++++++++---- app/assets/stylesheets/common/base/topic.scss | 8 +++---- .../stylesheets/common/components/badges.scss | 11 --------- .../common/components/topic-map.scss | 15 ++++++++---- .../stylesheets/common/foundation/mixins.scss | 18 +++++++++++++++ .../stylesheets/common/printer-friendly.scss | 2 +- app/assets/stylesheets/wcag.scss | 3 ++- config/locales/client.en.yml | 3 +++ 15 files changed, 82 insertions(+), 59 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/topic-map/topic-map-link.gjs b/app/assets/javascripts/discourse/app/components/topic-map/topic-map-link.gjs index 347f6665d2e..d8f64ec4672 100644 --- a/app/assets/javascripts/discourse/app/components/topic-map/topic-map-link.gjs +++ b/app/assets/javascripts/discourse/app/components/topic-map/topic-map-link.gjs @@ -1,5 +1,6 @@ import Component from "@glimmer/component"; import replaceEmoji from "discourse/helpers/replace-emoji"; +import i18n from "discourse-common/helpers/i18n"; import and from "truth-helpers/helpers/and"; const TRUNCATE_LENGTH_LIMIT = 85; @@ -27,6 +28,8 @@ export default class TopicMapLink extends Component { data-ignore-post-id="true" target="_blank" rel="nofollow ugc noopener noreferrer" + data-clicks={{@clickCount}} + aria-label={{i18n "topic_map.clicks" count=@clickCount}} > {{#if @title}} {{replaceEmoji this.truncatedContent}} diff --git a/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs b/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs index 3d379249ffe..14a39278c10 100644 --- a/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs +++ b/app/assets/javascripts/discourse/app/components/topic-map/topic-map-summary.gjs @@ -344,19 +344,13 @@ export default class TopicMapSummary extends Component {