mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 19:38:23 +00:00 
			
		
		
		
	Refactor global init code and add more comments (#33755)
Follow up #33748 Now there are 3 "global" functions: * registerGlobalSelectorFunc: for all elements matching the selector, eg: `.ui.dropdown` * registerGlobalInitFunc: for `data-global-init="initInputAutoFocusEnd"` * registerGlobalEventFunc: for `data-global-click="onCommentReactionButtonClick"` And introduce `initGlobalInput` to replace old `initAutoFocusEnd` and `attachDirAuto`, use `data-global-init` to replace fragile `.js-autofocus-end` selector. Another benefit is that by the new approach, no matter how many times `registerGlobalInitFunc` is called, we only need to do one "querySelectorAll" in the last step, it could slightly improve the performance.
This commit is contained in:
		| @@ -10,7 +10,7 @@ import {POST, GET} from '../modules/fetch.ts'; | ||||
| import {createTippy} from '../modules/tippy.ts'; | ||||
| import {invertFileFolding} from './file-fold.ts'; | ||||
| import {parseDom} from '../utils.ts'; | ||||
| import {observeAddedElement} from '../modules/observer.ts'; | ||||
| import {registerGlobalSelectorFunc} from '../modules/observer.ts'; | ||||
|  | ||||
| const {i18n} = window.config; | ||||
|  | ||||
| @@ -254,7 +254,7 @@ export function initRepoDiffView() { | ||||
|   initExpandAndCollapseFilesButton(); | ||||
|   initRepoDiffHashChangeListener(); | ||||
|  | ||||
|   observeAddedElement('#diff-file-boxes .diff-file-box', initRepoDiffFileBox); | ||||
|   registerGlobalSelectorFunc('#diff-file-boxes .diff-file-box', initRepoDiffFileBox); | ||||
|   addDelegatedEventListener(document, 'click', '.fold-file', (el) => { | ||||
|     invertFileFolding(el.closest('.file-content'), el); | ||||
|   }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user