diff options
author | Mike Greiling <mike@pixelcog.com> | 2017-06-24 09:41:49 +0300 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2017-06-26 22:10:01 +0300 |
commit | b7a0044a70020bf97d9f1d604f126ab23db3dc93 (patch) | |
tree | c7ddfbfb63cc652d029609576ddde46f6b0f7670 /app | |
parent | 35ee21d992a8d2fa65ee7601c8948dbf79b54c53 (diff) |
move normalizeEmojiName method to emoji helper module
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/awards_handler.js | 11 | ||||
-rw-r--r-- | app/assets/javascripts/emoji/index.js | 12 | ||||
-rw-r--r-- | app/assets/javascripts/emoji/is_emoji_name_valid.js | 11 |
3 files changed, 14 insertions, 20 deletions
diff --git a/app/assets/javascripts/awards_handler.js b/app/assets/javascripts/awards_handler.js index 2bae4f4d955..27b61a0c61f 100644 --- a/app/assets/javascripts/awards_handler.js +++ b/app/assets/javascripts/awards_handler.js @@ -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)); diff --git a/app/assets/javascripts/emoji/index.js b/app/assets/javascripts/emoji/index.js index 1e86ce822d2..ad4cdfb4355 100644 --- a/app/assets/javascripts/emoji/index.js +++ b/app/assets/javascripts/emoji/index.js @@ -1,12 +1,22 @@ 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, diff --git a/app/assets/javascripts/emoji/is_emoji_name_valid.js b/app/assets/javascripts/emoji/is_emoji_name_valid.js deleted file mode 100644 index be4aeb32c46..00000000000 --- a/app/assets/javascripts/emoji/is_emoji_name_valid.js +++ /dev/null @@ -1,11 +0,0 @@ -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; |