summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2017-06-24 01:44:57 -0500
committerMike Greiling <mike@pixelcog.com>2017-06-26 14:10:02 -0500
commit73c5c0013313ba184837da178bf3fe36d7dfecc8 (patch)
tree33170a8654c0238e64953d211be33885483cd60a
parenta7b603a2ac28a5c4c3e175cf4013c12d241b5452 (diff)
downloadgitlab-ce-73c5c0013313ba184837da178bf3fe36d7dfecc8.tar.gz
move emojiAlias logic into helper module
-rw-r--r--app/assets/javascripts/awards_handler.js22
-rw-r--r--app/assets/javascripts/emoji/index.js11
2 files changed, 17 insertions, 16 deletions
diff --git a/app/assets/javascripts/awards_handler.js b/app/assets/javascripts/awards_handler.js
index c91c56ff0a5..677f997895a 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, normalizeEmojiName } from './emoji';
+import { emojiMap, filterEmojiNamesByAlias, isEmojiNameValid, normalizeEmojiName } from './emoji';
const animationEndEventString = 'animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd';
const transitionEndEventString = 'transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd';
@@ -511,21 +511,11 @@ export default class AwardsHandler {
}
}
- findMatchingEmojiElements(term) {
- const safeTerm = term.toLowerCase();
-
- const namesMatchingAlias = [];
- Object.keys(emojiAliases).forEach((alias) => {
- 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}"]`)),
- $([]),
- );
+ findMatchingEmojiElements(query) {
+ const emojiMatches = filterEmojiNamesByAlias(query);
+ const $emojiElements = $('.emoji-menu-list:not(.frequent-emojis) [data-name]');
+ const $matchingElements = $emojiElements
+ .filter((i, elm) => emojiMatches.indexOf(elm.dataset.name) >= 0);
return $matchingElements.closest('li').clone();
}
diff --git a/app/assets/javascripts/emoji/index.js b/app/assets/javascripts/emoji/index.js
index ad4cdfb4355..e1edf376936 100644
--- a/app/assets/javascripts/emoji/index.js
+++ b/app/assets/javascripts/emoji/index.js
@@ -13,10 +13,21 @@ function isEmojiNameValid(name) {
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 {
emojiMap,
emojiAliases,
normalizeEmojiName,
+ filterEmojiNames,
+ filterEmojiNamesByAlias,
getUnicodeSupportMap,
isEmojiNameValid,
isEmojiUnicodeSupported,