stag-popup.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. function showStagPopup(_key, _noAutoFocus) {
  2. $('html, body').addClass('no-scroll');
  3. let stagPopup = $('[stag-popup-key="' + _key + '"]');
  4. stagPopup.addClass('show');
  5. stagPopup.find('[moe][initialized]').removeAttr('initialized');
  6. initMoes();
  7. if(!_noAutoFocus) {
  8. window.setTimeout(function() {
  9. stagPopup.find('input[type="text"]:not([readonly]):visible,select:visible').first().focus();
  10. }, 150);
  11. }
  12. return false;
  13. }
  14. function submitStagPopup(_form) {
  15. if(!_form[0].checkValidity()) {
  16. _form[0].reportValidity();
  17. return false;
  18. }
  19. showMask();
  20. $.post(_form.attr('action'), _form.serialize(), function(_data) {
  21. fastReload();
  22. });
  23. return false;
  24. }
  25. function closeStagPopup() {
  26. $('.stag-popup').removeClass('show');
  27. $('html, body').removeClass('no-scroll');
  28. return false;
  29. }
  30. (function() {
  31. window.initStagPopupEvents = function () {
  32. $(document).on('click', '.stag-popup', function(_e) {
  33. if($(_e.target).is('.stag-popup')) {
  34. closeStagPopup();
  35. }
  36. });
  37. // catch ESC and discard any visible popups
  38. $(document)
  39. .off('keydown.stag-popup-escape')
  40. .on('keydown.stag-popup-escape', function (e) {
  41. if(e.which === 27) {
  42. let visiblePopups = $('.stag-popup.show');
  43. if (visiblePopups.length) {
  44. closeStagPopup();
  45. return false;
  46. }
  47. }
  48. });
  49. }
  50. addMCInitializer('stag-popups', window.initStagPopupEvents);
  51. })();