added firefox websocket stuffs, only loads if it is not safari or chrome
This commit is contained in:
parent
9c1619059b
commit
3064d208eb
10 changed files with 36 additions and 15 deletions
|
|
@ -32,4 +32,9 @@ module ApplicationHelper
|
||||||
def mine?(post)
|
def mine?(post)
|
||||||
post.owner == User.first.email
|
post.owner == User.first.email
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def type_partial(post)
|
||||||
|
class_name = post.class.name.to_s.underscore
|
||||||
|
"#{class_name.pluralize}/#{class_name}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
module DashboardHelper
|
module DashboardHelper
|
||||||
|
|
||||||
def type_partial(post)
|
|
||||||
class_name = post.class.name.to_s.underscore
|
|
||||||
"#{class_name.pluralize}/#{class_name}"
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class Post
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def send_to_view
|
def send_to_view
|
||||||
WebSocket.update_clients (self.to_json)
|
WebSocket.update_clients(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_defaults
|
def set_defaults
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
%b shared a link
|
%b shared a link
|
||||||
%br
|
%br
|
||||||
= post.title
|
= 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)
|
%div.time= link_to "#{time_ago_in_words(post.updated_at)} ago", bookmark_path(post)
|
||||||
- if mine?(post)
|
- if mine?(post)
|
||||||
= link_to 'Destroy', bookmark_path(post), :confirm => 'Are you sure?', :method => :delete
|
= link_to 'Destroy', bookmark_path(post), :confirm => 'Are you sure?', :method => :delete
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,15 @@
|
||||||
= javascript_include_tag 'jquery142'
|
= javascript_include_tag 'jquery142'
|
||||||
/= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"
|
/= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"
|
||||||
= javascript_include_tag 'rails'
|
= 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?
|
= javascript_include_tag 'socket' if user_signed_in?
|
||||||
= csrf_meta_tag
|
= csrf_meta_tag
|
||||||
= yield(:head)
|
= yield(:head)
|
||||||
|
|
@ -42,6 +51,7 @@
|
||||||
= link_to "login", new_user_session_path
|
= link_to "login", new_user_session_path
|
||||||
|
|
||||||
#header_below
|
#header_below
|
||||||
|
|
||||||
- if user_signed_in?
|
- if user_signed_in?
|
||||||
%h1#user_name
|
%h1#user_name
|
||||||
= link_to User.first.real_name, root_url
|
= link_to User.first.real_name, root_url
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
%div.time
|
%div.time
|
||||||
= "#{time_ago_in_words(post.updated_at)} ago"
|
= "#{time_ago_in_words(post.updated_at)} ago"
|
||||||
- if mine?(post)
|
- 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,14 @@ module WebSocket
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
#this should get folded into message queue i think?
|
#this should get folded into message queue i think?
|
||||||
def self.update_clients(json)
|
def self.update_clients(object)
|
||||||
@channel.push(json) if @channel
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ $(document).ready(function(){
|
||||||
function debug(str){ $("#debug").append("<p>" + str); };
|
function debug(str){ $("#debug").append("<p>" + str); };
|
||||||
|
|
||||||
ws = new WebSocket("ws://localhost:8080/");
|
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.onclose = function() { debug("socket closed"); };
|
||||||
ws.onopen = function() {
|
ws.onopen = function() {
|
||||||
debug("connected...");
|
debug("connected...");
|
||||||
|
|
|
||||||
|
|
@ -125,14 +125,14 @@ ul#stream {
|
||||||
ul#stream > li {
|
ul#stream > li {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
border-bottom: 1px solid #f1f1f1; }
|
border-bottom: 1px solid #f1f1f1;
|
||||||
|
margin-bottom: 5px; }
|
||||||
|
|
||||||
li.message {
|
li.message {
|
||||||
line-height: 140%;
|
line-height: 140%;
|
||||||
font-size: 120%;
|
font-size: 120%;
|
||||||
font-family: "Lucida Grande";
|
font-family: "Lucida Grande";
|
||||||
color: #999999;
|
color: #999999; }
|
||||||
margin-bottom: 5px; }
|
|
||||||
li.message span.from {
|
li.message span.from {
|
||||||
color: black;
|
color: black;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,7 @@ ul#stream
|
||||||
:padding 1em
|
:padding 1em
|
||||||
:border
|
:border
|
||||||
:bottom 1px solid #f1f1f1
|
:bottom 1px solid #f1f1f1
|
||||||
|
:margin-bottom 5px
|
||||||
|
|
||||||
li.message
|
li.message
|
||||||
:line-height 140%
|
:line-height 140%
|
||||||
|
|
@ -158,7 +159,7 @@ li.message
|
||||||
:size 120%
|
:size 120%
|
||||||
:family 'Lucida Grande'
|
:family 'Lucida Grande'
|
||||||
:color #999
|
:color #999
|
||||||
:margin-bottom 5px
|
|
||||||
|
|
||||||
span.from
|
span.from
|
||||||
:color #000
|
:color #000
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue