added firefox websocket stuffs, only loads if it is not safari or chrome

This commit is contained in:
maxwell 2010-06-22 14:31:16 -07:00
parent 9c1619059b
commit 3064d208eb
10 changed files with 36 additions and 15 deletions

View file

@ -32,4 +32,9 @@ module ApplicationHelper
def mine?(post)
post.owner == User.first.email
end
def type_partial(post)
class_name = post.class.name.to_s.underscore
"#{class_name.pluralize}/#{class_name}"
end
end

View file

@ -1,8 +1,5 @@
module DashboardHelper
def type_partial(post)
class_name = post.class.name.to_s.underscore
"#{class_name.pluralize}/#{class_name}"
end
end

View file

@ -41,7 +41,7 @@ class Post
protected
def send_to_view
WebSocket.update_clients (self.to_json)
WebSocket.update_clients(self)
end
def set_defaults

View file

@ -4,7 +4,7 @@
%b shared a link
%br
= post.title
= link_to post.link
= link_to post.link.to_s, post.link
%div.time= link_to "#{time_ago_in_words(post.updated_at)} ago", bookmark_path(post)
- if mine?(post)
= link_to 'Destroy', bookmark_path(post), :confirm => 'Are you sure?', :method => :delete

View file

@ -10,6 +10,15 @@
= javascript_include_tag 'jquery142'
/= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"
= javascript_include_tag 'rails'
- unless request.user_agent.include? "Safari" ||"Chrome"
= javascript_include_tag 'FABridge'
= javascript_include_tag 'swfobject'
= javascript_include_tag 'web_socket'
:javascript
WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf";
= javascript_include_tag 'socket' if user_signed_in?
= csrf_meta_tag
= yield(:head)
@ -42,6 +51,7 @@
= link_to "login", new_user_session_path
#header_below
- if user_signed_in?
%h1#user_name
= link_to User.first.real_name, root_url

View file

@ -5,7 +5,7 @@
%div.time
= "#{time_ago_in_words(post.updated_at)} ago"
- if mine?(post)
= link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete
/= link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete

View file

@ -26,8 +26,14 @@ module WebSocket
end
}
#this should get folded into message queue i think?
def self.update_clients(json)
@channel.push(json) if @channel
def self.update_clients(object)
view = ActionView::Base.new(ActionController::Base.view_paths, {})
class << view
include ApplicationHelper
include Rails.application.routes.url_helpers
end
n = view.render(:partial =>view.type_partial(object), :locals => {:post => object})
@channel.push(n) if @channel
end
end

View file

@ -1,8 +1,10 @@
$(document).ready(function(){
$(document).ready(function(){
function debug(str){ $("#debug").append("<p>" + str); };
ws = new WebSocket("ws://localhost:8080/");
ws.onmessage = function(evt) { $(".msg").prepend("<p>"+evt.data+"</p>"); };
ws.onmessage = function(evt) {
$("#stream").prepend($(evt.data).fadeIn("fast"));
};
ws.onclose = function() { debug("socket closed"); };
ws.onopen = function() {
debug("connected...");

View file

@ -125,14 +125,14 @@ ul#stream {
ul#stream > li {
list-style: none;
padding: 1em;
border-bottom: 1px solid #f1f1f1; }
border-bottom: 1px solid #f1f1f1;
margin-bottom: 5px; }
li.message {
line-height: 140%;
font-size: 120%;
font-family: "Lucida Grande";
color: #999999;
margin-bottom: 5px; }
color: #999999; }
li.message span.from {
color: black;
font-weight: bold;

View file

@ -151,6 +151,7 @@ ul#stream
:padding 1em
:border
:bottom 1px solid #f1f1f1
:margin-bottom 5px
li.message
:line-height 140%
@ -158,7 +159,7 @@ li.message
:size 120%
:family 'Lucida Grande'
:color #999
:margin-bottom 5px
span.from
:color #000