Skip to content
Browse files

Enhancements to the youtube embedder

  • Loading branch information...
1 parent 6b0da89 commit cb14e84c828c1b1339c48fb03ba54d0a66481080 @sgrove sgrove committed Apr 11, 2012
Showing with 20 additions and 3 deletions.
  1. +20 −3 app/assets/javascripts/backbone/plugins/youtube_embed.js.coffee
View
23 app/assets/javascripts/backbone/plugins/youtube_embed.js.coffee
@@ -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.
Something went wrong with that request. Please try again.