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.

46 lines
1.6 KiB

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