Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[dist] pre-release

Commit prerelease, still alpha, first atent to make this work like a
working module. Plus new features like edit, delete and markdown
enabled.
  • Loading branch information...
commit ac05fdda189ce6575dfefdbab14a1e9ad0badd4a 1 parent a66fb72
@alejandro authored
Showing with 64 additions and 50 deletions.
  1. +58 −46 app.js
  2. +1 −1  lib/comments.js
  3. +4 −2 views/form.jade
  4. +1 −1  views/layout.jade
View
104 app.js
@@ -3,7 +3,7 @@ var express = require('express'),
url = require('url'),
sys = require('util'),
util = require('./lib/utils').util,
- app = module.exports = express.createServer( express.cookieParser(),express.session({ secret: 'keyboard cat' })),
+ app = module.exports = express.createServer( express.cookieParser(),express.logger('dev'),express.session({ secret: 'keyboard cat' })),
nowjs = require('now'),
groups =[],
escape = require('./lib/autolink'),
@@ -82,51 +82,63 @@ function isMember(array,path){
});
return f;
}
-app.listen(process.env.PORT || 8080);
-console.log('Server on port: %s \non: %s ',app.address().port,app.settings.env);
+app.listen(8080);
+var ncomm = exports;
-var everyone = nowjs.initialize(app);
-everyone.now.joinRoom = function(req){
- nowjs.getGroup(req.url).addUser(this.user.clientId);
-}
-everyone.now.sendComment = function(req) {
- var self = this;
- req = new Comment(req);
- req.save(function(e,d){
- if (d) {
- nowjs.getGroup(req.url).now.receiveMessage(req.data.authorId,escape.autoLink(util.toStaticHTML(req.data.comment)));
- } else {
- nowjs.getClient(self.user.clientId, function(){
- this.now.receiveMessage('SERVER:', req.validateC());
- });
- }
+
+var neveryone = ncomm.everyone = function (server) {
+ var everyone = ncomm.comment = nowjs.initialize(server)
+ everyone.now.joinRoom = function(req){
+ nowjs.getGroup(req.url).addUser(this.user.clientId);
+ }
+ everyone.now.sendComment = function(req) {
+ var self = this;
+ req = new Comment(req);
+ req.save(function(e,d){
+ if (d) {
+ nowjs.getGroup(req.url).now.receiveMessage(
+ req.data.authorId,
+ escape.autoLink(util.toStaticHTML(req.data.comment))
+ );
+ } else {
+ nowjs.getClient(self.user.clientId, function(){
+ this.now.receiveMessage('SERVER:', req.validateC());
+ });
+ }
+ });
+ }
+ everyone.now.fetchBySite = function(req,res){
+ comments.fetchBySite(req.url,function(e,r){
+ res(e,r);
});
-}
-everyone.now.fetchBySite = function(req,res){
- comments.fetchBySite(req.url,function(e,r){
- res(e,r);
- });
-}
-everyone.now.fetchByThread = function(req,res){
- comments.fetchByThread(req,function(e,r){
- res(e,r);
- });
-}
-everyone.now.send = function(req){
- if (req.data) {
- nowjs.getGroup(req.url).now.receiveMessage(req.data.id, req.data.msg)
- }
-}
-everyone.now.delete = function(req){
- comments.deleteComment(req,function(e,d){
- nowjs.getGroup(req.url).now.onEditMessage(req.data.authorId,util.toStaticHTML(req.data.comment));
- });
-}
-everyone.now.edit = function(req){
- comments.edit(req,function(e,d){
- nowjs.getGroup(req.url).now.onEditMessage(req.data.authorId,util.toStaticHTML(req.data.comment));
- });
-}
-everyone.now.autoLink = function(req, res){
- res(escape.autoLink(req));
+ }
+ everyone.now.fetchByThread = function(req,res){
+ comments.fetchByThread(req,function(e,r){
+ res(e,r);
+ });
+ }
+ everyone.now.send = function(req){
+ if (req.data) {
+ nowjs.getGroup(req.url).now.receiveMessage(req.data.id, req.data.msg)
+ }
+ }
+ everyone.now.delete = function(req){
+ comments.deleteComment(req,function(e,d){
+ nowjs.getGroup(req.url).now.onEditMessage(
+ req.data.authorId,
+ util.toStaticHTML(req.data.comment)
+ );
+ });
+ }
+ everyone.now.edit = function(req){
+ comments.edit(req,function(e,d){
+ nowjs.getGroup(req.url).now.onEditMessage(
+ req.data.authorId,
+ util.toStaticHTML(req.data.comment));
+ });
+ }
+ everyone.now.autoLink = function(req, res){
+ res(escape.autoLink(req));
+ }
+ return this;
}
View
2  lib/comments.js
@@ -82,7 +82,7 @@ Array.prototype.unique = function () {
Comment.prototype.validate = function(res){
var log =[]
try {
- if (/^(http:\/\/)([\w]+\.){1,}[A-Z]{2,}\b/gi.test(this.url)){} else { log.push('Invalid URL');}
+ //if (/^(http:\/\/)([\w]+\.){1,}[A-Z]{2,}\b/gi.test(this.url)){} else { log.push('Invalid URL');}
if (this.data.comment.length<50) { log.push('The comment has to be at least 50 chars long')}
if (!this.data.authorId) {log.push('I need a username')}
if (log.length===0) {
View
6 views/form.jade
@@ -1,4 +1,5 @@
-form(action="javascript:alert('success!');",id="form")
+
+form(action="javascript:void('success!');",id="form")
input(type="hidden",id="reply",name="reply")
input(type="hidden",id="userId",name="userId",value= user.id || "")
input(type="hidden",id="url")
@@ -7,6 +8,7 @@ form(action="javascript:alert('success!');",id="form")
input(type="submit",value="submit")
#comments
+ div
script
var p = document.getElementById('url');
@@ -59,7 +61,7 @@ script
now.sendComment({url: window.location.href,
data: {
authorId:"#{user.id}",
- comment: $('#comment').val() || 'Null',
+ comment: $('#comment').val() || null,
time: new Date(Date.now()),
parent:$('#reply').val() || window.location.href
}
View
2  views/layout.jade
@@ -3,6 +3,6 @@ html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
- script(type="text/javascript" ,src="//numbus.co/assets/javascripts/jquery-1.5.1.min.js")
+ script(type="text/javascript" ,src="http://code.jquery.com/jquery.js")
script(src="/nowjs/now.js")
body!= body
Please sign in to comment.
Something went wrong with that request. Please try again.