move emojiAlias logic into helper module

This commit is contained in:
Mike Greiling 2017-06-24 01:44:57 -05:00
parent a7b603a2ac
commit 73c5c00133
2 changed files with 17 additions and 16 deletions

View File

@ -3,7 +3,7 @@
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import { glEmojiTag } from './behaviors/gl_emoji'; import { glEmojiTag } from './behaviors/gl_emoji';
import { emojiMap, emojiAliases, isEmojiNameValid, normalizeEmojiName } from './emoji'; import { emojiMap, filterEmojiNamesByAlias, isEmojiNameValid, normalizeEmojiName } from './emoji';
const animationEndEventString = 'animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd'; const animationEndEventString = 'animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd';
const transitionEndEventString = 'transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'; const transitionEndEventString = 'transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd';
@ -511,21 +511,11 @@ export default class AwardsHandler {
} }
} }
findMatchingEmojiElements(term) { findMatchingEmojiElements(query) {
const safeTerm = term.toLowerCase(); const emojiMatches = filterEmojiNamesByAlias(query);
const $emojiElements = $('.emoji-menu-list:not(.frequent-emojis) [data-name]');
const namesMatchingAlias = []; const $matchingElements = $emojiElements
Object.keys(emojiAliases).forEach((alias) => { .filter((i, elm) => emojiMatches.indexOf(elm.dataset.name) >= 0);
if (alias.indexOf(safeTerm) >= 0) {
namesMatchingAlias.push(emojiAliases[alias]);
}
});
const $matchingElements = namesMatchingAlias.concat(safeTerm)
.reduce(
($result, searchTerm) =>
$result.add($(`.emoji-menu-list:not(.frequent-emojis) [data-name*="${searchTerm}"]`)),
$([]),
);
return $matchingElements.closest('li').clone(); return $matchingElements.closest('li').clone();
} }

View File

@ -13,10 +13,21 @@ function isEmojiNameValid(name) {
return validEmojiNames.indexOf(name) >= 0; return validEmojiNames.indexOf(name) >= 0;
} }
function filterEmojiNames(filter) {
const match = filter.toLowerCase();
return validEmojiNames.filter(name => name.indexOf(match) >= 0);
}
function filterEmojiNamesByAlias(filter) {
return _.uniq(filterEmojiNames(filter).map(name => normalizeEmojiName(name)));
}
export { export {
emojiMap, emojiMap,
emojiAliases, emojiAliases,
normalizeEmojiName, normalizeEmojiName,
filterEmojiNames,
filterEmojiNamesByAlias,
getUnicodeSupportMap, getUnicodeSupportMap,
isEmojiNameValid, isEmojiNameValid,
isEmojiUnicodeSupported, isEmojiUnicodeSupported,