use translation key for comment error

pull/1/head
David Benqué 5 years ago
parent 4037270a23
commit 0eb89871cf

@ -6,11 +6,11 @@ define([
'/common/hyperscript.js', '/common/hyperscript.js',
'/common/common-interface.js', '/common/common-interface.js',
'/customize/messages.js' '/customize/messages.js'
], function ($, Sortify, Util, Hash, h, UI, Messages) { ], function($, Sortify, Util, Hash, h, UI, Messages) {
var Comments = {}; var Comments = {};
/* /*
{ {
authors: { authors: {
"id": { "id": {
name: "", name: "",
@ -32,18 +32,18 @@ define([
d: undefined/1, d: undefined/1,
} }
} }
} }
*/ */
var COMMENTS = { var COMMENTS = {
authors: {}, authors: {},
data: {} data: {}
}; };
var canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); }; var canonicalize = function(t) { return t.replace(/\r\n/g, '\n'); };
// XXX function duplicated from www/code/markers.js // XXX function duplicated from www/code/markers.js
var authorUid = function (existing) { var authorUid = function(existing) {
if (!Array.isArray(existing)) { existing = []; } if (!Array.isArray(existing)) { existing = []; }
var n; var n;
var i = 0; var i = 0;
@ -54,12 +54,12 @@ define([
if (existing.indexOf(n) !== -1) { n = 0; } if (existing.indexOf(n) !== -1) { n = 0; }
return n; return n;
}; };
var getAuthorId = function (Env, curve) { var getAuthorId = function(Env, curve) {
var existing = Object.keys(Env.comments.authors || {}).map(Number); var existing = Object.keys(Env.comments.authors || {}).map(Number);
if (!Env.common.isLoggedIn()) { return authorUid(existing); } if (!Env.common.isLoggedIn()) { return authorUid(existing); }
var uid; var uid;
existing.some(function (id) { existing.some(function(id) {
var author = Env.comments.authors[id] || {}; var author = Env.comments.authors[id] || {};
if (author.curvePublic !== curve) { return; } if (author.curvePublic !== curve) { return; }
uid = Number(id); uid = Number(id);
@ -70,7 +70,7 @@ define([
// Return the author ID and add/update the data for registered users // Return the author ID and add/update the data for registered users
// Return the username for unregistered users // Return the username for unregistered users
var updateAuthorData = function (Env, onChange) { var updateAuthorData = function(Env, onChange) {
var userData = Env.metadataMgr.getUserData(); var userData = Env.metadataMgr.getUserData();
if (!Env.common.isLoggedIn()) { if (!Env.common.isLoggedIn()) {
return userData.name; return userData.name;
@ -89,13 +89,13 @@ define([
return myAuthorId; return myAuthorId;
}; };
var updateMetadata = function (Env) { var updateMetadata = function(Env) {
var md = Util.clone(Env.metadataMgr.getMetadata()); var md = Util.clone(Env.metadataMgr.getMetadata());
md.comments = Util.clone(Env.comments); md.comments = Util.clone(Env.comments);
Env.metadataMgr.updateMetadata(md); Env.metadataMgr.updateMetadata(md);
}; };
var sendReplyNotification = function (Env, uid) { var sendReplyNotification = function(Env, uid) {
if (!Env.comments || !Env.comments.data || !Env.comments.authors) { return; } if (!Env.comments || !Env.comments.data || !Env.comments.authors) { return; }
if (!Env.common.isLoggedIn()) { return; } if (!Env.common.isLoggedIn()) { return; }
var thread = Env.comments.data[uid]; var thread = Env.comments.data[uid];
@ -104,7 +104,7 @@ define([
var privateData = Env.metadataMgr.getPrivateData(); var privateData = Env.metadataMgr.getPrivateData();
var others = {}; var others = {};
// Get all the other registered users with a mailbox // Get all the other registered users with a mailbox
thread.m.forEach(function (obj) { thread.m.forEach(function(obj) {
var u = obj.u; var u = obj.u;
if (typeof(u) !== "number") { return; } if (typeof(u) !== "number") { return; }
var author = Env.comments.authors[u]; var author = Env.comments.authors[u];
@ -118,7 +118,7 @@ define([
}; };
}); });
// Send the notification // Send the notification
Object.keys(others).forEach(function (id) { Object.keys(others).forEach(function(id) {
var data = others[id]; var data = others[id];
Env.common.mailbox.sendTo("COMMENT_REPLY", { Env.common.mailbox.sendTo("COMMENT_REPLY", {
channel: privateData.channel, channel: privateData.channel,
@ -132,12 +132,12 @@ define([
}; };
var cleanMentions = function ($el) { var cleanMentions = function($el) {
$el.html(''); $el.html('');
var el = $el[0]; var el = $el[0];
var allowed = ['data-profile', 'data-name', 'data-avatar', 'class']; var allowed = ['data-profile', 'data-name', 'data-avatar', 'class'];
// Remove unnecessary/unsafe attributes // Remove unnecessary/unsafe attributes
for (var i=el.attributes.length-1; i>0; i--) { for (var i = el.attributes.length - 1; i > 0; i--) {
var name = el.attributes[i] && el.attributes[i].name; var name = el.attributes[i] && el.attributes[i].name;
if (allowed.indexOf(name) === -1) { if (allowed.indexOf(name) === -1) {
$el.removeAttr(name); $el.removeAttr(name);
@ -146,7 +146,7 @@ define([
}; };
// Seletc all text of a contenteditable element // Seletc all text of a contenteditable element
var selectAll = function (element) { var selectAll = function(element) {
var selection = window.getSelection(); var selection = window.getSelection();
var range = document.createRange(); var range = document.createRange();
range.selectNodeContents(element); range.selectNodeContents(element);
@ -159,7 +159,7 @@ define([
Messages.comments_submit = "Submit"; // XXX Messages.comments_submit = "Submit"; // XXX
Messages.comments_reply = "Reply"; // XXX Messages.comments_reply = "Reply"; // XXX
Messages.comments_resolve = "Resolve"; // XXX Messages.comments_resolve = "Resolve"; // XXX
var getCommentForm = function (Env, reply, _cb, editContent) { var getCommentForm = function(Env, reply, _cb, editContent) {
var cb = Util.once(_cb); var cb = Util.once(_cb);
var userData = Env.metadataMgr.getUserData(); var userData = Env.metadataMgr.getUserData();
var name = Util.fixHTML(userData.name || Messages.anonymous); var name = Util.fixHTML(userData.name || Messages.anonymous);
@ -188,12 +188,12 @@ define([
]); ]);
// List of allowed attributes in mentions // List of allowed attributes in mentions
$(submit).click(function (e) { $(submit).click(function(e) {
e.stopPropagation(); e.stopPropagation();
var clone = textarea.cloneNode(true); var clone = textarea.cloneNode(true);
var notify = {}; var notify = {};
var $clone = $(clone); var $clone = $(clone);
$clone.find('span.cp-mentions').each(function (i, el) { $clone.find('span.cp-mentions').each(function(i, el) {
var $el = $(el); var $el = $(el);
var curve = $el.attr('data-curve'); var curve = $el.attr('data-curve');
var notif = $el.attr('data-notifications'); var notif = $el.attr('data-notifications');
@ -209,7 +209,7 @@ define([
// Send notification // Send notification
var privateData = Env.metadataMgr.getPrivateData(); var privateData = Env.metadataMgr.getPrivateData();
var userData = Env.metadataMgr.getUserData(); var userData = Env.metadataMgr.getUserData();
Object.keys(notify).forEach(function (curve) { Object.keys(notify).forEach(function(curve) {
if (curve === userData.curvePublic) { return; } if (curve === userData.curvePublic) { return; }
Env.common.mailbox.sendTo("MENTION", { Env.common.mailbox.sendTo("MENTION", {
channel: privateData.channel, channel: privateData.channel,
@ -222,12 +222,12 @@ define([
// Push the content // Push the content
cb(content); cb(content);
}); });
$(cancel).click(function (e) { $(cancel).click(function(e) {
e.stopPropagation(); e.stopPropagation();
cb(); cb();
}); });
var $text = $(textarea).keydown(function (e) { var $text = $(textarea).keydown(function(e) {
e.stopPropagation(); e.stopPropagation();
if (e.which === 27) { if (e.which === 27) {
$(cancel).click(); $(cancel).click();
@ -243,14 +243,14 @@ define([
e.stopImmediatePropagation(); e.stopImmediatePropagation();
e.preventDefault(); e.preventDefault();
} }
}).click(function (e) { }).click(function(e) {
e.stopPropagation(); e.stopPropagation();
}); });
if (Env.common.isLoggedIn()) { if (Env.common.isLoggedIn()) {
var authors = {}; var authors = {};
Object.keys((Env.comments && Env.comments.authors) || {}).forEach(function (id) { Object.keys((Env.comments && Env.comments.authors) ||  {}).forEach(function(id) {
var obj = Util.clone(Env.comments.authors[id]); var obj = Util.clone(Env.comments.authors[id]);
authors[obj.curvePublic] = obj; authors[obj.curvePublic] = obj;
}); });
@ -273,14 +273,14 @@ define([
h('i.fa.fa-times'), h('i.fa.fa-times'),
Messages.kanban_delete Messages.kanban_delete
]); ]);
$(deleteButton).click(function (e) { $(deleteButton).click(function(e) {
e.stopPropagation(); e.stopPropagation();
cb(false); cb(false);
}); });
} }
setTimeout(function () { setTimeout(function() {
$(textarea).focus(); $(textarea).focus();
selectAll(textarea); selectAll(textarea);
}); });
@ -300,13 +300,13 @@ define([
]); ]);
}; };
var isVisible = function (el, $container) { var isVisible = function(el, $container) {
var size = $container.outerHeight(); var size = $container.outerHeight();
var pos = el.getBoundingClientRect(); var pos = el.getBoundingClientRect();
return (pos.bottom < size) && (pos.y > 0); return (pos.bottom < size) && (pos.y > 0);
}; };
var redrawComments = function (Env) { var redrawComments = function(Env) {
// Don't redraw if there were no change // Don't redraw if there were no change
var str = Sortify(Env.comments || {}); var str = Sortify(Env.comments || {});
if (str === Env.oldComments) { return; } if (str === Env.oldComments) { return; }
@ -347,15 +347,15 @@ define([
var userData = Env.metadataMgr.getUserData(); var userData = Env.metadataMgr.getUserData();
// Get all the comment threads in their order in the pad // Get all the comment threads in their order in the pad
var threads = Env.$inner.find('comment').map(function (i, el) { var threads = Env.$inner.find('comment').map(function(i, el) {
return el.getAttribute('data-uid'); return el.getAttribute('data-uid');
}).toArray(); }).toArray();
// Draw all comment threads // Draw all comment threads
Util.deduplicateString(threads).forEach(function (key) { Util.deduplicateString(threads).forEach(function(key) {
// Get thread data // Get thread data
var obj = Env.comments.data[key]; var obj = Env.comments.data[key];
if (!obj || obj.d || !Array.isArray(obj.m) || !obj.m.length) { if (!obj || obj.d ||  !Array.isArray(obj.m) ||  !obj.m.length) {
return; return;
} }
@ -367,23 +367,22 @@ define([
var $actions; var $actions;
// Draw all messages for this thread // Draw all messages for this thread
(obj.m || []).forEach(function (msg, i) { (obj.m || []).forEach(function(msg, i) {
var replyCls = i === 0 ? '' : '.cp-comment-reply'; var replyCls = i === 0 ? '' : '.cp-comment-reply';
if (msg.d) { if (msg.d) {
content.push(h('div.cp-comment.cp-comment-deleted'+replyCls, content.push(h('div.cp-comment.cp-comment-deleted' + replyCls,
Messages.comments_deleted)); Messages.comments_deleted));
return; return;
} }
var author = typeof(msg.u) === "number" ? var author = typeof(msg.u) === "number" ?
((Env.comments.authors || {})[msg.u] || {}) : ((Env.comments.authors || {})[msg.u] || {}) : { name: msg.u };
{ name: msg.u };
var name = Util.fixHTML(author.name || Messages.anonymous); var name = Util.fixHTML(author.name || Messages.anonymous);
var date = new Date(msg.t); var date = new Date(msg.t);
var avatar = h('span.cp-avatar'); var avatar = h('span.cp-avatar');
Env.common.displayAvatar($(avatar), author.avatar, name); Env.common.displayAvatar($(avatar), author.avatar, name);
if (author.profile) { if (author.profile) {
$(avatar).click(function (e) { $(avatar).click(function(e) {
Env.common.openURL(Hash.hashToHref(author.profile, 'profile')); Env.common.openURL(Hash.hashToHref(author.profile, 'profile'));
e.stopPropagation(); e.stopPropagation();
}); });
@ -394,7 +393,7 @@ define([
m.innerHTML = msg.m; m.innerHTML = msg.m;
var $m = $(m); var $m = $(m);
$m.find('> *:not(span.cp-mentions)').remove(); $m.find('> *:not(span.cp-mentions)').remove();
$m.find('span.cp-mentions').each(function (i, el) { $m.find('span.cp-mentions').each(function(i, el) {
var $el = $(el); var $el = $(el);
var name = $el.attr('data-name'); var name = $el.attr('data-name');
var avatarUrl = $el.attr('data-avatar'); var avatarUrl = $el.attr('data-avatar');
@ -412,11 +411,11 @@ define([
]); ]);
if (profile) { if (profile) {
$el.attr('tabindex', 1); $el.attr('tabindex', 1);
$el.addClass('cp-mentions-clickable').click(function (e) { $el.addClass('cp-mentions-clickable').click(function(e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
Env.common.openURL(Hash.hashToHref(profile, 'profile')); Env.common.openURL(Hash.hashToHref(profile, 'profile'));
}).focus(function (e) { }).focus(function(e) {
e.stopPropagation(); e.stopPropagation();
}); });
} }
@ -432,18 +431,18 @@ define([
// Add edit button when applicable (last message of the thread, written by ourselves) // Add edit button when applicable (last message of the thread, written by ourselves)
var edit; var edit;
if (i === (obj.m.length -1) && author.curvePublic === userData.curvePublic) { if (i === (obj.m.length - 1) && author.curvePublic === userData.curvePublic) {
edit = h('span.cp-comment-edit', { edit = h('span.cp-comment-edit', {
tabindex:1, tabindex: 1,
title: Messages.clickToEdit title: Messages.clickToEdit
}, h('i.fa.fa-pencil')); }, h('i.fa.fa-pencil'));
$(edit).click(function (e) { $(edit).click(function(e) {
Env.$container.find('.cp-comment-active').removeClass('cp-comment-active'); Env.$container.find('.cp-comment-active').removeClass('cp-comment-active');
$div.addClass('cp-comment-active'); $div.addClass('cp-comment-active');
e.stopPropagation(); e.stopPropagation();
Env.$container.find('.cp-comment-form').remove(); Env.$container.find('.cp-comment-form').remove();
if ($actions) { $actions.hide(); } if ($actions) { $actions.hide(); }
var form = getCommentForm(Env, key, function (val) { var form = getCommentForm(Env, key, function(val) {
// Show the "reply" and "resolve" buttons again // Show the "reply" and "resolve" buttons again
$(form).closest('.cp-comment-container') $(form).closest('.cp-comment-container')
.find('.cp-comment-actions').css('display', ''); .find('.cp-comment-actions').css('display', '');
@ -481,7 +480,7 @@ define([
} }
// Add the comment // Add the comment
content.push(container = h('div.cp-comment'+replyCls, [ content.push(container = h('div.cp-comment' + replyCls, [
h('div.cp-comment-header', [ h('div.cp-comment-header', [
avatar, avatar,
h('span.cp-comment-metadata', [ h('span.cp-comment-metadata', [
@ -523,10 +522,10 @@ define([
}, content)); }, content));
$div = $(div); $div = $(div);
$(reply).click(function (e) { $(reply).click(function(e) {
e.stopPropagation(); e.stopPropagation();
$actions.hide(); $actions.hide();
var form = getCommentForm(Env, key, function (val) { var form = getCommentForm(Env, key, function(val) {
// Show the "reply" and "resolve" buttons again // Show the "reply" and "resolve" buttons again
$(form).closest('.cp-comment-container') $(form).closest('.cp-comment-container')
.find('.cp-comment-actions').css('display', ''); .find('.cp-comment-actions').css('display', '');
@ -537,8 +536,8 @@ define([
if (!obj || !Array.isArray(obj.m)) { return; } if (!obj || !Array.isArray(obj.m)) { return; }
// Get the value of the commented text // Get the value of the commented text
var res = Env.$inner.find('comment[data-uid="'+key+'"]').toArray(); var res = Env.$inner.find('comment[data-uid="' + key + '"]').toArray();
var value = res.map(function (el) { var value = res.map(function(el) {
return el.innerText; return el.innerText;
}).join('\n'); }).join('\n');
@ -562,7 +561,7 @@ define([
$div.append(form); $div.append(form);
// Make sure the submit button is visible: scroll by the height of the form // Make sure the submit button is visible: scroll by the height of the form
setTimeout(function () { setTimeout(function() {
var yContainer = Env.$container[0].getBoundingClientRect().bottom; var yContainer = Env.$container[0].getBoundingClientRect().bottom;
var yActions = form.getBoundingClientRect().bottom; var yActions = form.getBoundingClientRect().bottom;
if (yActions > yContainer) { if (yActions > yContainer) {
@ -573,7 +572,7 @@ define([
UI.confirmButton(resolve, { UI.confirmButton(resolve, {
classes: 'btn-danger' classes: 'btn-danger'
}, function () { }, function() {
// Delete the comment // Delete the comment
delete Env.comments.data[key]; delete Env.comments.data[key];
@ -582,11 +581,11 @@ define([
Env.framework.localChange(); Env.framework.localChange();
}); });
var focusContent = function () { var focusContent = function() {
// Add class "active" // Add class "active"
Env.$inner.find('comment.active').removeClass('active'); Env.$inner.find('comment.active').removeClass('active');
Env.$inner.find('comment[data-uid="'+key+'"]').addClass('active'); Env.$inner.find('comment[data-uid="' + key + '"]').addClass('active');
var $last = Env.$inner.find('comment[data-uid="'+key+'"]').last(); var $last = Env.$inner.find('comment[data-uid="' + key + '"]').last();
// Scroll into view // Scroll into view
if (!$last.length) { return; } if (!$last.length) { return; }
@ -594,7 +593,7 @@ define([
if (!visible) { $last[0].scrollIntoView(); } if (!visible) { $last[0].scrollIntoView(); }
}; };
$div.on('click focus', function (e) { $div.on('click focus', function(e) {
// Prevent the click event to propagate if we're already selected // Prevent the click event to propagate if we're already selected
// The propagation to #cp-app-pad-inner would trigger the "unselect" handler // The propagation to #cp-app-pad-inner would trigger the "unselect" handler
e.stopPropagation(); e.stopPropagation();
@ -621,7 +620,7 @@ define([
// Restore selection // Restore selection
if (oldRangeObj) { if (oldRangeObj) {
setTimeout(function () { setTimeout(function() {
if (!oldRangeObj) { return; } if (!oldRangeObj) { return; }
var range = document.createRange(); var range = document.createRange();
range.setStart(oldRangeObj.start, oldRangeObj.startO); range.setStart(oldRangeObj.start, oldRangeObj.startO);
@ -639,7 +638,7 @@ define([
} }
}; };
var onChange = function (Env) { var onChange = function(Env) {
var md = Util.clone(Env.metadataMgr.getMetadata()); var md = Util.clone(Env.metadataMgr.getMetadata());
Env.comments = md.comments; Env.comments = md.comments;
var changed = false; var changed = false;
@ -649,7 +648,7 @@ define([
} }
if (Env.ready === 0) { if (Env.ready === 0) {
Env.ready = true; Env.ready = true;
updateAuthorData(Env, function () { updateAuthorData(Env, function() {
changed = true; changed = true;
}); });
// On ready, if our user data have changed or if we've added the initial structure // On ready, if our user data have changed or if we've added the initial structure
@ -661,7 +660,7 @@ define([
} else if (Env.ready) { } else if (Env.ready) {
// Everytime there is a metadata change, check if our user data have changed // Everytime there is a metadata change, check if our user data have changed
// and push the updates if necessary // and push the updates if necessary
updateAuthorData(Env, function () { updateAuthorData(Env, function() {
updateMetadata(Env); updateMetadata(Env);
Env.framework.localChange(); Env.framework.localChange();
}); });
@ -670,7 +669,7 @@ define([
}; };
// Check if comments have been deleted from the document but not from metadata // Check if comments have been deleted from the document but not from metadata
var checkDeleted = function (Env) { var checkDeleted = function(Env) {
if (!Env.comments || !Env.comments.data) { return; } if (!Env.comments || !Env.comments.data) { return; }
// Don't recheck if there were no change // Don't recheck if there were no change
@ -679,7 +678,7 @@ define([
Env.oldCheck = str; Env.oldCheck = str;
// If there is no comment stored in the metadata, abort // If there is no comment stored in the metadata, abort
var comments = Object.keys(Env.comments.data || {}).filter(function (id) { var comments = Object.keys(Env.comments.data || {}).filter(function(id) {
return !Env.comments.data[id].d; return !Env.comments.data[id].d;
}); });
@ -687,7 +686,7 @@ define([
// Get the comments from the document // Get the comments from the document
var toUncomment = {}; var toUncomment = {};
var uids = Env.$inner.find('comment').map(function (i, el) { var uids = Env.$inner.find('comment').map(function(i, el) {
var id = el.getAttribute('data-uid'); var id = el.getAttribute('data-uid');
// Empty comment: remove from dom // Empty comment: remove from dom
if (!el.innerHTML && el.parentElement) { if (!el.innerHTML && el.parentElement) {
@ -713,13 +712,13 @@ define([
}).toArray(); }).toArray();
if (Object.keys(toUncomment).length) { if (Object.keys(toUncomment).length) {
Object.keys(toUncomment).forEach(function (id) { Object.keys(toUncomment).forEach(function(id) {
Env.editor.plugins.comments.uncomment(id, toUncomment[id]); Env.editor.plugins.comments.uncomment(id, toUncomment[id]);
}); });
} }
// Check if a comment has been deleted // Check if a comment has been deleted
comments.forEach(function (uid) { comments.forEach(function(uid) {
if (uids.indexOf(uid) !== -1) { return; } if (uids.indexOf(uid) !== -1) { return; }
// comment has been deleted // comment has been deleted
var data = Env.comments.data[uid]; var data = Env.comments.data[uid];
@ -734,19 +733,19 @@ define([
} }
}; };
var removeCommentBubble = function (Env) { var removeCommentBubble = function(Env) {
Env.bubble = undefined; Env.bubble = undefined;
Env.$contentContainer.find('.cp-comment-bubble').remove(); Env.$contentContainer.find('.cp-comment-bubble').remove();
}; };
var updateBubble = function (Env) { var updateBubble = function(Env) {
if (!Env.bubble) { return; } if (!Env.bubble) { return; }
var pos = Env.bubble.node.getBoundingClientRect(); var pos = Env.bubble.node.getBoundingClientRect();
if (pos.y < 0 || pos.y > Env.$inner.outerHeight()) { if (pos.y < 0 || pos.y > Env.$inner.outerHeight()) {
//removeCommentBubble(Env); //removeCommentBubble(Env);
} }
Env.bubble.button.setAttribute('style', 'top:'+pos.y+'px'); Env.bubble.button.setAttribute('style', 'top:' + pos.y + 'px');
}; };
var addCommentBubble = function (Env) { var addCommentBubble = function(Env) {
var ranges = Env.editor.getSelectedRanges(); var ranges = Env.editor.getSelectedRanges();
if (!ranges.length) { return; } if (!ranges.length) { return; }
var el = ranges[0].endContainer || ranges[0].startContainer; var el = ranges[0].endContainer || ranges[0].startContainer;
@ -760,14 +759,14 @@ define([
var y = pos.y; var y = pos.y;
if (y < 0 || y > Env.$inner.outerHeight()) { return; } if (y < 0 || y > Env.$inner.outerHeight()) { return; }
var button = h('button.btn.btn-secondary', { var button = h('button.btn.btn-secondary', {
style: 'top:'+y+'px;', style: 'top:' + y + 'px;',
title: Messages.comments_comment title: Messages.comments_comment
},h('i.fa.fa-comment')); }, h('i.fa.fa-comment'));
Env.bubble = { Env.bubble = {
node: node, node: node,
button: button button: button
}; };
$(button).click(function (e) { $(button).click(function(e)  {
e.stopPropagation(); e.stopPropagation();
Env.editor.execCommand('comment'); Env.editor.execCommand('comment');
Env.bubble = undefined; Env.bubble = undefined;
@ -775,8 +774,8 @@ define([
Env.$contentContainer.append(h('div.cp-comment-bubble', button)); Env.$contentContainer.append(h('div.cp-comment-bubble', button));
}; };
var addAddCommentHandler = function (Env) { var addAddCommentHandler = function(Env) {
Env.editor.plugins.comments.addComment = function (uid, addMark) { Env.editor.plugins.comments.addComment = function(uid, addMark) {
if (!Env.ready) { return; } if (!Env.ready) { return; }
if (!Env.comments) { Env.comments = Util.clone(COMMENTS); } if (!Env.comments) { Env.comments = Util.clone(COMMENTS); }
@ -786,14 +785,14 @@ define([
// Abort if our selection contains a comment // Abort if our selection contains a comment
console.error("Can't add a comment here"); console.error("Can't add a comment here");
// XXX show error // XXX show error
UI.warn(Messages.error); UI.warn(Messages.comments_error);
return; return;
} }
// Remove active class on other comments // Remove active class on other comments
Env.$container.find('.cp-comment-active').removeClass('cp-comment-active'); Env.$container.find('.cp-comment-active').removeClass('cp-comment-active');
Env.$container.find('.cp-comment-form').remove(); Env.$container.find('.cp-comment-form').remove();
var form = getCommentForm(Env, false, function (val) { var form = getCommentForm(Env, false, function(val) {
$(form).remove(); $(form).remove();
Env.$inner.focus(); Env.$inner.focus();
@ -833,10 +832,10 @@ define([
}; };
Env.$iframe.on('scroll', function () { Env.$iframe.on('scroll', function() {
updateBubble(Env); updateBubble(Env);
}); });
$(Env.ifrWindow.document).on('selectionchange', function () { $(Env.ifrWindow.document).on('selectionchange', function() {
removeCommentBubble(Env); removeCommentBubble(Env);
var applicable = Env.editor.plugins.comments.isApplicable(); var applicable = Env.editor.plugins.comments.isApplicable();
if (!applicable) { return; } if (!applicable) { return; }
@ -844,14 +843,14 @@ define([
}); });
}; };
var onContentUpdate = function (Env) { var onContentUpdate = function(Env) {
if (!Env.ready) { return; } if (!Env.ready) { return; }
// Check deleted // Check deleted
onChange(Env); onChange(Env);
checkDeleted(Env); checkDeleted(Env);
}; };
var ready = function (Env) { var ready = function(Env) {
Env.ready = 0; Env.ready = 0;
// If you're the only edit user online, clear "deleted" comments // If you're the only edit user online, clear "deleted" comments
@ -862,7 +861,7 @@ define([
// Clear data // Clear data
var data = (Env.comments && Env.comments.data) || {}; var data = (Env.comments && Env.comments.data) || {};
Object.keys(data).forEach(function (uid) { Object.keys(data).forEach(function(uid) {
if (data[uid].d) { delete data[uid]; } if (data[uid].d) { delete data[uid]; }
}); });
@ -871,12 +870,12 @@ define([
Env.framework.localChange(); Env.framework.localChange();
}; };
Comments.create = function (cfg) { Comments.create = function(cfg) {
var Env = cfg; var Env = cfg;
Env.comments = Util.clone(COMMENTS); Env.comments = Util.clone(COMMENTS);
var ro = cfg.framework.isReadOnly(); var ro = cfg.framework.isReadOnly();
var onEditableChange = function (unlocked) { var onEditableChange = function(unlocked) {
Env.$container.removeClass('cp-comments-readonly'); Env.$container.removeClass('cp-comments-readonly');
if (ro || !unlocked) { if (ro || !unlocked) {
Env.$container.addClass('cp-comments-readonly'); Env.$container.addClass('cp-comments-readonly');
@ -888,7 +887,7 @@ define([
addAddCommentHandler(Env); addAddCommentHandler(Env);
// Unselect comment when clicking outside // Unselect comment when clicking outside
$(window).click(function (e) { $(window).click(function(e) {
var $target = $(e.target); var $target = $(e.target);
if (!$target.length) { return; } if (!$target.length) { return; }
if ($target.is('.cp-comment-container')) { return; } if ($target.is('.cp-comment-container')) { return; }
@ -903,21 +902,21 @@ define([
Env.$container.find('.cp-comment-form').remove(); Env.$container.find('.cp-comment-form').remove();
}); });
// Unselect comment when clicking on another part of the doc // Unselect comment when clicking on another part of the doc
Env.$inner.on('click', function (e) { Env.$inner.on('click', function(e) {
if ($(e.target).closest('comment').length) { return; } if ($(e.target).closest('comment').length) { return; }
Env.$container.find('.cp-comment-active').removeClass('cp-comment-active'); Env.$container.find('.cp-comment-active').removeClass('cp-comment-active');
Env.$inner.find('comment.active').removeClass('active'); Env.$inner.find('comment.active').removeClass('active');
Env.$container.find('.cp-comment-form').remove(); Env.$container.find('.cp-comment-form').remove();
}); });
Env.$inner.on('click', 'comment', function (e) { Env.$inner.on('click', 'comment', function(e) {
var $comment = $(e.target); var $comment = $(e.target);
var uid = $comment.attr('data-uid'); var uid = $comment.attr('data-uid');
if (!uid) { return; } if (!uid) { return; }
Env.$container.find('.cp-comment-container[data-uid="'+uid+'"]').click(); Env.$container.find('.cp-comment-container[data-uid="' + uid + '"]').click();
}); });
var call = function (f) { var call = function(f) {
return function () { return function() {
try { try {
[].unshift.call(arguments, Env); [].unshift.call(arguments, Env);
return f.apply(null, arguments); return f.apply(null, arguments);

Loading…
Cancel
Save