Skip to content
Extraits de code Groupes Projets
Valider f2af56f4 rédigé par archi's avatar archi
Parcourir les fichiers

Youtubelink support :)

Tested with Firefox, Chrome and Mobile Safari (IE8 is broken anyway)
parent f676e284
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -19,19 +19,20 @@ module StatusMessagesHelper
# next line is important due to XSS! (h is rail's make_html_safe-function)
message = h(message).html_safe
message.gsub!(/( |^)(www\.[^ ]+\.[^ ])/, '\1http://\2')
message.gsub!(/( |^)http:\/\/www\.youtube\.com\/watch.*v=([A-Za-z0-9_]+)[^ ]*/, '\1youtube.com::\2')
message.gsub!(/( |^)http:\/\/www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_]+)/, '\1youtube.com::\2')
message.gsub!(/(http|ftp):\/\/([^ ]+)/, '<a target="_blank" href="\1://\2">\2</a>')
youtube = message.match(/youtube\.com::([A-Za-z0-9_]+)/)
youtube.to_a.each do |videoid|
if videoid.match('::').nil?
message.gsub!('youtube.com::'+videoid, '<a onclick="openVideo(\'youtube.com\', \'' + videoid + '\', this)" href="#video">Youtube: ' + youtube_title(videoid) + '</a>')
end
while youtube = message.match(/youtube\.com::([A-Za-z0-9_]+)/)
videoid = youtube[1]
message.gsub!('youtube.com::'+videoid, '<a onclick="openVideo(\'youtube.com\', \'' + videoid + '\', this)" href="#video">Youtube: ' + youtube_title(videoid) + '</a>')
end
return message
end
def youtube_title(id)
#TODO Check if id is cached, and return cached value
unless @@youtube_title_cache[id] == 'no-title'
return @@youtube_title_cache[id]
end
ret = 'Unknown Video Title' #TODO add translation
http = Net::HTTP.new('gdata.youtube.com', 80)
......@@ -42,7 +43,7 @@ module StatusMessagesHelper
ret = title.to_s[7..-9]
end
#TODO Cache the value of ret for id
@@youtube_title_cache[id] = ret;
return ret
end
......
......@@ -72,6 +72,8 @@ $.fn.clearForm = function() {
});
};
var video_active_container = null;
function openVideo(type, videoid, link) {
var container = document.createElement('div');
if(type == 'youtube.com') {
......@@ -79,6 +81,10 @@ function openVideo(type, videoid, link) {
} else {
container.innerHTML = 'Invalid videotype <i>'+type+'</i> (ID: '+videoid+')';
}
if(video_active_container != null) {
video_active_container.parentNode.removeChild(video_active_container);
}
video_active_container = container;
$(container).hide();
link.parentNode.insertBefore(container, this.nextSibling);
$(container).slideDown('fast', function() { });
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter