Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated express example

  • Loading branch information...
commit 4c9832869e3dc66688df330b906e154643cc1a62 1 parent 957e7ac
@mdesign83 authored
View
49 examples/express_example/app.js
@@ -1,44 +1,41 @@
-var express = require('express');
-
-var app = express.createServer();
-
-// Configuration
-
-app.set('views', __dirname + '/views');
-app.set('view engine', 'ejs');
-
-
+var port = 8080;
+var express = require('express');
+var app = express.createServer();
+var server = app.listen(port);
+console.log("Express server listening on port " + port);
+
+// App Configuration
+app.configure(function(){
+ app.use(express.methodOverride());
+ app.use(express.bodyParser());
+ app.use(express.static(__dirname + '/public'));
+ app.set('views', __dirname + '/views');
+ app.set('view engine', 'jade');
+});
// Routes
-
app.get('/', function(req, res){
- res.render('index', {locals: {
- title: 'NowJS + Express Example'
- }});
+ res.render('index', {
+ 'title': 'NowJS + Express Example'
+ });
});
app.get('/chat', function(req, res){
- res.render('chat', {locals: {
+ res.render('chat', {
title: 'NowJS + Express Example'
- }});
+ });
});
-app.listen(8080);
-console.log("Express server listening on port %d", app.address().port);
-
-
// NowJS component
-var nowjs = require("now");
-var everyone = nowjs.initialize(app);
-
+var nowjs = require("now");
+var everyone = nowjs.initialize(server);
nowjs.on('connect', function(){
- console.log("Joined: " + this.now.name);
+ console.log("Joined: " + this.now.name);
});
-
nowjs.on('disconnect', function(){
- console.log("Left: " + this.now.name);
+ console.log("Left: " + this.now.name);
});
everyone.now.distributeMessage = function(message){
View
10 examples/express_example/package.json
@@ -1,7 +1,7 @@
{
"name": "nowjs-express-example",
- "version": "0.0.2",
- "author": "ericz (Eric Zhang) <eric@nowjs.com>",
+ "version": "0.0.3",
+ "author": "mdesign83 (Karoly Marton) <m.karoly@martondesign.com>",
"description": "This is an example of an embedded chat window added to any site.",
"keywords": [
"nowjs",
@@ -9,9 +9,9 @@
"example"
],
"dependencies" : {
- "now" : ">=0.7",
- "express" : ">=2.4",
- "ejs" : ">=0.5"
+ "now" : ">=0.8.1",
+ "express" : ">=3.0.0",
+ "jade" : ">=0.26.3"
},
"engine": {
"node": ">=0.4"
View
15 examples/express_example/public/javascript/chat.js
@@ -0,0 +1,15 @@
+$(document).ready(function(){
+
+ now.receiveMessage = function(name, message){
+ $("#messages").append("<br>" + name + ": " + message);
+ }
+
+ $("#send-button").click(function(){
+ now.distributeMessage($("#text-input").val());
+ $("#text-input").val("");
+ $("#text-input").focus();
+ });
+
+ now.name = prompt("What's your name?", "");
+
+});
View
6 examples/express_example/public/javascript/index.js
@@ -0,0 +1,6 @@
+$(document).ready(function() {
+$('#chat').click(function(e) {
+ e.preventDefault();
+ $('<iframe width="300px" height="100%" sandbox="allow-same-origin allow-forms allow-scripts" src="http://localhost:8080/chat"></iframe>').appendTo('#floater');
+ });
+});
View
33 examples/express_example/views/chat.ejs
@@ -1,33 +0,0 @@
-<h2>Chat Window</h2>
-<div id="messages"></div>
-<div style="position: absolute; bottom: 25;">
-<input type="text" id="text-input">
-<input type="button" value="Send" id="send-button">
-</div>
-
-<script>
- $(document).ready(function(){
-
- now.receiveMessage = function(name, message){
- $("#messages").append("<br>" + name + ": " + message);
- }
-
- $("#send-button").click(function(){
- now.distributeMessage($("#text-input").val());
- $("#text-input").val("");
- $("#text-input").focus();
- });
-
- $("#text-input").keypress(function (e) {
- if (e.which && e.which === 13) {
- $("#send-button").click();
- return false;
- }
- });
-
- now.name = prompt("What's your name?", "");
-
- $("#text-input").focus();
-
- });
-</script>
View
8 examples/express_example/views/chat.jade
@@ -0,0 +1,8 @@
+extends layout
+block content
+ h2 Chat Window
+ div(id='messages')
+ div(style='position: absolute; bottom: 25;)
+ input(type='text', id='text-input')
+ input(type='button', value='Send', id='send-button')
+ script(src='/javascript/chat.js')
View
4 examples/express_example/views/header.jade
@@ -0,0 +1,4 @@
+head
+ title NowJS+Express+Jade Example
+ script(type="text/javascript", src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js")
+ script(type="text/javascript", src="/nowjs/now.js")
View
12 examples/express_example/views/index.ejs
@@ -1,12 +0,0 @@
-<h1><%= title %></h1>
-<p>Welcome to <%= title %></p>
-<p>This is an example of an embedded chat window added to any site. <a href='#' id='chat'>Chat with us</a></p>
-<div id="floater" style="position: absolute; right: 0; top:0; width: 300px; height: 100%;"></div>
-<script>
- $(document).ready(function() {
- $('#chat').click(function(e) {
- e.preventDefault();
- $('#floater').css("border-left", "1px solid #000").append('<iframe style="width: 300px; border: 0;" sandbox="allow-same-origin allow-forms allow-scripts" src="http://localhost:8080/chat"></iframe>');
- });
- });
-</script>
View
8 examples/express_example/views/index.jade
@@ -0,0 +1,8 @@
+extends layout
+block content
+ h1 test
+ p welcome
+ p This is an example of an embedded chat window added to any site.
+ a(href='#', id='chat') Chat with us
+ div(id='floater', style='position: absolute; right: 0; top:0; width:25%; height:100%;')
+ script(src='/javascript/index.js')
View
11 examples/express_example/views/layout.ejs
@@ -1,11 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title><%= title %></title>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
- <script src="/nowjs/now.js"></script>
- </head>
- <body>
- <%- body %>
- </body>
-</html>
View
5 examples/express_example/views/layout.jade
@@ -0,0 +1,5 @@
+!!! 5
+html
+ include header
+ body
+ block content
Please sign in to comment.
Something went wrong with that request. Please try again.