aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/features/repo-wiki.js
diff options
context:
space:
mode:
Diffstat (limited to 'web_src/js/features/repo-wiki.js')
-rw-r--r--web_src/js/features/repo-wiki.js56
1 files changed, 29 insertions, 27 deletions
diff --git a/web_src/js/features/repo-wiki.js b/web_src/js/features/repo-wiki.js
index 58036fde37..d51bf35c81 100644
--- a/web_src/js/features/repo-wiki.js
+++ b/web_src/js/features/repo-wiki.js
@@ -1,50 +1,51 @@
-import $ from 'jquery';
import {initMarkupContent} from '../markup/content.js';
import {validateTextareaNonEmpty, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js';
import {fomanticMobileScreen} from '../modules/fomantic.js';
-
-const {csrfToken} = window.config;
+import {POST} from '../modules/fetch.js';
async function initRepoWikiFormEditor() {
- const $editArea = $('.repository.wiki .combo-markdown-editor textarea');
- if (!$editArea.length) return;
+ const editArea = document.querySelector('.repository.wiki .combo-markdown-editor textarea');
+ if (!editArea) return;
- const $form = $('.repository.wiki.new .ui.form');
- const $editorContainer = $form.find('.combo-markdown-editor');
+ const form = document.querySelector('.repository.wiki.new .ui.form');
+ const editorContainer = form.querySelector('.combo-markdown-editor');
let editor;
let renderRequesting = false;
let lastContent;
- const renderEasyMDEPreview = function () {
+ const renderEasyMDEPreview = async function () {
if (renderRequesting) return;
- const $previewFull = $editorContainer.find('.EasyMDEContainer .editor-preview-active');
- const $previewSide = $editorContainer.find('.EasyMDEContainer .editor-preview-active-side');
- const $previewTarget = $previewSide.length ? $previewSide : $previewFull;
- const newContent = $editArea.val();
- if (editor && $previewTarget.length && lastContent !== newContent) {
+ const previewFull = editorContainer.querySelector('.EasyMDEContainer .editor-preview-active');
+ const previewSide = editorContainer.querySelector('.EasyMDEContainer .editor-preview-active-side');
+ const previewTarget = previewSide || previewFull;
+ const newContent = editArea.value;
+ if (editor && previewTarget && lastContent !== newContent) {
renderRequesting = true;
- $.post(editor.previewUrl, {
- _csrf: csrfToken,
- mode: editor.previewMode,
- context: editor.previewContext,
- text: newContent,
- wiki: editor.previewWiki,
- }).done((data) => {
+ const formData = new FormData();
+ formData.append('mode', editor.previewMode);
+ formData.append('context', editor.previewContext);
+ formData.append('text', newContent);
+ formData.append('wiki', editor.previewWiki);
+ try {
+ const response = await POST(editor.previewUrl, {data: formData});
+ const data = await response.text();
lastContent = newContent;
- $previewTarget.html(`<div class="markup ui segment">${data}</div>`);
+ previewTarget.innerHTML = `<div class="markup ui segment">${data}</div>`;
initMarkupContent();
- }).always(() => {
+ } catch (error) {
+ console.error('Error rendering preview:', error);
+ } finally {
renderRequesting = false;
setTimeout(renderEasyMDEPreview, 1000);
- });
+ }
} else {
setTimeout(renderEasyMDEPreview, 1000);
}
};
renderEasyMDEPreview();
- editor = await initComboMarkdownEditor($editorContainer, {
+ editor = await initComboMarkdownEditor(editorContainer, {
useScene: 'wiki',
// EasyMDE has some problems of height definition, it has inline style height 300px by default, so we also use inline styles to override it.
// And another benefit is that we only need to write the style once for both editors.
@@ -64,9 +65,10 @@ async function initRepoWikiFormEditor() {
},
});
- $form.on('submit', () => {
- if (!validateTextareaNonEmpty($editArea)) {
- return false;
+ form.addEventListener('submit', (e) => {
+ if (!validateTextareaNonEmpty(editArea)) {
+ e.preventDefault();
+ e.stopPropagation();
}
});
}