Skip to content

Commit 59eb660

Browse files
authored
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.
1 parent 12fff36 commit 59eb660

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

templates/repo/diff/options_dropdown.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="ui dropdown tiny basic button icon-button" data-tooltip-content="{{.locale.Tr "repo.diff.options_button"}}">
22
{{svg "octicon-kebab-horizontal"}}
33
<div class="menu">
4-
<a class="item tiny basic toggle button" id="show-file-list-btn">{{.locale.Tr "repo.diff.show_diff_stats"}}</a>
4+
<a class="item" id="show-file-list-btn">{{.locale.Tr "repo.diff.show_diff_stats"}}</a>
55
{{if .Issue.Index}}
66
<a class="item" href="{{$.RepoLink}}/pulls/{{.Issue.Index}}.patch" download="{{.Issue.Index}}.patch">{{.locale.Tr "repo.diff.download_patch"}}</a>
77
<a class="item" href="{{$.RepoLink}}/pulls/{{.Issue.Index}}.diff" download="{{.Issue.Index}}.diff">{{.locale.Tr "repo.diff.download_diff"}}</a>

templates/repo/diff/whitespace_dropdown.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
</a>
2929
</div>
3030
</div>
31-
<a class="ui tiny basic toggle button icon-button" href="?style={{if .IsSplitStyle}}unified{{else}}split{{end}}&whitespace={{$.WhitespaceBehavior}}" data-tooltip-content="{{if .IsSplitStyle}}{{.locale.Tr "repo.diff.show_unified_view"}}{{else}}{{.locale.Tr "repo.diff.show_split_view"}}{{end}}">{{if .IsSplitStyle}}{{svg "gitea-join"}}{{else}}{{svg "gitea-split"}}{{end}}</a>
31+
<a class="ui tiny basic button icon-button" href="?style={{if .IsSplitStyle}}unified{{else}}split{{end}}&whitespace={{$.WhitespaceBehavior}}" data-tooltip-content="{{if .IsSplitStyle}}{{.locale.Tr "repo.diff.show_unified_view"}}{{else}}{{.locale.Tr "repo.diff.show_split_view"}}{{end}}">{{if .IsSplitStyle}}{{svg "gitea-join"}}{{else}}{{svg "gitea-split"}}{{end}}</a>

templates/repo/settings/webhook/history.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{{else}}
1919
<span class="text red">{{svg "octicon-alert"}}</span>
2020
{{end}}
21-
<a class="ui primary sha label toggle button" data-target="#info-{{.ID}}">{{.UUID}}</a>
21+
<a class="ui primary sha label toggle button show-panel" data-panel="#info-{{.ID}}">{{.UUID}}</a>
2222
<div class="ui right">
2323
<span class="text grey time">
2424
{{.DeliveredString}}

web_src/js/features/common-global.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ export function initGlobalCommon() {
118118

119119
$('.tabular.menu .item').tab();
120120

121-
$('.toggle.button').on('click', function () {
122-
toggleElem($($(this).data('target')));
123-
});
124-
125121
// prevent multiple form submissions on forms containing .loading-button
126122
document.addEventListener('submit', (e) => {
127123
const btn = e.target.querySelector('.loading-button');
@@ -310,8 +306,15 @@ export function initGlobalButtons() {
310306
});
311307

312308
$('.show-panel.button').on('click', function (e) {
309+
// a '.show-panel.button' can show a panel, by `data-panel="selector"`
310+
// if the button is a "toggle" button, it toggles the panel
313311
e.preventDefault();
314-
showElem($(this).data('panel'));
312+
const sel = $(this).attr('data-panel');
313+
if (this.classList.contains('toggle')) {
314+
toggleElem(sel);
315+
} else {
316+
showElem(sel);
317+
}
315318
});
316319

317320
$('.hide-panel.button').on('click', function (e) {

0 commit comments

Comments
 (0)