闭社主体 forked from https://github.com/tootsuite/mastodon
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.

48 lines
1.8 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. checkAllElement.indeterminate = !checkAllElement.checked && [].some.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked);
  23. }
  24. });
  25. delegate(document, '.media-spoiler-show-button', 'click', () => {
  26. [].forEach.call(document.querySelectorAll('button.media-spoiler'), (element) => {
  27. element.click();
  28. });
  29. });
  30. delegate(document, '.media-spoiler-hide-button', 'click', () => {
  31. [].forEach.call(document.querySelectorAll('.spoiler-button.spoiler-button--visible button'), (element) => {
  32. element.click();
  33. });
  34. });
  35. delegate(document, '#domain_block_severity', 'change', ({ target }) => {
  36. const rejectMediaDiv = document.querySelector('.input.with_label.domain_block_reject_media');
  37. if (rejectMediaDiv) {
  38. rejectMediaDiv.style.display = (target.value === 'suspend') ? 'none' : 'block';
  39. }
  40. });