stag-popup.js 1.8 KB

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