瀏覽代碼

Move stag-popup functionality into stag-popup.js

Vijayakrishnan 4 年之前
父節點
當前提交
09c315837e
共有 2 個文件被更改,包括 52 次插入53 次删除
  1. 51 0
      public/js/stag-popup.js
  2. 1 53
      resources/views/layouts/template.blade.php

+ 51 - 0
public/js/stag-popup.js

@@ -0,0 +1,51 @@
+function showStagPopup(_key, _noAutoFocus) {
+    $('html, body').addClass('no-scroll');
+    let stagPopup = $('[stag-popup-key="' + _key + '"]');
+    stagPopup.addClass('show');
+    stagPopup.find('[moe][initialized]').removeAttr('initialized');
+    initMoes();
+    if(!_noAutoFocus) {
+        window.setTimeout(function() {
+            stagPopup.find('input[type="text"]:not([readonly]):visible,select:visible').first().focus();
+        }, 150);
+    }
+    return false;
+}
+function submitStagPopup(_form) {
+    if(!_form[0].checkValidity()) {
+        _form[0].reportValidity();
+        return false;
+    }
+    showMask();
+    $.post(_form.attr('action'), _form.serialize(), function(_data) {
+        fastReload();
+    });
+    return false;
+}
+function closeStagPopup() {
+    $('.stag-popup').removeClass('show');
+    $('html, body').removeClass('no-scroll');
+    return false;
+}
+(function() {
+    window.initStagPopupEvents = function () {
+        $(document).on('click', '.stag-popup', function(_e) {
+            if($(_e.target).is('.stag-popup')) {
+                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);
+})();

+ 1 - 53
resources/views/layouts/template.blade.php

@@ -274,59 +274,7 @@
             }, 15000); // once in 15 seconds
         });
     </script>
-    <script>
-        function showStagPopup(_key, _noAutoFocus) {
-            $('html, body').addClass('no-scroll');
-            let stagPopup = $('[stag-popup-key="' + _key + '"]');
-            stagPopup.addClass('show');
-            stagPopup.find('[moe][initialized]').removeAttr('initialized');
-            initMoes();
-            if(!_noAutoFocus) {
-                window.setTimeout(function() {
-                    stagPopup.find('input[type="text"]:not([readonly]):visible,select:visible').first().focus();
-                }, 150);
-            }
-            return false;
-        }
-        function submitStagPopup(_form) {
-            if(!_form[0].checkValidity()) {
-                _form[0].reportValidity();
-                return false;
-            }
-            showMask();
-            $.post(_form.attr('action'), _form.serialize(), function(_data) {
-                fastReload();
-            });
-            return false;
-        }
-        function closeStagPopup() {
-            $('.stag-popup').removeClass('show');
-            $('html, body').removeClass('no-scroll');
-            return false;
-        }
-        (function() {
-            window.initStagPopupEvents = function () {
-                $(document).on('click', '.stag-popup', function(_e) {
-                    if($(_e.target).is('.stag-popup')) {
-                        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);
-        })();
-    </script>
+    <script src="/js/stag-popup.js"></script>
     <script>
         (function() {
             function init() {