Skip to content

Commit 3561414

Browse files
committed
Refactor initRepoEllipsisButton using the new registerGlobalEventFunc
1 parent 43c8d85 commit 3561414

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
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">...</button>
51+
<button class="ui button js-toggle-commit-body 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">...</button>
26+
<button class="ui button js-toggle-commit-body 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/repo-commit.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import {createTippy} from '../modules/tippy.ts';
22
import {toggleElem} from '../utils/dom.ts';
3+
import {registerGlobalEventFunc} from '../modules/observer.ts';
34

45
export function initRepoEllipsisButton() {
5-
for (const button of document.querySelectorAll<HTMLButtonElement>('.js-toggle-commit-body')) {
6-
button.addEventListener('click', function (e) {
7-
e.preventDefault();
8-
const expanded = this.getAttribute('aria-expanded') === 'true';
9-
toggleElem(this.parentElement.querySelector('.commit-body'));
10-
this.setAttribute('aria-expanded', String(!expanded));
11-
});
12-
}
6+
registerGlobalEventFunc('click', 'onRepoEllipsisButtonClick', async (el: HTMLInputElement, e: Event) => {
7+
e.preventDefault();
8+
const expanded = el.getAttribute('aria-expanded') === 'true';
9+
toggleElem(el.parentElement.querySelector('.commit-body'));
10+
el.setAttribute('aria-expanded', String(!expanded));
11+
});
1312
}
1413

1514
export function initCommitStatuses() {

0 commit comments

Comments
 (0)