mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 12:54:53 -05:00
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
|
@ -253,7 +253,7 @@ func FileHistory(ctx *context.Context) {
|
||||||
func Diff(ctx *context.Context) {
|
func Diff(ctx *context.Context) {
|
||||||
ctx.Data["PageIsDiff"] = true
|
ctx.Data["PageIsDiff"] = true
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
|
|
||||||
userName := ctx.Repo.Owner.Name
|
userName := ctx.Repo.Owner.Name
|
||||||
|
|
|
@ -761,7 +761,7 @@ func CompareDiff(ctx *context.Context) {
|
||||||
ctx.Data["IsRepoToolbarCommits"] = true
|
ctx.Data["IsRepoToolbarCommits"] = true
|
||||||
ctx.Data["IsDiffCompare"] = true
|
ctx.Data["IsDiffCompare"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
||||||
setTemplateIfExists(ctx, pullRequestTemplateKey, nil, pullRequestTemplateCandidates)
|
setTemplateIfExists(ctx, pullRequestTemplateKey, nil, pullRequestTemplateCandidates)
|
||||||
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
||||||
|
|
|
@ -69,7 +69,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
|
||||||
ctx.Data["PageIsEdit"] = true
|
ctx.Data["PageIsEdit"] = true
|
||||||
ctx.Data["IsNewFile"] = isNewFile
|
ctx.Data["IsNewFile"] = isNewFile
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
canCommit := renderCommitRights(ctx)
|
canCommit := renderCommitRights(ctx)
|
||||||
|
|
||||||
treePath := cleanUploadFileName(ctx.Repo.TreePath)
|
treePath := cleanUploadFileName(ctx.Repo.TreePath)
|
||||||
|
@ -200,7 +200,7 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
|
||||||
ctx.Data["PageHasPosted"] = true
|
ctx.Data["PageHasPosted"] = true
|
||||||
ctx.Data["IsNewFile"] = isNewFile
|
ctx.Data["IsNewFile"] = isNewFile
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
ctx.Data["TreePath"] = form.TreePath
|
ctx.Data["TreePath"] = form.TreePath
|
||||||
ctx.Data["TreeNames"] = treeNames
|
ctx.Data["TreeNames"] = treeNames
|
||||||
ctx.Data["TreePaths"] = treePaths
|
ctx.Data["TreePaths"] = treePaths
|
||||||
|
@ -544,7 +544,7 @@ func DeleteFilePost(ctx *context.Context) {
|
||||||
func UploadFile(ctx *context.Context) {
|
func UploadFile(ctx *context.Context) {
|
||||||
ctx.Data["PageIsUpload"] = true
|
ctx.Data["PageIsUpload"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
upload.AddUploadContext(ctx, "repo")
|
upload.AddUploadContext(ctx, "repo")
|
||||||
canCommit := renderCommitRights(ctx)
|
canCommit := renderCommitRights(ctx)
|
||||||
treePath := cleanUploadFileName(ctx.Repo.TreePath)
|
treePath := cleanUploadFileName(ctx.Repo.TreePath)
|
||||||
|
@ -580,7 +580,7 @@ func UploadFilePost(ctx *context.Context) {
|
||||||
form := web.GetForm(ctx).(*forms.UploadRepoFileForm)
|
form := web.GetForm(ctx).(*forms.UploadRepoFileForm)
|
||||||
ctx.Data["PageIsUpload"] = true
|
ctx.Data["PageIsUpload"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
upload.AddUploadContext(ctx, "repo")
|
upload.AddUploadContext(ctx, "repo")
|
||||||
canCommit := renderCommitRights(ctx)
|
canCommit := renderCommitRights(ctx)
|
||||||
|
|
||||||
|
|
|
@ -786,7 +786,7 @@ func NewIssue(ctx *context.Context) {
|
||||||
ctx.Data["PageIsIssueList"] = true
|
ctx.Data["PageIsIssueList"] = true
|
||||||
ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
|
ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
||||||
title := ctx.FormString("title")
|
title := ctx.FormString("title")
|
||||||
|
@ -959,7 +959,7 @@ func NewIssuePost(ctx *context.Context) {
|
||||||
ctx.Data["PageIsIssueList"] = true
|
ctx.Data["PageIsIssueList"] = true
|
||||||
ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
|
ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
||||||
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
||||||
upload.AddUploadContext(ctx, "comment")
|
upload.AddUploadContext(ctx, "comment")
|
||||||
|
@ -1144,7 +1144,7 @@ func ViewIssue(ctx *context.Context) {
|
||||||
|
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(unit.TypeProjects)
|
ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(unit.TypeProjects)
|
||||||
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
||||||
upload.AddUploadContext(ctx, "comment")
|
upload.AddUploadContext(ctx, "comment")
|
||||||
|
|
|
@ -701,7 +701,7 @@ func ViewPullFiles(ctx *context.Context) {
|
||||||
setCompareContext(ctx, baseCommit, commit, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
setCompareContext(ctx, baseCommit, commit, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||||
|
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
if ctx.Data["Assignees"], err = models.GetRepoAssignees(ctx.Repo.Repository); err != nil {
|
if ctx.Data["Assignees"], err = models.GetRepoAssignees(ctx.Repo.Repository); err != nil {
|
||||||
ctx.ServerError("GetAssignees", err)
|
ctx.ServerError("GetAssignees", err)
|
||||||
|
@ -1045,7 +1045,7 @@ func CompareAndPullRequestPost(ctx *context.Context) {
|
||||||
ctx.Data["IsDiffCompare"] = true
|
ctx.Data["IsDiffCompare"] = true
|
||||||
ctx.Data["IsRepoToolbarCommits"] = true
|
ctx.Data["IsRepoToolbarCommits"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
ctx.Data["RequireHighlightJS"] = true
|
ctx.Data["RequireHighlightJS"] = true
|
||||||
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
||||||
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
||||||
|
|
|
@ -262,7 +262,7 @@ func LatestRelease(ctx *context.Context) {
|
||||||
func NewRelease(ctx *context.Context) {
|
func NewRelease(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
|
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
|
||||||
ctx.Data["PageIsReleaseList"] = true
|
ctx.Data["PageIsReleaseList"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch
|
ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch
|
||||||
if tagName := ctx.FormString("tag"); len(tagName) > 0 {
|
if tagName := ctx.FormString("tag"); len(tagName) > 0 {
|
||||||
|
@ -296,7 +296,7 @@ func NewReleasePost(ctx *context.Context) {
|
||||||
form := web.GetForm(ctx).(*forms.NewReleaseForm)
|
form := web.GetForm(ctx).(*forms.NewReleaseForm)
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
|
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
|
||||||
ctx.Data["PageIsReleaseList"] = true
|
ctx.Data["PageIsReleaseList"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
|
@ -415,7 +415,7 @@ func EditRelease(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
|
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
|
||||||
ctx.Data["PageIsReleaseList"] = true
|
ctx.Data["PageIsReleaseList"] = true
|
||||||
ctx.Data["PageIsEditRelease"] = true
|
ctx.Data["PageIsEditRelease"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
|
||||||
upload.AddUploadContext(ctx, "release")
|
upload.AddUploadContext(ctx, "release")
|
||||||
|
@ -454,7 +454,7 @@ func EditReleasePost(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
|
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
|
||||||
ctx.Data["PageIsReleaseList"] = true
|
ctx.Data["PageIsReleaseList"] = true
|
||||||
ctx.Data["PageIsEditRelease"] = true
|
ctx.Data["PageIsEditRelease"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
ctx.Data["RequireTribute"] = true
|
ctx.Data["RequireTribute"] = true
|
||||||
|
|
||||||
tagName := ctx.Params("*")
|
tagName := ctx.Params("*")
|
||||||
|
|
|
@ -622,7 +622,7 @@ func WikiRaw(ctx *context.Context) {
|
||||||
func NewWiki(ctx *context.Context) {
|
func NewWiki(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
||||||
ctx.Data["PageIsWiki"] = true
|
ctx.Data["PageIsWiki"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
|
|
||||||
if !ctx.Repo.Repository.HasWiki() {
|
if !ctx.Repo.Repository.HasWiki() {
|
||||||
ctx.Data["title"] = "Home"
|
ctx.Data["title"] = "Home"
|
||||||
|
@ -639,7 +639,7 @@ func NewWikiPost(ctx *context.Context) {
|
||||||
form := web.GetForm(ctx).(*forms.NewWikiForm)
|
form := web.GetForm(ctx).(*forms.NewWikiForm)
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
||||||
ctx.Data["PageIsWiki"] = true
|
ctx.Data["PageIsWiki"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(http.StatusOK, tplWikiNew)
|
ctx.HTML(http.StatusOK, tplWikiNew)
|
||||||
|
@ -677,7 +677,7 @@ func NewWikiPost(ctx *context.Context) {
|
||||||
func EditWiki(ctx *context.Context) {
|
func EditWiki(ctx *context.Context) {
|
||||||
ctx.Data["PageIsWiki"] = true
|
ctx.Data["PageIsWiki"] = true
|
||||||
ctx.Data["PageIsWikiEdit"] = true
|
ctx.Data["PageIsWikiEdit"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
|
|
||||||
if !ctx.Repo.Repository.HasWiki() {
|
if !ctx.Repo.Repository.HasWiki() {
|
||||||
ctx.Redirect(ctx.Repo.RepoLink + "/wiki")
|
ctx.Redirect(ctx.Repo.RepoLink + "/wiki")
|
||||||
|
@ -697,7 +697,7 @@ func EditWikiPost(ctx *context.Context) {
|
||||||
form := web.GetForm(ctx).(*forms.NewWikiForm)
|
form := web.GetForm(ctx).(*forms.NewWikiForm)
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
||||||
ctx.Data["PageIsWiki"] = true
|
ctx.Data["PageIsWiki"] = true
|
||||||
ctx.Data["RequireSimpleMDE"] = true
|
ctx.Data["RequireEasyMDE"] = true
|
||||||
|
|
||||||
if ctx.HasError() {
|
if ctx.HasError() {
|
||||||
ctx.HTML(http.StatusOK, tplWikiNew)
|
ctx.HTML(http.StatusOK, tplWikiNew)
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
{{template "custom/body_outer_post" .}}
|
{{template "custom/body_outer_post" .}}
|
||||||
|
|
||||||
{{template "base/footer_content" .}}
|
{{template "base/footer_content" .}}
|
||||||
{{if .RequireSimpleMDE}}
|
{{if .RequireEasyMDE}}
|
||||||
<script src="{{AssetUrlPrefix}}/js/easymde.js?v={{MD5 AppVer}}"></script>
|
<script src="{{AssetUrlPrefix}}/js/easymde.js?v={{MD5 AppVer}}"></script>
|
||||||
<script src="{{AssetUrlPrefix}}/vendor/plugins/codemirror/addon/mode/loadmode.js"></script>
|
<script src="{{AssetUrlPrefix}}/vendor/plugins/codemirror/addon/mode/loadmode.js"></script>
|
||||||
<script src="{{AssetUrlPrefix}}/vendor/plugins/codemirror/mode/meta.js"></script>
|
<script src="{{AssetUrlPrefix}}/vendor/plugins/codemirror/mode/meta.js"></script>
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
</script>
|
</script>
|
||||||
<link rel="icon" href="{{AssetUrlPrefix}}/img/logo.svg" type="image/svg+xml">
|
<link rel="icon" href="{{AssetUrlPrefix}}/img/logo.svg" type="image/svg+xml">
|
||||||
<link rel="alternate icon" href="{{AssetUrlPrefix}}/img/favicon.png" type="image/png">
|
<link rel="alternate icon" href="{{AssetUrlPrefix}}/img/favicon.png" type="image/png">
|
||||||
{{if .RequireSimpleMDE}}
|
{{if .RequireEasyMDE}}
|
||||||
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/easymde.css?v={{MD5 AppVer}}">
|
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/easymde.css?v={{MD5 AppVer}}">
|
||||||
{{end}}
|
{{end}}
|
||||||
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/index.css?v={{MD5 AppVer}}">
|
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/index.css?v={{MD5 AppVer}}">
|
||||||
|
|
|
@ -3,6 +3,5 @@ import EasyMDE from 'easymde';
|
||||||
import CodeMirror from 'codemirror/lib/codemirror.js';
|
import CodeMirror from 'codemirror/lib/codemirror.js';
|
||||||
|
|
||||||
window.EasyMDE = EasyMDE;
|
window.EasyMDE = EasyMDE;
|
||||||
window.SimpleMDE = EasyMDE;
|
|
||||||
window.CodeMirror = CodeMirror;
|
window.CodeMirror = CodeMirror;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
import attachTribute from '../tribute.js';
|
import attachTribute from '../tribute.js';
|
||||||
|
|
||||||
export function createCommentSimpleMDE($editArea) {
|
/**
|
||||||
if ($editArea.length === 0) {
|
* create an EasyMDE editor for comment
|
||||||
|
* @param textarea jQuery or HTMLElement
|
||||||
|
* @returns {null|EasyMDE}
|
||||||
|
*/
|
||||||
|
export function createCommentEasyMDE(textarea) {
|
||||||
|
if (textarea instanceof jQuery) {
|
||||||
|
textarea = textarea[0];
|
||||||
|
}
|
||||||
|
if (!textarea) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const simplemde = new SimpleMDE({
|
const easyMDE = new window.EasyMDE({
|
||||||
autoDownloadFontAwesome: false,
|
autoDownloadFontAwesome: false,
|
||||||
element: $editArea[0],
|
element: textarea,
|
||||||
forceSync: true,
|
forceSync: true,
|
||||||
renderingConfig: {
|
renderingConfig: {
|
||||||
singleLineBreaks: false
|
singleLineBreaks: false
|
||||||
|
@ -50,8 +58,9 @@ export function createCommentSimpleMDE($editArea) {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
$(simplemde.codemirror.getInputField()).addClass('js-quick-submit');
|
const inputField = easyMDE.codemirror.getInputField();
|
||||||
simplemde.codemirror.setOption('extraKeys', {
|
inputField.classList.add('js-quick-submit');
|
||||||
|
easyMDE.codemirror.setOption('extraKeys', {
|
||||||
Enter: () => {
|
Enter: () => {
|
||||||
const tributeContainer = document.querySelector('.tribute-container');
|
const tributeContainer = document.querySelector('.tribute-container');
|
||||||
if (!tributeContainer || tributeContainer.style.display === 'none') {
|
if (!tributeContainer || tributeContainer.style.display === 'none') {
|
||||||
|
@ -65,8 +74,25 @@ export function createCommentSimpleMDE($editArea) {
|
||||||
cm.execCommand('delCharBefore');
|
cm.execCommand('delCharBefore');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
attachTribute(simplemde.codemirror.getInputField(), {mentions: true, emoji: true});
|
attachTribute(inputField, {mentions: true, emoji: true});
|
||||||
$editArea.data('simplemde', simplemde);
|
|
||||||
$(simplemde.codemirror.getInputField()).data('simplemde', simplemde);
|
// TODO: that's the only way we can do now to attach the EasyMDE object to a HTMLElement
|
||||||
return simplemde;
|
inputField._data_easyMDE = easyMDE;
|
||||||
|
textarea._data_easyMDE = easyMDE;
|
||||||
|
return easyMDE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the attached EasyMDE editor created by createCommentEasyMDE
|
||||||
|
* @param el jQuery or HTMLElement
|
||||||
|
* @returns {null|EasyMDE}
|
||||||
|
*/
|
||||||
|
export function getAttachedEasyMDE(el) {
|
||||||
|
if (el instanceof jQuery) {
|
||||||
|
el = el[0];
|
||||||
|
}
|
||||||
|
if (!el) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return el._data_easyMDE;
|
||||||
}
|
}
|
|
@ -76,14 +76,14 @@ export function initCompImagePaste($target) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initSimpleMDEImagePaste(simplemde, dropzone, files) {
|
export function initEasyMDEImagePaste(easyMDE, dropzone, files) {
|
||||||
const uploadUrl = dropzone.getAttribute('data-upload-url');
|
const uploadUrl = dropzone.getAttribute('data-upload-url');
|
||||||
simplemde.codemirror.on('paste', async (_, e) => {
|
easyMDE.codemirror.on('paste', async (_, e) => {
|
||||||
for (const img of clipboardPastedImages(e)) {
|
for (const img of clipboardPastedImages(e)) {
|
||||||
const name = img.name.substr(0, img.name.lastIndexOf('.'));
|
const name = img.name.substr(0, img.name.lastIndexOf('.'));
|
||||||
const data = await uploadFile(img, uploadUrl);
|
const data = await uploadFile(img, uploadUrl);
|
||||||
const pos = simplemde.codemirror.getCursor();
|
const pos = easyMDE.codemirror.getCursor();
|
||||||
simplemde.codemirror.replaceRange(`![${name}](/attachments/${data.uuid})`, pos);
|
easyMDE.codemirror.replaceRange(`![${name}](/attachments/${data.uuid})`, pos);
|
||||||
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
|
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
|
||||||
files.append(input);
|
files.append(input);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {htmlEscape} from 'escape-goat';
|
import {htmlEscape} from 'escape-goat';
|
||||||
import attachTribute from './tribute.js';
|
import attachTribute from './tribute.js';
|
||||||
import {createCommentSimpleMDE} from './comp/CommentSimpleMDE.js';
|
import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/CommentEasyMDE.js';
|
||||||
import {initCompImagePaste} from './comp/ImagePaste.js';
|
import {initCompImagePaste} from './comp/ImagePaste.js';
|
||||||
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
||||||
|
|
||||||
|
@ -213,8 +213,8 @@ export function initRepoIssueStatusButton() {
|
||||||
// Change status
|
// Change status
|
||||||
const $statusButton = $('#status-button');
|
const $statusButton = $('#status-button');
|
||||||
$('#comment-form textarea').on('keyup', function () {
|
$('#comment-form textarea').on('keyup', function () {
|
||||||
const $simplemde = $(this).data('simplemde');
|
const easyMDE = getAttachedEasyMDE(this);
|
||||||
const value = ($simplemde && $simplemde.value()) ? $simplemde.value() : $(this).val();
|
const value = easyMDE?.value() || $(this).val();
|
||||||
$statusButton.text($statusButton.data(value.length === 0 ? 'status' : 'status-and-comment'));
|
$statusButton.text($statusButton.data(value.length === 0 ? 'status' : 'status-and-comment'));
|
||||||
});
|
});
|
||||||
$statusButton.on('click', () => {
|
$statusButton.on('click', () => {
|
||||||
|
@ -445,22 +445,19 @@ export function initRepoPullRequestReview() {
|
||||||
const form = $(this).closest('.comment-code-cloud').find('.comment-form');
|
const form = $(this).closest('.comment-code-cloud').find('.comment-form');
|
||||||
form.removeClass('hide');
|
form.removeClass('hide');
|
||||||
const $textarea = form.find('textarea');
|
const $textarea = form.find('textarea');
|
||||||
let $simplemde;
|
let easyMDE = getAttachedEasyMDE($textarea);
|
||||||
if ($textarea.data('simplemde')) {
|
if (!easyMDE) {
|
||||||
$simplemde = $textarea.data('simplemde');
|
|
||||||
} else {
|
|
||||||
attachTribute($textarea.get(), {mentions: true, emoji: true});
|
attachTribute($textarea.get(), {mentions: true, emoji: true});
|
||||||
$simplemde = createCommentSimpleMDE($textarea);
|
easyMDE = createCommentEasyMDE($textarea);
|
||||||
$textarea.data('simplemde', $simplemde);
|
|
||||||
}
|
}
|
||||||
$textarea.focus();
|
$textarea.focus();
|
||||||
$simplemde.codemirror.focus();
|
easyMDE.codemirror.focus();
|
||||||
assignMenuAttributes(form.find('.menu'));
|
assignMenuAttributes(form.find('.menu'));
|
||||||
});
|
});
|
||||||
|
|
||||||
const $reviewBox = $('.review-box');
|
const $reviewBox = $('.review-box');
|
||||||
if ($reviewBox.length === 1) {
|
if ($reviewBox.length === 1) {
|
||||||
createCommentSimpleMDE($reviewBox.find('textarea'));
|
createCommentEasyMDE($reviewBox.find('textarea'));
|
||||||
initCompImagePaste($reviewBox);
|
initCompImagePaste($reviewBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,9 +516,9 @@ export function initRepoPullRequestReview() {
|
||||||
td.find("input[name='path']").val(path);
|
td.find("input[name='path']").val(path);
|
||||||
const $textarea = commentCloud.find('textarea');
|
const $textarea = commentCloud.find('textarea');
|
||||||
attachTribute($textarea.get(), {mentions: true, emoji: true});
|
attachTribute($textarea.get(), {mentions: true, emoji: true});
|
||||||
const $simplemde = createCommentSimpleMDE($textarea);
|
const easyMDE = createCommentEasyMDE($textarea);
|
||||||
$textarea.focus();
|
$textarea.focus();
|
||||||
$simplemde.codemirror.focus();
|
easyMDE.codemirror.focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {createCommentSimpleMDE} from './comp/CommentSimpleMDE.js';
|
import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/CommentEasyMDE.js';
|
||||||
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
||||||
import {initCompImagePaste, initSimpleMDEImagePaste} from './comp/ImagePaste.js';
|
import {initCompImagePaste, initEasyMDEImagePaste} from './comp/ImagePaste.js';
|
||||||
import {
|
import {
|
||||||
initRepoIssueBranchSelect, initRepoIssueCodeCommentCancel,
|
initRepoIssueBranchSelect, initRepoIssueCodeCommentCancel,
|
||||||
initRepoIssueCommentDelete,
|
initRepoIssueCommentDelete,
|
||||||
|
@ -63,7 +63,7 @@ export function initRepoCommentForm() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createCommentSimpleMDE($('.comment.form textarea:not(.review-textarea)'));
|
createCommentEasyMDE($('.comment.form textarea:not(.review-textarea)'));
|
||||||
initBranchSelector();
|
initBranchSelector();
|
||||||
initCompMarkupContentPreviewTab($('.comment.form'));
|
initCompMarkupContentPreviewTab($('.comment.form'));
|
||||||
initCompImagePaste($('.comment.form'));
|
initCompImagePaste($('.comment.form'));
|
||||||
|
@ -262,7 +262,7 @@ async function onEditContent(event) {
|
||||||
const $renderContent = $segment.find('.render-content');
|
const $renderContent = $segment.find('.render-content');
|
||||||
const $rawContent = $segment.find('.raw-content');
|
const $rawContent = $segment.find('.raw-content');
|
||||||
let $textarea;
|
let $textarea;
|
||||||
let $simplemde;
|
let easyMDE;
|
||||||
|
|
||||||
// Setup new form
|
// Setup new form
|
||||||
if ($editContentZone.html().length === 0) {
|
if ($editContentZone.html().length === 0) {
|
||||||
|
@ -341,11 +341,11 @@ async function onEditContent(event) {
|
||||||
$tabMenu.find('.preview.item').attr('data-tab', $editContentZone.data('preview'));
|
$tabMenu.find('.preview.item').attr('data-tab', $editContentZone.data('preview'));
|
||||||
$editContentForm.find('.write').attr('data-tab', $editContentZone.data('write'));
|
$editContentForm.find('.write').attr('data-tab', $editContentZone.data('write'));
|
||||||
$editContentForm.find('.preview').attr('data-tab', $editContentZone.data('preview'));
|
$editContentForm.find('.preview').attr('data-tab', $editContentZone.data('preview'));
|
||||||
$simplemde = createCommentSimpleMDE($textarea);
|
easyMDE = createCommentEasyMDE($textarea);
|
||||||
|
|
||||||
initCompMarkupContentPreviewTab($editContentForm);
|
initCompMarkupContentPreviewTab($editContentForm);
|
||||||
if ($dropzone.length === 1) {
|
if ($dropzone.length === 1) {
|
||||||
initSimpleMDEImagePaste($simplemde, $dropzone[0], $dropzone.find('.files'));
|
initEasyMDEImagePaste(easyMDE, $dropzone[0], $dropzone.find('.files'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$editContentZone.find('.cancel.button').on('click', () => {
|
$editContentZone.find('.cancel.button').on('click', () => {
|
||||||
|
@ -395,7 +395,7 @@ async function onEditContent(event) {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$textarea = $segment.find('textarea');
|
$textarea = $segment.find('textarea');
|
||||||
$simplemde = $textarea.data('simplemde');
|
easyMDE = getAttachedEasyMDE($textarea);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show write/preview tab and copy raw content as needed
|
// Show write/preview tab and copy raw content as needed
|
||||||
|
@ -403,11 +403,11 @@ async function onEditContent(event) {
|
||||||
$renderContent.hide();
|
$renderContent.hide();
|
||||||
if ($textarea.val().length === 0) {
|
if ($textarea.val().length === 0) {
|
||||||
$textarea.val($rawContent.text());
|
$textarea.val($rawContent.text());
|
||||||
$simplemde.value($rawContent.text());
|
easyMDE.value($rawContent.text());
|
||||||
}
|
}
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
$textarea.focus();
|
$textarea.focus();
|
||||||
$simplemde.codemirror.focus();
|
easyMDE.codemirror.focus();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,9 +527,9 @@ export function initRepository() {
|
||||||
$(this).parent().hide();
|
$(this).parent().hide();
|
||||||
|
|
||||||
const $form = $repoComparePull.find('.pullrequest-form');
|
const $form = $repoComparePull.find('.pullrequest-form');
|
||||||
const $simplemde = $form.find('textarea.edit_area').data('simplemde');
|
const easyMDE = getAttachedEasyMDE($form.find('textarea.edit_area'));
|
||||||
$form.show();
|
$form.show();
|
||||||
$simplemde.codemirror.refresh();
|
easyMDE.codemirror.refresh();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -547,24 +547,24 @@ function initRepoIssueCommentEdit() {
|
||||||
const target = $(this).data('target');
|
const target = $(this).data('target');
|
||||||
const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> ');
|
const quote = $(`#comment-${target}`).text().replace(/\n/g, '\n> ');
|
||||||
const content = `> ${quote}\n\n`;
|
const content = `> ${quote}\n\n`;
|
||||||
let $simplemde;
|
let easyMDE;
|
||||||
if ($(this).hasClass('quote-reply-diff')) {
|
if ($(this).hasClass('quote-reply-diff')) {
|
||||||
const $parent = $(this).closest('.comment-code-cloud');
|
const $parent = $(this).closest('.comment-code-cloud');
|
||||||
$parent.find('button.comment-form-reply').trigger('click');
|
$parent.find('button.comment-form-reply').trigger('click');
|
||||||
$simplemde = $parent.find('[name="content"]').data('simplemde');
|
easyMDE = getAttachedEasyMDE($parent.find('[name="content"]'));
|
||||||
} else {
|
} else {
|
||||||
// for normal issue/comment page
|
// for normal issue/comment page
|
||||||
$simplemde = $('#comment-form .edit_area').data('simplemde');
|
easyMDE = getAttachedEasyMDE($('#comment-form .edit_area'));
|
||||||
}
|
}
|
||||||
if ($simplemde) {
|
if (easyMDE) {
|
||||||
if ($simplemde.value() !== '') {
|
if (easyMDE.value() !== '') {
|
||||||
$simplemde.value(`${$simplemde.value()}\n\n${content}`);
|
easyMDE.value(`${easyMDE.value()}\n\n${content}`);
|
||||||
} else {
|
} else {
|
||||||
$simplemde.value(`${content}`);
|
easyMDE.value(`${content}`);
|
||||||
}
|
}
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
$simplemde.codemirror.focus();
|
easyMDE.codemirror.focus();
|
||||||
$simplemde.codemirror.setCursor($simplemde.codemirror.lineCount(), 0);
|
easyMDE.codemirror.setCursor(easyMDE.codemirror.lineCount(), 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import attachTribute from './tribute.js';
|
import attachTribute from './tribute.js';
|
||||||
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
|
||||||
import {initSimpleMDEImagePaste} from './comp/ImagePaste.js';
|
import {initEasyMDEImagePaste} from './comp/ImagePaste.js';
|
||||||
import {createCommentSimpleMDE} from './comp/CommentSimpleMDE.js';
|
import {createCommentEasyMDE} from './comp/CommentEasyMDE.js';
|
||||||
|
|
||||||
export function initRepoRelease() {
|
export function initRepoRelease() {
|
||||||
$(document).on('click', '.remove-rel-attach', function() {
|
$(document).on('click', '.remove-rel-attach', function() {
|
||||||
|
@ -22,8 +22,8 @@ export function initRepoReleaseEditor() {
|
||||||
const $textarea = $editor.find('textarea');
|
const $textarea = $editor.find('textarea');
|
||||||
attachTribute($textarea.get(), {mentions: false, emoji: true});
|
attachTribute($textarea.get(), {mentions: false, emoji: true});
|
||||||
const $files = $editor.parent().find('.files');
|
const $files = $editor.parent().find('.files');
|
||||||
const $simplemde = createCommentSimpleMDE($textarea);
|
const easyMDE = createCommentEasyMDE($textarea);
|
||||||
initCompMarkupContentPreviewTab($editor);
|
initCompMarkupContentPreviewTab($editor);
|
||||||
const dropzone = $editor.parent().find('.dropzone')[0];
|
const dropzone = $editor.parent().find('.dropzone')[0];
|
||||||
initSimpleMDEImagePaste($simplemde, dropzone, $files);
|
initEasyMDEImagePaste(easyMDE, dropzone, $files);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,11 @@ export function initRepoWikiForm() {
|
||||||
const $editArea = $('.repository.wiki textarea#edit_area');
|
const $editArea = $('.repository.wiki textarea#edit_area');
|
||||||
let sideBySideChanges = 0;
|
let sideBySideChanges = 0;
|
||||||
let sideBySideTimeout = null;
|
let sideBySideTimeout = null;
|
||||||
let hasSimpleMDE = true;
|
let hasEasyMDE = true;
|
||||||
|
|
||||||
if ($editArea.length > 0) {
|
if ($editArea.length > 0) {
|
||||||
const $form = $('.repository.wiki.new .ui.form');
|
const $form = $('.repository.wiki.new .ui.form');
|
||||||
const simplemde = new SimpleMDE({
|
const easyMDE = new window.EasyMDE({
|
||||||
autoDownloadFontAwesome: false,
|
autoDownloadFontAwesome: false,
|
||||||
element: $editArea[0],
|
element: $editArea[0],
|
||||||
forceSync: true,
|
forceSync: true,
|
||||||
|
@ -36,7 +36,7 @@ export function initRepoWikiForm() {
|
||||||
};
|
};
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!simplemde.isSideBySideActive()) {
|
if (!easyMDE.isSideBySideActive()) {
|
||||||
render();
|
render();
|
||||||
} else {
|
} else {
|
||||||
// delay preview by keystroke counting
|
// delay preview by keystroke counting
|
||||||
|
@ -52,7 +52,7 @@ export function initRepoWikiForm() {
|
||||||
sideBySideTimeout = setTimeout(render, 600);
|
sideBySideTimeout = setTimeout(render, 600);
|
||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
if (!simplemde.isSideBySideActive()) {
|
if (!easyMDE.isSideBySideActive()) {
|
||||||
return 'Loading...';
|
return 'Loading...';
|
||||||
}
|
}
|
||||||
return preview.innerHTML;
|
return preview.innerHTML;
|
||||||
|
@ -106,7 +106,7 @@ export function initRepoWikiForm() {
|
||||||
name: 'revert-to-textarea',
|
name: 'revert-to-textarea',
|
||||||
action(e) {
|
action(e) {
|
||||||
e.toTextArea();
|
e.toTextArea();
|
||||||
hasSimpleMDE = false;
|
hasEasyMDE = false;
|
||||||
const $root = $form.find('.field.content');
|
const $root = $form.find('.field.content');
|
||||||
const loading = $root.data('loading');
|
const loading = $root.data('loading');
|
||||||
$root.append(`<div class="ui bottom tab markup" data-tab="preview">${loading}</div>`);
|
$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');
|
$markdownEditorTextArea.addClass('js-quick-submit');
|
||||||
|
|
||||||
$form.on('submit', function (e) {
|
$form.on('submit', function (e) {
|
||||||
// The original edit area HTML element is hidden and replaced by the
|
// 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.
|
// This is a workaround for this upstream bug.
|
||||||
// See https://github.com/sparksuite/simplemde-markdown-editor/issues/324
|
// See https://github.com/sparksuite/simplemde-markdown-editor/issues/324
|
||||||
const input = $editArea.val();
|
const input = $editArea.val();
|
||||||
|
@ -143,7 +143,7 @@ export function initRepoWikiForm() {
|
||||||
const $bPreview = $('.editor-toolbar button.preview');
|
const $bPreview = $('.editor-toolbar button.preview');
|
||||||
const $bSideBySide = $('.editor-toolbar a.fa-columns');
|
const $bSideBySide = $('.editor-toolbar a.fa-columns');
|
||||||
$bEdit.on('click', (e) => {
|
$bEdit.on('click', (e) => {
|
||||||
if (!hasSimpleMDE) {
|
if (!hasEasyMDE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
e.stopImmediatePropagation();
|
e.stopImmediatePropagation();
|
||||||
|
@ -154,7 +154,7 @@ export function initRepoWikiForm() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$bPrev.on('click', (e) => {
|
$bPrev.on('click', (e) => {
|
||||||
if (!hasSimpleMDE) {
|
if (!hasEasyMDE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
e.stopImmediatePropagation();
|
e.stopImmediatePropagation();
|
||||||
|
|
Loading…
Reference in a new issue