summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/behaviors/markdown/highlight_current_user.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/behaviors/markdown/highlight_current_user.js')
-rw-r--r--app/assets/javascripts/behaviors/markdown/highlight_current_user.js17
1 files changed, 17 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');
+ }
+ });
+}