From 3338246533a0adc86866800559090b9e6f0b411f Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 22 Dec 2021 21:14:02 +0800 Subject: [PATCH 1/2] Load EasyMDE/CodeMirror dynamically, remove RequireEasyMDE --- routers/web/repo/commit.go | 1 - routers/web/repo/compare.go | 1 - routers/web/repo/editor.go | 4 - routers/web/repo/issue.go | 3 - routers/web/repo/pull.go | 2 - routers/web/repo/release.go | 4 - routers/web/repo/wiki.go | 4 - templates/base/footer.tmpl | 8 - templates/base/head.tmpl | 3 - web_src/js/easymde.js | 7 - .../comp/{CommentEasyMDE.js => EasyMDE.js} | 71 +++- web_src/js/features/repo-issue.js | 13 +- web_src/js/features/repo-legacy.js | 5 +- web_src/js/features/repo-release.js | 18 +- web_src/js/features/repo-wiki.js | 336 +++++++++--------- webpack.config.js | 4 - 16 files changed, 254 insertions(+), 230 deletions(-) delete mode 100644 web_src/js/easymde.js rename web_src/js/features/comp/{CommentEasyMDE.js => EasyMDE.js} (56%) diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index e012bc24d287f..304f76158cdb6 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -254,7 +254,6 @@ func FileHistory(ctx *context.Context) { func Diff(ctx *context.Context) { ctx.Data["PageIsDiff"] = true ctx.Data["RequireHighlightJS"] = true - ctx.Data["RequireEasyMDE"] = true ctx.Data["RequireTribute"] = true userName := ctx.Repo.Owner.Name diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index c540cbc08ae50..73a9d0ef3a3cb 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -760,7 +760,6 @@ func CompareDiff(ctx *context.Context) { ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["IsDiffCompare"] = true ctx.Data["RequireTribute"] = true - ctx.Data["RequireEasyMDE"] = true setTemplateIfExists(ctx, pullRequestTemplateKey, nil, pullRequestTemplateCandidates) ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "comment") diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index 12098ddc69112..1a7edb7bb40ed 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -69,7 +69,6 @@ func editFile(ctx *context.Context, isNewFile bool) { ctx.Data["PageIsEdit"] = true ctx.Data["IsNewFile"] = isNewFile ctx.Data["RequireHighlightJS"] = true - ctx.Data["RequireEasyMDE"] = true canCommit := renderCommitRights(ctx) treePath := cleanUploadFileName(ctx.Repo.TreePath) @@ -200,7 +199,6 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b ctx.Data["PageHasPosted"] = true ctx.Data["IsNewFile"] = isNewFile ctx.Data["RequireHighlightJS"] = true - ctx.Data["RequireEasyMDE"] = true ctx.Data["TreePath"] = form.TreePath ctx.Data["TreeNames"] = treeNames ctx.Data["TreePaths"] = treePaths @@ -544,7 +542,6 @@ func DeleteFilePost(ctx *context.Context) { func UploadFile(ctx *context.Context) { ctx.Data["PageIsUpload"] = true ctx.Data["RequireTribute"] = true - ctx.Data["RequireEasyMDE"] = true upload.AddUploadContext(ctx, "repo") canCommit := renderCommitRights(ctx) treePath := cleanUploadFileName(ctx.Repo.TreePath) @@ -580,7 +577,6 @@ func UploadFilePost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.UploadRepoFileForm) ctx.Data["PageIsUpload"] = true ctx.Data["RequireTribute"] = true - ctx.Data["RequireEasyMDE"] = true upload.AddUploadContext(ctx, "repo") canCommit := renderCommitRights(ctx) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index d55b6c96b6aff..d8af8c84d91ca 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -789,7 +789,6 @@ func NewIssue(ctx *context.Context) { ctx.Data["PageIsIssueList"] = true ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0 ctx.Data["RequireHighlightJS"] = true - ctx.Data["RequireEasyMDE"] = true ctx.Data["RequireTribute"] = true ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes title := ctx.FormString("title") @@ -962,7 +961,6 @@ func NewIssuePost(ctx *context.Context) { ctx.Data["PageIsIssueList"] = true ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0 ctx.Data["RequireHighlightJS"] = true - ctx.Data["RequireEasyMDE"] = true ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "comment") @@ -1147,7 +1145,6 @@ func ViewIssue(ctx *context.Context) { ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireTribute"] = true - ctx.Data["RequireEasyMDE"] = true ctx.Data["IsProjectsEnabled"] = ctx.Repo.CanRead(unit.TypeProjects) ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "comment") diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index bf80a7e5dfe62..d67c26bed9a10 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -701,7 +701,6 @@ func ViewPullFiles(ctx *context.Context) { setCompareContext(ctx, baseCommit, commit, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) ctx.Data["RequireHighlightJS"] = true - ctx.Data["RequireEasyMDE"] = true ctx.Data["RequireTribute"] = true if ctx.Data["Assignees"], err = models.GetRepoAssignees(ctx.Repo.Repository); err != nil { ctx.ServerError("GetAssignees", err) @@ -1050,7 +1049,6 @@ func CompareAndPullRequestPost(ctx *context.Context) { ctx.Data["IsDiffCompare"] = true ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["RequireTribute"] = true - ctx.Data["RequireEasyMDE"] = true ctx.Data["RequireHighlightJS"] = true ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index 8478cb44aef55..f2ab8b85f227e 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -262,7 +262,6 @@ func LatestRelease(ctx *context.Context) { func NewRelease(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.release.new_release") ctx.Data["PageIsReleaseList"] = true - ctx.Data["RequireEasyMDE"] = true ctx.Data["RequireTribute"] = true ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch if tagName := ctx.FormString("tag"); len(tagName) > 0 { @@ -296,7 +295,6 @@ func NewReleasePost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.NewReleaseForm) ctx.Data["Title"] = ctx.Tr("repo.release.new_release") ctx.Data["PageIsReleaseList"] = true - ctx.Data["RequireEasyMDE"] = true ctx.Data["RequireTribute"] = true if ctx.HasError() { @@ -415,7 +413,6 @@ func EditRelease(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.release.edit_release") ctx.Data["PageIsReleaseList"] = true ctx.Data["PageIsEditRelease"] = true - ctx.Data["RequireEasyMDE"] = true ctx.Data["RequireTribute"] = true ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled upload.AddUploadContext(ctx, "release") @@ -454,7 +451,6 @@ func EditReleasePost(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.release.edit_release") ctx.Data["PageIsReleaseList"] = true ctx.Data["PageIsEditRelease"] = true - ctx.Data["RequireEasyMDE"] = true ctx.Data["RequireTribute"] = true tagName := ctx.Params("*") diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go index 7bce7cf11cc12..d449800b84417 100644 --- a/routers/web/repo/wiki.go +++ b/routers/web/repo/wiki.go @@ -622,7 +622,6 @@ func WikiRaw(ctx *context.Context) { func NewWiki(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page") ctx.Data["PageIsWiki"] = true - ctx.Data["RequireEasyMDE"] = true if !ctx.Repo.Repository.HasWiki() { ctx.Data["title"] = "Home" @@ -639,7 +638,6 @@ func NewWikiPost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.NewWikiForm) ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page") ctx.Data["PageIsWiki"] = true - ctx.Data["RequireEasyMDE"] = true if ctx.HasError() { ctx.HTML(http.StatusOK, tplWikiNew) @@ -677,7 +675,6 @@ func NewWikiPost(ctx *context.Context) { func EditWiki(ctx *context.Context) { ctx.Data["PageIsWiki"] = true ctx.Data["PageIsWikiEdit"] = true - ctx.Data["RequireEasyMDE"] = true if !ctx.Repo.Repository.HasWiki() { ctx.Redirect(ctx.Repo.RepoLink + "/wiki") @@ -697,7 +694,6 @@ func EditWikiPost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.NewWikiForm) ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page") ctx.Data["PageIsWiki"] = true - ctx.Data["RequireEasyMDE"] = true if ctx.HasError() { ctx.HTML(http.StatusOK, tplWikiNew) diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl index 2b641cc9de734..122b3b46b4e96 100644 --- a/templates/base/footer.tmpl +++ b/templates/base/footer.tmpl @@ -12,14 +12,6 @@ {{template "custom/body_outer_post" .}} {{template "base/footer_content" .}} -{{if .RequireEasyMDE}} - - - - -{{end}} {{if .RequireU2F}} diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index e9c2d512dfbd4..4c7fb7999cc00 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -56,9 +56,6 @@ -{{if .RequireEasyMDE}} - -{{end}}