-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Bushido/Kandan
- Loading branch information
Showing
7 changed files
with
48 additions
and
21 deletions.
There are no files selected for viewing
22 changes: 14 additions & 8 deletions
22
app/assets/javascripts/backbone/plugins/image_embed.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
image_url: url, | ||
subtitle: subtitle | ||
}) | ||
return Kandan.Helpers.Activities.build_from_message_template(message) | ||
|
||
return Kandan.Helpers.Activities.build_from_message_template(message) |
7 changes: 4 additions & 3 deletions
7
app/assets/javascripts/backbone/plugins/me_announce.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
class Kandan.Plugins.MeAnnounce | ||
|
||
@regex: /^\/me / | ||
@regex: /^/me / | ||
|
||
@init: ()-> | ||
Kandan.Modifiers.register @regex, (message, state)=> | ||
Kandan.Modifiers.register @regex, (message, state) => | ||
actor = message.user.first_name || message.user.email | ||
message.content = message.content.replace @regex, "#{message.user.first_name} " | ||
return Kandan.Helpers.Activities.build_from_base_template(message) | ||
|
||
# Kandan.Plugins.register "Kandan.Plugins.MeAnnounce" | ||
# Kandan.Plugins.register "Kandan.Plugins.MeAnnounce" |
27 changes: 22 additions & 5 deletions
27
app/assets/javascripts/backbone/plugins/youtube_embed.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,39 @@ | ||
class Kandan.Plugins.YouTubeEmbed | ||
|
||
@youtube_regex: /^http(s)?:\/\/www.youtube.com\/watch/i | ||
@youtube_regex: /^http(s)?.+www.youtube.com.+watch/i | ||
@youtube_id_regex: /\Wv=([\w|\-]*)/ | ||
|
||
@youtube_embed_template: _.template ''' | ||
<div class="youtube-preview"> | ||
<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) | ||
return Kandan.Helpers.Activities.build_from_message_template(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters