From 25130e31f87b511e458c436e98478ea60aa07d3a Mon Sep 17 00:00:00 2001 From: William Harris Date: Wed, 30 Mar 2011 04:07:07 +0000 Subject: [PATCH] that was easier than I thought. updated readme a bit more and. Need to js doc the plugin and see if I've missed anything else --- README.md | 16 ++++++++++++---- client/js/jquery.socket.io.js | 30 +----------------------------- client/js/main.js | 26 ++++++++++++++++++++++++++ server-example/views/layout.jade | 1 + 4 files changed, 40 insertions(+), 33 deletions(-) create mode 100644 client/js/main.js diff --git a/README.md b/README.md index 6f3cf98..975e232 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ $(document).ready( function () { - var jqSH = $.socketHandler(); + var jqSH = $.socketio(); // greet the user on their console $(jqSH).bind('greeting', function(event, message){ @@ -14,12 +14,13 @@ }); +## How it works -## Repository Layout +It binds: -the wrapper branch shows how it works behind the scenes +1) socket.io messages sent from the server to jquery events and -the master or plugin branch allows you to just include and go +2) jquery events fired from the browser to socket.io messages sent from the client ## Usage @@ -27,6 +28,13 @@ the master or plugin branch allows you to just include and go there is both a client and a (node.js) server example in this repository to help you get started +## Repository Layout + +the wrapper branch shows how it works behind the scenes + +the master or plugin branch allows you to just include and go + + ## Credits client code and parts of the server code inspired by this article diff --git a/client/js/jquery.socket.io.js b/client/js/jquery.socket.io.js index 3bab8e2..e838c2d 100644 --- a/client/js/jquery.socket.io.js +++ b/client/js/jquery.socket.io.js @@ -1,6 +1,6 @@ (function( $ ){ - $.socketHandler = function() { + $.socketio = function() { // Create SocketIO instance, connect var socket = new io.Socket(); @@ -45,31 +45,3 @@ } })( jQuery ); - - -$(document).ready( function () { - - var jqSH = $.socketHandler(); - - // greet the user on their console - $(jqSH).bind('greeting', function(event, message){ - - if(window.console) console.log(message); - - }); - - //the client is calling the client - $(jqSH).bind('calling', function(event, message){ - - var messageContainer = $("div#message"); - - if (messageContainer.length) { - - messageContainer.effect("pulsate", { times:6 }, 1500); - messageContainer.text(message); - - } - - }); - -}); diff --git a/client/js/main.js b/client/js/main.js new file mode 100644 index 0000000..ec2cce7 --- /dev/null +++ b/client/js/main.js @@ -0,0 +1,26 @@ +$(document).ready( function () { + + var jqSH = $.socketio(); + + // greet the user on their console + $(jqSH).bind('greeting', function(event, message){ + + if(window.console) console.log(message); + + }); + + //the client is calling the client + $(jqSH).bind('calling', function(event, message){ + + var messageContainer = $("div#message"); + + if (messageContainer.length) { + + messageContainer.effect("pulsate", { times:6 }, 1500); + messageContainer.text(message); + + } + + }); + +}); diff --git a/server-example/views/layout.jade b/server-example/views/layout.jade index 87cca84..bfd1569 100644 --- a/server-example/views/layout.jade +++ b/server-example/views/layout.jade @@ -7,6 +7,7 @@ html script(src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js") script(src="socket.io/socket.io.js") script(src="js/jquery.socket.io.js") + script(src="js/main.js") link(rel="stylesheet", type="text/css", href="css/styles.css") body