Skip to content

Commit

Permalink
Initial implementation of emoticons
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrove committed Apr 12, 2012
1 parent 13520aa commit 6915765
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Binary file added app/assets/images/emoticons/y_u_no.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/javascripts/backbone/kandan.js.coffee.erb
Expand Up @@ -34,6 +34,7 @@ window.Kandan =
,"Pastie"
,"Attachments"
,"MeAnnounce"
,"Emoticons"
]

for plugin in plugins
Expand Down
24 changes: 24 additions & 0 deletions app/assets/javascripts/backbone/plugins/emoticons.js.coffee
@@ -0,0 +1,24 @@
class Kandan.Plugins.Emoticons

@options:
regex: /\([a-zA-Z])/g
template: _.template '''
<img class="emoticon-embed" src="/assets/<%= emoticon %>" height="20" width="20" />
'''


@emoticons: {
"(yuno)": "y_u_no.jog"
}

@init: ()->
Kandan.Modifiers.register @regex, (message, state)=>
matches = message.content.match(@regex)
for match in _.unique(matches)
emoticon = @emoticons[match]
search = new Regex(match, 'g')
replacement = @options.template({ emoticon: emoticon })
message.content.replace(search, replacement) if emoticon
return Kandan.Helpers.Activities.build_from_base_template(message)

# Kandan.Plugins.register "Kandan.Plugins.MeAnnounce"

0 comments on commit 6915765

Please sign in to comment.