-# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. = javascript_include_tag 'FABridge', 'swfobject', 'web_socket' :javascript WebSocket.__swfLocation = "#{javascript_path 'WebSocketMain.swf'}"; $(document).ready(function(){ function debug(str){ $("#debug").append("
" + str); }; ws = new WebSocket("ws://#{request.host}:#{APP_CONFIG[:socket_port]}/#{CGI::escape(current_user.id.to_s)}"); //Attach onmessage to websocket ws.onmessage = function(evt) { var obj = jQuery.parseJSON(evt.data); //console.log(obj); debug("got a " + obj['class'] + " for aspects " + obj['aspect_ids']); if (obj['class']=="retractions"){ processRetraction(obj['post_id']); }else if (obj['class']=="comments"){ processComment(obj['post_id'], obj['html']) }else if (obj['class']=='photos' && onPageForClass('albums')){ processPhotoInAlbum(obj['photo_hash']) }else{ processPost(obj['class'], obj['html'], obj['aspect_ids']) } }; ws.onclose = function() { debug("socket closed"); }; ws.onopen = function() { ws.send(location.pathname); debug("connected..."); }; }); function processRetraction(post_id){ $("*[data-guid='"+post_id+"']").fadeOut(400, function(){$(this).remove()}); if($("#stream")[0].childElementCount == 0){ $("#no_posts").fadeIn(200); } } function processComment(post_id, html){ post = $("*[data-guid='"+post_id+"']'"); $(' .comment_set li:last', post ).before( $(html).fadeIn("fast", function(){}) ); toggler = $('.show_post_comments', post) if(toggler.length > 0){ toggler.html( toggler.html().replace(/\d+/,$('.comment_set', post)[0].childElementCount -1)); if( !$(".comments", post).is(':visible') ){ toggler.click(); } } } function processPost(className, html, aspectIds){ if(onPageForAspects(aspectIds)){ var addPostToStream = function (html){ $("#stream").prepend( $(html).fadeIn("fast", function(){ $("#stream label:first").inFieldLabels(); }) ) }; if( $("#no_posts").is(":visible") ){ $("#no_posts").fadeOut(400, addPostToStream(html)).hide(); } else { addPostToStream(html); } } } function processPhotoInAlbum(photoHash){ if (location.href.indexOf(photoHash['album_id']) == -1){ return ; } html = "