From 9947af639c24d185ace096d3f25098ff94c0790e Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 14 Dec 2023 16:51:05 +0800 Subject: [PATCH 1/5] Only use SHA256 feature when git >= 2.42 (#28466) And fix some comments --- modules/git/git.go | 6 +++--- modules/git/object_format.go | 2 -- modules/git/object_id.go | 8 +++----- modules/git/repo.go | 7 +++++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/modules/git/git.go b/modules/git/git.go index 12d2f94e514cc..166655eb738f5 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -33,8 +33,8 @@ var ( // DefaultContext is the default context to run git commands in, must be initialized by git.InitXxx DefaultContext context.Context - // SupportProcReceive version >= 2.29.0 - SupportProcReceive bool + SupportProcReceive bool // >= 2.29 + SupportHashSha256 bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’ gitVersion *version.Version ) @@ -189,7 +189,7 @@ func InitFull(ctx context.Context) (err error) { globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=") } SupportProcReceive = CheckGitVersionAtLeast("2.29") == nil - + SupportHashSha256 = CheckGitVersionAtLeast("2.42") == nil if setting.LFS.StartServer { if CheckGitVersionAtLeast("2.1.2") != nil { return errors.New("LFS server support requires Git >= 2.1.2") diff --git a/modules/git/object_format.go b/modules/git/object_format.go index 7f5d09170c6fb..3c52de772bb37 100644 --- a/modules/git/object_format.go +++ b/modules/git/object_format.go @@ -40,7 +40,6 @@ type ObjectFormat interface { NewHasher() HasherInterface } -/* SHA1 Type */ type Sha1ObjectFormat struct{} func (*Sha1ObjectFormat) ID() ObjectFormatID { return Sha1 } @@ -83,7 +82,6 @@ func (h *Sha1ObjectFormat) NewHasher() HasherInterface { return &Sha1Hasher{sha1.New()} } -// utils func ObjectFormatFromID(id ObjectFormatID) ObjectFormat { switch id { case Sha1: diff --git a/modules/git/object_id.go b/modules/git/object_id.go index 3cba6d4f724db..21e1c67c646c2 100644 --- a/modules/git/object_id.go +++ b/modules/git/object_id.go @@ -20,7 +20,6 @@ type ObjectID interface { Type() ObjectFormat } -/* SHA1 */ type Sha1Hash [20]byte func (h *Sha1Hash) String() string { @@ -38,7 +37,7 @@ func NewSha1() *Sha1Hash { return &Sha1Hash{} } -// generic implementations +// NewHash is for generic implementations func NewHash(hash string) (ObjectID, error) { hash = strings.ToLower(hash) switch hash { @@ -73,7 +72,6 @@ func genericIDFromString(h ObjectFormat, s string) (ObjectID, error) { return h.NewID(b) } -// utils func IDFromString(hexHash string) (ObjectID, error) { switch len(hexHash) { case 40: @@ -101,7 +99,7 @@ func IsEmptyCommitID(commitID string) bool { return id.IsZero() } -// HashInterface is a struct that will generate a Hash +// HasherInterface is a struct that will generate a Hash type HasherInterface interface { hash.Hash @@ -127,7 +125,7 @@ func ComputeHash(hashType ObjectFormat, t ObjectType, content []byte) ObjectID { return h.HashSum() } -// Sum generates a SHA1 for the provided hash +// HashSum generates a SHA1 for the provided hash func (h *Sha1Hasher) HashSum() ObjectID { var sha1 Sha1Hash copy(sha1[:], h.Hash.Sum(nil)) diff --git a/modules/git/repo.go b/modules/git/repo.go index 871d267a5b84c..c036a217eb25c 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -63,7 +63,7 @@ func IsRepoURLAccessible(ctx context.Context, url string) bool { return err == nil } -// GetObjectFormatOfRepo returns the hash type of a repository at a given path +// GetObjectFormatOfRepo returns the hash type of repository at a given path func GetObjectFormatOfRepo(ctx context.Context, repoPath string) (ObjectFormat, error) { var stdout, stderr strings.Builder @@ -96,7 +96,10 @@ func InitRepository(ctx context.Context, repoPath string, bare bool, objectForma return err } - cmd := NewCommand(ctx, "init", "--object-format").AddDynamicArguments(objectFormat.String()) + cmd := NewCommand(ctx, "init") + if SupportHashSha256 { + cmd.AddOptionValues("--object-format", objectFormat.String()) + } if bare { cmd.AddArguments("--bare") } From e85db6c8c37bd0643deb704e857d369288a3ca0f Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 14 Dec 2023 16:52:16 +0800 Subject: [PATCH 2/5] Fix documents for "custom/public/assets/" (#28465) Fix #28463 --- docs/content/administration/adding-legal-pages.en-us.md | 4 ++-- docs/content/administration/adding-legal-pages.zh-cn.md | 4 ++-- docs/content/administration/customizing-gitea.zh-cn.md | 4 ++-- docs/content/administration/external-renderers.zh-cn.md | 2 +- docs/content/help/faq.zh-cn.md | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/content/administration/adding-legal-pages.en-us.md b/docs/content/administration/adding-legal-pages.en-us.md index c6f68edcd0e5e..1ff0c0132d296 100644 --- a/docs/content/administration/adding-legal-pages.en-us.md +++ b/docs/content/administration/adding-legal-pages.en-us.md @@ -19,10 +19,10 @@ Some jurisdictions (such as EU), requires certain legal pages (e.g. Privacy Poli ## Getting Pages -Gitea source code ships with sample pages, available in `contrib/legal` directory. Copy them to `custom/public/`. For example, to add Privacy Policy: +Gitea source code ships with sample pages, available in `contrib/legal` directory. Copy them to `custom/public/assets/`. For example, to add Privacy Policy: ``` -wget -O /path/to/custom/public/privacy.html https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/legal/privacy.html.sample +wget -O /path/to/custom/public/assets/privacy.html https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/legal/privacy.html.sample ``` Now you need to edit the page to meet your requirements. In particular you must change the email addresses, web addresses and references to "Your Gitea Instance" to match your situation. diff --git a/docs/content/administration/adding-legal-pages.zh-cn.md b/docs/content/administration/adding-legal-pages.zh-cn.md index 5d582e871de56..3e18c6e6b03b1 100644 --- a/docs/content/administration/adding-legal-pages.zh-cn.md +++ b/docs/content/administration/adding-legal-pages.zh-cn.md @@ -19,10 +19,10 @@ menu: ## 获取页面 -Gitea 源代码附带了示例页面,位于 `contrib/legal` 目录中。将它们复制到 `custom/public/` 目录下。例如,如果要添加隐私政策: +Gitea 源代码附带了示例页面,位于 `contrib/legal` 目录中。将它们复制到 `custom/public/assets/` 目录下。例如,如果要添加隐私政策: ``` -wget -O /path/to/custom/public/privacy.html https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/legal/privacy.html.sample +wget -O /path/to/custom/public/assets/privacy.html https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/legal/privacy.html.sample ``` 现在,你需要编辑该页面以满足你的需求。特别是,你必须更改电子邮件地址、网址以及与 "Your Gitea Instance" 相关的引用,以匹配你的情况。 diff --git a/docs/content/administration/customizing-gitea.zh-cn.md b/docs/content/administration/customizing-gitea.zh-cn.md index d828704557cfa..f41533c69cb75 100644 --- a/docs/content/administration/customizing-gitea.zh-cn.md +++ b/docs/content/administration/customizing-gitea.zh-cn.md @@ -42,11 +42,11 @@ Gitea 引用 `custom` 目录中的自定义配置文件来覆盖配置、模板 将自定义的公共文件(比如页面和图片)作为 webroot 放在 `custom/public/` 中来让 Gitea 提供这些自定义内容(符号链接将被追踪)。 -举例说明:`image.png` 存放在 `custom/public/`中,那么它可以通过链接 http://gitea.domain.tld/assets/image.png 访问。 +举例说明:`image.png` 存放在 `custom/public/assets/`中,那么它可以通过链接 http://gitea.domain.tld/assets/image.png 访问。 ## 修改默认头像 -替换以下目录中的 png 图片: `custom/public/img/avatar\_default.png` +替换以下目录中的 png 图片: `custom/public/assets/img/avatar\_default.png` ## 自定义 Gitea 页面 diff --git a/docs/content/administration/external-renderers.zh-cn.md b/docs/content/administration/external-renderers.zh-cn.md index 0b53b452776a2..fdf7315d7b7b2 100644 --- a/docs/content/administration/external-renderers.zh-cn.md +++ b/docs/content/administration/external-renderers.zh-cn.md @@ -194,7 +194,7 @@ ALLOW_DATA_URI_IMAGES = true } ``` -将您的样式表添加到自定义目录中,例如 `custom/public/css/my-style-XXXXX.css`,并使用自定义的头文件 `custom/templates/custom/header.tmpl` 进行导入: +将您的样式表添加到自定义目录中,例如 `custom/public/assets/css/my-style-XXXXX.css`,并使用自定义的头文件 `custom/templates/custom/header.tmpl` 进行导入: ```html diff --git a/docs/content/help/faq.zh-cn.md b/docs/content/help/faq.zh-cn.md index 096ac05f48beb..d7847a148de70 100644 --- a/docs/content/help/faq.zh-cn.md +++ b/docs/content/help/faq.zh-cn.md @@ -189,7 +189,7 @@ Gitea 目前支持三个官方主题,分别是 `gitea-light`、`gitea-dark` 假设我们的主题是 `arc-blue`(这是一个真实的主题,可以在[此问题](https://github.com/go-gitea/gitea/issues/6011)中找到) -将`.css`文件命名为`theme-arc-blue.css`并将其添加到`custom/public/css`文件夹中 +将`.css`文件命名为`theme-arc-blue.css`并将其添加到`custom/public/assets/css`文件夹中 通过将`arc-blue`添加到`app.ini`中的`THEMES`列表中,允许用户使用该主题 From e08f1a9cbd582c73918e401eeba36261627f44a7 Mon Sep 17 00:00:00 2001 From: sebastian-sauer Date: Thu, 14 Dec 2023 10:26:59 +0100 Subject: [PATCH 3/5] Add combined index for issue_user.uid and issue_id (#28080) fixes #27877 --------- Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lunny Xiao --- models/issues/issue_user.go | 4 +-- .../issue_user.yml | 20 +++++++++++ models/migrations/migrations.go | 2 ++ models/migrations/v1_22/main_test.go | 14 ++++++++ models/migrations/v1_22/v283.go | 34 +++++++++++++++++++ models/migrations/v1_22/v283_test.go | 28 +++++++++++++++ 6 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 models/migrations/fixtures/Test_AddCombinedIndexToIssueUser/issue_user.yml create mode 100644 models/migrations/v1_22/main_test.go create mode 100644 models/migrations/v1_22/v283.go create mode 100644 models/migrations/v1_22/v283_test.go diff --git a/models/issues/issue_user.go b/models/issues/issue_user.go index 24bb74648d9ce..6b59e0725edeb 100644 --- a/models/issues/issue_user.go +++ b/models/issues/issue_user.go @@ -14,8 +14,8 @@ import ( // IssueUser represents an issue-user relation. type IssueUser struct { ID int64 `xorm:"pk autoincr"` - UID int64 `xorm:"INDEX"` // User ID. - IssueID int64 `xorm:"INDEX"` + UID int64 `xorm:"INDEX unique(uid_to_issue)"` // User ID. + IssueID int64 `xorm:"INDEX unique(uid_to_issue)"` IsRead bool IsMentioned bool } diff --git a/models/migrations/fixtures/Test_AddCombinedIndexToIssueUser/issue_user.yml b/models/migrations/fixtures/Test_AddCombinedIndexToIssueUser/issue_user.yml new file mode 100644 index 0000000000000..7bbb6f2f307f4 --- /dev/null +++ b/models/migrations/fixtures/Test_AddCombinedIndexToIssueUser/issue_user.yml @@ -0,0 +1,20 @@ +- + id: 1 + uid: 1 + issue_id: 1 + is_read: true + is_mentioned: false + +- + id: 2 + uid: 2 + issue_id: 1 + is_read: true + is_mentioned: false + +- + id: 3 + uid: 2 + issue_id: 1 # duplicated with id 2 + is_read: false + is_mentioned: true diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 28e3be503b299..578cbca035d85 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -550,6 +550,8 @@ var migrations = []Migration{ NewMigration("Add auth_token table", v1_22.CreateAuthTokenTable), // v282 -> v283 NewMigration("Add Index to pull_auto_merge.doer_id", v1_22.AddIndexToPullAutoMergeDoerID), + // v283 -> v284 + NewMigration("Add combined Index to issue_user.uid and issue_id", v1_22.AddCombinedIndexToIssueUser), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_22/main_test.go b/models/migrations/v1_22/main_test.go new file mode 100644 index 0000000000000..efd8dbaa8c6b5 --- /dev/null +++ b/models/migrations/v1_22/main_test.go @@ -0,0 +1,14 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_22 //nolint + +import ( + "testing" + + "code.gitea.io/gitea/models/migrations/base" +) + +func TestMain(m *testing.M) { + base.MainTest(m) +} diff --git a/models/migrations/v1_22/v283.go b/models/migrations/v1_22/v283.go new file mode 100644 index 0000000000000..b2b94845d905e --- /dev/null +++ b/models/migrations/v1_22/v283.go @@ -0,0 +1,34 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_22 //nolint + +import ( + "xorm.io/xorm" +) + +func AddCombinedIndexToIssueUser(x *xorm.Engine) error { + type OldIssueUser struct { + IssueID int64 + UID int64 + Cnt int64 + } + + var duplicatedIssueUsers []OldIssueUser + if err := x.SQL("select * from (select issue_id, uid, count(1) as cnt from issue_user group by issue_id, uid) a where a.cnt > 1"). + Find(&duplicatedIssueUsers); err != nil { + return err + } + for _, issueUser := range duplicatedIssueUsers { + if _, err := x.Exec("delete from issue_user where id in (SELECT id FROM issue_user WHERE issue_id = ? and uid = ? limit ?)", issueUser.IssueID, issueUser.UID, issueUser.Cnt-1); err != nil { + return err + } + } + + type IssueUser struct { + UID int64 `xorm:"INDEX unique(uid_to_issue)"` // User ID. + IssueID int64 `xorm:"INDEX unique(uid_to_issue)"` + } + + return x.Sync(&IssueUser{}) +} diff --git a/models/migrations/v1_22/v283_test.go b/models/migrations/v1_22/v283_test.go new file mode 100644 index 0000000000000..864f47f840c01 --- /dev/null +++ b/models/migrations/v1_22/v283_test.go @@ -0,0 +1,28 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_22 //nolint + +import ( + "testing" + + "code.gitea.io/gitea/models/migrations/base" +) + +func Test_AddCombinedIndexToIssueUser(t *testing.T) { + type IssueUser struct { + UID int64 `xorm:"INDEX unique(uid_to_issue)"` // User ID. + IssueID int64 `xorm:"INDEX unique(uid_to_issue)"` + } + + // Prepare and load the testing database + x, deferable := base.PrepareTestEnv(t, 0, new(IssueUser)) + defer deferable() + if x == nil || t.Failed() { + return + } + + if err := AddCombinedIndexToIssueUser(x); err != nil { + t.Fatal(err) + } +} From 8c91e315406730937322fcbeea5115c6ac3f82c2 Mon Sep 17 00:00:00 2001 From: CaiCandong <50507092+CaiCandong@users.noreply.github.com> Date: Fri, 15 Dec 2023 00:00:04 +0800 Subject: [PATCH 4/5] Fix Chinese translation of config cheat sheet[API] (#28472) --- docs/content/administration/config-cheat-sheet.zh-cn.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/content/administration/config-cheat-sheet.zh-cn.md b/docs/content/administration/config-cheat-sheet.zh-cn.md index c4e3876c1fedc..eed752c1cbd7d 100644 --- a/docs/content/administration/config-cheat-sheet.zh-cn.md +++ b/docs/content/administration/config-cheat-sheet.zh-cn.md @@ -1039,10 +1039,11 @@ Gitea 创建以下非唯一队列: ## API (`api`) -- `ENABLE_SWAGGER`: **true**: 是否启用swagger路由 (`/api/swagger`, `/api/v1/swagger`, …)。 -- `MAX_RESPONSE_ITEMS`: **50**: 单个页面的最大 Feed. -- `ENABLE_OPENID_SIGNIN`: **false**: 允许使用OpenID登录,当设置为`true`时可以通过 `/user/login` 页面进行OpenID登录。 -- `DISABLE_REGISTRATION`: **false**: 关闭用户注册。 +- `ENABLE_SWAGGER`: **true**: 启用API文档接口 (`/api/swagger`, `/api/v1/swagger`, …). True or false。 +- `MAX_RESPONSE_ITEMS`: **50**: API分页的最大单页项目数。 +- `DEFAULT_PAGING_NUM`: **30**: API分页的默认分页数。 +- `DEFAULT_GIT_TREES_PER_PAGE`: **1000**: Git trees API的默认单页项目数。 +- `DEFAULT_MAX_BLOB_SIZE`: **10485760** (10MiB): blobs API的默认最大文件大小。 ## OAuth2 (`oauth2`) From 6632d1497c9fc644c696e9a1239cd62baa5dc29e Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 15 Dec 2023 07:26:36 +0800 Subject: [PATCH 5/5] Polyfill SubmitEvent for PaleMoon (#28441) --- web_src/js/features/common-global.js | 6 ++++-- web_src/js/features/common-issue-list.js | 4 ++-- web_src/js/features/repo-diff.js | 3 ++- web_src/js/modules/tippy.js | 2 +- web_src/js/utils/dom.js | 21 +++++++++++++++++++++ web_src/js/webcomponents/webcomponents.js | 2 +- 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index c2e0111849b08..0b00eb8e8ea74 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -6,7 +6,7 @@ import {initCompColorPicker} from './comp/ColorPicker.js'; import {showGlobalErrorMessage} from '../bootstrap.js'; import {handleGlobalEnterQuickSubmit} from './comp/QuickSubmit.js'; import {svg} from '../svg.js'; -import {hideElem, showElem, toggleElem} from '../utils/dom.js'; +import {hideElem, showElem, toggleElem, initSubmitEventPolyfill, submitEventSubmitter} from '../utils/dom.js'; import {htmlEscape} from 'escape-goat'; import {showTemporaryTooltip} from '../modules/tippy.js'; import {confirmModal} from './comp/ConfirmModal.js'; @@ -121,7 +121,8 @@ async function formFetchAction(e) { const formMethod = formEl.getAttribute('method') || 'get'; const formActionUrl = formEl.getAttribute('action'); const formData = new FormData(formEl); - const [submitterName, submitterValue] = [e.submitter?.getAttribute('name'), e.submitter?.getAttribute('value')]; + const formSubmitter = submitEventSubmitter(e); + const [submitterName, submitterValue] = [formSubmitter?.getAttribute('name'), formSubmitter?.getAttribute('value')]; if (submitterName) { formData.append(submitterName, submitterValue || ''); } @@ -192,6 +193,7 @@ export function initGlobalCommon() { $('.tabular.menu .item').tab(); + initSubmitEventPolyfill(); document.addEventListener('submit', formFetchAction); document.addEventListener('click', linkAction); } diff --git a/web_src/js/features/common-issue-list.js b/web_src/js/features/common-issue-list.js index 3a28cf900ca5c..317c11219bd27 100644 --- a/web_src/js/features/common-issue-list.js +++ b/web_src/js/features/common-issue-list.js @@ -1,5 +1,5 @@ import $ from 'jquery'; -import {isElemHidden, onInputDebounce, toggleElem} from '../utils/dom.js'; +import {isElemHidden, onInputDebounce, submitEventSubmitter, toggleElem} from '../utils/dom.js'; import {GET} from '../modules/fetch.js'; const {appSubUrl} = window.config; @@ -40,7 +40,7 @@ export function initCommonIssueListQuickGoto() { $form.on('submit', (e) => { // if there is no goto button, or the form is submitted by non-quick-goto elements, submit the form directly let doQuickGoto = !isElemHidden($goto); - const submitter = e.originalEvent.submitter; + const submitter = submitEventSubmitter(e.originalEvent); if (submitter !== $form[0] && submitter !== $input[0] && submitter !== $goto[0]) doQuickGoto = false; if (!doQuickGoto) return; diff --git a/web_src/js/features/repo-diff.js b/web_src/js/features/repo-diff.js index e74db04d08ff3..eeb80e91b2cc5 100644 --- a/web_src/js/features/repo-diff.js +++ b/web_src/js/features/repo-diff.js @@ -7,6 +7,7 @@ import {validateTextareaNonEmpty} from './comp/ComboMarkdownEditor.js'; import {initViewedCheckboxListenerFor, countAndUpdateViewedFiles, initExpandAndCollapseFilesButton} from './pull-view-file.js'; import {initImageDiff} from './imagediff.js'; import {showErrorToast} from '../modules/toast.js'; +import {submitEventSubmitter} from '../utils/dom.js'; const {csrfToken, pageData, i18n} = window.config; @@ -57,7 +58,7 @@ function initRepoDiffConversationForm() { const formData = new FormData($form[0]); // if the form is submitted by a button, append the button's name and value to the form data - const submitter = e.originalEvent?.submitter; + const submitter = submitEventSubmitter(e.originalEvent); const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit'); if (isSubmittedByButton && submitter.name) { formData.append(submitter.name, submitter.value); diff --git a/web_src/js/modules/tippy.js b/web_src/js/modules/tippy.js index d27908962f53a..7f8423e3191cf 100644 --- a/web_src/js/modules/tippy.js +++ b/web_src/js/modules/tippy.js @@ -106,7 +106,7 @@ function switchTitleToTooltip(target) { /** * Creating tooltip tippy instance is expensive, so we only create it when the user hovers over the element * According to https://www.w3.org/TR/DOM-Level-3-Events/#events-mouseevent-event-order , mouseover event is fired before mouseenter event - * Some old browsers like Pale Moon doesn't support "mouseenter(capture)" + * Some browsers like PaleMoon don't support "addEventListener('mouseenter', capture)" * The tippy by default uses "mouseenter" event to show, so we use "mouseover" event to switch to tippy * @param e {Event} */ diff --git a/web_src/js/utils/dom.js b/web_src/js/utils/dom.js index 403933883ad23..64a6a5affc482 100644 --- a/web_src/js/utils/dom.js +++ b/web_src/js/utils/dom.js @@ -194,3 +194,24 @@ export function loadElem(el, src) { el.src = src; }); } + +// some browsers like PaleMoon don't have "SubmitEvent" support, so polyfill it by a tricky method: use the last clicked button as submitter +// it can't use other transparent polyfill patches because PaleMoon also doesn't support "addEventListener(capture)" +const needSubmitEventPolyfill = typeof SubmitEvent === 'undefined'; + +export function submitEventSubmitter(e) { + return needSubmitEventPolyfill ? (e.target._submitter || null) : e.submitter; +} + +function submitEventPolyfillListener(e) { + const form = e.target.closest('form'); + if (!form) return; + form._submitter = e.target.closest('button:not([type]), button[type="submit"], input[type="submit"]'); +} + +export function initSubmitEventPolyfill() { + if (!needSubmitEventPolyfill) return; + console.warn(`This browser doesn't have "SubmitEvent" support, use a tricky method to polyfill`); + document.body.addEventListener('click', submitEventPolyfillListener); + document.body.addEventListener('focus', submitEventPolyfillListener); +} diff --git a/web_src/js/webcomponents/webcomponents.js b/web_src/js/webcomponents/webcomponents.js index b17a4a832f704..916a588db64bf 100644 --- a/web_src/js/webcomponents/webcomponents.js +++ b/web_src/js/webcomponents/webcomponents.js @@ -1,4 +1,4 @@ -import '@webcomponents/custom-elements'; // polyfill for some browsers like Pale Moon +import '@webcomponents/custom-elements'; // polyfill for some browsers like PaleMoon import './polyfill.js'; import '@github/relative-time-element';