resize_controller.js 975 B

123456789101112131415161718192021222324252627
  1. import { Controller } from '@hotwired/stimulus';
  2. export default class extends Controller {
  3. connect() {
  4. const main = document.querySelector('main')
  5. const form = document.querySelector('form')
  6. if (sessionStorage.getItem('size')) {
  7. main.classList.toggle('size-max', true)
  8. if (form) form.classList.toggle('size-max-form', true)
  9. } else {
  10. main.classList.toggle('size-max', false)
  11. if (form) form.classList.toggle('size-max-form', false)
  12. }
  13. }
  14. resize() {
  15. const main = document.querySelector('main')
  16. const form = document.querySelector('form')
  17. if (main.classList.toggle('size-max')) {
  18. if (form) form.classList.toggle('size-max-form', true)
  19. sessionStorage.setItem('size', 'size-max')
  20. } else {
  21. if (form) form.classList.toggle('size-max-form', false)
  22. sessionStorage.removeItem('size')
  23. }
  24. }
  25. }