comment-by-viewer.js 640 B

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