Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b70b5714
Commit
b70b5714
authored
Jul 06, 2020
by
Tim Zallmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improvements to Emoji Loading Mechanism
Fixed Emojis FrontendFixture Creature
parent
7db81dd6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
75 deletions
+79
-75
app/assets/javascripts/behaviors/gl_emoji.js
app/assets/javascripts/behaviors/gl_emoji.js
+42
-47
app/assets/javascripts/emoji/index.js
app/assets/javascripts/emoji/index.js
+36
-27
spec/frontend/fixtures/emojis.rb
spec/frontend/fixtures/emojis.rb
+1
-1
No files found.
app/assets/javascripts/behaviors/gl_emoji.js
View file @
b70b5714
...
...
@@ -13,62 +13,57 @@ class GlEmoji extends HTMLElement {
const
{
fallbackSpriteClass
,
fallbackSrc
}
=
this
.
dataset
;
let
{
name
,
unicodeVersion
}
=
this
.
dataset
;
return
initEmojiMap
()
.
then
(()
=>
{
if
(
!
unicodeVersion
)
{
const
emojiInfo
=
getEmojiInfo
(
name
);
return
initEmojiMap
().
then
(()
=>
{
if
(
!
unicodeVersion
)
{
const
emojiInfo
=
getEmojiInfo
(
name
);
if
(
emojiInfo
)
{
if
(
name
!==
emojiInfo
.
name
)
{
({
name
}
=
emojiInfo
);
this
.
dataset
.
name
=
emojiInfo
.
name
;
}
unicodeVersion
=
emojiInfo
.
u
;
this
.
dataset
.
uni
=
unicodeVersion
;
if
(
emojiInfo
)
{
if
(
name
!==
emojiInfo
.
name
)
{
({
name
}
=
emojiInfo
);
this
.
dataset
.
name
=
emojiInfo
.
name
;
}
unicodeVersion
=
emojiInfo
.
u
;
this
.
dataset
.
unicodeVersion
=
unicodeVersion
;
emojiUnicode
=
emojiInfo
.
e
;
this
.
innerHTML
=
emojiInfo
.
e
;
emojiUnicode
=
emojiInfo
.
e
;
this
.
innerHTML
=
emojiInfo
.
e
;
this
.
title
=
emojiInfo
.
d
;
}
this
.
title
=
emojiInfo
.
d
;
}
}
const
isEmojiUnicode
=
this
.
childNodes
&&
Array
.
prototype
.
every
.
call
(
this
.
childNodes
,
childNode
=>
childNode
.
nodeType
===
3
);
const
isEmojiUnicode
=
this
.
childNodes
&&
Array
.
prototype
.
every
.
call
(
this
.
childNodes
,
childNode
=>
childNode
.
nodeType
===
3
);
if
(
emojiUnicode
&&
isEmojiUnicode
&&
!
isEmojiUnicodeSupported
(
emojiUnicode
,
unicodeVersion
)
)
{
const
hasImageFallback
=
fallbackSrc
&&
fallbackSrc
.
length
>
0
;
const
hasCssSpriteFallback
=
fallbackSpriteClass
&&
fallbackSpriteClass
.
length
>
0
;
if
(
emojiUnicode
&&
isEmojiUnicode
&&
!
isEmojiUnicodeSupported
(
emojiUnicode
,
unicodeVersion
)
)
{
const
hasImageFallback
=
fallbackSrc
&&
fallbackSrc
.
length
>
0
;
const
hasCssSpriteFallback
=
fallbackSpriteClass
&&
fallbackSpriteClass
.
length
>
0
;
// CSS sprite fallback takes precedence over image fallback
if
(
hasCssSpriteFallback
)
{
if
(
!
gon
.
emoji_sprites_css_added
&&
gon
.
emoji_sprites_css_path
)
{
const
emojiSpriteLinkTag
=
document
.
createElement
(
'
link
'
);
emojiSpriteLinkTag
.
setAttribute
(
'
rel
'
,
'
stylesheet
'
);
emojiSpriteLinkTag
.
setAttribute
(
'
href
'
,
gon
.
emoji_sprites_css_path
);
document
.
head
.
appendChild
(
emojiSpriteLinkTag
);
gon
.
emoji_sprites_css_added
=
true
;
}
// IE 11 doesn't like adding multiple at once :(
this
.
classList
.
add
(
'
emoji-icon
'
);
this
.
classList
.
add
(
fallbackSpriteClass
);
}
else
if
(
hasImageFallback
)
{
this
.
innerHTML
=
emojiImageTag
(
name
,
fallbackSrc
);
}
else
{
const
src
=
emojiFallbackImageSrc
(
name
);
this
.
innerHTML
=
emojiImageTag
(
name
,
src
);
// CSS sprite fallback takes precedence over image fallback
if
(
hasCssSpriteFallback
)
{
if
(
!
gon
.
emoji_sprites_css_added
&&
gon
.
emoji_sprites_css_path
)
{
const
emojiSpriteLinkTag
=
document
.
createElement
(
'
link
'
);
emojiSpriteLinkTag
.
setAttribute
(
'
rel
'
,
'
stylesheet
'
);
emojiSpriteLinkTag
.
setAttribute
(
'
href
'
,
gon
.
emoji_sprites_css_path
);
document
.
head
.
appendChild
(
emojiSpriteLinkTag
);
gon
.
emoji_sprites_css_added
=
true
;
}
// IE 11 doesn't like adding multiple at once :(
this
.
classList
.
add
(
'
emoji-icon
'
);
this
.
classList
.
add
(
fallbackSpriteClass
);
}
else
if
(
hasImageFallback
)
{
this
.
innerHTML
=
emojiImageTag
(
name
,
fallbackSrc
);
}
else
{
const
src
=
emojiFallbackImageSrc
(
name
);
this
.
innerHTML
=
emojiImageTag
(
name
,
src
);
}
})
.
catch
(
error
=>
{
// Only reject is already handled in initEmojiMap
throw
error
;
});
}
});
}
}
...
...
app/assets/javascripts/emoji/index.js
View file @
b70b5714
...
...
@@ -5,40 +5,49 @@ import axios from '../lib/utils/axios_utils';
import
AccessorUtilities
from
'
../lib/utils/accessor
'
;
let
emojiMap
=
null
;
let
emojiPromise
=
null
;
let
validEmojiNames
=
null
;
export
const
EMOJI_VERSION
=
'
1
'
;
const
EMOJI_VERSION_LOCALSTORAGE
=
`EMOJIS_
${
EMOJI_VERSION
}
`
;
const
isLocalStorageAvailable
=
AccessorUtilities
.
isLocalStorageAccessSafe
();
export
function
initEmojiMap
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
emojiMap
)
{
resolve
(
emojiMap
);
}
else
if
(
isLocalStorageAvailable
&&
window
.
localStorage
.
getItem
(
EMOJI_VERSION_LOCALSTORAGE
))
{
emojiMap
=
JSON
.
parse
(
window
.
localStorage
.
getItem
(
EMOJI_VERSION_LOCALSTORAGE
));
validEmojiNames
=
[...
Object
.
keys
(
emojiMap
),
...
Object
.
keys
(
emojiAliases
)];
resolve
(
emojiMap
);
}
else
{
// We load the JSON file direct from the server
// because it can't be loaded from a CDN due to
// cross domain problems with JSON
axios
.
get
(
`
${
gon
.
relative_url_root
||
''
}
/-/emojis/
${
EMOJI_VERSION
}
/emojis.json`
)
.
then
(({
data
})
=>
{
emojiMap
=
data
;
validEmojiNames
=
[...
Object
.
keys
(
emojiMap
),
...
Object
.
keys
(
emojiAliases
)];
resolve
(
emojiMap
);
if
(
isLocalStorageAvailable
)
{
window
.
localStorage
.
setItem
(
EMOJI_VERSION_LOCALSTORAGE
,
JSON
.
stringify
(
emojiMap
));
}
})
.
catch
(
err
=>
{
reject
(
err
);
});
}
});
emojiPromise
=
emojiPromise
||
new
Promise
((
resolve
,
reject
)
=>
{
if
(
emojiMap
)
{
resolve
(
emojiMap
);
}
else
if
(
isLocalStorageAvailable
&&
window
.
localStorage
.
getItem
(
'
gl-emoji-map-version
'
)
===
EMOJI_VERSION
&&
window
.
localStorage
.
getItem
(
'
gl-emoji-map
'
)
)
{
emojiMap
=
JSON
.
parse
(
window
.
localStorage
.
getItem
(
'
gl-emoji-map
'
));
validEmojiNames
=
[...
Object
.
keys
(
emojiMap
),
...
Object
.
keys
(
emojiAliases
)];
resolve
(
emojiMap
);
}
else
{
// We load the JSON file direct from the server
// because it can't be loaded from a CDN due to
// cross domain problems with JSON
axios
.
get
(
`
${
gon
.
relative_url_root
||
''
}
/-/emojis/
${
EMOJI_VERSION
}
/emojis.json`
)
.
then
(({
data
})
=>
{
emojiMap
=
data
;
validEmojiNames
=
[...
Object
.
keys
(
emojiMap
),
...
Object
.
keys
(
emojiAliases
)];
resolve
(
emojiMap
);
if
(
isLocalStorageAvailable
)
{
window
.
localStorage
.
setItem
(
'
gl-emoji-map-version
'
,
EMOJI_VERSION
);
window
.
localStorage
.
setItem
(
'
gl-emoji-map
'
,
JSON
.
stringify
(
emojiMap
));
}
})
.
catch
(
err
=>
{
reject
(
err
);
});
}
});
return
emojiPromise
;
}
export
function
normalizeEmojiName
(
name
)
{
...
...
spec/frontend/fixtures/emojis.rb
View file @
b70b5714
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
describe
'Emojis (JavaScript fixtures)'
,
type: :request
do
RSpec
.
describe
'Emojis (JavaScript fixtures)'
,
type: :request
do
include
JavaScriptFixturesHelpers
before
(
:all
)
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment