Skip to content

Commit 91090b1

Browse files
committed
clean up
1 parent 61d6b66 commit 91090b1

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

templates/repo/commits_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
{{end}}
4949
</span>
5050
{{if IsMultilineCommitMessage .Message}}
51-
<button class="ui button js-toggle-commit-body ellipsis-button" aria-expanded="false" data-global-click="onRepoEllipsisButtonClick">...</button>
51+
<button class="ui button ellipsis-button" aria-expanded="false" data-global-click="onRepoEllipsisButtonClick">...</button>
5252
{{end}}
5353
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses}}
5454
{{if IsMultilineCommitMessage .Message}}

templates/repo/latest_commit.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
{{$commitLink:= printf "%s/commit/%s" .RepoLink (PathEscape .LatestCommit.ID.String)}}
2424
<span class="grey commit-summary" title="{{.LatestCommit.Summary}}"><span class="message-wrapper">{{ctx.RenderUtils.RenderCommitMessageLinkSubject .LatestCommit.Message $commitLink ($.Repository.ComposeMetas ctx)}}</span>
2525
{{if IsMultilineCommitMessage .LatestCommit.Message}}
26-
<button class="ui button js-toggle-commit-body ellipsis-button" aria-expanded="false" data-global-click="onRepoEllipsisButtonClick">...</button>
26+
<button class="ui button ellipsis-button" aria-expanded="false" data-global-click="onRepoEllipsisButtonClick">...</button>
2727
<pre class="commit-body tw-hidden">{{ctx.RenderUtils.RenderCommitBody .LatestCommit.Message ($.Repository.ComposeMetas ctx)}}</pre>
2828
{{end}}
2929
</span>

web_src/js/features/common-button.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {POST} from '../modules/fetch.ts';
22
import {addDelegatedEventListener, hideElem, showElem, toggleElem} from '../utils/dom.ts';
33
import {fomanticQuery} from '../modules/fomantic/base.ts';
4-
import {registerGlobalSelectorFunc} from '../modules/observer.ts';
54
import {camelize} from 'vue';
65

76
export function initGlobalButtonClickOnEnter(): void {
@@ -75,10 +74,9 @@ export function initGlobalDeleteButton(): void {
7574
}
7675
}
7776

78-
function onShowPanelClick(e: MouseEvent) {
77+
function onShowPanelClick(el: HTMLElement, e: MouseEvent) {
7978
// a '.show-panel' element can show a panel, by `data-panel="selector"`
8079
// if it has "toggle" class, it toggles the panel
81-
const el = e.currentTarget as HTMLElement;
8280
e.preventDefault();
8381
const sel = el.getAttribute('data-panel');
8482
if (el.classList.contains('toggle')) {
@@ -88,9 +86,8 @@ function onShowPanelClick(e: MouseEvent) {
8886
}
8987
}
9088

91-
function onHidePanelClick(e: MouseEvent) {
89+
function onHidePanelClick(el: HTMLElement, e: MouseEvent) {
9290
// a `.hide-panel` element can hide a panel, by `data-panel="selector"` or `data-panel-closest="selector"`
93-
const el = e.currentTarget as HTMLElement;
9491
e.preventDefault();
9592
let sel = el.getAttribute('data-panel');
9693
if (sel) {
@@ -105,15 +102,14 @@ function onHidePanelClick(e: MouseEvent) {
105102
throw new Error('no panel to hide'); // should never happen, otherwise there is a bug in code
106103
}
107104

108-
function onShowModalClick(e: MouseEvent) {
105+
function onShowModalClick(el: HTMLElement, e: MouseEvent) {
109106
// A ".show-modal" button will show a modal dialog defined by its "data-modal" attribute.
110107
// Each "data-modal-{target}" attribute will be filled to target element's value or text-content.
111108
// * First, try to query '#target'
112109
// * Then, try to query '[name=target]'
113110
// * Then, try to query '.target'
114111
// * Then, try to query 'target' as HTML tag
115112
// If there is a ".{attr}" part like "data-modal-form.action", then the form's "action" attribute will be set.
116-
const el = e.currentTarget as HTMLElement;
117113
e.preventDefault();
118114
const modalSelector = el.getAttribute('data-modal');
119115
const elModal = document.querySelector(modalSelector);
@@ -161,7 +157,15 @@ export function initGlobalButtons(): void {
161157
// There are a few cancel buttons in non-modal forms, and there are some dynamically created forms (eg: the "Edit Issue Content")
162158
addDelegatedEventListener(document, 'click', 'form button.ui.cancel.button', (_ /* el */, e) => e.preventDefault());
163159

164-
registerGlobalSelectorFunc('.show-panel', (el) => el.addEventListener('click', onShowPanelClick));
165-
registerGlobalSelectorFunc('.hide-panel', (el) => el.addEventListener('click', onHidePanelClick));
166-
registerGlobalSelectorFunc('.show-modal', (el) => el.addEventListener('click', onShowModalClick));
160+
// Ideally these "button" events should be handled by registerGlobalEventFunc
161+
// Refactoring would involve too many changes, so at the moment, just use the global event listener.
162+
addDelegatedEventListener(document, 'click', '.show-panel, .hide-panel, .show-modal', (el, e: MouseEvent) => {
163+
if (el.classList.contains('show-panel')) {
164+
onShowPanelClick(el, e);
165+
} else if (el.classList.contains('hide-panel')) {
166+
onHidePanelClick(el, e);
167+
} else if (el.classList.contains('show-modal')) {
168+
onShowModalClick(el, e);
169+
}
170+
});
167171
}

0 commit comments

Comments
 (0)