summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/behaviors/markdown/highlight_current_user.js
blob: 6208b3f0032a1be6619f3936fae7266d285c20db (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');
    }
  });
}