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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
9d6bbc92
Commit
9d6bbc92
authored
Jun 27, 2017
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move glEmojiTag method to emoji helper
parent
27a1348f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
87 deletions
+68
-87
app/assets/javascripts/awards_handler.js
app/assets/javascripts/awards_handler.js
+2
-3
app/assets/javascripts/behaviors/gl_emoji.js
app/assets/javascripts/behaviors/gl_emoji.js
+3
-64
app/assets/javascripts/behaviors/index.js
app/assets/javascripts/behaviors/index.js
+1
-1
app/assets/javascripts/emoji/index.js
app/assets/javascripts/emoji/index.js
+60
-16
app/assets/javascripts/gfm_auto_complete.js
app/assets/javascripts/gfm_auto_complete.js
+1
-2
spec/javascripts/emoji_spec.js
spec/javascripts/emoji_spec.js
+1
-1
No files found.
app/assets/javascripts/awards_handler.js
View file @
9d6bbc92
...
...
@@ -2,7 +2,6 @@
/* global Flash */
import
Cookies
from
'
js-cookie
'
;
import
{
glEmojiTag
}
from
'
./behaviors/gl_emoji
'
;
import
*
as
Emoji
from
'
./emoji
'
;
const
animationEndEventString
=
'
animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd
'
;
...
...
@@ -30,7 +29,7 @@ function renderCategory(name, emojiList, opts = {}) {
${
emojiList
.
map
(
emojiName
=>
`
<li class="emoji-menu-list-item">
<button class="emoji-menu-btn text-center js-emoji-btn" type="button">
${
glEmojiTag
(
emojiName
,
{
${
Emoji
.
glEmojiTag
(
emojiName
,
{
sprite
:
true
,
})}
</button>
...
...
@@ -369,7 +368,7 @@ export default class AwardsHandler {
createAwardButtonForVotesBlock
(
votesBlock
,
emojiName
)
{
const
buttonHtml
=
`
<button class="btn award-control js-emoji-btn has-tooltip active" title="You" data-placement="bottom">
${
glEmojiTag
(
emojiName
)}
${
Emoji
.
glEmojiTag
(
emojiName
)}
<span class="award-control-text js-counter">1</span>
</button>
`
;
...
...
app/assets/javascripts/behaviors/gl_emoji.js
View file @
9d6bbc92
import
installCustomElements
from
'
document-register-element
'
;
import
{
emoji
Map
,
normalizeEmojiName
}
from
'
../emoji
'
;
import
{
emoji
ImageTag
,
emojiFallbackImageSrc
}
from
'
../emoji
'
;
import
isEmojiUnicodeSupported
from
'
../emoji/support
'
;
installCustomElements
(
window
);
function
emojiImageTag
(
name
,
src
)
{
return
`<img class="emoji" title=":
${
name
}
:" alt=":
${
name
}
:" src="
${
src
}
" width="20" height="20" align="absmiddle" />`
;
}
function
assembleFallbackImageSrc
(
inputName
)
{
let
name
=
normalizeEmojiName
(
inputName
);
let
emojiInfo
=
emojiMap
[
name
];
// Fallback to question mark for unknown emojis
if
(
!
emojiInfo
)
{
name
=
'
grey_question
'
;
emojiInfo
=
emojiMap
[
name
];
}
const
fallbackImageSrc
=
`
${
gon
.
asset_host
||
''
}${
gon
.
relative_url_root
||
''
}
/assets/emoji/
${
name
}
-
${
emojiInfo
.
digest
}
.png`
;
return
fallbackImageSrc
;
}
function
glEmojiTag
(
inputName
,
options
)
{
const
opts
=
{
sprite
:
false
,
forceFallback
:
false
,
...
options
};
let
name
=
normalizeEmojiName
(
inputName
);
let
emojiInfo
=
emojiMap
[
name
];
// Fallback to question mark for unknown emojis
if
(
!
emojiInfo
)
{
name
=
'
grey_question
'
;
emojiInfo
=
emojiMap
[
name
];
}
const
fallbackImageSrc
=
assembleFallbackImageSrc
(
name
);
const
fallbackSpriteClass
=
`emoji-
${
name
}
`
;
const
classList
=
[];
if
(
opts
.
forceFallback
&&
opts
.
sprite
)
{
classList
.
push
(
'
emoji-icon
'
);
classList
.
push
(
fallbackSpriteClass
);
}
const
classAttribute
=
classList
.
length
>
0
?
`class="
${
classList
.
join
(
'
'
)}
"`
:
''
;
const
fallbackSpriteAttribute
=
opts
.
sprite
?
`data-fallback-sprite-class="
${
fallbackSpriteClass
}
"`
:
''
;
let
contents
=
emojiInfo
.
moji
;
if
(
opts
.
forceFallback
&&
!
opts
.
sprite
)
{
contents
=
emojiImageTag
(
name
,
fallbackImageSrc
);
}
return
`
<gl-emoji
${
classAttribute
}
data-name="
${
name
}
"
data-fallback-src="
${
fallbackImageSrc
}
"
${
fallbackSpriteAttribute
}
data-unicode-version="
${
emojiInfo
.
unicodeVersion
}
"
title="
${
emojiInfo
.
description
}
"
>
${
contents
}
</gl-emoji>
`
;
}
function
installGlEmojiElement
()
{
export
default
function
installGlEmojiElement
()
{
const
GlEmojiElementProto
=
Object
.
create
(
HTMLElement
.
prototype
);
GlEmojiElementProto
.
createdCallback
=
function
createdCallback
()
{
const
emojiUnicode
=
this
.
textContent
.
trim
();
...
...
@@ -91,7 +35,7 @@ function installGlEmojiElement() {
}
else
if
(
hasImageFallback
)
{
this
.
innerHTML
=
emojiImageTag
(
name
,
fallbackSrc
);
}
else
{
const
src
=
assemble
FallbackImageSrc
(
name
);
const
src
=
emoji
FallbackImageSrc
(
name
);
this
.
innerHTML
=
emojiImageTag
(
name
,
src
);
}
}
...
...
@@ -101,8 +45,3 @@ function installGlEmojiElement() {
prototype
:
GlEmojiElementProto
,
});
}
export
{
installGlEmojiElement
,
glEmojiTag
,
};
app/assets/javascripts/behaviors/index.js
View file @
9d6bbc92
import
'
./autosize
'
;
import
'
./bind_in_out
'
;
import
'
./details_behavior
'
;
import
{
installGlEmojiElement
}
from
'
./gl_emoji
'
;
import
installGlEmojiElement
from
'
./gl_emoji
'
;
import
'
./quick_submit
'
;
import
'
./requires_input
'
;
import
'
./toggler_behavior
'
;
...
...
app/assets/javascripts/emoji/index.js
View file @
9d6bbc92
import
emojiMap
from
'
emojis/digests.json
'
;
import
emojiAliases
from
'
emojis/aliases.json
'
;
const
validEmojiNames
=
[...
Object
.
keys
(
emojiMap
),
...
Object
.
keys
(
emojiAliases
)];
export
const
validEmojiNames
=
[...
Object
.
keys
(
emojiMap
),
...
Object
.
keys
(
emojiAliases
)];
function
normalizeEmojiName
(
name
)
{
export
function
normalizeEmojiName
(
name
)
{
return
Object
.
prototype
.
hasOwnProperty
.
call
(
emojiAliases
,
name
)
?
emojiAliases
[
name
]
:
name
;
}
function
isEmojiNameValid
(
name
)
{
export
function
isEmojiNameValid
(
name
)
{
return
validEmojiNames
.
indexOf
(
name
)
>=
0
;
}
function
filterEmojiNames
(
filter
)
{
export
function
filterEmojiNames
(
filter
)
{
const
match
=
filter
.
toLowerCase
();
return
validEmojiNames
.
filter
(
name
=>
name
.
indexOf
(
match
)
>=
0
);
}
function
filterEmojiNamesByAlias
(
filter
)
{
export
function
filterEmojiNamesByAlias
(
filter
)
{
return
_
.
uniq
(
filterEmojiNames
(
filter
).
map
(
name
=>
normalizeEmojiName
(
name
)));
}
let
emojiByCategory
;
function
getEmojiByCategory
(
category
=
null
)
{
export
function
getEmojiByCategory
(
category
=
null
)
{
if
(
!
emojiByCategory
)
{
emojiByCategory
=
{
activity
:
[],
...
...
@@ -43,13 +43,57 @@ function getEmojiByCategory(category = null) {
return
category
?
emojiByCategory
[
category
]
:
emojiByCategory
;
}
export
{
emojiMap
,
emojiAliases
,
normalizeEmojiName
,
filterEmojiNames
,
filterEmojiNamesByAlias
,
getEmojiByCategory
,
isEmojiNameValid
,
validEmojiNames
,
};
export
function
getEmojiInfo
(
query
)
{
let
name
=
normalizeEmojiName
(
query
);
let
emojiInfo
=
emojiMap
[
name
];
// Fallback to question mark for unknown emojis
if
(
!
emojiInfo
)
{
name
=
'
grey_question
'
;
emojiInfo
=
emojiMap
[
name
];
}
return
{
...
emojiInfo
,
name
};
}
export
function
emojiFallbackImageSrc
(
inputName
)
{
const
{
name
,
digest
}
=
getEmojiInfo
(
inputName
);
return
`
${
gon
.
asset_host
||
''
}${
gon
.
relative_url_root
||
''
}
/assets/emoji/
${
name
}
-
${
digest
}
.png`
;
}
export
function
emojiImageTag
(
name
,
src
)
{
return
`<img class="emoji" title=":
${
name
}
:" alt=":
${
name
}
:" src="
${
src
}
" width="20" height="20" align="absmiddle" />`
;
}
export
function
glEmojiTag
(
inputName
,
options
)
{
const
opts
=
{
sprite
:
false
,
forceFallback
:
false
,
...
options
};
const
{
name
,
...
emojiInfo
}
=
getEmojiInfo
(
inputName
);
const
fallbackImageSrc
=
emojiFallbackImageSrc
(
name
);
const
fallbackSpriteClass
=
`emoji-
${
name
}
`
;
const
classList
=
[];
if
(
opts
.
forceFallback
&&
opts
.
sprite
)
{
classList
.
push
(
'
emoji-icon
'
);
classList
.
push
(
fallbackSpriteClass
);
}
const
classAttribute
=
classList
.
length
>
0
?
`class="
${
classList
.
join
(
'
'
)}
"`
:
''
;
const
fallbackSpriteAttribute
=
opts
.
sprite
?
`data-fallback-sprite-class="
${
fallbackSpriteClass
}
"`
:
''
;
let
contents
=
emojiInfo
.
moji
;
if
(
opts
.
forceFallback
&&
!
opts
.
sprite
)
{
contents
=
emojiImageTag
(
name
,
fallbackImageSrc
);
}
return
`
<gl-emoji
${
classAttribute
}
data-name="
${
name
}
"
data-fallback-src="
${
fallbackImageSrc
}
"
${
fallbackSpriteAttribute
}
data-unicode-version="
${
emojiInfo
.
unicodeVersion
}
"
title="
${
emojiInfo
.
description
}
"
>
${
contents
}
</gl-emoji>
`
;
}
app/assets/javascripts/gfm_auto_complete.js
View file @
9d6bbc92
import
{
glEmojiTag
}
from
'
./behaviors/gl_emoji
'
;
import
{
validEmojiNames
}
from
'
./emoji
'
;
import
{
validEmojiNames
,
glEmojiTag
}
from
'
./emoji
'
;
import
glRegexp
from
'
./lib/utils/regexp
'
;
import
AjaxCache
from
'
./lib/utils/ajax_cache
'
;
...
...
spec/javascripts/
gl_
emoji_spec.js
→
spec/javascripts/emoji_spec.js
View file @
9d6bbc92
import
{
glEmojiTag
}
from
'
~/
behaviors/gl_
emoji
'
;
import
{
glEmojiTag
}
from
'
~/emoji
'
;
import
isEmojiUnicodeSupported
,
{
isFlagEmoji
,
isKeycapEmoji
,
...
...
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