@@ -11,7 +11,6 @@ import {initImageDiff} from './features/imagediff.ts';
1111import { initRepoMigration } from './features/repo-migration.ts' ;
1212import { initRepoProject } from './features/repo-projects.ts' ;
1313import { initTableSort } from './features/tablesort.ts' ;
14- import { initAutoFocusEnd } from './features/autofocus-end.ts' ;
1514import { initAdminUserListSearchForm } from './features/admin/users.ts' ;
1615import { initAdminConfigs } from './features/admin/config.ts' ;
1716import { initMarkupAnchors } from './markup/anchors.ts' ;
@@ -62,61 +61,47 @@ import {initRepoContributors} from './features/contributors.ts';
6261import { initRepoCodeFrequency } from './features/code-frequency.ts' ;
6362import { initRepoRecentCommits } from './features/recent-commits.ts' ;
6463import { initRepoDiffCommitBranchesAndTags } from './features/repo-diff-commit.ts' ;
65- import { initAddedElementObserver } from './modules/observer.ts' ;
64+ import { initGlobalSelectorObserver } from './modules/observer.ts' ;
6665import { initRepositorySearch } from './features/repo-search.ts' ;
6766import { initColorPickers } from './features/colorpicker.ts' ;
6867import { initAdminSelfCheck } from './features/admin/selfcheck.ts' ;
6968import { initOAuth2SettingsDisableCheckbox } from './features/oauth2-settings.ts' ;
7069import { 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' ;
8773
8874initGiteaFomantic ( ) ;
89- initAddedElementObserver ( ) ;
9075initSubmitEventPolyfill ( ) ;
9176
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 ++ ) {
10589 // 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 ) } ` ) ;
11191 }
11292 }
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 ( ) ;
116100 }
117101}
118102
119103onDomReady ( ( ) => {
104+ const initStartTime = performance . now ( ) ;
120105 callInitFunctions ( [
121106 initGlobalDropdown ,
122107 initGlobalTabularMenu ,
@@ -129,6 +114,7 @@ onDomReady(() => {
129114 initGlobalFormDirtyLeaveConfirm ,
130115 initGlobalComboMarkdownEditor ,
131116 initGlobalDeleteButton ,
117+ initGlobalInput ,
132118
133119 initCommonOrganization ,
134120 initCommonIssueListQuickGoto ,
@@ -150,7 +136,6 @@ onDomReady(() => {
150136 initSshKeyFormParser ,
151137 initStopwatch ,
152138 initTableSort ,
153- initAutoFocusEnd ,
154139 initFindFileInRepo ,
155140 initCopyContent ,
156141
@@ -212,4 +197,13 @@ onDomReady(() => {
212197
213198 initOAuth2SettingsDisableCheckbox ,
214199 ] ) ;
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+ }
215209} ) ;
0 commit comments