Skip to content

Commit bc4d167

Browse files
committed
first commit
0 parents  commit bc4d167

15 files changed

+714
-0
lines changed

Diff for: .ep_initialized

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
done

Diff for: .npmignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git*
2+
docs/
3+
examples/
4+
support/
5+
test/
6+
testing.js
7+
.DS_Store
8+
.ep_initialized

Diff for: commentManager.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
var db = require('ep_etherpad-lite/node/db/DB').db;
3+
var ERR = require("ep_etherpad-lite/node_modules/async-stacktrace");
4+
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
5+
6+
exports.getComments = function (padId, callback)
7+
{
8+
//get the globalComments
9+
db.get("comments:" + padId, function(err, comments)
10+
{
11+
if(ERR(err, callback)) return;
12+
13+
//comment does not exists
14+
if(comments == null) comments = {};
15+
16+
/*var comments = [];
17+
var jsonComments = globalComments.comments;
18+
for (var commentId in jsonComments)
19+
{
20+
comments[commentId] = jsonComments;
21+
}*/
22+
23+
callback(null, { comments: comments });
24+
});
25+
};
26+
27+
exports.addComment = function(padId, data, callback)
28+
{
29+
//create the new comment
30+
var commentId = "c-" + randomString(16);
31+
32+
//get the entry
33+
db.get("comments:" + padId, function(err, comments){
34+
35+
if(ERR(err, callback)) return;
36+
37+
// the entry doesn't exist so far, let's create it
38+
if(comments == null) comments = {};
39+
40+
var comment = {
41+
"author": data.author,
42+
"name": data.name,
43+
"text": data.text,
44+
"timestamp": new Date().getTime()
45+
};
46+
47+
//add the entry for this pad
48+
comments[commentId] = comment;
49+
50+
//save the new element back
51+
db.set("comments:" + padId, comments);
52+
53+
callback(null, commentId, comment);
54+
});
55+
};

Diff for: comments.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
var commentManager = require('./commentManager');
3+
var padManager = require("ep_etherpad-lite/node/db/PadManager");
4+
var ERR = require("ep_etherpad-lite/node_modules/async-stacktrace");
5+
6+
function padExists(padID){
7+
padManager.doesPadExists(padID, function(err, exists){
8+
return exists;
9+
});
10+
}
11+
12+
exports.getPadComments = function(padID, callback)
13+
{
14+
commentManager.getComments(padID, function (err, padComments)
15+
{
16+
if(ERR(err, callback)) return;
17+
18+
if(padComments !== null) callback(null, padComments);
19+
});
20+
};
21+
22+
exports.addPadComment = function(padID, data, callback)
23+
{
24+
commentManager.addComment(padID, data, function (err, commentID)
25+
{
26+
if(ERR(err, callback)) return;
27+
28+
if(commentID !== null) callback(null, commentID);
29+
});
30+
};

Diff for: ep.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"parts": [
3+
{
4+
"name": "main",
5+
"pre": ["ep_etherpad-lite/webaccess"],
6+
"client_hooks": {
7+
"postAceInit": "ep_comments/static/js/index",
8+
"aceAttribsToClasses": "ep_comments/static/js/index",
9+
"aceEditorCSS": "ep_comments/static/js/index"
10+
},
11+
"hooks": {
12+
"socketio": "ep_comments/index",
13+
"eejsBlock_editbarMenuLeft": "ep_comments/index",
14+
"eejsBlock_scripts": "ep_comments/index",
15+
"eejsBlock_styles": "ep_comments/index"
16+
}
17+
}
18+
]
19+
}

Diff for: index.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
var eejs = require('ep_etherpad-lite/node/eejs/');
3+
var commentManager = require('./commentManager');
4+
5+
exports.socketio = function (hook_name, args, cb){
6+
var app = args.app;
7+
var io = args.io;
8+
var pushComment;
9+
var padComment = io;
10+
11+
var commentSocket = io
12+
.of('/comment')
13+
.on('connection', function (socket) {
14+
15+
socket.on('getComments', function (data, callback) {
16+
var padId = data.padId;
17+
18+
socket.join(padId);
19+
20+
commentManager.getComments(padId, function (err, comments){
21+
callback(comments);
22+
});
23+
});
24+
25+
socket.on('addComment', function (data, callback) {
26+
var padId = data.padId;
27+
var content = data.comment;
28+
29+
commentManager.addComment(padId, content, function (err, commentId, comment){
30+
socket.broadcast.to(padId).emit('pushAddComment', commentId, comment);
31+
callback(commentId, comment);
32+
});
33+
});
34+
35+
});
36+
};
37+
38+
exports.eejsBlock_editbarMenuLeft = function (hook_name, args, cb) {
39+
args.content = args.content + eejs.require("ep_comments/templates/commentBarButtons.ejs");
40+
return cb();
41+
};
42+
43+
exports.eejsBlock_scripts = function (hook_name, args, cb) {
44+
args.content = args.content + eejs.require("ep_comments/templates/comments.html", {}, module);
45+
return cb();
46+
};
47+
48+
exports.eejsBlock_styles = function (hook_name, args, cb) {
49+
args.content = args.content + eejs.require("ep_comments/templates/styles.html", {}, module);
50+
return cb();
51+
};
52+
53+
/*
54+
exports.expressCreateServer = function (hook_name, args, cb) {
55+
var app = args.app;
56+
57+
app.get('/p/:pad/:rev?/comments', function(req, res, next) {
58+
var padId = req.params.pad;
59+
var revision = req.params.rev ? req.params.rev : null;
60+
61+
comments.getPadComments(padId, revision, function(err, padComments) {
62+
res.render('comments.ejs', { locals: { comments: padComments } });
63+
});
64+
});
65+
66+
app.get('/p/:pad/:rev?/add/comment/:name/:text', function(req, res, next) {
67+
var padId = req.params.pad;
68+
var revision = req.params.rev ? req.params.rev : null;
69+
var data = {
70+
author: "empty",
71+
selection: "empty",
72+
name: req.params.name,
73+
text: req.params.text
74+
};
75+
76+
comments.addPadComment(padId, data, revision, function(err, commentId) {
77+
res.contentType('text/x-json');
78+
res.send('{ "commentId": "'+ commentId +'" }');
79+
});
80+
});
81+
app.configure(function(){
82+
args.app.set('views', __dirname + '/views');
83+
args.app.set('view options', {layout: false});
84+
args.app.engine('ejs', require('ejs').renderFile);
85+
}
86+
};*/

