@@ -11,7 +11,6 @@ import {initImageDiff} from './features/imagediff.ts';
11
11
import { initRepoMigration } from './features/repo-migration.ts' ;
12
12
import { initRepoProject } from './features/repo-projects.ts' ;
13
13
import { initTableSort } from './features/tablesort.ts' ;
14
- import { initAutoFocusEnd } from './features/autofocus-end.ts' ;
15
14
import { initAdminUserListSearchForm } from './features/admin/users.ts' ;
16
15
import { initAdminConfigs } from './features/admin/config.ts' ;
17
16
import { initMarkupAnchors } from './markup/anchors.ts' ;
@@ -62,61 +61,47 @@ import {initRepoContributors} from './features/contributors.ts';
62
61
import { initRepoCodeFrequency } from './features/code-frequency.ts' ;
63
62
import { initRepoRecentCommits } from './features/recent-commits.ts' ;
64
63
import { initRepoDiffCommitBranchesAndTags } from './features/repo-diff-commit.ts' ;
65
- import { initAddedElementObserver } from './modules/observer.ts' ;
64
+ import { initGlobalSelectorObserver } from './modules/observer.ts' ;
66
65
import { initRepositorySearch } from './features/repo-search.ts' ;
67
66
import { initColorPickers } from './features/colorpicker.ts' ;
68
67
import { initAdminSelfCheck } from './features/admin/selfcheck.ts' ;
69
68
import { initOAuth2SettingsDisableCheckbox } from './features/oauth2-settings.ts' ;
70
69
import { initGlobalFetchAction } from './features/common-fetch-action.ts' ;
71
- import {
72
- initFootLanguageMenu ,
73
- initGlobalDropdown ,
74
- initGlobalTabularMenu ,
75
- initHeadNavbarContentToggle ,
76
- } from './features/common-page.ts' ;
77
- import {
78
- initGlobalButtonClickOnEnter ,
79
- initGlobalButtons ,
80
- initGlobalDeleteButton ,
81
- } from './features/common-button.ts' ;
82
- import {
83
- initGlobalComboMarkdownEditor ,
84
- initGlobalEnterQuickSubmit ,
85
- initGlobalFormDirtyLeaveConfirm ,
86
- } from './features/common-form.ts' ;
70
+ import { initFootLanguageMenu , initGlobalDropdown , initGlobalInput , initGlobalTabularMenu , initHeadNavbarContentToggle } from './features/common-page.ts' ;
71
+ import { initGlobalButtonClickOnEnter , initGlobalButtons , initGlobalDeleteButton } from './features/common-button.ts' ;
72
+ import { initGlobalComboMarkdownEditor , initGlobalEnterQuickSubmit , initGlobalFormDirtyLeaveConfirm } from './features/common-form.ts' ;
87
73
88
74
initGiteaFomantic ( ) ;
89
- initAddedElementObserver ( ) ;
90
75
initSubmitEventPolyfill ( ) ;
91
76
92
- function callInitFunctions ( functions : ( ( ) => any ) [ ] ) {
93
- // Start performance trace by accessing a URL by "https://localhost/?_ui_performance_trace=1" or "https://localhost/?key=value&_ui_performance_trace=1"
94
- // It is a quick check, no side effect so no need to do slow URL parsing.
95
- const initStart = performance . now ( ) ;
96
- if ( window . location . search . includes ( '_ui_performance_trace=1' ) ) {
97
- let results : { name : string , dur : number } [ ] = [ ] ;
98
- for ( const func of functions ) {
99
- const start = performance . now ( ) ;
100
- func ( ) ;
101
- results . push ( { name : func . name , dur : performance . now ( ) - start } ) ;
102
- }
103
- results = results . sort ( ( a , b ) => b . dur - a . dur ) ;
104
- for ( let i = 0 ; i < 20 && i < results . length ; i ++ ) {
77
+ // Start performance trace by accessing a URL by "https://localhost/?_ui_performance_trace=1" or "https://localhost/?key=value&_ui_performance_trace=1"
78
+ // It is a quick check, no side effect so no need to do slow URL parsing.
79
+ const traceInitPerformance = ! window . location . search . includes ( '_ui_performance_trace=1' ) ? null : new class {
80
+ results : { name : string , dur : number } [ ] = [ ] ;
81
+ recordCall ( name : string , func : ( ) => void ) {
82
+ const start = performance . now ( ) ;
83
+ func ( ) ;
84
+ this . results . push ( { name, dur : performance . now ( ) - start } ) ;
85
+ }
86
+ printResults ( ) {
87
+ this . results = this . results . sort ( ( a , b ) => b . dur - a . dur ) ;
88
+ for ( let i = 0 ; i < 20 && i < this . results . length ; i ++ ) {
105
89
// eslint-disable-next-line no-console
106
- console . log ( `performance trace: ${ results [ i ] . name } ${ results [ i ] . dur . toFixed ( 3 ) } ` ) ;
107
- }
108
- } else {
109
- for ( const func of functions ) {
110
- func ( ) ;
90
+ console . log ( `performance trace: ${ this . results [ i ] . name } ${ this . results [ i ] . dur . toFixed ( 3 ) } ` ) ;
111
91
}
112
92
}
113
- const initDur = performance . now ( ) - initStart ;
114
- if ( initDur > 500 ) {
115
- console . error ( `slow init functions took ${ initDur . toFixed ( 3 ) } ms` ) ;
93
+ } ( ) ;
94
+
95
+ function callInitFunctions ( functions : ( ( ) => any ) [ ] ) {
96
+ if ( traceInitPerformance ) {
97
+ for ( const func of functions ) traceInitPerformance . recordCall ( func . name , func ) ;
98
+ } else {
99
+ for ( const func of functions ) func ( ) ;
116
100
}
117
101
}
118
102
119
103
onDomReady ( ( ) => {
104
+ const initStartTime = performance . now ( ) ;
120
105
callInitFunctions ( [
121
106
initGlobalDropdown ,
122
107
initGlobalTabularMenu ,
@@ -129,6 +114,7 @@ onDomReady(() => {
129
114
initGlobalFormDirtyLeaveConfirm ,
130
115
initGlobalComboMarkdownEditor ,
131
116
initGlobalDeleteButton ,
117
+ initGlobalInput ,
132
118
133
119
initCommonOrganization ,
134
120
initCommonIssueListQuickGoto ,
@@ -150,7 +136,6 @@ onDomReady(() => {
150
136
initSshKeyFormParser ,
151
137
initStopwatch ,
152
138
initTableSort ,
153
- initAutoFocusEnd ,
154
139
initFindFileInRepo ,
155
140
initCopyContent ,
156
141
@@ -212,4 +197,13 @@ onDomReady(() => {
212
197
213
198
initOAuth2SettingsDisableCheckbox ,
214
199
] ) ;
200
+
201
+ // it must be the last one, then the "querySelectorAll" only needs to be executed once for global init functions.
202
+ initGlobalSelectorObserver ( traceInitPerformance ) ;
203
+
204
+ if ( traceInitPerformance ) traceInitPerformance . printResults ( ) ;
205
+ const initDur = performance . now ( ) - initStartTime ;
206
+ if ( initDur > 500 ) {
207
+ console . error ( `slow init functions took ${ initDur . toFixed ( 3 ) } ms` ) ;
208
+ }
215
209
} ) ;
0 commit comments