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
d8c27e4e
Commit
d8c27e4e
authored
May 11, 2016
by
Zeger-Jan van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge awards-handler.coffee from another branch
parent
7e6dcf9c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
49 deletions
+48
-49
app/assets/javascripts/awards_handler.coffee
app/assets/javascripts/awards_handler.coffee
+48
-49
No files found.
app/assets/javascripts/awards_handler.coffee
View file @
d8c27e4e
class
@
AwardsHandler
class
@
AwardsHandler
constructor
:
->
constructor
:
->
@
aliases
=
gl
.
emoji
.
emojiAliases
()
@
aliases
=
emojiAliases
()
$
(
document
)
$
(
document
)
.
off
"click"
,
".js-add-award"
.
off
"click"
,
".js-add-award"
.
on
"click"
,
".js-add-award"
,
(
e
)
=>
.
on
"click"
,
".js-add-award"
,
(
e
vent
)
=>
e
.
stopPropagation
()
e
vent
.
stopPropagation
()
e
.
preventDefault
()
e
vent
.
preventDefault
()
@
showEmojiMenu
$
(
e
.
currentTarget
)
@
showEmojiMenu
$
(
e
vent
.
currentTarget
)
$
(
"html"
).
on
'click'
,
(
e
)
->
$
(
"html"
).
on
'click'
,
(
e
vent
)
->
if
!
$
(
e
.
target
).
closest
(
".emoji-menu"
).
length
if
!
$
(
e
vent
.
target
).
closest
(
".emoji-menu"
).
length
if
$
(
".emoji-menu"
).
is
(
":visible"
)
if
$
(
".emoji-menu"
).
is
(
":visible"
)
$
(
'.js-add-award.is-active'
).
removeClass
'is-active'
$
(
'.js-add-award.is-active'
).
removeClass
'is-active'
$
(
".emoji-menu"
).
removeClass
"is-visible"
$
(
".emoji-menu"
).
removeClass
"is-visible"
$
(
document
)
$
(
document
)
.
off
"click"
,
".js-emoji-btn"
.
off
"click"
,
".js-emoji-btn"
.
on
"click"
,
".js-emoji-btn"
,
@
handleClick
.
bind
(
@
)
.
on
"click"
,
".js-emoji-btn"
,
@
handleClick
handleClick
:
(
e
)
-
>
handleClick
:
(
e
)
=
>
e
.
preventDefault
()
e
.
preventDefault
()
$emojiBtn
=
$
(
e
.
currentTarget
)
$emojiBtn
=
$
(
e
.
currentTarget
)
$addAwardBtn
=
$
(
'.js-add-award.is-active'
)
$addAwardBtn
=
$
(
'.js-add-award.is-active'
)
...
@@ -31,27 +31,16 @@ class @AwardsHandler
...
@@ -31,27 +31,16 @@ class @AwardsHandler
else
if
$votesBlock
.
length
is
0
else
if
$votesBlock
.
length
is
0
$votesBlock
=
$addAwardBtn
.
closest
(
'.js-awards-block'
)
$votesBlock
=
$addAwardBtn
.
closest
(
'.js-awards-block'
)
@
currentVoteBlock
=
$votesBlock
$votesBlock
.
addClass
'js-awards-block-current'
awardUrl
=
$votesBlock
.
data
'award-url'
awardUrl
=
$votesBlock
.
data
'award-url'
emoji
=
$emojiBtn
emoji
=
$emojiBtn
.
find
(
".icon"
)
.
find
(
".icon"
)
.
data
"emoji"
.
data
"emoji"
if
emoji
is
"thumbsup"
and
@
didUserClickEmoji
$emojiBtn
,
"thumbsdown"
@
addAward
awardUrl
,
"thumbsdown"
else
if
emoji
is
"thumbsdown"
and
@
didUserClickEmoji
$emojiBtn
,
"thumbsup"
@
addAward
awardUrl
,
"thumbsup"
@
addAward
awardUrl
,
emoji
@
addAward
awardUrl
,
emoji
didUserClickEmoji
:
(
emojiBtn
,
emoji
)
->
if
emojiBtn
.
siblings
(
"button:has([data-emoji=
#{
emoji
}
])"
).
attr
(
"data-original-title"
)
emojiBtn
.
siblings
(
"button:has([data-emoji=
#{
emoji
}
])"
).
attr
(
"data-original-title"
).
indexOf
(
'me'
)
>
-
1
showEmojiMenu
:
(
$addBtn
)
->
showEmojiMenu
:
(
$addBtn
)
->
$menu
=
$
(
'.emoji-menu'
)
$menu
=
$
(
'.emoji-menu'
)
if
$menu
.
length
if
$menu
.
length
$holder
=
$addBtn
.
closest
(
'.js-award-holder'
)
$holder
=
$addBtn
.
closest
(
'.js-award-holder'
)
...
@@ -60,7 +49,6 @@ class @AwardsHandler
...
@@ -60,7 +49,6 @@ class @AwardsHandler
$menu
.
removeClass
"is-visible"
$menu
.
removeClass
"is-visible"
$
(
"#emoji_search"
).
blur
()
$
(
"#emoji_search"
).
blur
()
else
else
$
(
".emoji-menu"
).
addClass
"is-visible"
$addBtn
.
addClass
"is-active"
$addBtn
.
addClass
"is-active"
@
positionMenu
(
$menu
,
$addBtn
)
@
positionMenu
(
$menu
,
$addBtn
)
...
@@ -77,6 +65,7 @@ class @AwardsHandler
...
@@ -77,6 +65,7 @@ class @AwardsHandler
@
positionMenu
(
$menu
,
$addBtn
)
@
positionMenu
(
$menu
,
$addBtn
)
@
renderFrequentlyUsedBlock
()
@
renderFrequentlyUsedBlock
()
setTimeout
=>
setTimeout
=>
$menu
.
addClass
"is-visible"
$menu
.
addClass
"is-visible"
$
(
"#emoji_search"
).
focus
()
$
(
"#emoji_search"
).
focus
()
...
@@ -101,16 +90,18 @@ class @AwardsHandler
...
@@ -101,16 +90,18 @@ class @AwardsHandler
$menu
.
css
(
css
)
$menu
.
css
(
css
)
addAward
:
(
awardUrl
,
emoji
)
->
addAward
:
(
awardUrl
,
emoji
)
->
emoji
=
@
norm
i
lizeEmojiName
(
emoji
)
emoji
=
@
norm
a
lizeEmojiName
(
emoji
)
@
postEmoji
awardUrl
,
emoji
,
=>
@
postEmoji
awardUrl
,
emoji
,
=>
@
addAwardToEmojiBar
(
emoji
)
@
addAwardToEmojiBar
(
emoji
)
$
(
'.emoji-menu'
).
removeClass
'is-visible'
$
(
'.js-awards-block-current'
).
removeClass
'js-awards-block-current'
$
(
".emoji-menu"
).
removeClass
"is-visible"
addAwardToEmojiBar
:
(
emoji
)
->
addAwardToEmojiBar
:
(
emoji
)
->
@
addEmojiToFrequentlyUsedList
(
emoji
)
@
addEmojiToFrequentlyUsedList
(
emoji
)
emoji
=
@
norm
i
lizeEmojiName
(
emoji
)
emoji
=
@
norm
a
lizeEmojiName
(
emoji
)
$emojiBtn
=
@
findEmojiIcon
(
emoji
).
parent
()
$emojiBtn
=
@
findEmojiIcon
(
emoji
).
parent
()
if
$emojiBtn
.
length
>
0
if
$emojiBtn
.
length
>
0
...
@@ -146,12 +137,16 @@ class @AwardsHandler
...
@@ -146,12 +137,16 @@ class @AwardsHandler
$emojiBtn
.
removeClass
(
"active"
)
$emojiBtn
.
removeClass
(
"active"
)
if
!
isntNoteBody
and
$awardsBlock
.
children
(
'.js-emoji-btn'
).
length
is
0
# If this is a note body, we just hide the award emoji row like the initial state
$awardsBlock
.
addClass
'hidden'
removeMeFromUserList
:
(
$emojiBtn
,
emoji
)
->
removeMeFromUserList
:
(
$emojiBtn
,
emoji
)
->
award_block
=
$emojiBtn
award_block
=
$emojiBtn
authors
=
award_block
authors
=
award_block
.
attr
(
"data-original-title"
)
.
attr
(
"data-original-title"
)
.
split
(
", "
)
.
split
(
", "
)
authors
.
splice
(
authors
.
indexOf
(
"me"
),
1
)
authors
.
splice
(
authors
.
indexOf
(
"me"
),
1
)
award_block
award_block
.
closest
(
".js-emoji-btn"
)
.
closest
(
".js-emoji-btn"
)
.
attr
(
"data-original-title"
,
authors
.
join
(
", "
))
.
attr
(
"data-original-title"
,
authors
.
join
(
", "
))
...
@@ -164,17 +159,18 @@ class @AwardsHandler
...
@@ -164,17 +159,18 @@ class @AwardsHandler
if
origTitle
if
origTitle
users
=
origTitle
.
split
(
', '
)
users
=
origTitle
.
split
(
', '
)
users
.
push
(
"me"
)
users
.
push
(
"me"
)
award_block
.
attr
(
"
data-original-
title"
,
users
.
join
(
", "
))
award_block
.
attr
(
"title"
,
users
.
join
(
", "
))
@
resetTooltip
(
award_block
)
@
resetTooltip
(
award_block
)
resetTooltip
:
(
award
)
->
resetTooltip
:
(
award
)
->
award
.
tooltip
(
'destroy'
)
award
.
tooltip
(
"destroy"
)
# "destroy" call is asynchronous and there is no appropriate callback on it, this is why we need to set timeout.
# "destroy" call is asynchronous and there is no appropriate callback on it, this is why we need to set timeout.
setTimeout
(
->
setTimeout
(
->
award
.
tooltip
()
award
.
tooltip
()
),
200
),
200
createEmoji
:
(
emoji
)
->
createEmoji
:
(
emoji
)
->
emojiCssClass
=
@
resolveNameToCssClass
(
emoji
)
emojiCssClass
=
@
resolveNameToCssClass
(
emoji
)
...
@@ -194,13 +190,13 @@ class @AwardsHandler
...
@@ -194,13 +190,13 @@ class @AwardsHandler
$currentBlock
.
removeClass
'hidden'
$currentBlock
.
removeClass
'hidden'
resolveNameToCssClass
:
(
emoji
)
->
resolveNameToCssClass
:
(
emoji
)
->
emoji
I
con
=
$
(
".emoji-menu-content [data-emoji='
#{
emoji
}
']"
)
emoji
_i
con
=
$
(
".emoji-menu-content [data-emoji='
#{
emoji
}
']"
)
if
emoji
I
con
.
length
>
0
if
emoji
_i
con
.
length
>
0
unicodeName
=
emoji
Icon
.
data
(
'unicode-name'
)
unicodeName
=
emoji
_icon
.
data
(
"unicode-name"
)
else
else
# Find by alias
# Find by alias
unicodeName
=
$
(
".emoji-menu-content [data-aliases*=':
#{
emoji
}
:']"
).
data
(
'unicode-name'
)
unicodeName
=
$
(
".emoji-menu-content [data-aliases*=':
#{
emoji
}
:']"
).
data
(
"unicode-name"
)
"emoji-
#{
unicodeName
}
"
"emoji-
#{
unicodeName
}
"
...
@@ -210,49 +206,52 @@ class @AwardsHandler
...
@@ -210,49 +206,52 @@ class @AwardsHandler
callback
.
call
()
callback
.
call
()
findEmojiIcon
:
(
emoji
)
->
findEmojiIcon
:
(
emoji
)
->
@
currentVoteBlock
.
find
(
"
.js-emoji-btn [data-emoji='
#{
emoji
}
']"
)
$
(
".js-awards-block-current.awards >
.js-emoji-btn [data-emoji='
#{
emoji
}
']"
)
scrollToAwards
:
->
scrollToAwards
:
->
$
(
'body, html'
).
animate
({
$
(
'body, html'
).
animate
({
scrollTop
:
$
(
'.awards'
).
offset
().
top
-
80
scrollTop
:
$
(
'.awards'
).
offset
().
top
-
80
},
200
)
},
200
)
normalizeEmojiName
:
(
emoji
)
->
@
aliases
[
emoji
]
||
emoji
addEmojiToFrequentlyUsedList
:
(
emoji
)
->
addEmojiToFrequentlyUsedList
:
(
emoji
)
->
frequently
UsedE
mojis
=
@
getFrequentlyUsedEmojis
()
frequently
_used_e
mojis
=
@
getFrequentlyUsedEmojis
()
frequently
UsedE
mojis
.
push
(
emoji
)
frequently
_used_e
mojis
.
push
(
emoji
)
$
.
cookie
(
'frequently_used_emojis'
,
frequently
UsedEmojis
.
join
(
','
),
{
expires
:
365
})
$
.
cookie
(
'frequently_used_emojis'
,
frequently
_used_emojis
.
join
(
","
),
{
expires
:
365
})
getFrequentlyUsedEmojis
:
->
getFrequentlyUsedEmojis
:
->
frequently
UsedEmojis
=
(
$
.
cookie
(
'frequently_used_emojis'
)
||
''
).
split
(
','
)
frequently
_used_emojis
=
(
$
.
cookie
(
'frequently_used_emojis'
)
||
""
).
split
(
","
)
_
.
compact
(
_
.
uniq
(
frequently
UsedE
mojis
))
_
.
compact
(
_
.
uniq
(
frequently
_used_e
mojis
))
renderFrequentlyUsedBlock
:
->
renderFrequentlyUsedBlock
:
->
if
$
.
cookie
(
'frequently_used_emojis'
)
if
$
.
cookie
(
'frequently_used_emojis'
)
frequently
UsedE
mojis
=
@
getFrequentlyUsedEmojis
()
frequently
_used_e
mojis
=
@
getFrequentlyUsedEmojis
()
ul
=
$
(
"<ul class='clearfix emoji-menu-list'>"
)
ul
=
$
(
"<ul class='clearfix emoji-menu-list'>"
)
for
emoji
in
frequently_used_emojis
for
emoji
in
frequently_used_emojis
$
(
".emoji-menu-content [data-emoji='
#{
emoji
}
']"
).
closest
(
"li"
).
clone
().
appendTo
(
ul
)
$
(
".emoji-menu-content [data-emoji='
#{
emoji
}
']"
).
closest
(
"li"
).
clone
().
appendTo
(
ul
)
$
(
'input.emoji-search'
).
after
(
ul
).
after
(
$
(
'<h5>'
).
text
(
'Frequently used'
))
$
(
"input.emoji-search"
).
after
(
ul
).
after
(
$
(
"<h5>"
).
text
(
"Frequently used"
))
setupSearch
:
->
setupSearch
:
->
$
(
'input.emoji-search'
).
keyup
(
ev
)
=>
$
(
"input.emoji-search"
).
on
'keyup'
,
(
ev
)
=>
term
=
$
(
ev
.
target
).
val
()
term
=
$
(
ev
.
target
).
val
()
# Clean previous search results
# Clean previous search results
$
(
'ul.emoji-menu-search, h5.emoji-search'
).
remove
()
$
(
"ul.emoji-menu-search, h5.emoji-search"
).
remove
()
if
term
if
term
# Generate a search result block
# Generate a search result block
h5
=
$
(
'<h5>'
).
text
(
'Search results'
).
addClass
(
'emoji-search'
)
h5
=
$
(
"<h5>"
).
text
(
"Search results"
).
addClass
(
"emoji-search"
)
found
E
mojis
=
@
searchEmojis
(
term
).
show
()
found
_e
mojis
=
@
searchEmojis
(
term
).
show
()
ul
=
$
(
'<ul>'
).
addClass
(
'emoji-menu-list emoji-menu-search'
).
append
(
foundE
mojis
)
ul
=
$
(
"<ul>"
).
addClass
(
"emoji-menu-list emoji-menu-search"
).
append
(
found_e
mojis
)
$
(
'.emoji-menu-content ul, .emoji-menu-content h5'
).
hide
()
$
(
".emoji-menu-content ul, .emoji-menu-content h5"
).
hide
()
$
(
'.emoji-menu-content'
).
append
(
h5
).
append
(
ul
)
$
(
".emoji-menu-content"
).
append
(
h5
).
append
(
ul
)
else
else
$
(
'.emoji-menu-content'
).
children
().
show
()
$
(
".emoji-menu-content"
).
children
().
show
()
searchEmojis
:
(
term
)
->
searchEmojis
:
(
term
)
->
$
(
".emoji-menu-content [data-emoji*='
#{
term
}
']"
).
closest
(
"li"
).
clone
()
$
(
".emoji-menu-content [data-emoji*='
#{
term
}
']"
).
closest
(
"li"
).
clone
()
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