فهرست منبع

Close moes and stag popups on ESC

Vijayakrishnan 4 سال پیش
والد
کامیت
67a15f4b4a
2فایلهای تغییر یافته به همراه30 افزوده شده و 1 حذف شده
  1. 18 1
      public/js/yemi.js
  2. 12 0
      resources/views/layouts/template.blade.php

+ 18 - 1
public/js/yemi.js

@@ -308,7 +308,8 @@ var initMoes = function() {
                             hideMoeFormMask();
                             $(realForm).toggle(100);
                         }else{
-                            if($(realForm).is('form')) $(realForm)[0].reset();
+                            // keep data in moes, don't force reset
+                            // if($(realForm).is('form')) $(realForm)[0].reset();
                             showMoeFormMask();
                             setTimeout(function() {
                                 $('[moe]>form:not([show]):visible').hide();
@@ -954,3 +955,19 @@ $(function () {
         });
     });
 });
+
+// catch ESC and discard any visible moes
+$(document).ready(function () {
+    $(document)
+        .off('keydown.moe-escape')
+        .on('keydown.moe-escape', function (e) {
+            if(e.which === 27) {
+                let visibleMoes = $('[moe] [url]:not([show]):visible');
+                if (visibleMoes.length) {
+                    hideMoeFormMask();
+                    visibleMoes.hide();
+                    return false;
+                }
+            }
+        });
+});

+ 12 - 0
resources/views/layouts/template.blade.php

@@ -290,6 +290,18 @@
                         closeStagPopup();
                     }
                 });
+                // catch ESC and discard any visible popups
+                $(document)
+                    .off('keydown.stag-popup-escape')
+                    .on('keydown.stag-popup-escape', function (e) {
+                        if(e.which === 27) {
+                            let visiblePopups = $('.stag-popup.show');
+                            if (visiblePopups.length) {
+                                closeStagPopup();
+                                return false;
+                            }
+                        }
+                    });
             }
             addMCInitializer('stag-popups', window.initStagPopupEvents);
         })();