2du 4 лет назад
Родитель
Сommit
2c7151848f
2 измененных файлов с 17 добавлено и 12 удалено
  1. 8 6
      route/edit.py
  2. 9 6
      views/main_css/js/load_editor.js

+ 8 - 6
route/edit.py

@@ -156,7 +156,7 @@ def edit_2(conn, name):
                 require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.20.0/min/vs' }});
                 require(["vs/editor/editor.main"], function () {
                     window.editor = monaco.editor.create(document.getElementById('monaco_editor'), {
-                        value: document.getElementById('content').value,
+                        value: document.getElementById('textarea_edit_view').value,
                         language: 'plaintext',
                         theme: \'''' + monaco_thema + '''\'
                     });
@@ -186,16 +186,18 @@ def edit_2(conn, name):
                     <div    id="monaco_editor"
                             class="content" 
                             ''' + monaco_display + '''></div>
-                    <textarea   id="content"
+                    <textarea   id="textarea_edit_view"
                                 ''' + editor_display + '''
-                                class="content" 
-                                placeholder="''' + p_text + '''" 
-                                name="content">''' + html.escape(data) + '''</textarea>
+                                class="content"
+                                placeholder="''' + p_text + '''">''' + html.escape(data) + '''</textarea>
                     <hr class="main_hr">
                     <input  placeholder="''' + load_lang('why') + '''" 
                             name="send">
                     <textarea   style="display: none;" 
                                 id="origin">''' + html.escape(data) + '''</textarea>
+                    <textarea   style="display: none;"
+                                name="content"
+                                id="content"></textarea>
                     <input  style="display: none;" 
                             name="ver" 
                             value="''' + doc_ver + '''">
@@ -211,7 +213,7 @@ def edit_2(conn, name):
                     <button id="preview" 
                             type="button" 
                             onclick="
-                                monaco_to_content(); 
+                                monaco_to_content();
                                 load_preview(\'''' + url_pas(name) + '''\');
                             ">''' + load_lang('preview') + '''</button>
                 </form>

+ 9 - 6
views/main_css/js/load_editor.js

@@ -35,7 +35,7 @@ function do_insert_data(name, data, monaco = 0) {
 
 function monaco_to_content() {
     try {
-        document.getElementById('content').innerHTML = window.editor.getValue();
+        document.getElementById('textarea_edit_view').value = window.editor.getValue();
     } catch(e) {}
 }
 
@@ -43,6 +43,7 @@ function do_not_out() {
     window.addEventListener('DOMContentLoaded', function() {
         window.onbeforeunload = function() {
             monaco_to_content();
+            section_edit_do();
             
             data = document.getElementById('content').value;
             origin = document.getElementById('origin').value;
@@ -130,7 +131,7 @@ function pasteListener(e) {
 
 function load_preview(name) {
     var s_data = new FormData();
-    s_data.append('data', document.getElementById('content').value);
+    s_data.append('data', document.getElementById('textarea_edit_view').value);
 
     var url = "/api/w/" + name;
     var url_2 = "/api/markup";
@@ -162,7 +163,7 @@ function section_edit_init() {
     );
     
     if(data_server['markup'] === 'namumark') {
-        var data = document.getElementById('content').value;
+        var data = document.getElementById('textarea_edit_view').value;
         var data_org = data;
         var data_section = Number(data_server['section']);
         var re_heading = /(^|\n)(={1,6})(#)? ?([^=]+) ?#?={1,6}(\n|$)/;
@@ -185,7 +186,7 @@ function section_edit_init() {
                 data = data_org.slice(start_point, end_point);
                 data = data.replace(/\n$/, '');
                 
-                document.getElementById('content').value = data;
+                document.getElementById('textarea_edit_view').value = data;
                 
                 data_server['start_point'] = start_point;
                 data_server['end_point'] = end_point;
@@ -209,12 +210,12 @@ function section_edit_do() {
     
     if(data_server['start_point'] !== undefined) {
         var data = document.getElementById('origin').value;
-        var data_section = document.getElementById('content').value;
+        var data_section = document.getElementById('textarea_edit_view').value;
         
         var start_point = data_server['start_point'];
         var end_point = data_server['end_point'];
         
-        if(data.length >= end_point) {            
+        if(data.length >= end_point) {
             var data_new = '';
             data_new += data.slice(0, start_point);
             data_new += data_section;
@@ -222,5 +223,7 @@ function section_edit_do() {
             
             document.getElementById('content').value = data_new;
         }
+    } else {
+        document.getElementById('content').value = document.getElementById('textarea_edit_view').value;
     }
 }