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.

43 lines
1.5 KiB

  1. // This file will be loaded on admin pages, regardless of theme.
  2. import { delegate } from 'rails-ujs';
  3. function handleDeleteStatus(event) {
  4. const [data] = event.detail;
  5. const element = document.querySelector(`[data-id="${data.id}"]`);
  6. if (element) {
  7. element.parentNode.removeChild(element);
  8. }
  9. }
  10. [].forEach.call(document.querySelectorAll('.trash-button'), (content) => {
  11. content.addEventListener('ajax:success', handleDeleteStatus);
  12. });
  13. const batchCheckboxClassName = '.batch-checkbox input[type="checkbox"]';
  14. delegate(document, '#batch_checkbox_all', 'change', ({ target }) => {
  15. [].forEach.call(document.querySelectorAll(batchCheckboxClassName), (content) => {
  16. content.checked = target.checked;
  17. });
  18. });
  19. delegate(document, batchCheckboxClassName, 'change', () => {
  20. const checkAllElement = document.querySelector('#batch_checkbox_all');
  21. if (checkAllElement) {
  22. checkAllElement.checked = [].every.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked);
  23. checkAllElement.indeterminate = !checkAllElement.checked && [].some.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked);
  24. }
  25. });
  26. delegate(document, '.media-spoiler-show-button', 'click', () => {
  27. [].forEach.call(document.querySelectorAll('button.media-spoiler'), (element) => {
  28. element.click();
  29. });
  30. });
  31. delegate(document, '.media-spoiler-hide-button', 'click', () => {
  32. [].forEach.call(document.querySelectorAll('.spoiler-button.spoiler-button--visible button'), (element) => {
  33. element.click();
  34. });
  35. });