Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit f8c93108eeb720821ca2a1d785f7e6d5bd498a1a @kevinohara80 committed
Showing with 138 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 Procfile
  3. +55 −0 app.js
  4. +10 −0 package.json
  5. +18 −0 public/javascripts/hover.js
  6. +27 −0 public/stylesheets/style.css
  7. +16 −0 views/index.jade
  8. +9 −0 views/layout.jade
2 .gitignore
@@ -0,0 +1,2 @@
+node_modules
+
1 Procfile
@@ -0,0 +1 @@
+web: node app.js
55 app.js
@@ -0,0 +1,55 @@
+
+/**
+ * Module dependencies.
+ */
+
+var express = require('express');
+var io = require('socket.io');
+var app = express.createServer();
+var io = io.listen(app);
+
+var port = process.env.PORT || 3000;
+
+// Configuration
+
+app.configure(function(){
+ app.set('views', __dirname + '/views');
+ app.set('view engine', 'jade');
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(app.router);
+ app.use(express.static(__dirname + '/public'));
+});
+
+app.configure('development', function(){
+ app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+});
+
+app.configure('production', function(){
+ app.use(express.errorHandler());
+});
+
+// Routes
+
+app.get('/', function(req, res){
+ res.render('index', {
+ title: 'Express'
+ });
+});
+
+// Sockets
+
+var count = 0;
+
+io.sockets.on('connection', function (socket) {
+
+ socket.on('hover', function (msg) {
+ count++;
+ var resp = 'Processed hover event on ' + msg + '. Event #' + count;
+ socket.emit('data', resp);
+ });
+
+});
+
+app.listen(port);
+console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
10 package.json
@@ -0,0 +1,10 @@
+{
+ "name": "roundtrip"
+ , "version": "0.0.1"
+ , "private": true
+ , "dependencies": {
+ "express": "*"
+ , "jade": ">= 0.0.1"
+ , "socket.io": "*"
+ }
+}
18 public/javascripts/hover.js
@@ -0,0 +1,18 @@
+(function($, io) {
+
+ var socket = io.connect('http://localhost:3000');
+
+ socket.on('connect', function () {
+ socket.on('data', function(data){
+ $('.results ul').append('<li>' + data + '</li>');
+ });
+ });
+
+ $(document).ready(function(){
+ $('.box').mouseover(function(){
+ var txt = $(this).children().first('p').text();
+ socket.emit('hover', txt);
+ });
+ });
+
+})(jQuery, io);
27 public/stylesheets/style.css
@@ -0,0 +1,27 @@
+body {
+ padding: 50px;
+ font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+}
+
+a {
+ color: #00B7FF;
+}
+
+.box {
+ float:left;
+ width:120px;
+ height:120px;
+ margin:5px;
+ border:3px solid #CCC;
+ border-radius: 5px;
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+}
+
+.box p {
+ text-align:center;
+}
+
+.results {
+ clear:both;
+}
16 views/index.jade
@@ -0,0 +1,16 @@
+div.box
+ p Box #1
+div.box
+ p Box #2
+div.box
+ p Box #3
+div.box
+ p Box #4
+div.box
+ p Box #5
+br
+br
+br
+div.results
+ ul
+
9 views/layout.jade
@@ -0,0 +1,9 @@
+!!!
+html
+ head
+ title= title
+ link(rel='stylesheet', href='/stylesheets/style.css')
+ script(src='http://code.jquery.com/jquery-1.6.1.min.js')
+ script(src='/socket.io/socket.io.js');
+ script(src='/javascripts/hover.js');
+ body!= body

0 comments on commit f8c9310

Please sign in to comment.
Something went wrong with that request. Please try again.