summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/behaviors
diff options
context:
space:
mode:
authorWinnie Hellmann <winnie@gitlab.com>2018-08-28 18:19:52 +0200
committerWinnie Hellmann <winnie@gitlab.com>2018-10-02 11:12:22 +0200
commit23563f5e0a5f3875289569126562f0f2fc63d3a6 (patch)
treedc7b3935d22f7ad12ef2508b0713e24780d7d95c /app/assets/javascripts/behaviors
parent7c1cfd0bf5fd394e0e4387e350d69767aa873f84 (diff)
downloadgitlab-ce-23563f5e0a5f3875289569126562f0f2fc63d3a6.tar.gz
Highlight current user in comments and system notes
Diffstat (limited to 'app/assets/javascripts/behaviors')
-rw-r--r--app/assets/javascripts/behaviors/markdown/highlight_current_user.js17
-rw-r--r--app/assets/javascripts/behaviors/markdown/render_gfm.js2
2 files changed, 19 insertions, 0 deletions
diff --git a/app/assets/javascripts/behaviors/markdown/highlight_current_user.js b/app/assets/javascripts/behaviors/markdown/highlight_current_user.js
new file mode 100644
index 00000000000..6208b3f0032
--- /dev/null
+++ b/app/assets/javascripts/behaviors/markdown/highlight_current_user.js
@@ -0,0 +1,17 @@
+/**
+ * Highlights the current user in existing elements with a user ID data attribute.
+ *
+ * @param elements DOM elements that represent user mentions
+ */
+export default function highlightCurrentUser(elements) {
+ const currentUserId = gon && gon.current_user_id;
+ if (!currentUserId) {
+ return;
+ }
+
+ elements.forEach(element => {
+ if (parseInt(element.dataset.user, 10) === currentUserId) {
+ element.classList.add('current-user');
+ }
+ });
+}
diff --git a/app/assets/javascripts/behaviors/markdown/render_gfm.js b/app/assets/javascripts/behaviors/markdown/render_gfm.js
index 429455f97ec..a2d4331b6d1 100644
--- a/app/assets/javascripts/behaviors/markdown/render_gfm.js
+++ b/app/assets/javascripts/behaviors/markdown/render_gfm.js
@@ -2,6 +2,7 @@ import $ from 'jquery';
import syntaxHighlight from '~/syntax_highlight';
import renderMath from './render_math';
import renderMermaid from './render_mermaid';
+import highlightCurrentUser from './highlight_current_user';
// Render GitLab flavoured Markdown
//
@@ -11,6 +12,7 @@ $.fn.renderGFM = function renderGFM() {
syntaxHighlight(this.find('.js-syntax-highlight'));
renderMath(this.find('.js-render-math'));
renderMermaid(this.find('.js-render-mermaid'));
+ highlightCurrentUser(this.find('.gfm-project_member').get());
return this;
};