mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-28 11:45:15 +00:00
Optimize the calling code of queryElems (#34235)
This commit is contained in:
parent
21b43fce08
commit
aeb7005245
@ -1,6 +1,6 @@
|
|||||||
{{- /* we do not need to set for/id here, global aria init code will add them automatically */ -}}
|
{{- /* we do not need to set for/id here, global aria init code will add them automatically */ -}}
|
||||||
<label>{{.LabelText}}</label>
|
<label>{{.LabelText}}</label>
|
||||||
<input class="avatar-file-with-cropper" name="avatar" type="file" accept="image/png,image/jpeg,image/gif,image/webp">
|
<input class="avatar-file-with-cropper" name="avatar" type="file" accept="image/png,image/jpeg,image/gif,image/webp" data-global-init="initAvatarUploader">
|
||||||
{{- /* the cropper-panel must be next sibling of the input "avatar" */ -}}
|
{{- /* the cropper-panel must be next sibling of the input "avatar" */ -}}
|
||||||
<div class="cropper-panel tw-hidden">
|
<div class="cropper-panel tw-hidden">
|
||||||
<div class="tw-my-2">{{ctx.Locale.Tr "settings.cropper_prompt"}}</div>
|
<div class="tw-my-2">{{ctx.Locale.Tr "settings.cropper_prompt"}}</div>
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import {checkAppUrl} from '../common-page.ts';
|
import {checkAppUrl} from '../common-page.ts';
|
||||||
import {hideElem, queryElems, showElem, toggleElem} from '../../utils/dom.ts';
|
import {hideElem, queryElems, showElem, toggleElem} from '../../utils/dom.ts';
|
||||||
import {POST} from '../../modules/fetch.ts';
|
import {POST} from '../../modules/fetch.ts';
|
||||||
import {initAvatarUploaderWithCropper} from '../comp/Cropper.ts';
|
|
||||||
import {fomanticQuery} from '../../modules/fomantic/base.ts';
|
import {fomanticQuery} from '../../modules/fomantic/base.ts';
|
||||||
|
|
||||||
const {appSubUrl} = window.config;
|
const {appSubUrl} = window.config;
|
||||||
@ -23,8 +22,6 @@ export function initAdminCommon(): void {
|
|||||||
initAdminUser();
|
initAdminUser();
|
||||||
initAdminAuthentication();
|
initAdminAuthentication();
|
||||||
initAdminNotice();
|
initAdminNotice();
|
||||||
|
|
||||||
queryElems(document, '.avatar-file-with-cropper', initAvatarUploaderWithCropper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initAdminUser() {
|
function initAdminUser() {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import {initCompLabelEdit} from './comp/LabelEdit.ts';
|
import {initCompLabelEdit} from './comp/LabelEdit.ts';
|
||||||
import {queryElems, toggleElem} from '../utils/dom.ts';
|
import {toggleElem} from '../utils/dom.ts';
|
||||||
import {initAvatarUploaderWithCropper} from './comp/Cropper.ts';
|
|
||||||
|
|
||||||
export function initCommonOrganization() {
|
export function initCommonOrganization() {
|
||||||
if (!document.querySelectorAll('.organization').length) {
|
if (!document.querySelectorAll('.organization').length) {
|
||||||
@ -14,6 +13,4 @@ export function initCommonOrganization() {
|
|||||||
|
|
||||||
// Labels
|
// Labels
|
||||||
initCompLabelEdit('.page-content.organization.settings.labels');
|
initCompLabelEdit('.page-content.organization.settings.labels');
|
||||||
|
|
||||||
queryElems(document, '.avatar-file-with-cropper', initAvatarUploaderWithCropper);
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import {showGlobalErrorMessage} from '../bootstrap.ts';
|
|||||||
import {fomanticQuery} from '../modules/fomantic/base.ts';
|
import {fomanticQuery} from '../modules/fomantic/base.ts';
|
||||||
import {queryElems} from '../utils/dom.ts';
|
import {queryElems} from '../utils/dom.ts';
|
||||||
import {registerGlobalInitFunc, registerGlobalSelectorFunc} from '../modules/observer.ts';
|
import {registerGlobalInitFunc, registerGlobalSelectorFunc} from '../modules/observer.ts';
|
||||||
|
import {initAvatarUploaderWithCropper} from './comp/Cropper.ts';
|
||||||
|
|
||||||
const {appUrl} = window.config;
|
const {appUrl} = window.config;
|
||||||
|
|
||||||
@ -80,6 +81,10 @@ export function initGlobalTabularMenu() {
|
|||||||
fomanticQuery('.ui.menu.tabular:not(.custom) .item').tab();
|
fomanticQuery('.ui.menu.tabular:not(.custom) .item').tab();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function initGlobalAvatarUploader() {
|
||||||
|
registerGlobalInitFunc('initAvatarUploader', initAvatarUploaderWithCropper);
|
||||||
|
}
|
||||||
|
|
||||||
// for performance considerations, it only uses performant syntax
|
// for performance considerations, it only uses performant syntax
|
||||||
function attachInputDirAuto(el: Partial<HTMLInputElement | HTMLTextAreaElement>) {
|
function attachInputDirAuto(el: Partial<HTMLInputElement | HTMLTextAreaElement>) {
|
||||||
if (el.type !== 'hidden' &&
|
if (el.type !== 'hidden' &&
|
||||||
|
@ -2,7 +2,6 @@ import {minimatch} from 'minimatch';
|
|||||||
import {createMonaco} from './codeeditor.ts';
|
import {createMonaco} from './codeeditor.ts';
|
||||||
import {onInputDebounce, queryElems, toggleClass, toggleElem} from '../utils/dom.ts';
|
import {onInputDebounce, queryElems, toggleClass, toggleElem} from '../utils/dom.ts';
|
||||||
import {POST} from '../modules/fetch.ts';
|
import {POST} from '../modules/fetch.ts';
|
||||||
import {initAvatarUploaderWithCropper} from './comp/Cropper.ts';
|
|
||||||
import {initRepoSettingsBranchesDrag} from './repo-settings-branches.ts';
|
import {initRepoSettingsBranchesDrag} from './repo-settings-branches.ts';
|
||||||
import {fomanticQuery} from '../modules/fomantic/base.ts';
|
import {fomanticQuery} from '../modules/fomantic/base.ts';
|
||||||
|
|
||||||
@ -149,6 +148,4 @@ export function initRepoSettings() {
|
|||||||
initRepoSettingsSearchTeamBox();
|
initRepoSettingsSearchTeamBox();
|
||||||
initRepoSettingsGitHook();
|
initRepoSettingsGitHook();
|
||||||
initRepoSettingsBranchesDrag();
|
initRepoSettingsBranchesDrag();
|
||||||
|
|
||||||
queryElems(document, '.avatar-file-with-cropper', initAvatarUploaderWithCropper);
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
import {hideElem, queryElems, showElem} from '../utils/dom.ts';
|
import {hideElem, showElem} from '../utils/dom.ts';
|
||||||
import {initAvatarUploaderWithCropper} from './comp/Cropper.ts';
|
|
||||||
|
|
||||||
export function initUserSettings() {
|
export function initUserSettings() {
|
||||||
if (!document.querySelector('.user.settings.profile')) return;
|
if (!document.querySelector('.user.settings.profile')) return;
|
||||||
|
|
||||||
queryElems(document, '.avatar-file-with-cropper', initAvatarUploaderWithCropper);
|
|
||||||
|
|
||||||
const usernameInput = document.querySelector<HTMLInputElement>('#username');
|
const usernameInput = document.querySelector<HTMLInputElement>('#username');
|
||||||
if (!usernameInput) return;
|
if (!usernameInput) return;
|
||||||
usernameInput.addEventListener('input', function () {
|
usernameInput.addEventListener('input', function () {
|
||||||
|
@ -60,7 +60,7 @@ import {initColorPickers} from './features/colorpicker.ts';
|
|||||||
import {initAdminSelfCheck} from './features/admin/selfcheck.ts';
|
import {initAdminSelfCheck} from './features/admin/selfcheck.ts';
|
||||||
import {initOAuth2SettingsDisableCheckbox} from './features/oauth2-settings.ts';
|
import {initOAuth2SettingsDisableCheckbox} from './features/oauth2-settings.ts';
|
||||||
import {initGlobalFetchAction} from './features/common-fetch-action.ts';
|
import {initGlobalFetchAction} from './features/common-fetch-action.ts';
|
||||||
import {initFootLanguageMenu, initGlobalDropdown, initGlobalInput, initGlobalTabularMenu, initHeadNavbarContentToggle} from './features/common-page.ts';
|
import {initFootLanguageMenu, initGlobalAvatarUploader, initGlobalDropdown, initGlobalInput, initGlobalTabularMenu, initHeadNavbarContentToggle} from './features/common-page.ts';
|
||||||
import {initGlobalButtonClickOnEnter, initGlobalButtons, initGlobalDeleteButton} from './features/common-button.ts';
|
import {initGlobalButtonClickOnEnter, initGlobalButtons, initGlobalDeleteButton} from './features/common-button.ts';
|
||||||
import {initGlobalComboMarkdownEditor, initGlobalEnterQuickSubmit, initGlobalFormDirtyLeaveConfirm} from './features/common-form.ts';
|
import {initGlobalComboMarkdownEditor, initGlobalEnterQuickSubmit, initGlobalFormDirtyLeaveConfirm} from './features/common-form.ts';
|
||||||
import {callInitFunctions} from './modules/init.ts';
|
import {callInitFunctions} from './modules/init.ts';
|
||||||
@ -72,6 +72,7 @@ initSubmitEventPolyfill();
|
|||||||
onDomReady(() => {
|
onDomReady(() => {
|
||||||
const initStartTime = performance.now();
|
const initStartTime = performance.now();
|
||||||
const initPerformanceTracer = callInitFunctions([
|
const initPerformanceTracer = callInitFunctions([
|
||||||
|
initGlobalAvatarUploader,
|
||||||
initGlobalDropdown,
|
initGlobalDropdown,
|
||||||
initGlobalTabularMenu,
|
initGlobalTabularMenu,
|
||||||
initGlobalFetchAction,
|
initGlobalFetchAction,
|
||||||
|
@ -89,7 +89,7 @@ export function queryElemChildren<T extends Element>(parent: Element | ParentNod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// it works like parent.querySelectorAll: all descendants are selected
|
// it works like parent.querySelectorAll: all descendants are selected
|
||||||
// in the future, all "queryElems(document, ...)" should be refactored to use a more specific parent
|
// in the future, all "queryElems(document, ...)" should be refactored to use a more specific parent if the targets are not for page-level components.
|
||||||
export function queryElems<T extends HTMLElement>(parent: Element | ParentNode, selector: string, fn?: ElementsCallback<T>): ArrayLikeIterable<T> {
|
export function queryElems<T extends HTMLElement>(parent: Element | ParentNode, selector: string, fn?: ElementsCallback<T>): ArrayLikeIterable<T> {
|
||||||
return applyElemsCallback<T>(parent.querySelectorAll(selector), fn);
|
return applyElemsCallback<T>(parent.querySelectorAll(selector), fn);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user