index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import $ from 'jquery';
  2. import './add';
  3. import './move';
  4. import './delete';
  5. import './unset';
  6. import './disable-buttons';
  7. import PageMedia, { Instance as PageMediaInstances } from './media';
  8. import './multilang';
  9. const switcher = $('input[type="radio"][name="mode-switch"]');
  10. if (switcher) {
  11. let link = switcher.closest(':checked').data('leave-url');
  12. let fakeLink = $(`<a href="${link}" />`);
  13. switcher.parent().append(fakeLink);
  14. switcher.siblings('label').on('mousedown touchdown', (event) => {
  15. event.preventDefault();
  16. // let remodal = $.remodal.lookup[$('[data-remodal-id="changes"]').data('remodal')];
  17. let confirm = $('[data-remodal-id="changes"] [data-leave-action="continue"]');
  18. confirm.one('click', () => {
  19. $(global).on('beforeunload._grav');
  20. fakeLink.off('click._grav');
  21. $(event.target).trigger('click');
  22. });
  23. fakeLink.trigger('click._grav');
  24. });
  25. switcher.on('change', (event) => {
  26. let radio = $(event.target);
  27. link = radio.data('leave-url');
  28. setTimeout(() => fakeLink.attr('href', link).get(0).click(), 5);
  29. });
  30. }
  31. export default {
  32. Media: {
  33. PageMedia,
  34. PageMediaInstances
  35. }
  36. };