Skip to content

Commit 61dc435

Browse files
committed
Added real emoticons to emoticons plugin.
- Added underscore.string to dependecies
1 parent a0b07b5 commit 61dc435

File tree

7 files changed

+647
-29
lines changed

7 files changed

+647
-29
lines changed

app/assets/images/emoticons/happy.png

1.28 KB
Loading

app/assets/images/emoticons/sad.png

1.28 KB
Loading
1.17 KB
Loading

app/assets/javascripts/application.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//= require jquery_ujs
1616
//= require lib/jquery.filedrop
1717
//= require lib/underscore
18+
//= require lib/underscore.string
1819
//= require lib/backbone
1920
//= require backbone/kandan
2021
//= require_tree .
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,56 @@
11
class Kandan.Plugins.Emoticons
22

33
@options:
4-
regex: /\([a-zA-Z]+\)/g
4+
regex: /\([a-zA-Z]+\)|(^|\s)+([:|=][\)|\(|P|p])($|\s)/g
55
template: _.template '''
6-
<img class="emoticon-embed" src="/assets/emoticons/<%= emoticon %>" title="<%= title %>" height="40" width="40" />
6+
<img class="emoticon-embed <%= css %>" src="/assets/emoticons/<%= src %>" title="<%= title %>" />
77
'''
88

99

1010
@emoticons: {
11-
"(alone)" : "alone.jpg",
12-
"(awwyea)" : "awwyea.jpg",
13-
"(badass)" : "badass.png",
14-
"(bitchplease)" : "bitchplease.jpg",
15-
"(cereal)" : "cereal.jpg",
16-
"(challenge)" : "challenge.jpg",
17-
"(fuckyeah)" : "fuckyeah.jpg",
18-
"(gtfo)" : "seriously.jpg",
19-
"(ilied)" : "ilied.jpg",
20-
"(megusta)" : "megusta.jpg",
21-
"(notbad)" : "notbad.jpg",
22-
"(okay)" : "okay.jpg",
23-
"(omgface)" : "omgface.jpg",
24-
"(pokerface)" : "pokerface.jpg",
25-
"(problem)" : "trollface.jpg",
26-
"(rageguy)" : "rageguy.jpg",
27-
"(seriously)" : "seriously.jpg",
28-
"(sweetjesus)" : "sweetjesus.jpg",
29-
"(trollface)" : "trollface.jpg",
30-
"(truestory)" : "truestory.png",
31-
"(youdontsay)" : "youdontsay.png",
32-
"(yuno)" : "yuno.jpg"
11+
"(alone)" : { src : "alone.jpg", css : "big", title : "alone"},
12+
"(awwyea)" : { src : "awwyea.jpg", css : "big", title : "awwyea"},
13+
"(badass)" : { src : "badass.jpg", css : "big", title : "badass"},
14+
"(bitchplease)" : { src : "bitchplease.jpg", css : "big", title : "bitchplease"},
15+
"(cereal)" : { src : "cereal.jpg", css : "big", title : "cereal"},
16+
"(challenge)" : { src : "challenge.jpg", css : "big", title : "challenge"},
17+
"(fuckyeah)" : { src : "fuckyeah.jpg", css : "big", title : "fuckyeah"},
18+
"(gtfo)" : { src : "gtfo.jpg", css : "big", title : "gtfo"},
19+
"(ilied)" : { src : "ilied.jpg", css : "big", title : "ilied"},
20+
"(megusta)" : { src : "megusta.jpg", css : "big", title : "megusta"},
21+
"(notbad)" : { src : "notbad.jpg", css : "big", title : "notbad"},
22+
"(okay)" : { src : "okay.jpg", css : "big", title : "okay"},
23+
"(omgface)" : { src : "omgface.jpg", css : "big", title : "omgface"},
24+
"(pokerface)" : { src : "pokerface.jpg", css : "big", title : "pokerface"},
25+
"(problem)" : { src : "problem.jpg", css : "big", title : "problem"},
26+
"(rageguy)" : { src : "rageguy.jpg", css : "big", title : "rageguy"},
27+
"(seriously)" : { src : "seriously.jpg", css : "big", title : "seriously"},
28+
"(sweetjesus)" : { src : "sweetjesus.jpg", css : "big", title : "sweetjesus"},
29+
"(trollface)" : { src : "trollface.jpg", css : "big", title : "trollface"},
30+
"(truestory)" : { src : "truestory.jpg", css : "big", title : "truestory"},
31+
"(youdontsay)" : { src : "youdontsay.jpg", css : "big", title : "youdontsay"},
32+
"(yuno)" : { src : "yuno.jpg", css : "big", title : "yuno"},
33+
":(" : { src : "sad.png", css : "small", title : "sad"},
34+
"=(" : { src : "sad.png", css : "small", title : "sad"},
35+
":)" : { src : "happy.png", css : "small", title : "happy"},
36+
"=)" : { src : "sad.png", css : "small", title : "happy"},
37+
":p" : { src : "tongue.png", css : "small", title : ":p"}
38+
"=p" : { src : "tongue.png", css : "small", title : "=p"}
3339
}
3440

3541
@init: ()->
3642
Kandan.Modifiers.register @options.regex, (message, state) =>
3743
matches = message.content.match(@options.regex)
3844
for match in _.unique(matches)
45+
match = match.trim();
3946
emoticon = @emoticons[match]
40-
title = match.replace(/\(|\)/g, "")
41-
needle = match.replace('(', '\\(').replace(')', '\\)')
42-
search = new RegExp(needle, 'g')
43-
replacement = @options.template({ emoticon: emoticon, title: title})
44-
message.content = message.content.replace(search, replacement) if emoticon
47+
48+
if emoticon
49+
needle = match.replace('(', '\\(').replace(')', '\\)')
50+
search = new RegExp(needle, 'g')
51+
replacement = @options.template(emoticon)
52+
message.content = message.content.replace(search, replacement)
53+
4554
return Kandan.Helpers.Activities.buildFromMessageTemplate(message)
4655

4756
# Kandan.Plugins.register "Kandan.Plugins.Emoticons"

0 commit comments

Comments
 (0)