You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.4 KiB

  1. import { delegate } from 'rails-ujs';
  2. function handleDeleteStatus(event) {
  3. const [data] = event.detail;
  4. const element = document.querySelector(`[data-id="${data.id}"]`);
  5. if (element) {
  6. element.parentNode.removeChild(element);
  7. }
  8. }
  9. [].forEach.call(document.querySelectorAll('.trash-button'), (content) => {
  10. content.addEventListener('ajax:success', handleDeleteStatus);
  11. });
  12. const batchCheckboxClassName = '.batch-checkbox input[type="checkbox"]';
  13. delegate(document, '#batch_checkbox_all', 'change', ({ target }) => {
  14. [].forEach.call(document.querySelectorAll(batchCheckboxClassName), (content) => {
  15. content.checked = target.checked;
  16. });
  17. });
  18. delegate(document, batchCheckboxClassName, 'change', () => {
  19. const checkAllElement = document.querySelector('#batch_checkbox_all');
  20. if (checkAllElement) {
  21. checkAllElement.checked = [].every.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked);
  22. }
  23. });
  24. delegate(document, '.media-spoiler-show-button', 'click', () => {
  25. [].forEach.call(document.querySelectorAll('.activity-stream .media-spoiler-wrapper'), (content) => {
  26. content.classList.add('media-spoiler-wrapper__visible');
  27. });
  28. });
  29. delegate(document, '.media-spoiler-hide-button', 'click', () => {
  30. [].forEach.call(document.querySelectorAll('.activity-stream .media-spoiler-wrapper'), (content) => {
  31. content.classList.remove('media-spoiler-wrapper__visible');
  32. });
  33. });