Commit b7a0044a authored by Mike Greiling's avatar Mike Greiling

move normalizeEmojiName method to emoji helper module

parent 35ee21d9
......@@ -3,7 +3,7 @@
import Cookies from 'js-cookie';
import { glEmojiTag } from './behaviors/gl_emoji';
import { emojiMap, emojiAliases, isEmojiNameValid } from './emoji';
import { emojiMap, emojiAliases, isEmojiNameValid, normalizeEmojiName } from './emoji';
const animationEndEventString = 'animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd';
const transitionEndEventString = 'transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd';
......@@ -65,7 +65,6 @@ function renderCategory(name, emojiList, opts = {}) {
export default class AwardsHandler {
constructor() {
this.eventListeners = [];
this.aliases = emojiAliases;
// If the user shows intent let's pre-build the menu
this.registerEventListener('one', $(document), 'mouseenter focus', '.js-add-award', 'mouseenter focus', () => {
const $menu = $('.emoji-menu');
......@@ -260,7 +259,7 @@ export default class AwardsHandler {
checkMutuality,
callback,
) {
const normalizedEmoji = this.normalizeEmojiName(emoji);
const normalizedEmoji = normalizeEmojiName(emoji);
const $emojiButton = this.findEmojiIcon(votesBlock, normalizedEmoji).parent();
this.postEmoji($emojiButton, awardUrl, normalizedEmoji, () => {
this.addAwardToEmojiBar(votesBlock, normalizedEmoji, checkMutuality);
......@@ -279,7 +278,7 @@ export default class AwardsHandler {
this.checkMutuality(votesBlock, emoji);
}
this.addEmojiToFrequentlyUsedList(emoji);
const normalizedEmoji = this.normalizeEmojiName(emoji);
const normalizedEmoji = normalizeEmojiName(emoji);
const $emojiButton = this.findEmojiIcon(votesBlock, normalizedEmoji).parent();
if ($emojiButton.length > 0) {
if (this.isActive($emojiButton)) {
......@@ -469,10 +468,6 @@ export default class AwardsHandler {
return $('body, html').animate(options, 200);
}
normalizeEmojiName(emoji) {
return Object.prototype.hasOwnProperty.call(this.aliases, emoji) ? this.aliases[emoji] : emoji;
}
addEmojiToFrequentlyUsedList(emoji) {
if (isEmojiNameValid(emoji)) {
this.frequentlyUsedEmojis = _.uniq(this.getFrequentlyUsedEmojis().concat(emoji));
......
import emojiMap from 'emojis/digests.json';
import emojiAliases from 'emojis/aliases.json';
import getUnicodeSupportMap from './unicode_support_map';
import isEmojiNameValid from './is_emoji_name_valid';
import isEmojiUnicodeSupported from './is_emoji_unicode_supported';
const validEmojiNames = [...Object.keys(emojiMap), ...Object.keys(emojiAliases)];
function normalizeEmojiName(name) {
return Object.prototype.hasOwnProperty.call(emojiAliases, name) ? emojiAliases[name] : name;
}
function isEmojiNameValid(name) {
return validEmojiNames.indexOf(name) >= 0;
}
export {
emojiMap,
emojiAliases,
normalizeEmojiName,
getUnicodeSupportMap,
isEmojiNameValid,
isEmojiUnicodeSupported,
......
import emojiMap from 'emojis/digests.json';
import emojiAliases from 'emojis/aliases.json';
function isEmojiNameValid(inputName) {
const name = Object.prototype.hasOwnProperty.call(emojiAliases, inputName) ?
emojiAliases[inputName] : inputName;
return name && emojiMap[name];
}
export default isEmojiNameValid;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment