mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-15 23:25:10 +00:00
refactor: wiki edit form (#38918)
1. the fragile `document.querySelector('.repository.wiki.new
.ui.form')!` is broken (again), rewrite to "data-global-init"
* regression from #37571 because a new form was added
3. use "form-fetch-action" and JSON response instead of
"RenderWithErrDeprecated"
This commit is contained in:
@@ -3,13 +3,11 @@ import {fomanticMobileScreen} from '../modules/fomantic.ts';
|
||||
import {POST} from '../modules/fetch.ts';
|
||||
import type {ComboMarkdownEditor} from './comp/ComboMarkdownEditor.ts';
|
||||
import {html, htmlRaw} from '../utils/html.ts';
|
||||
import {registerGlobalInitFunc} from '../modules/observer.ts';
|
||||
|
||||
async function initRepoWikiFormEditor() {
|
||||
const editArea = document.querySelector<HTMLTextAreaElement>('.repository.wiki .combo-markdown-editor textarea');
|
||||
if (!editArea) return;
|
||||
|
||||
const form = document.querySelector('.repository.wiki.new .ui.form')!;
|
||||
async function initRepoWikiForm(form: HTMLFormElement) {
|
||||
const editorContainer = form.querySelector<HTMLElement>('.combo-markdown-editor')!;
|
||||
const editArea = editorContainer.querySelector<HTMLTextAreaElement>('textarea')!;
|
||||
let editor: ComboMarkdownEditor;
|
||||
|
||||
let renderRequesting = false;
|
||||
@@ -69,17 +67,13 @@ async function initRepoWikiFormEditor() {
|
||||
});
|
||||
}
|
||||
|
||||
function collapseWikiTocForMobile(collapse: boolean) {
|
||||
if (collapse) {
|
||||
document.querySelector('.wiki-content-toc details')?.removeAttribute('open');
|
||||
}
|
||||
}
|
||||
|
||||
export function initRepoWikiForm() {
|
||||
if (!document.querySelector('.page-content.repository.wiki')) return;
|
||||
|
||||
fomanticMobileScreen.addEventListener('change', (e) => collapseWikiTocForMobile(e.matches));
|
||||
collapseWikiTocForMobile(fomanticMobileScreen.matches);
|
||||
|
||||
initRepoWikiFormEditor();
|
||||
export function initRepoWiki() {
|
||||
registerGlobalInitFunc('initRepoWikiSidebarToc', (el) => {
|
||||
const collapseWikiTocForMobile = (collapse: boolean) => {
|
||||
if (collapse) el.querySelector('details')?.removeAttribute('open');
|
||||
};
|
||||
fomanticMobileScreen.addEventListener('change', (e) => collapseWikiTocForMobile(e.matches));
|
||||
collapseWikiTocForMobile(fomanticMobileScreen.matches);
|
||||
});
|
||||
registerGlobalInitFunc('initRepoWikiForm', initRepoWikiForm);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user