Visual link between comments and commented content

pull/1/head
yflory 5 years ago
parent 70545c64fc
commit c2f26775d8

@ -45,12 +45,13 @@
cursor: pointer; cursor: pointer;
.tools_unselectable(); .tools_unselectable();
} }
&:not(:last-child) { //&:not(:last-child) {
margin-bottom: 10px; // margin-bottom: 10px;
} //}
.cp-comment-form { .cp-comment-form {
margin-top: 5px; margin-top: 5px;
} }
padding: 5px;
} }
.cp-comment { .cp-comment {
&:not(:first-child) { &:not(:first-child) {
@ -77,7 +78,8 @@
.cp-comment-content { .cp-comment-content {
background-color: white; background-color: white;
padding: 10px 5px 5px; padding: 10px 5px 5px;
display: pre-wrap; white-space: pre-wrap;
word-break: break-all;
} }
.cp-comment-actions { .cp-comment-actions {
display: none; display: none;
@ -88,6 +90,7 @@
} }
} }
.cp-comment-active { .cp-comment-active {
background-color: rgba(0,0,0,0.2);
.cp-comment-actions { .cp-comment-actions {
display: block; display: block;
} }

@ -1,21 +1,23 @@
(function () { (function () {
var CKEDITOR = window.CKEDITOR;
function isUnstylable (el) { function isUnstylable (el) {
console.log(el); var b = el.getAttribute( 'contentEditable' ) === 'false' ||
console.log(el.getAttribute('contentEditable'));
console.log(el.getAttribute('data-nostyle'));
var b = el.getAttribute( 'contentEditable' ) == 'false' ||
el.getAttribute( 'data-nostyle' ); el.getAttribute( 'data-nostyle' );
console.log(b);
return b; return b;
} }
var color1 = 'rgba(252, 165, 3, 0.8);';
var color2 = 'rgba(252, 231, 3, 0.8);';
CKEDITOR.plugins.add('comments', { CKEDITOR.plugins.add('comments', {
//requires: 'dialog,widget', //requires: 'dialog,widget',
//icons: 'image', //icons: 'image',
//hidpi: true, //hidpi: true,
onLoad: function () { onLoad: function () {
CKEDITOR.addCss('comment { background-color: rgba(252, 165, 3, 0.8); }' + CKEDITOR.addCss('comment { background-color: '+color1+' }' +
'@keyframes color { 0% { background-color: '+color2+' } 50% { background-color: '+color1+' } 100% { background-color: '+color2+' } }' +
'comment:focus { animation-name: color; animation-duration: 1s; animation-iteration-count: 2; background-color: '+color2+' outline: none;}' +
'comment * { background-color: transparent !important; }'); 'comment * { background-color: transparent !important; }');
}, },
init: function (editor) { init: function (editor) {
@ -28,7 +30,8 @@
var styleDef = { var styleDef = {
element: 'comment', element: 'comment',
attributes: { attributes: {
'data-uid': '#(uid)' 'data-uid': '#(uid)',
'tabindex': '1'
}, },
overrides: [ { overrides: [ {
element: 'comment' element: 'comment'
@ -71,7 +74,7 @@
}); });
// Uncomment provided element // Uncomment provided element
editor.plugins.comments.uncomment = function (id) { editor.plugins.comments.uncomment = function (id, els) {
if (editor.readOnly) { return; } if (editor.readOnly) { return; }
editor.fire('saveSnapshot'); editor.fire('saveSnapshot');
@ -79,14 +82,20 @@
var style = new CKEDITOR.style({ var style = new CKEDITOR.style({
element: 'comment', element: 'comment',
attributes: { attributes: {
'data-uid': id 'data-uid': id,
'tabindex': '1'
}, },
}); });
style.alwaysRemoveElement = true;
els.forEach(function (el) {
// Create range for the entire document // Create range for the entire document
var node = new CKEDITOR.dom.node(el);
var range = editor.createRange(); var range = editor.createRange();
range.selectNodeContents( editor.document.getBody() ); range.setStart(node, 0);
range.setEnd(node, Number.MAX_SAFE_INTEGER);
// Remove style for the document // Remove style for the document
style.removeFromRange(range, editor); style.removeFromRange(range, editor);
});
setTimeout( function() { setTimeout( function() {
editor.fire('saveSnapshot'); editor.fire('saveSnapshot');

@ -1,10 +1,11 @@
define([ define([
'jquery',
'json.sortify', 'json.sortify',
'/common/common-util.js', '/common/common-util.js',
'/common/hyperscript.js', '/common/hyperscript.js',
'/common/common-interface.js', '/common/common-interface.js',
'/customize/messages.js' '/customize/messages.js'
], function (Sortify, Util, h, UI, Messages) { ], function ($, Sortify, Util, h, UI, Messages) {
var Comments = {}; var Comments = {};
/* /*
@ -262,20 +263,27 @@ define([
}, function () { }, function () {
// Delete the comment // Delete the comment
delete Env.comments.data[key]; delete Env.comments.data[key];
Env.editor.plugins.comments.uncomment(key); var els = Env.$inner.find('comment[data-uid="'+key+'"]').toArray();
Env.editor.plugins.comments.uncomment(key, els);
// Send to chainpad // Send to chainpad
updateMetadata(Env); updateMetadata(Env);
Env.framework.localChange(); Env.framework.localChange();
}); });
var focusContent = function () {
Env.$inner.find('comment[data-uid="'+key+'"]').focus();
};
$div.click(function () { $div.click(function () {
if ($div.hasClass('cp-comment-active')) { return; } if ($div.hasClass('cp-comment-active')) { return; }
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');
div.scrollIntoView();
$actions.css('display', ''); $actions.css('display', '');
Env.$container.find('.cp-comment-form').remove(); Env.$container.find('.cp-comment-form').remove();
// XXX highlight (and scroll to) the comment in the doc?
focusContent();
}); });
if ($oldInput && $oldInput.attr('data-uid') === key) { if ($oldInput && $oldInput.attr('data-uid') === key) {
@ -283,6 +291,7 @@ define([
$actions.hide(); $actions.hide();
$div.append($oldInput); $div.append($oldInput);
$oldInput.find('textarea').focus(); $oldInput.find('textarea').focus();
focusContent();
} }
}); });
@ -338,7 +347,7 @@ define([
} }
// Comment not in the metadata: uncomment (probably an undo) // Comment not in the metadata: uncomment (probably an undo)
if (comments.indexOf(id) === -1) { if (comments.indexOf(id) === -1) {
Env.editor.plugins.comments.uncomment(id); Env.editor.plugins.comments.uncomment(id, [el]);
changed = true; changed = true;
return; return;
} }
@ -459,6 +468,12 @@ sel.forEach(function (el) {
} }
Env.$container.find('.cp-comment-active').removeClass('cp-comment-active'); Env.$container.find('.cp-comment-active').removeClass('cp-comment-active');
}); });
Env.$inner.on('click', 'comment', function (e) {
var $comment = $(e.target);
var uid = $comment.attr('data-uid');
if (!uid) { return; }
Env.$container.find('.cp-comment-container[data-uid="'+uid+'"]').click();
});
var call = function (f) { var call = function (f) {
return function () { return function () {

Loading…
Cancel
Save