diff --git a/app/assets/javascripts/behaviors/gl_emoji.js b/app/assets/javascripts/behaviors/gl_emoji.js index 3a29254cf99..17422f5cece 100644 --- a/app/assets/javascripts/behaviors/gl_emoji.js +++ b/app/assets/javascripts/behaviors/gl_emoji.js @@ -1,10 +1,9 @@ import installCustomElements from 'document-register-element'; -import { emojiMap, normalizeEmojiName, isEmojiUnicodeSupported, getUnicodeSupportMap } from '../emoji'; +import { emojiMap, normalizeEmojiName } from '../emoji'; +import isEmojiUnicodeSupported from '../emoji/support'; installCustomElements(window); -const generatedUnicodeSupportMap = getUnicodeSupportMap(); - function emojiImageTag(name, src) { return `:${name}:`; } @@ -82,7 +81,7 @@ function installGlEmojiElement() { if ( emojiUnicode && isEmojiUnicode && - !isEmojiUnicodeSupported(generatedUnicodeSupportMap, emojiUnicode, unicodeVersion) + !isEmojiUnicodeSupported(emojiUnicode, unicodeVersion) ) { // CSS sprite fallback takes precedence over image fallback if (hasCssSpriteFalback) { @@ -106,5 +105,4 @@ function installGlEmojiElement() { export { installGlEmojiElement, glEmojiTag, - emojiImageTag, }; diff --git a/app/assets/javascripts/emoji/index.js b/app/assets/javascripts/emoji/index.js index 70346c985e9..7c3bab1e4a9 100644 --- a/app/assets/javascripts/emoji/index.js +++ b/app/assets/javascripts/emoji/index.js @@ -1,7 +1,5 @@ import emojiMap from 'emojis/digests.json'; import emojiAliases from 'emojis/aliases.json'; -import getUnicodeSupportMap from './unicode_support_map'; -import isEmojiUnicodeSupported from './is_emoji_unicode_supported'; const validEmojiNames = [...Object.keys(emojiMap), ...Object.keys(emojiAliases)]; @@ -52,8 +50,6 @@ export { filterEmojiNames, filterEmojiNamesByAlias, getEmojiByCategory, - getUnicodeSupportMap, isEmojiNameValid, - isEmojiUnicodeSupported, validEmojiNames, }; diff --git a/app/assets/javascripts/emoji/support/index.js b/app/assets/javascripts/emoji/support/index.js new file mode 100644 index 00000000000..1f7852dd487 --- /dev/null +++ b/app/assets/javascripts/emoji/support/index.js @@ -0,0 +1,10 @@ +import isEmojiUnicodeSupported from './is_emoji_unicode_supported'; +import getUnicodeSupportMap from './unicode_support_map'; + +// cache browser support map between calls +let browserUnicodeSupportMap; + +export default function isEmojiUnicodeSupportedByBrowser(emojiUnicode, unicodeVersion) { + browserUnicodeSupportMap = browserUnicodeSupportMap || getUnicodeSupportMap(); + return isEmojiUnicodeSupported(browserUnicodeSupportMap, emojiUnicode, unicodeVersion); +} diff --git a/app/assets/javascripts/emoji/is_emoji_unicode_supported.js b/app/assets/javascripts/emoji/support/is_emoji_unicode_supported.js similarity index 100% rename from app/assets/javascripts/emoji/is_emoji_unicode_supported.js rename to app/assets/javascripts/emoji/support/is_emoji_unicode_supported.js diff --git a/app/assets/javascripts/emoji/unicode_support_map.js b/app/assets/javascripts/emoji/support/unicode_support_map.js similarity index 99% rename from app/assets/javascripts/emoji/unicode_support_map.js rename to app/assets/javascripts/emoji/support/unicode_support_map.js index 2a0c013a70c..755381c2f95 100644 --- a/app/assets/javascripts/emoji/unicode_support_map.js +++ b/app/assets/javascripts/emoji/support/unicode_support_map.js @@ -1,4 +1,4 @@ -import AccessorUtilities from '../lib/utils/accessor'; +import AccessorUtilities from '../../lib/utils/accessor'; const unicodeSupportTestMap = { // man, student (emojione does not have any of these yet), http://emojipedia.org/emoji-zwj-sequences/ diff --git a/spec/javascripts/behaviors/gl_emoji/unicode_support_map_spec.js b/spec/javascripts/behaviors/gl_emoji/unicode_support_map_spec.js index 1c6b6ffe435..ec2c549e032 100644 --- a/spec/javascripts/behaviors/gl_emoji/unicode_support_map_spec.js +++ b/spec/javascripts/behaviors/gl_emoji/unicode_support_map_spec.js @@ -1,4 +1,4 @@ -import getUnicodeSupportMap from '~/emoji/unicode_support_map'; +import getUnicodeSupportMap from '~/emoji/support/unicode_support_map'; import AccessorUtilities from '~/lib/utils/accessor'; describe('Unicode Support Map', () => { diff --git a/spec/javascripts/gl_emoji_spec.js b/spec/javascripts/gl_emoji_spec.js index 17c8981971c..be1ced4aaf9 100644 --- a/spec/javascripts/gl_emoji_spec.js +++ b/spec/javascripts/gl_emoji_spec.js @@ -5,7 +5,7 @@ import isEmojiUnicodeSupported, { isSkinToneComboEmoji, isHorceRacingSkinToneComboEmoji, isPersonZwjEmoji, -} from '~/emoji/is_emoji_unicode_supported'; +} from '~/emoji/support/is_emoji_unicode_supported'; const emptySupportMap = { personZwj: false,