Skip to content

Commit

Permalink
Enhancements to the youtube embedder
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrove committed Apr 12, 2012
1 parent 6b0da89 commit cb14e84
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions app/assets/javascripts/backbone/plugins/youtube_embed.js.coffee
Expand Up @@ -8,15 +8,32 @@ class Kandan.Plugins.YouTubeEmbed
<a target="_blank" class="youtube-preview-link" href="<%= video_url %>">
<img class="youtube-preview-image" src="<%= thumb_url %>" />
</a>
<div class="name"><%= subtitle %></div>
</div>
'''

@init: ()->
Kandan.Modifiers.register @youtube_regex, (message, state)=>
Kandan.Modifiers.register @youtube_regex, (message, state) =>
comment = null

# No spaces in message content indicates just a link
if message.content.indexOf(" ") == -1
video_url = message.content
else
# Spaces indicate a subtitle
comment = $.trim(message.content.substr(message.content.indexOf(" ") + 1));
video_url = message.content.split(" ")[0]

video_id = message.content.match(@youtube_id_regex)[1]
thumb_url = "http://img.youtube.com/vi/#{ video_id }/0.jpg"

subtitle = null
subtitle = "Youtube: #{comment}" if comment? and comment.length > 0
subtitle ||= video_url

message.content = @youtube_embed_template({
video_url: message.content,
thumb_url: thumb_url
video_url: video_url,
thumb_url: thumb_url,
subtitle: subtitle
})
return Kandan.Helpers.Activities.build_from_message_template(message)

0 comments on commit cb14e84

Please sign in to comment.