Diff for: package.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"description": "Adds comments on sidebar and link it to the text.",
3+
"name": "ep_comments",
4+
"version": "0.0.1",
5+
"author": {
6+
"name": "Nicolas Lescop",
7+
"email": "[email protected]"
8+
},
9+
"contributors": [
10+
{
11+
"name": "Nicolas Lescop",
12+
"email": "[email protected]"
13+
}
14+
],
15+
"dependencies": {},
16+
"engines": {
17+
"node": "*"
18+
},
19+
"homepage": "https://github.com/nicolas-lescop/etherpad-plugins",
20+
"devDependencies": {},
21+
"repository": {
22+
"type": "git",
23+
"url": "git://github.com/nicolas-lescop/etherpad-plugins.git"
24+
},
25+
26+
"_from": "etherpad-plugins/ep_comments",
27+
"readme": "ERROR: No README.md file found!",
28+
"dist": {
29+
"shasum": "99884ed7ddab0e5b74f57d7d59cc618e8cf681f3"
30+
}
31+
}

Diff for: static/css/comment.css

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
.comment {
2+
background: #FFCC91 !important;
3+
border-radius: 2px;
4+
}
5+
6+
#comments {
7+
width: 180px;
8+
font-family: Helvetica, Arial, sans-serif;
9+
}
10+
11+
.sidebar-comment {
12+
margin-left: 10px;
13+
padding: 8px 5px;
14+
margin-top: 10px;
15+
background: white;
16+
width: 167px;
17+
border-top-left-radius: 2px;
18+
border-bottom-left-radius: 2px;
19+
-moz-box-shadow: 0 0 2px #888;
20+
-webkit-box-shadow: 0 0 2px #888;
21+
box-shadow: 0 0 2px #888;
22+
}
23+
24+
.sidebar-comment.mouseover {
25+
margin: 8px 0 0 14px;
26+
/*-moz-box-shadow: 0 0 2px #EB5C2E;
27+
-webkit-box-shadow: 0 0 2px #EB5C2E;
28+
box-shadow: 0 0 2px #EB5C2E;*/
29+
background: #FFF9F7;
30+
-webkit-transition: margin 300ms ease-in, background 300ms ease-in;
31+
-moz-transition: margin 300ms ease-in, background 300ms ease-in;
32+
-ms-transition: margin 300ms ease-in, background 300ms ease-in;
33+
-o-transition: margin 300ms ease-in, background 300ms ease-in;
34+
transition: margin 300ms ease-in, background 300ms ease-in;
35+
}
36+
37+
.comment-author-name {
38+
color: #555;
39+
font-weight:bold;
40+
font-size: 1.2em;
41+
}
42+
43+
.comment-date {
44+
line-height: 0.9em;
45+
font-size: 0.9em;
46+
}
47+
48+
.comment-text {
49+
margin-top: 5px;
50+
font-size: 1em;
51+
color: #333;
52+
width: 160px;
53+
word-wrap: break-word;
54+
white-space : normal;
55+
}
56+
57+
.comment-content {
58+
border: 2px solid #DDD;
59+
background: #fff;
60+
width: 160px;
61+
height: 60px;
62+
padding: 2px;
63+
}
64+
65+
.comment-content:focus {
66+
border: 2px solid #ccc;
67+
}
68+
69+
.comment-buttons input {
70+
color: #666;
71+
border: 2px solid #DDD;
72+
background: #EEE;
73+
width: 81px;
74+
height: 30px;
75+
}
76+
77+
.comment-buttons input[type="submit"] {
78+
margin-right: 5px;
79+
}
80+
81+
.comment-buttons input:hover {
82+
color: #333;
83+
cursor: pointer;
84+
}

Diff for: static/css/main.css

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)