From 59eb660b1a6881b2cdded486b67c3c283207c255 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 26 Mar 2023 20:06:11 +0800 Subject: [PATCH] Fix incorrect `toggle` buttons (#23676) Some of those are still Copy&Paste problems. This PR: * Only cleans the legacy incorrect code, doesn't change or improve the "action" logic. * Remove the redundant `$('.toggle.button').on('click')`, now `$('.show-panel.button').on('click')` handles that kinds of buttons Actually, there is only one correct "toggle button" in code, the one on the webhook page. No need to backport. --- templates/repo/diff/options_dropdown.tmpl | 2 +- templates/repo/diff/whitespace_dropdown.tmpl | 2 +- templates/repo/settings/webhook/history.tmpl | 2 +- web_src/js/features/common-global.js | 13 ++++++++----- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/templates/repo/diff/options_dropdown.tmpl b/templates/repo/diff/options_dropdown.tmpl index 8bb92c45fe..93e1183d1b 100644 --- a/templates/repo/diff/options_dropdown.tmpl +++ b/templates/repo/diff/options_dropdown.tmpl @@ -1,7 +1,7 @@ -{{if .IsSplitStyle}}{{svg "gitea-join"}}{{else}}{{svg "gitea-split"}}{{end}} +{{if .IsSplitStyle}}{{svg "gitea-join"}}{{else}}{{svg "gitea-split"}}{{end}} diff --git a/templates/repo/settings/webhook/history.tmpl b/templates/repo/settings/webhook/history.tmpl index ff482846a7..e573d221d1 100644 --- a/templates/repo/settings/webhook/history.tmpl +++ b/templates/repo/settings/webhook/history.tmpl @@ -18,7 +18,7 @@ {{else}} {{svg "octicon-alert"}} {{end}} - {{.UUID}} + {{.UUID}}
{{.DeliveredString}} diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index a061e53d8a..96fa8a7dd2 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -118,10 +118,6 @@ export function initGlobalCommon() { $('.tabular.menu .item').tab(); - $('.toggle.button').on('click', function () { - toggleElem($($(this).data('target'))); - }); - // prevent multiple form submissions on forms containing .loading-button document.addEventListener('submit', (e) => { const btn = e.target.querySelector('.loading-button'); @@ -310,8 +306,15 @@ export function initGlobalButtons() { }); $('.show-panel.button').on('click', function (e) { + // a '.show-panel.button' can show a panel, by `data-panel="selector"` + // if the button is a "toggle" button, it toggles the panel e.preventDefault(); - showElem($(this).data('panel')); + const sel = $(this).attr('data-panel'); + if (this.classList.contains('toggle')) { + toggleElem(sel); + } else { + showElem(sel); + } }); $('.hide-panel.button').on('click', function (e) {