parent
1d76e9aabf
commit
bda875b6e6
@ -122,22 +122,22 @@ class ComboMarkdownEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setupTab() {
|
setupTab() {
|
||||||
const $container = $(this.container);
|
const tabs = this.container.querySelectorAll('.tabular.menu > .item');
|
||||||
const tabs = $container[0].querySelectorAll('.tabular.menu > .item');
|
|
||||||
|
|
||||||
// Fomantic Tab requires the "data-tab" to be globally unique.
|
// Fomantic Tab requires the "data-tab" to be globally unique.
|
||||||
// So here it uses our defined "data-tab-for" and "data-tab-panel" to generate the "data-tab" attribute for Fomantic.
|
// So here it uses our defined "data-tab-for" and "data-tab-panel" to generate the "data-tab" attribute for Fomantic.
|
||||||
const tabEditor = Array.from(tabs).find((tab) => tab.getAttribute('data-tab-for') === 'markdown-writer');
|
this.tabEditor = Array.from(tabs).find((tab) => tab.getAttribute('data-tab-for') === 'markdown-writer');
|
||||||
const tabPreviewer = Array.from(tabs).find((tab) => tab.getAttribute('data-tab-for') === 'markdown-previewer');
|
this.tabPreviewer = Array.from(tabs).find((tab) => tab.getAttribute('data-tab-for') === 'markdown-previewer');
|
||||||
tabEditor.setAttribute('data-tab', `markdown-writer-${elementIdCounter}`);
|
this.tabEditor.setAttribute('data-tab', `markdown-writer-${elementIdCounter}`);
|
||||||
tabPreviewer.setAttribute('data-tab', `markdown-previewer-${elementIdCounter}`);
|
this.tabPreviewer.setAttribute('data-tab', `markdown-previewer-${elementIdCounter}`);
|
||||||
const panelEditor = $container[0].querySelector('.ui.tab[data-tab-panel="markdown-writer"]');
|
|
||||||
const panelPreviewer = $container[0].querySelector('.ui.tab[data-tab-panel="markdown-previewer"]');
|
const panelEditor = this.container.querySelector('.ui.tab[data-tab-panel="markdown-writer"]');
|
||||||
|
const panelPreviewer = this.container.querySelector('.ui.tab[data-tab-panel="markdown-previewer"]');
|
||||||
panelEditor.setAttribute('data-tab', `markdown-writer-${elementIdCounter}`);
|
panelEditor.setAttribute('data-tab', `markdown-writer-${elementIdCounter}`);
|
||||||
panelPreviewer.setAttribute('data-tab', `markdown-previewer-${elementIdCounter}`);
|
panelPreviewer.setAttribute('data-tab', `markdown-previewer-${elementIdCounter}`);
|
||||||
elementIdCounter++;
|
elementIdCounter++;
|
||||||
|
|
||||||
tabEditor.addEventListener('click', () => {
|
this.tabEditor.addEventListener('click', () => {
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
this.focus();
|
this.focus();
|
||||||
});
|
});
|
||||||
@ -145,11 +145,11 @@ class ComboMarkdownEditor {
|
|||||||
|
|
||||||
$(tabs).tab();
|
$(tabs).tab();
|
||||||
|
|
||||||
this.previewUrl = tabPreviewer.getAttribute('data-preview-url');
|
this.previewUrl = this.tabPreviewer.getAttribute('data-preview-url');
|
||||||
this.previewContext = tabPreviewer.getAttribute('data-preview-context');
|
this.previewContext = this.tabPreviewer.getAttribute('data-preview-context');
|
||||||
this.previewMode = this.options.previewMode ?? 'comment';
|
this.previewMode = this.options.previewMode ?? 'comment';
|
||||||
this.previewWiki = this.options.previewWiki ?? false;
|
this.previewWiki = this.options.previewWiki ?? false;
|
||||||
tabPreviewer.addEventListener('click', async () => {
|
this.tabPreviewer.addEventListener('click', async () => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('mode', this.previewMode);
|
formData.append('mode', this.previewMode);
|
||||||
formData.append('context', this.previewContext);
|
formData.append('context', this.previewContext);
|
||||||
@ -161,6 +161,10 @@ class ComboMarkdownEditor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switchTabToEditor() {
|
||||||
|
this.tabEditor.click();
|
||||||
|
}
|
||||||
|
|
||||||
prepareEasyMDEToolbarActions() {
|
prepareEasyMDEToolbarActions() {
|
||||||
this.easyMDEToolbarDefault = [
|
this.easyMDEToolbarDefault = [
|
||||||
'bold', 'italic', 'strikethrough', '|', 'heading-1', 'heading-2', 'heading-3',
|
'bold', 'italic', 'strikethrough', '|', 'heading-1', 'heading-2', 'heading-3',
|
||||||
|
@ -179,6 +179,7 @@ async function onEditContent(event) {
|
|||||||
if (!comboMarkdownEditor.value()) {
|
if (!comboMarkdownEditor.value()) {
|
||||||
comboMarkdownEditor.value(rawContent.textContent);
|
comboMarkdownEditor.value(rawContent.textContent);
|
||||||
}
|
}
|
||||||
|
comboMarkdownEditor.switchTabToEditor();
|
||||||
comboMarkdownEditor.focus();
|
comboMarkdownEditor.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user