Skip to content

Commit 54081da

Browse files
committed
Refactor initRepoBranchTagSelector using the new registerGlobalInitFunc
1 parent 43c8d85 commit 54081da

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

templates/repo/branch_dropdown.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
Search "repo/branch_dropdown" in the template directory to find all occurrences.
1616
*/}}
17-
<div class="js-branch-tag-selector {{if .ContainerClasses}}{{.ContainerClasses}}{{end}}"
17+
<div class="js-branch-tag-selector data-global-init="initRepoBranchTagSelector" {{if .ContainerClasses}}{{.ContainerClasses}}{{end}}"
1818
data-text-release-compare="{{ctx.Locale.Tr "repo.release.compare"}}"
1919
data-text-branches="{{ctx.Locale.Tr "repo.branches"}}"
2020
data-text-tags="{{ctx.Locale.Tr "repo.tags"}}"

web_src/js/features/repo-legacy.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {registerGlobalInitFunc} from '../modules/observer.ts';
12
import {
23
initRepoCommentFormAndSidebar,
34
initRepoIssueBranchSelect, initRepoIssueCodeCommentCancel, initRepoIssueCommentDelete,
@@ -20,10 +21,10 @@ import {initRepoNew} from './repo-new.ts';
2021
import {createApp} from 'vue';
2122
import RepoBranchTagSelector from '../components/RepoBranchTagSelector.vue';
2223

23-
function initRepoBranchTagSelector(selector: string) {
24-
for (const elRoot of document.querySelectorAll(selector)) {
25-
createApp(RepoBranchTagSelector, {elRoot}).mount(elRoot);
26-
}
24+
function initRepoBranchTagSelector() {
25+
registerGlobalInitFunc('initRepoBranchTagSelector', async (el: HTMLInputElement) => {
26+
createApp(RepoBranchTagSelector, {el}).mount(el);
27+
});
2728
}
2829

2930
export function initBranchSelectorTabs() {
@@ -42,7 +43,7 @@ export function initRepository() {
4243
const pageContent = document.querySelector('.page-content.repository');
4344
if (!pageContent) return;
4445

45-
initRepoBranchTagSelector('.js-branch-tag-selector');
46+
initRepoBranchTagSelector();
4647
initRepoCommentFormAndSidebar();
4748

4849
// Labels

0 commit comments

Comments
 (0)