comment-by-viewer.es6.js 613 B

12345678910111213141516171819202122
  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 parseInt(this.getAttribute('data-comment-user-id'), 10) === currentUserID;
  17. })
  18. .addClass('by-viewer');
  19. },
  20. };
  21. }(jQuery, Drupal, drupalSettings));