Skip to content

Commit

Permalink
Merge pull request #202 from oponder/add_youtube_embed
Browse files Browse the repository at this point in the history
Issue #196
  • Loading branch information
fusion94 committed Mar 12, 2013
2 parents 804b508 + b80f097 commit 51837e1
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions app/assets/javascripts/backbone/plugins/youtube_embed.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ class Kandan.Plugins.YouTubeEmbed

template: _.template '''
<div class="youtube-preview">
<a target="_blank" class="youtube-preview-link" href="<%= videoUrl %>">
<img class="youtube-preview-image" src="<%= thumbUrl %>" />
</a>
<iframe width="560" height="315"
src="http://www.youtube.com/embed/<%= videoId %>"
frameborder="0" allowfullscreen>
</iframe>
<div class="name"><%= subtitle %></div>
</div>
'''
Expand All @@ -24,18 +25,15 @@ class Kandan.Plugins.YouTubeEmbed
else
# Spaces indicate a subtitle
comment = $.trim(message.content.substr(message.content.indexOf(" ") + 1));
videoUrl = message.content.split(" ")[0]

videoId = message.content.match(@options.idRegex)[1]
thumbUrl = "http://img.youtube.com/vi/#{ videoId }/0.jpg"

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

message.content = @options.template({
videoUrl: videoUrl,
thumbUrl: thumbUrl,
videoId: videoId,
subtitle: subtitle
})
return Kandan.Helpers.Activities.buildFromMessageTemplate(message)

0 comments on commit 51837e1

Please sign in to comment.