-
Notifications
You must be signed in to change notification settings - Fork 21
fix: ue image update handling #25
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,21 +86,20 @@ const setupObservers = () => { | |
| }; | ||
|
|
||
| const setupUEEventHandlers = () => { | ||
| // For each img source change, update the srcsets of the parent picture sources | ||
| document.addEventListener('aue:content-patch', (event) => { | ||
| if (event.detail.patch.name.match(/img.*\[src\]/)) { | ||
| const newImgSrc = event.detail.patch.value; | ||
| const picture = event.srcElement.querySelector('picture'); | ||
| // For each picture or img element change, update the srcsets of the picture element sources | ||
| document.body.addEventListener('aue:content-patch', ({ detail: { patch, request } }) => { | ||
| if (!/image/.test(patch.name)) return; | ||
|
|
||
| if (picture) { | ||
| picture.querySelectorAll('source').forEach((source) => { | ||
| source.setAttribute('srcset', newImgSrc); | ||
| }); | ||
| } | ||
| } | ||
| let element = document.querySelector(`[data-aue-resource="${request.target.resource}"]`); | ||
| if (element && element.getAttribute('data-aue-prop') !== patch.name) element = element.querySelector(`[data-aue-prop='${patch.name}']`); | ||
| if (element?.getAttribute('data-aue-type') !== 'media') return; | ||
|
|
||
| (element.tagName === 'IMG' ? element.closest('picture') : element) | ||
| ?.querySelectorAll('source') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we just search for all elements having srcset attribute set (so it would also include img tags) and remove them?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But source tags we would have to remove, while img srcset would would only need to remove the attribute. Will create a new PR for that. |
||
| .forEach((source) => source.setAttribute('srcset', patch.value)); | ||
| }); | ||
|
|
||
| document.addEventListener('aue:ui-select', (event) => { | ||
| document.body.addEventListener('aue:ui-select', (event) => { | ||
| const { detail } = event; | ||
| const resource = detail?.resource; | ||
|
|
||
|
|
||
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.
didn't we say that we move this to check of the data-aue-type as it is done in the cors.js?
What if someone is silly naming any text input field image?
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.
Ok, wanted to keep it simpler :-)
Actually we can remove that line and it should still work. A we check for media type 3 lines below.