index.js 1.2 KB

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