Skip to content

Commit

Permalink
Updates the image embedding plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrove committed Apr 12, 2012
1 parent 3c61952 commit 32f05ec
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/assets/javascripts/backbone/plugins/image_embed.js.coffee
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
class Kandan.Plugins.ImageEmbed
@image_regex: /^http.*\.(jpg|jpeg|gif|png)/i

@image_regex: /http.*\.(jpg|jpeg|gif|png)/i

@image_template: _.template '''
<div class="image-preview">
<a target="_blank" href="<%= image_url %>">
<img class="image-embed" src="<%= image_url %>" height="200" width="200" />
</a>
<div class="name"><%= name %></div>
<div class="name"><%= subtitle %></div>
</div>
'''

@init: ()->
Kandan.Modifiers.register @image_regex, (message, state)=>
file_name = message.content.split("/").pop()
Kandan.Modifiers.register @image_regex, (message, state) =>
url = message.content.match(@image_regex)[0]
fileName = url.split("/").pop()
comment = $.trim(message.content.split(url).join(""))
subtitle = null
subtitle = comment if comment.length > 0
subtitle ||= fileName

message.content = @image_template({
image_url: message.content,
name: file_name
subtitle: subtitle
})
return Kandan.Helpers.Activities.build_from_message_template(message)

return Kandan.Helpers.Activities.build_from_message_template(message)

0 comments on commit 32f05ec

Please sign in to comment.