diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-10-17 01:28:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-17 01:28:04 +0800 |
commit | 1a7473ff459479a7fd3ba62a0b7b04b237565bed (patch) | |
tree | 518aab9c14f36ed012831b389c0370adef2ab738 /web_src/js/features/comp/CommentSimpleMDE.js | |
parent | 3728f1daa08e4c228db212844612555e9e2904df (diff) | |
download | gitea-1a7473ff459479a7fd3ba62a0b7b04b237565bed.tar.gz gitea-1a7473ff459479a7fd3ba62a0b7b04b237565bed.zip |
Split `index.js` to separate files (#17315)
* split `index.js` to separate files
* tune clipboard
* fix promise
* fix document
* remove intermediate empty file
* fix async event listener
* use `export function` instead of `export {}`, add more comments
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'web_src/js/features/comp/CommentSimpleMDE.js')
-rw-r--r-- | web_src/js/features/comp/CommentSimpleMDE.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/web_src/js/features/comp/CommentSimpleMDE.js b/web_src/js/features/comp/CommentSimpleMDE.js new file mode 100644 index 0000000000..fbc0ec8baf --- /dev/null +++ b/web_src/js/features/comp/CommentSimpleMDE.js @@ -0,0 +1,72 @@ +import attachTribute from '../tribute.js'; + +export function createCommentSimpleMDE($editArea) { + if ($editArea.length === 0) { + return null; + } + + const simplemde = new SimpleMDE({ + autoDownloadFontAwesome: false, + element: $editArea[0], + forceSync: true, + renderingConfig: { + singleLineBreaks: false + }, + indentWithTabs: false, + tabSize: 4, + spellChecker: false, + toolbar: ['bold', 'italic', 'strikethrough', '|', + 'heading-1', 'heading-2', 'heading-3', 'heading-bigger', 'heading-smaller', '|', + 'code', 'quote', '|', { + name: 'checkbox-empty', + action(e) { + const cm = e.codemirror; + cm.replaceSelection(`\n- [ ] ${cm.getSelection()}`); + cm.focus(); + }, + className: 'fa fa-square-o', + title: 'Add Checkbox (empty)', + }, + { + name: 'checkbox-checked', + action(e) { + const cm = e.codemirror; + cm.replaceSelection(`\n- [x] ${cm.getSelection()}`); + cm.focus(); + }, + className: 'fa fa-check-square-o', + title: 'Add Checkbox (checked)', + }, '|', + 'unordered-list', 'ordered-list', '|', + 'link', 'image', 'table', 'horizontal-rule', '|', + 'clean-block', '|', + { + name: 'revert-to-textarea', + action(e) { + e.toTextArea(); + }, + className: 'fa fa-file', + title: 'Revert to simple textarea', + }, + ] + }); + $(simplemde.codemirror.getInputField()).addClass('js-quick-submit'); + simplemde.codemirror.setOption('extraKeys', { + Enter: () => { + const tributeContainer = document.querySelector('.tribute-container'); + if (!tributeContainer || tributeContainer.style.display === 'none') { + return CodeMirror.Pass; + } + }, + Backspace: (cm) => { + if (cm.getInputField().trigger) { + cm.getInputField().trigger('input'); + } + cm.execCommand('delCharBefore'); + } + }); + attachTribute(simplemde.codemirror.getInputField(), {mentions: true, emoji: true}); + $editArea.data('simplemde', simplemde); + $(simplemde.codemirror.getInputField()).data('simplemde', simplemde); + return simplemde; +} |