Add support for comments with multiple users
This commit is contained in:
parent
0a72ed2977
commit
17d78a3831
3 changed files with 39 additions and 21 deletions
|
@ -77,6 +77,7 @@
|
||||||
.cp-comment-content {
|
.cp-comment-content {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
padding: 10px 5px 5px;
|
padding: 10px 5px 5px;
|
||||||
|
display: pre-wrap;
|
||||||
}
|
}
|
||||||
.cp-comment-actions {
|
.cp-comment-actions {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
|
@ -70,6 +70,29 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Uncomment provided element
|
||||||
|
editor.plugins.comments.uncomment = function (id) {
|
||||||
|
if (editor.readOnly) { return; }
|
||||||
|
editor.fire('saveSnapshot');
|
||||||
|
|
||||||
|
//Create style for this id
|
||||||
|
var style = new CKEDITOR.style({
|
||||||
|
element: 'comment',
|
||||||
|
attributes: {
|
||||||
|
'data-uid': id
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// Create range for the entire document
|
||||||
|
var range = editor.createRange();
|
||||||
|
range.selectNodeContents( editor.document.getBody() );
|
||||||
|
// Remove style for the document
|
||||||
|
style.removeFromRange(range, editor);
|
||||||
|
|
||||||
|
setTimeout( function() {
|
||||||
|
editor.fire('saveSnapshot');
|
||||||
|
}, 0 );
|
||||||
|
};
|
||||||
|
|
||||||
editor.addCommand('uncomment', {
|
editor.addCommand('uncomment', {
|
||||||
exec: function (editor, data) {
|
exec: function (editor, data) {
|
||||||
if (editor.readOnly) { return; }
|
if (editor.readOnly) { return; }
|
||||||
|
@ -83,24 +106,6 @@
|
||||||
}, 0 );
|
}, 0 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Uncomment provided element
|
|
||||||
|
|
||||||
//Create style for this id
|
|
||||||
var style = new CKEDITOR.style({
|
|
||||||
element: 'comment',
|
|
||||||
attributes: {
|
|
||||||
'data-uid': data.id
|
|
||||||
},
|
|
||||||
});
|
|
||||||
// Create range for the entire document
|
|
||||||
var range = editor.createRange();
|
|
||||||
range.selectNodeContents( editor.document.getBody() );
|
|
||||||
// Remove style for the document
|
|
||||||
style.removeFromRange(range, editor);
|
|
||||||
|
|
||||||
setTimeout( function() {
|
|
||||||
editor.fire('saveSnapshot');
|
|
||||||
}, 0 );
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -118,11 +118,16 @@ define([
|
||||||
if (e.which === 27) {
|
if (e.which === 27) {
|
||||||
$(cancel).click();
|
$(cancel).click();
|
||||||
}
|
}
|
||||||
if (e.which === 13 && e.ctrlKey) {
|
if (e.which === 13 && !e.shiftKey) {
|
||||||
$(submit).click();
|
$(submit).click();
|
||||||
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
$(textarea).focus();
|
||||||
|
});
|
||||||
|
|
||||||
return h('div.cp-comment-form' + (reply ? '.cp-comment-reply' : ''), [
|
return h('div.cp-comment-form' + (reply ? '.cp-comment-reply' : ''), [
|
||||||
h('div.cp-comment-form-input', [
|
h('div.cp-comment-form-input', [
|
||||||
avatar,
|
avatar,
|
||||||
|
@ -300,6 +305,11 @@ define([
|
||||||
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
|
||||||
|
var str = Env.$inner[0].innerHTML;
|
||||||
|
if (str === Env.oldCheck) { return; }
|
||||||
|
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].deleted;
|
return !Env.comments.data[id].deleted;
|
||||||
|
@ -318,8 +328,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) {
|
||||||
console.error(id, el);
|
Env.editor.plugins.comments.uncomment(id);
|
||||||
Env.editor.execCommand('uncomment', {id:id});
|
|
||||||
changed = true;
|
changed = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -383,6 +392,8 @@ sel.forEach(function (el) {
|
||||||
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();
|
||||||
|
|
||||||
if (!val) { return; }
|
if (!val) { return; }
|
||||||
if (!editor.getSelection().getSelectedText()) {
|
if (!editor.getSelection().getSelectedText()) {
|
||||||
// text has been deleted by another user while we were typing our comment?
|
// text has been deleted by another user while we were typing our comment?
|
||||||
|
@ -410,6 +421,7 @@ sel.forEach(function (el) {
|
||||||
var onContentUpdate = function (Env) {
|
var onContentUpdate = function (Env) {
|
||||||
if (!Env.ready) { return; }
|
if (!Env.ready) { return; }
|
||||||
// Check deleted
|
// Check deleted
|
||||||
|
onChange(Env);
|
||||||
checkDeleted(Env);
|
checkDeleted(Env);
|
||||||
};
|
};
|
||||||
var localChange = function (Env) {
|
var localChange = function (Env) {
|
||||||
|
|
Loading…
Reference in a new issue