Skip to content

Commit 7848019

Browse files
committed
Fixes embed plugins and history formatting
Signed-off-by: Akash Manohar J <[email protected]>
1 parent 1c64ec5 commit 7848019

File tree

4 files changed

+59
-28
lines changed

4 files changed

+59
-28
lines changed

app/assets/javascripts/backbone/kandan.js.coffee

+13-6
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ window.Kandan =
2121
channels.fetch({success: ()=>
2222

2323
chat_area = new Kandan.Views.ChatArea({channels: channels})
24-
$('.container').html(chat_area.render().el)
2524

26-
chatbox = new Kandan.Views.Chatbox()
27-
$('.container').append(chatbox.render().el)
28-
$('#channels').tabs()
2925

3026
# TODO move broadcast subscription to a helper
3127
# TODO change this to use the broadcaster from the settings
@@ -41,14 +37,25 @@ window.Kandan =
4137

4238
active_users = new Kandan.Collections.ActiveUsers()
4339
active_users.fetch({
44-
success: ()->
45-
# TODO fix because the current user doesnt get the first event
40+
success: ()=>
41+
# NOTE fix because the current user doesn't get the first event
4642
active_users.add([$(document).data('current_user')])
4743
$(document).data("active_users", active_users.toJSON())
44+
45+
# NOTE init plugins so that modifiers are registered
4846
Kandan.Plugins.init_all()
47+
48+
$(".container").html(chat_area.render().el)
49+
chatbox = new Kandan.Views.Chatbox()
50+
$(".container").append(chatbox.render().el)
51+
$('#channels').tabs()
52+
53+
# NOTE render widgets only after the chat area is rendered
4954
Kandan.Widgets.init_all()
5055
})
5156

57+
58+
5259
})
5360

5461

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
class Kandan.Plugins.ImageEmbed
2-
@regex: /^http.*\.(jpg|jpeg|gif|png)/i
3-
@image_template: _.template('<a target="_blank" href="<%= image_url %>"><img class="image-embed" src="<%= image_url %>" height="200" width="200" /></a>')
2+
3+
44

55
@init: ()->
6-
Kandan.Modifiers.register @regex, (message, state)=>
7-
message.content = @image_template({ image_url: message.content })
8-
console.log message.content
9-
return Kandan.Helpers.Activities.build_from_message_template(message)
106

11-
Kandan.Plugins.register "Kandan.Plugins.ImageEmbed"
7+
8+
# Kandan.Plugins.register "Kandan.Plugins.ImageEmbed"
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
class Kandan.Plugins.LinkEmbed
22

3-
@regex: /http:\S*/g
4-
@link_template: _.template('<a target="_blank" href="<%- url %>"><%- url %></a>')
3+
@link_regex: /(http:\S*)/g
54

65
@init: ()->
7-
Kandan.Modifiers.register @regex, (message, state)=>
8-
message.content = message.content
9-
.replace(@regex, @link_template({ url: "$1" }))
10-
return Kandan.Helpers.Activities.build_from_message_template(message)
6+
# Kandan.Modifiers.register @regex, (message, state)=>
7+
# message.content = message.content
8+
# .replace(@regex, '<a target="_blank" href="$1">$1</a>')
9+
# return Kandan.Helpers.Activities.build_from_message_template(message)
1110

12-
Kandan.Plugins.register "Kandan.Plugins.LinkEmbed"
11+
# Kandan.Plugins.register "Kandan.Plugins.LinkEmbed"
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,46 @@
1-
class Kandan.Plugins.YoutubeEmbed
1+
class Kandan.Plugins.Embeds
22

3-
@regex: /^http(s)?:\/\/www.youtube.com\/watch/i
4-
@youtube_id_pattern: /\Wv=([\w|\-]*)/
3+
@youtube_regex: /^http(s)?:\/\/www.youtube.com\/watch/i
4+
@link_regex: /(http?:\S*)/g
5+
@image_regex: /^http.*\.(jpg|jpeg|gif|png)/i
6+
7+
@youtube_id_regex: /\Wv=([\w|\-]*)/
8+
9+
10+
@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>')
11+
12+
@image_template: _.template('<a target="_blank" href="<%= image_url %>"><img class="image-embed" src="<%= image_url %>" height="200" width="200" /></a>')
513

6-
@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>')
714

815
@init: ()->
9-
Kandan.Modifiers.register @regex, (message, state)=>
10-
video_id = message.content.match(@youtube_id_pattern)[1]
16+
@register_youtube_modifier()
17+
@register_image_modifier()
18+
@register_link_modifier()
19+
20+
21+
22+
@register_image_modifier: ()->
23+
Kandan.Modifiers.register @image_regex, (message, state)=>
24+
message.content = @image_template({ image_url: message.content })
25+
console.log message.content
26+
return Kandan.Helpers.Activities.build_from_message_template(message)
27+
28+
29+
@register_youtube_modifier: ()->
30+
Kandan.Modifiers.register @youtube_regex, (message, state)=>
31+
video_id = message.content.match(@youtube_id_regex)[1]
1132
thumb_url = "http://img.youtube.com/vi/#{ video_id }/0.jpg"
1233
message.content = @youtube_embed_template({
1334
video_url: message.content,
14-
image_url: thumb_url
35+
thumb_url: thumb_url
1536
})
1637
return Kandan.Helpers.Activities.build_from_message_template(message)
1738

18-
Kandan.Plugins.register "Kandan.Plugins.YoutubeEmbed"
39+
40+
@register_link_modifier: ()->
41+
Kandan.Modifiers.register @link_regex, (message, state)=>
42+
message.content = message.content
43+
.replace(@link_regex, '<a target="_blank" href="$1">$1</a>')
44+
return Kandan.Helpers.Activities.build_from_message_template(message)
45+
46+
Kandan.Plugins.register "Kandan.Plugins.Embeds"

0 commit comments

Comments
 (0)