| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- // "use strict";
- function do_stop_exit() {
- window.onbeforeunload = function() {
- do_insert_edit_data();
- let data = document.getElementById('opennamu_js_edit_textarea').value;
- let origin = document.getElementById('opennamu_js_edit_origin').value;
- if(data !== origin) {
- return '';
- }
- }
- }
- function do_insert_edit_data() {
- if(document.getElementById('opennamu_monaco_editor')) {
- do_monaco_to_textarea();
- }
-
- let get_data = document.getElementById('opennamu_js_edit_textarea_view').value;
-
- document.getElementById('opennamu_js_edit_textarea').value = get_data;
- }
- function do_stop_exit_release() {
- window.onbeforeunload = function () {}
- }
- function do_monaco_to_textarea() {
- try {
- document.getElementById('opennamu_js_edit_textarea_view').value = window.editor.getValue();
- } catch(e) {}
- }
- function do_insert_preview() {
- let s_data = new FormData();
- s_data.append('data', document.getElementById('opennamu_js_edit_textarea').value);
- let xhr = new XMLHttpRequest();
- xhr.open("POST", "/api/w/Test");
- xhr.send(s_data);
-
- xhr.onreadystatechange = function() {
- if(xhr.readyState === 4 && xhr.status === 200) {
- let o_p_data = JSON.parse(xhr.responseText);
-
- document.getElementById('opennamu_js_preview_area').innerHTML = o_p_data['data'];
- eval(o_p_data['js_data'])
- }
- }
- }
- if(window.location.pathname.match(/^\/(edit|edit_from|edit_section)\//)) {
- do_stop_exit();
-
- document.getElementById('opennamu_js_save').onclick = function() {
- do_insert_edit_data();
- do_stop_exit_release();
- };
- document.getElementById('opennamu_js_preview').onclick = function() {
- do_insert_edit_data();
- do_insert_preview();
- };
- }
- if(window.location.pathname.match(/^\/(thread)\//)) {
- document.getElementById('opennamu_js_preview').onclick = function() {
- do_insert_preview();
- };
- }
|