Skip to content

Commit f045e77

Browse files
committed
introduce avatar-file-with-cropper again
1 parent 2609e92 commit f045e77

File tree

7 files changed

+10
-11
lines changed

7 files changed

+10
-11
lines changed

templates/shared/avatar_upload_crop.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- /* we do not need to set for/id here, global aria init code will add them automatically */ -}}
22
<label>{{.LabelText}}</label>
3-
<input name="avatar" type="file" accept="image/png,image/jpeg,image/gif,image/webp">
3+
<input class="avatar-file-with-cropper" name="avatar" type="file" accept="image/png,image/jpeg,image/gif,image/webp">
44
{{- /* the cropper-panel must be next sibling of the input "avatar" */ -}}
55
<div class="cropper-panel tw-hidden">
66
<div class="tw-my-2">{{ctx.Locale.Tr "settings.cropper_prompt"}}</div>

web_src/css/features/cropper.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import "cropperjs/dist/cropper.css";
22

3-
input[name="avatar"] + .cropper-panel .cropper-wrapper {
3+
.avatar-file-with-cropper + .cropper-panel .cropper-wrapper {
44
max-width: 400px;
55
max-height: 400px;
66
}

web_src/js/features/admin/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22
import {checkAppUrl} from '../common-page.ts';
3-
import {hideElem, showElem, toggleElem} from '../../utils/dom.ts';
3+
import {hideElem, queryElems, showElem, toggleElem} from '../../utils/dom.ts';
44
import {POST} from '../../modules/fetch.ts';
55
import {initAvatarUploaderWithCropper} from '../comp/Cropper.ts';
66

@@ -260,5 +260,5 @@ export function initAdminCommon(): void {
260260
});
261261
}
262262

263-
initAvatarUploaderWithCropper(document.querySelector('.admin.edit.user input[name="avatar"]'));
263+
queryElems(document, '.avatar-file-with-cropper', initAvatarUploaderWithCropper);
264264
}

web_src/js/features/common-organization.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {initCompLabelEdit} from './comp/LabelEdit.ts';
2-
import {toggleElem} from '../utils/dom.ts';
2+
import {queryElems, toggleElem} from '../utils/dom.ts';
33
import {initAvatarUploaderWithCropper} from './comp/Cropper.ts';
44

55
export function initCommonOrganization() {
@@ -15,5 +15,5 @@ export function initCommonOrganization() {
1515
// Labels
1616
initCompLabelEdit('.page-content.organization.settings.labels');
1717

18-
initAvatarUploaderWithCropper(document.querySelector('.organization.settings.options input[name="avatar"]'));
18+
queryElems(document, '.avatar-file-with-cropper', initAvatarUploaderWithCropper);
1919
}

web_src/js/features/comp/Cropper.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ async function initCompCropper({container, fileInput, imageSource}: CropperOpts)
3939
});
4040
}
4141

42-
export async function initAvatarUploaderWithCropper(fileInput?: HTMLInputElement) {
43-
if (!fileInput) return;
42+
export async function initAvatarUploaderWithCropper(fileInput: HTMLInputElement) {
4443
const panel = fileInput.nextElementSibling as HTMLElement;
4544
if (!panel?.matches('.cropper-panel')) throw new Error('Missing cropper panel for avatar uploader');
4645
const imageSource = panel.querySelector<HTMLImageElement>('.cropper-source');

web_src/js/features/repo-settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,5 @@ export function initRepoSettings() {
158158
initRepoSettingsGitHook();
159159
initRepoSettingsBranchesDrag();
160160

161-
initAvatarUploaderWithCropper(document.querySelector('.repository.settings.options input[name="avatar"]'));
161+
queryElems(document, '.avatar-file-with-cropper', initAvatarUploaderWithCropper);
162162
}

web_src/js/features/user-settings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {hideElem, showElem} from '../utils/dom.ts';
1+
import {hideElem, queryElems, showElem} from '../utils/dom.ts';
22
import {initAvatarUploaderWithCropper} from './comp/Cropper.ts';
33

44
export function initUserSettings() {
55
if (!document.querySelector('.user.settings.profile')) return;
66

7-
initAvatarUploaderWithCropper(document.querySelector('.user.settings.profile input[name="avatar"]'));
7+
queryElems(document, '.avatar-file-with-cropper', initAvatarUploaderWithCropper);
88

99
const usernameInput = document.querySelector<HTMLInputElement>('#username');
1010
if (!usernameInput) return;

0 commit comments

Comments
 (0)