summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/behaviors/markdown/highlight_current_user.js
blob: 0fac278573e4aea97ace235b11cf03078121a223 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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');
    }
  });
}