stag-popup.js 2.2 KB

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