]> cat aescling's git repositories - mastodon.git/commitdiff
Added GIF hover-to-play support
authorkibigo! <marrus-sh@users.noreply.github.com>
Wed, 20 Sep 2017 09:19:36 +0000 (02:19 -0700)
committerkibigo! <marrus-sh@users.noreply.github.com>
Wed, 20 Sep 2017 09:19:36 +0000 (02:19 -0700)
app/javascript/glitch/components/status/gallery/item.js

index d646825a3779a714577b32b0a4f1e03cbdac1faf..ab4aab8dcd0c45ae4b723559f1fc09bfc368bc17 100644 (file)
@@ -17,6 +17,24 @@ export default class StatusGalleryItem extends React.PureComponent {
     autoPlayGif: PropTypes.bool.isRequired,
   };
 
+  handleMouseEnter = (e) => {
+    if (this.hoverToPlay()) {
+      e.target.play();
+    }
+  }
+
+  handleMouseLeave = (e) => {
+    if (this.hoverToPlay()) {
+      e.target.pause();
+      e.target.currentTime = 0;
+    }
+  }
+
+  hoverToPlay () {
+    const { attachment, autoPlayGif } = this.props;
+    return !autoPlayGif && attachment.get('type') === 'gifv';
+  }
+
   handleClick = (e) => {
     const { index, onClick } = this.props;
 
@@ -112,6 +130,8 @@ export default class StatusGalleryItem extends React.PureComponent {
             role='application'
             src={attachment.get('url')}
             onClick={this.handleClick}
+            onMouseEnter={this.handleMouseEnter}
+            onMouseLeave={this.handleMouseLeave}
             autoPlay={autoPlay}
             loop
             muted
This page took 0.021441 seconds and 3 git commands to generate.