about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/components/display_name.js
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-07-21 18:10:40 +0200
committerThibaut Girka <thib@sitedethib.com>2019-07-23 16:24:21 +0200
commitc1231a846ac7b4a83b5b5b05384bca670d66ccde (patch)
treeaa2486051173cf34d28ebdf8d7910265e348f913 /app/javascript/flavours/glitch/components/display_name.js
parent621590b4ab31dd12de97ded31f17a00ff2fc6dd6 (diff)
[Glitch] Play animated custom emoji on hover
Port 7de8c51873b51d8450f7a6597a43d454964d0407 to glitch-soc
Diffstat (limited to 'app/javascript/flavours/glitch/components/display_name.js')
-rw-r--r--app/javascript/flavours/glitch/components/display_name.js44
1 files changed, 43 insertions, 1 deletions
diff --git a/app/javascript/flavours/glitch/components/display_name.js b/app/javascript/flavours/glitch/components/display_name.js
index 7626fb25c..9d8c4a775 100644
--- a/app/javascript/flavours/glitch/components/display_name.js
+++ b/app/javascript/flavours/glitch/components/display_name.js
@@ -2,6 +2,7 @@ import React from 'react';
 import ImmutablePropTypes from 'react-immutable-proptypes';
 import PropTypes from 'prop-types';
 import classNames from 'classnames';
+import { autoPlayGif } from 'flavours/glitch/util/initial_state';
 
 export default class DisplayName extends React.PureComponent {
 
@@ -14,6 +15,47 @@ export default class DisplayName extends React.PureComponent {
     handleClick: PropTypes.func,
   };
 
+  _updateEmojis () {
+    const node = this.node;
+
+    if (!node || autoPlayGif) {
+      return;
+    }
+
+    const emojis = node.querySelectorAll('.custom-emoji');
+
+    for (var i = 0; i < emojis.length; i++) {
+      let emoji = emojis[i];
+      if (emoji.classList.contains('status-emoji')) {
+        continue;
+      }
+      emoji.classList.add('status-emoji');
+
+      emoji.addEventListener('mouseenter', this.handleEmojiMouseEnter, false);
+      emoji.addEventListener('mouseleave', this.handleEmojiMouseLeave, false);
+    }
+  }
+
+  componentDidMount () {
+    this._updateEmojis();
+  }
+
+  componentDidUpdate () {
+    this._updateEmojis();
+  }
+
+  handleEmojiMouseEnter = ({ target }) => {
+    target.src = target.getAttribute('data-original');
+  }
+
+  handleEmojiMouseLeave = ({ target }) => {
+    target.src = target.getAttribute('data-static');
+  }
+
+  setRef = (c) => {
+    this.node = c;
+  }
+
   render() {
     const { account, className, inline, localDomain, others, onAccountClick } = this.props;
 
@@ -58,7 +100,7 @@ export default class DisplayName extends React.PureComponent {
     }
 
     return (
-      <span className={computedClass}>
+      <span className={computedClass} ref={this.setRef}>
         {displayName}
         {inline ? ' ' : null}
         {suffix}