Просмотр исходного кода

나가기 방지 방법 개선

Surplus_Up (2DU) 6 лет назад
Родитель
Сommit
ec37e916b1
3 измененных файлов с 14 добавлено и 12 удалено
  1. 1 2
      route/edit.py
  2. 1 1
      route/tool/func.py
  3. 12 9
      views/main_css/js/do_stop_exit.js

+ 1 - 2
route/edit.py

@@ -185,7 +185,6 @@ def edit_2(conn, name):
             imp = [name, wiki_set(), custom(), other2([' (' + sub + ')', 0])],
             data =  get_name + '''
                 <form method="post">
-                    <script>do_stop_exit();</script>
                     ''' + edit_button() + '''
                     <textarea id="content" placeholder="''' + p_text + '''" name="content">''' + html.escape(data) + '''</textarea>
                     <textarea id="origin" name="o_content">''' + html.escape(data_old) + '''</textarea>
@@ -193,7 +192,7 @@ def edit_2(conn, name):
                     <input placeholder="''' + load_lang('why') + '''" name="send" type="text">
                     <hr class=\"main_hr\">
                     ''' + captcha_get() + ip_warring() + cccb_text + '''
-                    <button id="save" type="submit" onclick="go_save_zone = 1;">''' + save_button + '''</button>
+                    <button id="save" type="submit" onclick="save_stop_exit();">''' + save_button + '''</button>
                     <button id="preview" type="button" onclick="load_preview(\'''' + url_pas(name) + '\')">' + load_lang('preview') + '''</button>
                 </form>
                 ''' + b_text + '''

+ 1 - 1
route/tool/func.py

@@ -499,7 +499,7 @@ def other2(data):
         data += ['']
 
     req_list = ''
-    main_css_ver = 29
+    main_css_ver = 30
 
     if not 'main_css_load' in flask.session or not 'main_css_ver' in flask.session or flask.session['main_css_ver'] != main_css_ver:
         for i_data in os.listdir(os.path.join("views", "main_css", "css")):

+ 12 - 9
views/main_css/js/do_stop_exit.js

@@ -1,12 +1,15 @@
-var go_save_zone = 0;
-
-function do_stop_exit() {
-    window.onbeforeunload = function() {
-        console.log(go_save_zone);
-        data = document.getElementById('content').value;
-        origin = document.getElementById('origin').value;
-        if(data !== origin && go_save_zone != 1) {
-            return '';
+window.addEventListener('DOMContentLoaded', function() {
+    if(window.location.pathname.match(/^\/edit\//i)) {
+        window.onbeforeunload = function() {
+            data = document.getElementById('content').value;
+            origin = document.getElementById('origin').value;
+            if(data !== origin) {
+                return '';
+            }
         }
     }
+});
+
+function save_stop_exit() {
+    window.onbeforeunload = function () { }
 }