-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Add cropping support when modifying the user/org/repo avatar #33498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9f47b23
fixed #33321
kerwin612 2255362
fix
kerwin612 7ab8dc3
fix
kerwin612 546f133
refactor
wxiaoguang 006dd61
fix
wxiaoguang b34ab60
fine tune prompt margin
wxiaoguang 2609e92
Merge branch 'main' into fix_33321
wxiaoguang f045e77
introduce avatar-file-with-cropper again
wxiaoguang 8065660
Merge branch 'main' into fix_33321
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{- /* we do not need to set for/id here, global aria init code will add them automatically */ -}} | ||
<label>{{.LabelText}}</label> | ||
<input name="avatar" type="file" accept="image/png,image/jpeg,image/gif,image/webp"> | ||
{{- /* the cropper-panel must be next sibling of the input "avatar" */ -}} | ||
<div class="cropper-panel tw-hidden"> | ||
<div class="tw-my-2">{{ctx.Locale.Tr "settings.cropper_prompt"}}</div> | ||
<div class="cropper-wrapper"><img class="cropper-source" src alt></div> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
@import "cropperjs/dist/cropper.css"; | ||
|
||
.page-content.user.profile .cropper-panel .cropper-wrapper { | ||
input[name="avatar"] + .cropper-panel .cropper-wrapper { | ||
max-width: 400px; | ||
max-height: 400px; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks like a really fragile selector to me.
Can we perhaps have a distinct js class instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it is the right thing to do.
If you want to introduce a general selector, it needs much more work to make it compatible with multiple elements on the same page, which is not our case.
The current approach should be good and clear enough, and it is easy to refactor in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think it's worth to introduce a general selector, feel free to try to propose some changes to see whether it would be simpler and more stable than this selector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean…
As far as I can see, it's always the same action we perform.
So, wouldn't it make sense to invert the calls from
each specific component takes care of initializing only its selector using the same method
to
all elements matching this selector inside the document are initialized
?Or am I missing any case where we need additional logic?
If we don't need to customize the initialization of any avatar cropper (-> all avatar croppers are initialized exactly the same), then we can unify the logic.
Otherwise, I agree with you.
So, can you think of a case where we might want separate initialization logic or are already using it?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right, that's the key point.
Actually I have tried to use a general selector
js-avatar-with-cropper
(some traces were still left in 006dd61 🤣 ), but at last I decided to drop it because overall it looks stranger in this case ......TBH at the moment I haven't got a real case, that's just my opinion that such selector should be flexible and clear enough. (The combo-markdown-editor has a similar case: auto-init or not .... but that's another story)
gitea/web_src/js/features/common-form.ts
Line 34 in 7e596bd
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, I am planning some frontend changes to make the JS init system more stable. A brief idea is like this:
Then we could resolve many longstanding problems:
But it is only a brief idea, just FYI