-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing link embedding sometimes messing up, fixed vimeo embed not matchi... #343
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"> | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this might be a little controversial, but for cases like I think this makes more sense than having each image in a message imageified, since anything after what you are trying to embed is usually the subtitle rather than multiple embeds. |
||
endIndex = startIndex + url.length | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ends up being an image with subtitle |
||
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 | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sometimes the link embed would pull in the tag after the link, which we don't want. A url should never have a < or > in it, so let's make it a negative class group that wont match spaces or carots. |
||
|
||
@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>') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you said "Hey lets check out http://www.facebook.com" it would end up looking like Hey lets check outhttp://www.facebook.com (note the missing space) |
||
return message |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Youtube embed doesn't do this, so lets not do this for Vimeo, or at least have it the same across both. |
||
subtitle ||= videoUrl | ||
|
||
message = @options.template({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use a dot, then things like
http://static.azgor.com/wp-content/uploads/octobiwan.jpg http://static.azgor.com/wp-content/uploads/octobiwan.jpg
end up matching, even though they are two separate links. We should work off of non-space characters, vs all characters.