ep_comments_page
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -112,2 +112,3 @@ var db = require('ep_etherpad-lite/node/db/DB').db; | ||
"text": data.reply, | ||
"changeTo": data.changeTo || null, | ||
"author": metadata.author, | ||
@@ -114,0 +115,0 @@ "name": metadata.name, |
@@ -6,2 +6,3 @@ { | ||
"pre": ["ep_etherpad-lite/webaccess"], | ||
"post": ["ep_etherpad-lite/static"], | ||
"client_hooks": { | ||
@@ -8,0 +9,0 @@ "postAceInit": "ep_comments_page/static/js/index", |
@@ -65,6 +65,7 @@ var eejs = require('ep_etherpad-lite/node/eejs/'); | ||
var content = data.reply; | ||
var changeTo = data.changeTo || null; | ||
var commentId = data.commentId; | ||
commentManager.addCommentReply(padId, data, function (err, replyId, reply){ | ||
commentManager.addCommentReply(padId, data, function (err, replyId, reply, changeTo){ | ||
reply.replyId = replyId; | ||
socket.broadcast.to(padId).emit('pushAddCommentReply', replyId, reply); | ||
socket.broadcast.to(padId).emit('pushAddCommentReply', replyId, reply, changeTo); | ||
callback(replyId, reply); | ||
@@ -71,0 +72,0 @@ }); |
{ | ||
"description": "Adds comments on sidebar and link it to the text. Support for Page View, requires ep_page_view", | ||
"name": "ep_comments_page", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Nicolas Lescop", |
@@ -6,2 +6,3 @@ var _, $, jQuery; | ||
var padcookie = require('ep_etherpad-lite/static/js/pad_cookie').padcookie; | ||
var prettyDate = require('ep_comments_page/static/js/timeFormat').prettyDate; | ||
@@ -13,3 +14,3 @@ var cssFiles = ['ep_comments_page/static/css/comment.css']; | ||
/************************************************************************/ | ||
// Container | ||
// Container | ||
function ep_comments(context){ | ||
@@ -35,3 +36,5 @@ this.container = null; | ||
if(clientVars.readonly){ | ||
this.padInner.append("<style>.comment-changeTo-approve{display:none;}</style>"); | ||
this.padInner.append( | ||
"<style>.comment-changeTo-approve," + | ||
".comment-reply-changeTo-approve{display:none;}</style>"); | ||
} | ||
@@ -90,3 +93,3 @@ } | ||
self.collectComments(); | ||
}, 9000); | ||
@@ -101,3 +104,10 @@ } | ||
// On click comment icon toolbar | ||
// When language is changed, we need to reload the comments to make sure | ||
// all templates are localized | ||
html10n.bind('localized', function() { | ||
self.localizeExistingComments(); | ||
self.localizeNewCommentForm(); | ||
}); | ||
// On click comment icon toolbar | ||
$('.addComment').on('click', function(e){ | ||
@@ -107,4 +117,4 @@ $('iframe[name="ace_outer"]').contents().find('#comments').show(); | ||
e.preventDefault(); // stops focus from being lost | ||
// If a new comment box doesn't already exist | ||
// Add a new comment and link it to the selection | ||
// If a new comment box doesn't already exist | ||
// Add a new comment and link it to the selection | ||
// $('iframe[name="ace_outer"]').contents().find('#sidediv').removeClass('sidedivhidden'); | ||
@@ -128,5 +138,4 @@ if (self.container.find('#newComment').length == 0) self.addComment(); | ||
// Listen for include suggested change toggle | ||
this.container.on("change", '#reply-suggestion-checkbox', function(){ | ||
this.container.on("change", '.reply-suggestion-checkbox', function(){ | ||
if($(this).is(':checked')){ | ||
// Get current text -- cake | ||
var commentId = $(this).parent().parent().parent()[0].id; | ||
@@ -137,8 +146,6 @@ var padOuter = $('iframe[name="ace_outer"]').contents(); | ||
var currentString = padInner.contents().find("."+commentId).html(); | ||
console.log("cS", currentString); | ||
$(this).parent().parent().find(".comment-suggest-from").html(currentString); | ||
$('iframe[name="ace_outer"]').contents().find('.suggestion').show(); | ||
$(this).parent().parent().find(".reply-comment-suggest-from").html(currentString); | ||
$(this).parent().parent().find('.reply-suggestion').show(); | ||
}else{ | ||
$('iframe[name="ace_outer"]').contents().find('.suggestion').hide(); | ||
$(this).parent().parent().find('.reply-suggestion').hide(); | ||
} | ||
@@ -152,2 +159,20 @@ }); | ||
// DUPLICATE CODE REQUIRED FOR COMMENT REPLIES, see below for slightly different version | ||
this.container.on("click", ".comment-reply-changeTo-approve", function(e){ | ||
e.preventDefault(); | ||
var commentId = $(this).parent().parent().parent().parent()[0].id; | ||
var newString = $(this).parent().contents().find(".comment-changeTo-value").html(); | ||
var padOuter = $('iframe[name="ace_outer"]').contents(); | ||
var padInner = padOuter.find('iframe[name="ace_inner"]'); | ||
// Nuke all that aren't first lines of this comment | ||
padInner.contents().find("."+commentId+":not(:first)").html(""); | ||
var padCommentContent = padInner.contents().find("."+commentId).first(); | ||
newString = newString.replace(/(?:\r\n|\r|\n)/g, '<br />'); | ||
// Write the new pad contents | ||
$(padCommentContent).html(newString); | ||
}); | ||
// User accepts a change | ||
this.container.on("submit", ".comment-changeTo-form", function(e){ | ||
@@ -160,4 +185,10 @@ e.preventDefault(); | ||
var padInner = padOuter.find('iframe[name="ace_inner"]'); | ||
// We know the ID, so we can do a html replace no? | ||
var padCommentContent = padInner.contents().find("."+data.commentId); | ||
// Nuke all that aren't first lines of this comment | ||
padInner.contents().find("."+data.commentId+":not(:first)").html(""); | ||
var padCommentContent = padInner.contents().find("."+data.commentId).first(); | ||
newString = newString.replace(/(?:\r\n|\r|\n)/g, '<br />'); | ||
// Write the new pad contents | ||
$(padCommentContent).html(newString); | ||
@@ -172,3 +203,3 @@ }); | ||
data.reply = $(this).find(".comment-reply-input").val(); | ||
data.changeTo = $(this).find(".reply-comment-suggest-to").val() || null; | ||
self.socket.emit('addCommentReply', data, function (){ | ||
@@ -183,3 +214,5 @@ // Append the reply to the comment | ||
}); | ||
if($(this).parent().parent().find(".reply-suggestion-checkbox").is(':checked')){ | ||
$(this).parent().parent().find(".reply-suggestion-checkbox").click(); | ||
} | ||
}); | ||
@@ -213,3 +246,3 @@ | ||
// Insert comments container on element use for linenumbers | ||
// Insert comments container on element use for linenumbers | ||
ep_comments.prototype.findContainers = function(){ | ||
@@ -262,2 +295,5 @@ var padOuter = $('iframe[name="ace_outer"]').contents(); | ||
} | ||
// localize comment element | ||
self.localize(commentElm); | ||
} | ||
@@ -274,6 +310,6 @@ } | ||
var prevCommentHeight = prevCommentElm.innerHeight(); | ||
commentPos = parseInt(prevCommentPos) + prevCommentHeight + 30; | ||
} | ||
commentElm.css({ 'top': commentPos }); | ||
@@ -293,3 +329,3 @@ }); | ||
var commentId = e.currentTarget.id; | ||
var inner = $('iframe[name="ace_outer"]').contents().find('iframe[name="ace_inner"]'); | ||
var inner = $('iframe[name="ace_outer"]').contents().find('iframe[name="ace_inner"]'); | ||
inner.contents().find("head").append("<style>."+commentId+"{ color:black }</style>"); | ||
@@ -359,9 +395,5 @@ // TODO this could potentially break ep_font_color | ||
ep_comments.prototype.removeComment = function(className, id){ | ||
// console.log('remove comment', className, id); | ||
} | ||
// Insert comment container in sidebar | ||
ep_comments.prototype.insertContainer = function(){ | ||
// Add comments | ||
// Add comments | ||
$('iframe[name="ace_outer"]').contents().find("#outerdocbody").prepend('<div id="comments"></div>'); | ||
@@ -418,3 +450,3 @@ this.container = this.padOuter.find('#comments'); | ||
// Insert a comment node | ||
// Insert a comment node | ||
ep_comments.prototype.insertComment = function(commentId, comment, index, isNew){ | ||
@@ -429,2 +461,4 @@ var template = (isNew === true) ? 'newCommentTemplate' : 'commentsTemplate'; | ||
this.localize(content); | ||
// position doesn't seem to be relative to rep | ||
@@ -463,2 +497,35 @@ | ||
ep_comments.prototype.localize = function(element) { | ||
html10n.translateElement(html10n.translations, element.get(0)); | ||
}; | ||
ep_comments.prototype.localizeNewCommentForm = function() { | ||
var newCommentForm = this.container.find('#newComment'); | ||
if (newCommentForm.length !== 0) this.localize(newCommentForm); | ||
}; | ||
ep_comments.prototype.localizeExistingComments = function() { | ||
var self = this; | ||
var padComments = this.padInner.contents().find('.comment'); | ||
var comments = this.comments; | ||
padComments.each(function(it) { | ||
var $this = $(this); | ||
var cls = $this.attr('class'); | ||
var classCommentId = /(?:^| )(c-[A-Za-z0-9]*)/.exec(cls); | ||
var commentId = (classCommentId) ? classCommentId[1] : null; | ||
if (commentId !== null) { | ||
var commentElm = self.container.find('#'+ commentId); | ||
var comment = comments[commentId]; | ||
// localize comment element... | ||
self.localize(commentElm); | ||
// ... and update its date | ||
comment.data.date = prettyDate(comment.data.timestamp); | ||
commentElm.attr('title', comment.data.date); | ||
} | ||
}); | ||
}; | ||
// Set comments content data | ||
@@ -500,3 +567,3 @@ ep_comments.prototype.setComments = function(comments){ | ||
// Insert comment data | ||
// Insert comment data | ||
data.padId = this.padId; | ||
@@ -507,3 +574,3 @@ data.comment = {}; | ||
data.comment.timestamp = new Date().getTime(); | ||
// Si le client est Anonyme | ||
@@ -518,3 +585,3 @@ // In English please? :P | ||
// Add a pad comment | ||
// Add a pad comment | ||
ep_comments.prototype.addComment = function (callback){ | ||
@@ -545,18 +612,33 @@ var socket = this.socket; | ||
// TODO: allow selecting multiple lines.. Dunno why my brain can't handle this today.. | ||
/* | ||
var selectedText = ""; | ||
_(_.range(firstLine, lastLine + 1)).each(function(lineNumber){ | ||
// rep looks like -- starts at line 2, character 1, ends at line 4 char 1 | ||
/* | ||
{ | ||
rep.selStart[2,0], | ||
rep.selEnd[4,2] | ||
} | ||
*/ | ||
var line = rep.lines.atIndex(lineNumber); | ||
console.log("arbl", line.text); | ||
// If we span over multiple lines | ||
if(rep.selStart[0] !== selEnd[0]){ | ||
if(rep.selStart[0] === lineNumber){ | ||
// Is this the first line? | ||
if(rep.selStart[1] > 0){ | ||
var posStart = rep.selStart[1]; | ||
}else{ | ||
var posStart = 0; | ||
} | ||
} | ||
var selectedText = line.text.substring(rep.selStart[1], rep.selEnd[1]) | ||
console.log(selectedText); | ||
if(selectedText){ | ||
$('iframe[name="ace_outer"]').contents().find(".comment-suggest-from").append(escape(selectedText)); | ||
if(rep.selEnd[0] === lineNumber){ | ||
if(rep.selEnd[1] <= line.text.length){ | ||
var posEnd = rep.selEnd[1]; | ||
}else{ | ||
var posEnd = 0; | ||
} | ||
} | ||
var lineText = line.text.substring(posStart, posEnd); | ||
selectedText += lineText + "\n"; | ||
}); | ||
*/ | ||
@@ -568,3 +650,5 @@ // Set the top of the form | ||
this.insertNewComment(data, function (comment, index){ | ||
if(comment.changeTo) data.comment.changeTo = comment.changeTo; | ||
if(comment.changeTo){ | ||
data.comment.changeTo = comment.changeTo; | ||
} | ||
data.comment.text = comment.text; | ||
@@ -575,3 +659,3 @@ | ||
comment.commentId = commentId; | ||
//callback(commentId); | ||
@@ -589,5 +673,3 @@ ace.callWithAce(function (ace){ | ||
var line = rep.lines.atIndex(rep.selStart[0]); | ||
var selectedText = line.text.substring(rep.selStart[1], rep.selEnd[1]); | ||
// Write the text to the changeFrom form | ||
$('iframe[name="ace_outer"]').contents().find(".comment-suggest-from").val(selectedText); | ||
@@ -597,8 +679,2 @@ | ||
// Gets the original text of a comment | ||
ep_comments.prototype.getOriginalText = function(commentId){ | ||
console.log(this.text); | ||
console.log("CAKE need TODO -- get the text of a given commentId, this would return a string such as 'Hello world'"); | ||
} | ||
// Listen for comment replies | ||
@@ -608,4 +684,4 @@ ep_comments.prototype.commentRepliesListen = function(){ | ||
var socket = this.socket; | ||
socket.on('pushAddCommentReply', function (replyId, reply){ | ||
// console.warn("pAcR response", replyId, reply); | ||
socket.on('pushAddCommentReply', function (replyId, reply, changeTo){ | ||
console.warn("pAcR response", replyId, reply, changeTo); | ||
// callback(replyId, reply); | ||
@@ -660,3 +736,3 @@ // self.collectCommentReplies(); | ||
// Init pad comments | ||
// Init pad comments | ||
postAceInit: function(hook, context){ | ||
@@ -702,42 +778,2 @@ if(!pad.plugins) pad.plugins = {}; | ||
function prettyDate(time){ | ||
var time_formats = [ | ||
[60, 'seconds', 1], // 60 | ||
[120, '1 minute ago', '1 minute from now'], // 60*2 | ||
[3600, 'minutes', 60], // 60*60, 60 | ||
[7200, '1 hour ago', '1 hour from now'], // 60*60*2 | ||
[86400, 'hours', 3600], // 60*60*24, 60*60 | ||
[172800, 'yesterday', 'tomorrow'], // 60*60*24*2 | ||
[604800, 'days', 86400], // 60*60*24*7, 60*60*24 | ||
[1209600, 'last week', 'next week'], // 60*60*24*7*4*2 | ||
[2419200, 'weeks', 604800], // 60*60*24*7*4, 60*60*24*7 | ||
[4838400, 'last month', 'next month'], // 60*60*24*7*4*2 | ||
[29030400, 'months', 2419200], // 60*60*24*7*4*12, 60*60*24*7*4 | ||
[58060800, 'last year', 'next year'], // 60*60*24*7*4*12*2 | ||
[2903040000, 'years', 29030400], // 60*60*24*7*4*12*100, 60*60*24*7*4*12 | ||
[5806080000, 'last century', 'next century'], // 60*60*24*7*4*12*100*2 | ||
[58060800000, 'centuries', 2903040000] // 60*60*24*7*4*12*100*20, 60*60*24*7*4*12*100 | ||
]; | ||
/* | ||
var time = ('' + date_str).replace(/-/g,"/").replace(/[TZ]/g," ").replace(/^\s\s*/ /*rappel , '').replace(/\s\s*$/, ''); | ||
if(time.substr(time.length-4,1)==".") time =time.substr(0,time.length-4); | ||
*/ | ||
var seconds = (new Date - new Date(time)) / 1000; | ||
var token = 'ago', list_choice = 1; | ||
if (seconds < 0) { | ||
seconds = Math.abs(seconds); | ||
token = 'from now'; | ||
list_choice = 2; | ||
} | ||
var i = 0, format; | ||
while (format = time_formats[i++]) | ||
if (seconds < format[0]) { | ||
if (typeof format[2] == 'string') | ||
return format[list_choice]; | ||
else | ||
return Math.floor(seconds / format[2]) + ' ' + format[1] + ' ' + token; | ||
} | ||
return time; | ||
}; | ||
exports.aceEditorCSS = hooks.aceEditorCSS; | ||
@@ -744,0 +780,0 @@ exports.postAceInit = hooks.postAceInit; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
99425
27
2243