Skip to content
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

Add AnimationBlocker to prevent autoplay of GIFs and other potentially animated filetypes #16497

Open
wants to merge 26 commits into
base: 5.7
Choose a base branch
from

Conversation

gcamacho079
Copy link
Contributor

@gcamacho079 gcamacho079 commented Jan 23, 2025

Description

  • Pauses all GIFs added to the control panel by adding a canvas of the first frame over the image. Also does this for .webp images, which could be animated.
  • Adds a play/pause button when the image size allows for comfortable placement

Related issues

Resolves PT-25

@gcamacho079 gcamacho079 added the accessibility 👤 features related to accessibility label Jan 23, 2025
@gcamacho079 gcamacho079 marked this pull request as ready for review January 27, 2025 22:06
@gcamacho079
Copy link
Contributor Author

@brandonkelly the user preference has been removed. 👍🏼

Copy link
Contributor

@brianjhanson brianjhanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gcamacho079 Looking good! Just a few comments and I pushed up a few minor styling tweaks.

The biggest thing I noticed is that the animated images will play the first time they're inserted into the dom after you upload it (here's a quick video https://share.cleanshot.com/qXWpkXNh).

I think that's because when those are inserted into the DOM, they get an action URL that doesn't have .gif or .webp in the src or srcset. I'm not sure what the best way around it is. The only thing I can think of would be to output some kind of data-filename on the img so we can use that to determine if we should stop the animation.

I suppose another option would be to refactor this into a web component like Shoelace has. Then we could use PHP to determine if an image is animated or not and either output a <craft-animated-image/> wrapper or not. I'm not sure how involved that change would be though. It could be larger than we want it to be.

Comment on lines +26 to +28
public $depends = [
JqueryAsset::class,
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get rid of the jQuery dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely!

Comment on lines +11 to +13
protected get imageAddedObserver() {
return this.#imageAddedObserver;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this getter? It doesn't look like anything uses it, and if we want the imageAddedObserver to be available we could just make it public.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I may have had a purpose for this at one point, but I'll remove it for now. 👍🏼

@gcamacho079
Copy link
Contributor Author

@gcamacho079 Looking good! Just a few comments and I pushed up a few minor styling tweaks.

The biggest thing I noticed is that the animated images will play the first time they're inserted into the dom after you upload it (here's a quick video https://share.cleanshot.com/qXWpkXNh).

I think that's because when those are inserted into the DOM, they get an action URL that doesn't have .gif or .webp in the src or srcset. I'm not sure what the best way around it is. The only thing I can think of would be to output some kind of data-filename on the img so we can use that to determine if we should stop the animation.

I suppose another option would be to refactor this into a web component like Shoelace has. Then we could use PHP to determine if an image is animated or not and either output a <craft-animated-image/> wrapper or not. I'm not sure how involved that change would be though. It could be larger than we want it to be.

@brianjhanson thank you for catching that, and for your style updates. 👍🏼 I'll poke around and see what route makes sense. We could also do a hybrid approach of wrapping the image in a web component during the AnimationBlocker initialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility 👤 features related to accessibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants