comment-by-viewer.es6.js 649 B

12345678910111213141516171819202122232425
  1. /**
  2. * @file
  3. * Attaches behaviors for the Comment module's "by-viewer" class.
  4. */
  5. (function($, Drupal, drupalSettings) {
  6. /**
  7. * Add 'by-viewer' class to comments written by the current user.
  8. *
  9. * @type {Drupal~behavior}
  10. */
  11. Drupal.behaviors.commentByViewer = {
  12. attach(context) {
  13. const currentUserID = parseInt(drupalSettings.user.uid, 10);
  14. $('[data-comment-user-id]')
  15. .filter(function() {
  16. return (
  17. parseInt(this.getAttribute('data-comment-user-id'), 10) ===
  18. currentUserID
  19. );
  20. })
  21. .addClass('by-viewer');
  22. },
  23. };
  24. })(jQuery, Drupal, drupalSettings);