forked from forgejo/forgejo
Clean legacy SimpleMDE code (#17926)
Since we are using EasyMDE now, we do not need to keep the SimpleMDE code anymore. This PR removes all legacy SimpleMDE code, and makes some related changes: * `createCommentEasyMDE` can accept native DOM element, and it doesn't need `jQuery.data` to store EasyMDE editor object (as discussed about the frontend guideline). * introduce `getAttachedEasyMDE` to get the attached EasyMDE editor object, it's easier to find all the usage of EasyMDE. * rename variable names from `$simplemde` to `easyMDE`, the `$` was incorrect because it is a EasyMDE editor, not a jQuery object. With this PR, it will be easier to do more refactoring or replacing EasyMDE with other editors.
This commit is contained in:
parent
719bddcd76
commit
0a9fcf63a4
16 changed files with 104 additions and 82 deletions
|
@ -7,11 +7,11 @@ export function initRepoWikiForm() {
|
|||
const $editArea = $('.repository.wiki textarea#edit_area');
|
||||
let sideBySideChanges = 0;
|
||||
let sideBySideTimeout = null;
|
||||
let hasSimpleMDE = true;
|
||||
let hasEasyMDE = true;
|
||||
|
||||
if ($editArea.length > 0) {
|
||||
const $form = $('.repository.wiki.new .ui.form');
|
||||
const simplemde = new SimpleMDE({
|
||||
const easyMDE = new window.EasyMDE({
|
||||
autoDownloadFontAwesome: false,
|
||||
element: $editArea[0],
|
||||
forceSync: true,
|
||||
|
@ -36,7 +36,7 @@ export function initRepoWikiForm() {
|
|||
};
|
||||
|
||||
setTimeout(() => {
|
||||
if (!simplemde.isSideBySideActive()) {
|
||||
if (!easyMDE.isSideBySideActive()) {
|
||||
render();
|
||||
} else {
|
||||
// delay preview by keystroke counting
|
||||
|
@ -52,7 +52,7 @@ export function initRepoWikiForm() {
|
|||
sideBySideTimeout = setTimeout(render, 600);
|
||||
}
|
||||
}, 0);
|
||||
if (!simplemde.isSideBySideActive()) {
|
||||
if (!easyMDE.isSideBySideActive()) {
|
||||
return 'Loading...';
|
||||
}
|
||||
return preview.innerHTML;
|
||||
|
@ -106,7 +106,7 @@ export function initRepoWikiForm() {
|
|||
name: 'revert-to-textarea',
|
||||
action(e) {
|
||||
e.toTextArea();
|
||||
hasSimpleMDE = false;
|
||||
hasEasyMDE = false;
|
||||
const $root = $form.find('.field.content');
|
||||
const loading = $root.data('loading');
|
||||
$root.append(`<div class="ui bottom tab markup" data-tab="preview">${loading}</div>`);
|
||||
|
@ -118,12 +118,12 @@ export function initRepoWikiForm() {
|
|||
]
|
||||
});
|
||||
|
||||
const $markdownEditorTextArea = $(simplemde.codemirror.getInputField());
|
||||
const $markdownEditorTextArea = $(easyMDE.codemirror.getInputField());
|
||||
$markdownEditorTextArea.addClass('js-quick-submit');
|
||||
|
||||
$form.on('submit', function (e) {
|
||||
// The original edit area HTML element is hidden and replaced by the
|
||||
// SimpleMDE editor, breaking HTML5 input validation if the text area is empty.
|
||||
// SimpleMDE/EasyMDE editor, breaking HTML5 input validation if the text area is empty.
|
||||
// This is a workaround for this upstream bug.
|
||||
// See https://github.com/sparksuite/simplemde-markdown-editor/issues/324
|
||||
const input = $editArea.val();
|
||||
|
@ -143,7 +143,7 @@ export function initRepoWikiForm() {
|
|||
const $bPreview = $('.editor-toolbar button.preview');
|
||||
const $bSideBySide = $('.editor-toolbar a.fa-columns');
|
||||
$bEdit.on('click', (e) => {
|
||||
if (!hasSimpleMDE) {
|
||||
if (!hasEasyMDE) {
|
||||
return false;
|
||||
}
|
||||
e.stopImmediatePropagation();
|
||||
|
@ -154,7 +154,7 @@ export function initRepoWikiForm() {
|
|||
return false;
|
||||
});
|
||||
$bPrev.on('click', (e) => {
|
||||
if (!hasSimpleMDE) {
|
||||
if (!hasEasyMDE) {
|
||||
return false;
|
||||
}
|
||||
e.stopImmediatePropagation();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue