Skip to content

Commit

Permalink
Merge pull request #343 from scouttyg/more-embed-fixes
Browse files Browse the repository at this point in the history
Fixing link embedding sometimes messing up, fixed vimeo embed not matchi...
  • Loading branch information
fusion94 committed Apr 19, 2014
2 parents 507b006 + d36ba35 commit 49f4125
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/assets/javascripts/backbone/plugins/image_embed.js.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Kandan.Plugins.ImageEmbed
@options:
regex: /http.*\.(jpg|jpeg|gif|png)/i
regex: /http[\S]*\.(jpg|jpeg|gif|png)/i

template: _.template '''
<div class="image-preview">
Expand All @@ -15,8 +15,10 @@ class Kandan.Plugins.ImageEmbed
@init: ()->
Kandan.Modifiers.register @options.regex, (message, activity) =>
url = message.match(@options.regex)[0]
startIndex = message.match(@options.regex).index
endIndex = startIndex + url.length
fileName = url.split("/").pop()
comment = $.trim(message.split(url).join(""))
comment = $.trim(message.replace(message.substring(startIndex, endIndex),""))
subtitle = null
subtitle = comment if comment.length > 0
subtitle ||= fileName
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/backbone/plugins/link_embed.js.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Kandan.Plugins.LinkEmbed

@options:
regex: /(^| )(http?\S*)/g
regex: /(^| )(http?[^\s<>]*)/g

@init: ()->
Kandan.Modifiers.register @options.regex, (message, activity)=>
message = message.replace(@options.regex, '<a target="_blank" href="$2">$2</a>')
message = message.replace(@options.regex, '$1<a target="_blank" href="$2">$2</a>')
return message
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Kandan.Plugins.VimeoEmbed
videoId = message.match(@options.regex)[2]

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

message = @options.template({
Expand Down

0 comments on commit 49f4125

Please sign in to comment.