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.

53 lines
1.5 KiB

  1. // This file will be loaded on public pages, regardless of theme.
  2. import createHistory from 'history/createBrowserHistory';
  3. import ready from '../mastodon/ready';
  4. const { delegate } = require('rails-ujs');
  5. const { length } = require('stringz');
  6. ready(() => {
  7. const history = createHistory();
  8. const detailedStatuses = document.querySelectorAll('.public-layout .detailed-status');
  9. const location = history.location;
  10. if (detailedStatuses.length == 1 && (!location.state || !location.state.scrolledToDetailedStatus)) {
  11. detailedStatuses[0].scrollIntoView();
  12. history.replace(location.pathname, {...location.state, scrolledToDetailedStatus: true});
  13. }
  14. });
  15. delegate(document, '.webapp-btn', 'click', ({ target, button }) => {
  16. if (button !== 0) {
  17. return true;
  18. }
  19. window.location.href = target.href;
  20. return false;
  21. });
  22. delegate(document, '.status__content__spoiler-link', 'click', ({ target }) => {
  23. const contentEl = target.parentNode.parentNode.querySelector('.e-content');
  24. if (contentEl.style.display === 'block') {
  25. contentEl.style.display = 'none';
  26. target.parentNode.style.marginBottom = 0;
  27. } else {
  28. contentEl.style.display = 'block';
  29. target.parentNode.style.marginBottom = null;
  30. }
  31. return false;
  32. });
  33. delegate(document, '.modal-button', 'click', e => {
  34. e.preventDefault();
  35. let href;
  36. if (e.target.nodeName !== 'A') {
  37. href = e.target.parentNode.href;
  38. } else {
  39. href = e.target.href;
  40. }
  41. window.open(href, 'mastodon-intent', 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes');
  42. });