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 {
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;
}
return (
- <span className={computedClass}>
+ <span className={computedClass} ref={this.setRef}>
{displayName}
{inline ? ' ' : null}
{suffix}
import { FormattedMessage } from 'react-intl';
import Permalink from './permalink';
import classnames from 'classnames';
+import { autoPlayGif } from 'flavours/glitch/util/initial_state';
export default class StatusContent extends React.PureComponent {
}
}
+ _updateStatusEmojis () {
+ 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._updateStatusLinks();
+ this._updateStatusEmojis();
}
componentDidUpdate () {
this._updateStatusLinks();
+ this._updateStatusEmojis();
if (this.props.onUpdate) this.props.onUpdate();
}
}
}
+ handleEmojiMouseEnter = ({ target }) => {
+ target.src = target.getAttribute('data-original');
+ }
+
+ handleEmojiMouseLeave = ({ target }) => {
+ target.src = target.getAttribute('data-static');
+ }
+
handleMouseDown = (e) => {
this.startXY = [e.clientX, e.clientY];
}
window.open('/settings/profile', '_blank');
}
+ _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, intl, domain, identity_proofs } = this.props;
const acct = account.get('acct').indexOf('@') === -1 && domain ? `${account.get('acct')}@${domain}` : account.get('acct');
return (
- <div className={classNames('account__header', { inactive: !!account.get('moved') })}>
+ <div className={classNames('account__header', { inactive: !!account.get('moved') })} ref={this.setRef}>
<div className='account__header__image'>
<div className='account__header__info'>
{info}
function main() {
const IntlMessageFormat = require('intl-messageformat').default;
const { timeAgoString } = require('flavours/glitch/components/relative_timestamp');
+ const { delegate } = require('rails-ujs');
const emojify = require('flavours/glitch/util/emoji').default;
const { getLocale } = require('locales');
const { messages } = getLocale();
}
};
+ const getEmojiAnimationHandler = (swapTo) => {
+ return ({ target }) => {
+ target.src = target.getAttribute(swapTo);
+ };
+ };
+
ready(() => {
const locale = document.documentElement.lang;
document.head.appendChild(scrollbarWidthStyle);
scrollbarWidthStyle.sheet.insertRule(`body.with-modals--active { margin-right: ${scrollbarWidth}px; }`, 0);
}
+
+ delegate(document, '.custom-emoji', 'mouseover', getEmojiAnimationHandler('data-original'));
+ delegate(document, '.custom-emoji', 'mouseout', getEmojiAnimationHandler('data-static'));
});
}
// if you want additional emoji handler, add statements below which set replacement and return true.
if (shortname in customEmojis) {
const filename = autoPlayGif ? customEmojis[shortname].url : customEmojis[shortname].static_url;
- replacement = `<img draggable="false" class="emojione" alt="${shortname}" title="${shortname}" src="${filename}" />`;
+ replacement = `<img draggable="false" class="emojione custom-emoji" alt="${shortname}" title="${shortname}" src="${filename}" data-original="${customEmojis[shortname].url}" data-static="${customEmojis[shortname].static_url}" />`;
return true;
}
return false;