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
c9ba4f76
Commit
c9ba4f76
authored
Feb 04, 2019
by
Tim Zallmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved Class to its own class
parent
17ad4f8f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
47 deletions
+42
-47
app/assets/javascripts/behaviors/gl_emoji.js
app/assets/javascripts/behaviors/gl_emoji.js
+42
-47
No files found.
app/assets/javascripts/behaviors/gl_emoji.js
View file @
c9ba4f76
import
'
document-register-element
'
;
import
isEmojiUnicodeSupported
from
'
../emoji/support
'
;
export
default
function
installGlEmojiElement
()
{
if
(
!
customElements
.
get
(
'
gl-emoji
'
))
{
customElements
.
define
(
'
gl-emoji
'
,
class
extends
HTMLElement
{
constructor
()
{
super
();
class
GlEmoji
extends
HTMLElement
{
constructor
()
{
super
();
const
emojiUnicode
=
this
.
textContent
.
trim
();
const
{
name
,
unicodeVersion
,
fallbackSrc
,
fallbackSpriteClass
}
=
this
.
dataset
;
const
emojiUnicode
=
this
.
textContent
.
trim
();
const
{
name
,
unicodeVersion
,
fallbackSrc
,
fallbackSpriteClass
}
=
this
.
dataset
;
const
isEmojiUnicode
=
this
.
childNodes
&&
Array
.
prototype
.
every
.
call
(
this
.
childNodes
,
childNode
=>
childNode
.
nodeType
===
3
);
const
hasImageFallback
=
fallbackSrc
&&
fallbackSrc
.
length
>
0
;
const
hasCssSpriteFalback
=
fallbackSpriteClass
&&
fallbackSpriteClass
.
length
>
0
;
const
isEmojiUnicode
=
this
.
childNodes
&&
Array
.
prototype
.
every
.
call
(
this
.
childNodes
,
childNode
=>
childNode
.
nodeType
===
3
);
const
hasImageFallback
=
fallbackSrc
&&
fallbackSrc
.
length
>
0
;
const
hasCssSpriteFalback
=
fallbackSpriteClass
&&
fallbackSpriteClass
.
length
>
0
;
if
(
emojiUnicode
&&
isEmojiUnicode
&&
!
isEmojiUnicodeSupported
(
emojiUnicode
,
unicodeVersion
)
)
{
// CSS sprite fallback takes precedence over image fallback
if
(
hasCssSpriteFalback
)
{
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
);
if
(
emojiUnicode
&&
isEmojiUnicode
&&
!
isEmojiUnicodeSupported
(
emojiUnicode
,
unicodeVersion
))
{
// CSS sprite fallback takes precedence over image fallback
if
(
hasCssSpriteFalback
)
{
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
{
import
(
/* webpackChunkName: 'emoji' */
'
../emoji
'
)
.
then
(({
emojiImageTag
,
emojiFallbackImageSrc
})
=>
{
if
(
hasImageFallback
)
{
this
.
innerHTML
=
emojiImageTag
(
name
,
fallbackSrc
);
}
else
{
import
(
/* webpackChunkName: 'emoji' */
'
../emoji
'
)
.
then
(({
emojiImageTag
,
emojiFallbackImageSrc
})
=>
{
if
(
hasImageFallback
)
{
this
.
innerHTML
=
emojiImageTag
(
name
,
fallbackSrc
);
}
else
{
const
src
=
emojiFallbackImageSrc
(
name
);
this
.
innerHTML
=
emojiImageTag
(
name
,
src
);
}
})
.
catch
(()
=>
{
// do nothing
});
const
src
=
emojiFallbackImageSrc
(
name
);
this
.
innerHTML
=
emojiImageTag
(
name
,
src
);
}
}
}
},
);
})
.
catch
(()
=>
{
// do nothing
});
}
}
}
}
export
default
function
installGlEmojiElement
()
{
if
(
!
customElements
.
get
(
'
gl-emoji
'
))
{
customElements
.
define
(
'
gl-emoji
'
,
GlEmoji
);
}
}
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