Take signed in check out of websocket js
This commit is contained in:
parent
01dac4d173
commit
0092069372
1 changed files with 91 additions and 93 deletions
|
|
@ -1,103 +1,101 @@
|
||||||
- if user_signed_in?
|
= javascript_include_tag 'FABridge', 'swfobject', 'web_socket'
|
||||||
= javascript_include_tag 'FABridge', 'swfobject', 'web_socket'
|
:javascript
|
||||||
:javascript
|
WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf";
|
||||||
WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf";
|
$(document).ready(function(){
|
||||||
:javascript
|
function debug(str){ $("#debug").append("<p>" + str); };
|
||||||
$(document).ready(function(){
|
|
||||||
function debug(str){ $("#debug").append("<p>" + str); };
|
|
||||||
|
|
||||||
ws = new WebSocket("ws://#{request.host}:8080/#{CGI::escape(current_user.id.to_s)}");
|
ws = new WebSocket("ws://#{request.host}:8080/#{CGI::escape(current_user.id.to_s)}");
|
||||||
|
|
||||||
//Attach onmessage to websocket
|
//Attach onmessage to websocket
|
||||||
ws.onmessage = function(evt) {
|
ws.onmessage = function(evt) {
|
||||||
var obj = jQuery.parseJSON(evt.data);
|
var obj = jQuery.parseJSON(evt.data);
|
||||||
debug("got a " + obj['class'] + " for group " + obj['group_id']);
|
debug("got a " + obj['class'] + " for group " + obj['group_id']);
|
||||||
|
|
||||||
if (obj['class']=="retractions"){
|
if (obj['class']=="retractions"){
|
||||||
processRetraction(obj['post_id']);
|
processRetraction(obj['post_id']);
|
||||||
|
|
||||||
}else if (obj['class']=="comments"){
|
}else if (obj['class']=="comments"){
|
||||||
processComment(obj['post_id'], obj['html'])
|
processComment(obj['post_id'], obj['html'])
|
||||||
|
|
||||||
}else if (obj['class']=='photos' && onPageForClass('albums')){
|
}else if (obj['class']=='photos' && onPageForClass('albums')){
|
||||||
processPhotoInAlbum(obj['photo_hash'])
|
processPhotoInAlbum(obj['photo_hash'])
|
||||||
}else if (obj['class']=='status_messages'){
|
}else if (obj['class']=='status_messages'){
|
||||||
processStatusMessage(obj['class'], obj['html'], obj['status_message_hash'], obj['group_id'], obj['mine?'])
|
processStatusMessage(obj['class'], obj['html'], obj['status_message_hash'], obj['group_id'], obj['mine?'])
|
||||||
}else{
|
}else{
|
||||||
processPost(obj['class'], obj['html'], obj['group_id'], obj['mine?'])
|
processPost(obj['class'], obj['html'], obj['group_id'], obj['mine?'])
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
ws.onclose = function() { debug("socket closed"); };
|
|
||||||
ws.onopen = function() {
|
|
||||||
ws.send(location.pathname);
|
|
||||||
debug("connected...");
|
|
||||||
};
|
|
||||||
|
|
||||||
function processRetraction(post_id){
|
|
||||||
$('#' + post_id ).fadeOut(500, function(){
|
|
||||||
$(this).remove;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function processComment(post_id, html){
|
|
||||||
post = $('#' + post_id)[0]
|
};
|
||||||
$(' .comment_set li:last', post ).before(
|
ws.onclose = function() { debug("socket closed"); };
|
||||||
$(html).fadeIn("fast", function(){})
|
ws.onopen = function() {
|
||||||
|
ws.send(location.pathname);
|
||||||
|
debug("connected...");
|
||||||
|
};
|
||||||
|
|
||||||
|
function processRetraction(post_id){
|
||||||
|
$('#' + post_id ).fadeOut(500, function(){
|
||||||
|
$(this).remove;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function processComment(post_id, html){
|
||||||
|
post = $('#' + post_id)[0]
|
||||||
|
$(' .comment_set li:last', post ).before(
|
||||||
|
$(html).fadeIn("fast", function(){})
|
||||||
|
);
|
||||||
|
toggler = $('.show_post_comments', post)
|
||||||
|
toggler.html(
|
||||||
|
toggler.html().replace(/\d/,$('.comment_set', post)[0].childElementCount -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
function processPost(className, html, groupId, mineBool){
|
||||||
|
if(mineBool || onPageForClass(className) || onPageForGroup(groupId)){
|
||||||
|
$("#stream").prepend(
|
||||||
|
$(html).fadeIn("fast", function(){
|
||||||
|
$("#stream label:first").inFieldLabels();
|
||||||
|
})
|
||||||
);
|
);
|
||||||
toggler = $('.show_post_comments', post)
|
|
||||||
toggler.html(
|
|
||||||
toggler.html().replace(/\d/,$('.comment_set', post)[0].childElementCount -1));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function processPost(className, html, groupId, mineBool){
|
function processStatusMessage(className, html, messageHash, groupId, mineBool){
|
||||||
if(mineBool || onPageForClass(className) || onPageForGroup(groupId)){
|
processPost(className, html, groupId, mineBool);
|
||||||
$("#stream").prepend(
|
console.log(messageHash)
|
||||||
$(html).fadeIn("fast", function(){
|
if(messageHash['mine?']){
|
||||||
$("#stream label:first").inFieldLabels();
|
updateMyLatestStatus(messageHash);
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function processStatusMessage(className, html, messageHash, groupId, mineBool){
|
function updateMyLatestStatus(messageHash){
|
||||||
processPost(className, html, groupId, mineBool);
|
$("#latest_message").text(messageHash['text']);
|
||||||
console.log(messageHash)
|
$("#latest_message_time").text(' - just now');
|
||||||
if(messageHash['mine?']){
|
}
|
||||||
updateMyLatestStatus(messageHash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateMyLatestStatus(messageHash){
|
function processPhotoInAlbum(photoHash){
|
||||||
$("#latest_message").text(messageHash['text']);
|
if (location.href.indexOf(photoHash['album_id']) == -1){
|
||||||
$("#latest_message_time").text(' - just now');
|
return ;
|
||||||
}
|
}
|
||||||
|
html = "<div class=\'image_thumb\' id=\'"+photoHash['id']+"\' style=\'padding-right:3px;\'> \
|
||||||
|
<a href=\"/photos/"+ photoHash['id'] +"\"> \
|
||||||
|
<img alt=\"New thumbnail\" src=\""+ photoHash['thumb_url'] +"\" /> \
|
||||||
|
</a> </div>"
|
||||||
|
$("#thumbnails").append( $(html) )
|
||||||
|
$("#"+ photoHash['id'] + " img").load( function() {
|
||||||
|
$(this).fadeIn("slow");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function processPhotoInAlbum(photoHash){
|
function onPageForClass(className){
|
||||||
if (location.href.indexOf(photoHash['album_id']) == -1){
|
return ((location.href.indexOf(className) != -1 ) || (location.pathname == '/')) && onPageOne();
|
||||||
return ;
|
}
|
||||||
}
|
|
||||||
html = "<div class=\'image_thumb\' id=\'"+photoHash['id']+"\' style=\'padding-right:3px;\'> \
|
|
||||||
<a href=\"/photos/"+ photoHash['id'] +"\"> \
|
|
||||||
<img alt=\"New thumbnail\" src=\""+ photoHash['thumb_url'] +"\" /> \
|
|
||||||
</a> </div>"
|
|
||||||
$("#thumbnails").append( $(html) )
|
|
||||||
$("#"+ photoHash['id'] + " img").load( function() {
|
|
||||||
$(this).fadeIn("slow");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onPageForClass(className){
|
function onPageForGroup(groupId){
|
||||||
return ((location.href.indexOf(className) != -1 ) || (location.pathname == '/')) && onPageOne();
|
return (location.href.indexOf(groupId) != -1 )
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPageForGroup(groupId){
|
function onPageOne() {
|
||||||
return (location.href.indexOf(groupId) != -1 )
|
var c = document.location.search.charAt(document.location.search.length-1);
|
||||||
}
|
return ((c =='') || (c== '1'));
|
||||||
|
}
|
||||||
function onPageOne() {
|
});
|
||||||
var c = document.location.search.charAt(document.location.search.length-1);
|
|
||||||
return ((c =='') || (c== '1'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue