comments.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function (Drupal, once) {
  8. function init(comments) {
  9. comments.querySelectorAll('[data-drupal-selector="comment"]').forEach(function (comment) {
  10. if (comment.nextElementSibling != null && comment.nextElementSibling.matches('.indented')) {
  11. comment.classList.add('has-children');
  12. }
  13. });
  14. comments.querySelectorAll('.indented').forEach(function (commentGroup) {
  15. var showHideWrapper = document.createElement('div');
  16. showHideWrapper.setAttribute('class', 'show-hide-wrapper');
  17. var toggleCommentsBtn = document.createElement('button');
  18. toggleCommentsBtn.setAttribute('type', 'button');
  19. toggleCommentsBtn.setAttribute('aria-expanded', 'true');
  20. toggleCommentsBtn.setAttribute('class', 'show-hide-btn');
  21. toggleCommentsBtn.innerText = Drupal.t('Replies');
  22. commentGroup.parentNode.insertBefore(showHideWrapper, commentGroup);
  23. showHideWrapper.appendChild(toggleCommentsBtn);
  24. toggleCommentsBtn.addEventListener('click', function (e) {
  25. commentGroup.classList.toggle('hidden');
  26. e.currentTarget.setAttribute('aria-expanded', commentGroup.classList.contains('hidden') ? 'false' : 'true');
  27. });
  28. });
  29. }
  30. Drupal.behaviors.comments = {
  31. attach: function attach(context) {
  32. once('comments', '[data-drupal-selector="comments"]', context).forEach(init);
  33. }
  34. };
  35. })(Drupal, once);