diff --git a/customize.dist/ckeditor-config.js b/customize.dist/ckeditor-config.js index 5c4940c52..c55f5fe99 100644 --- a/customize.dist/ckeditor-config.js +++ b/customize.dist/ckeditor-config.js @@ -10,7 +10,7 @@ CKEDITOR.editorConfig = function( config ) { // document itself and causes problems when it's sent across the wire and reflected back config.removePlugins= 'resize,elementspath'; config.resize_enabled= false; //bottom-bar - config.extraPlugins= 'autolink,colorbutton,colordialog,font,indentblock,justify,mediatag,print,blockbase64,mathjax,wordcount'; + config.extraPlugins= 'autolink,colorbutton,colordialog,font,indentblock,justify,mediatag,print,blockbase64,mathjax,wordcount,comments'; config.toolbarGroups= [ // {"name":"clipboard","groups":["clipboard","undo"]}, //{"name":"editing","groups":["find","selection"]}, diff --git a/www/pad/comment.js b/www/pad/comment.js new file mode 100644 index 000000000..1bd184139 --- /dev/null +++ b/www/pad/comment.js @@ -0,0 +1,87 @@ +(function () { + + function isUnstylable (el) { + console.log(el); + console.log(el.getAttribute('contentEditable')); + console.log(el.getAttribute('data-nostyle')); + var b = el.getAttribute( 'contentEditable' ) == 'false' || + el.getAttribute( 'data-nostyle' ); + console.log(b); + return b; + } + + CKEDITOR.plugins.add('comments', { + //requires: 'dialog,widget', + //icons: 'image', + //hidpi: true, + onLoad: function () { + + /* + CKEDITOR.addCss( + 'media-tag *{' + + 'width:100%; height:100%;' + + '}'); + */ + }, + init: function (editor) { + var pluginName = 'comment'; + var Messages = CKEDITOR._commentsTranslations; // XXX + var targetWidget; + + var styles = {}; + + var styleDef = { + element: 'comment', + attributes: { + 'data-uid': '#(uid)' + }, + overrides: [ { + element: 'comment' + } ], + childRule: isUnstylable + }; + + // Register the command. + var removeStyle = new CKEDITOR.style(styleDef, { 'uid': '' }); + editor.addCommand(pluginName, { + exec: function (editor, data) { + if (editor.readOnly) { return; } + editor.focus(); + editor.fire('saveSnapshot'); + // XXX call cryptpad code here + Object.keys(styles).forEach(function (id) { + editor.removeStyle(styles[id]); + }); + var uid = CKEDITOR.tools.getUniqueId(); + styles[uid] = new CKEDITOR.style(styleDef, { 'uid': uid }); + editor.applyStyle(styles[uid]); + + //editor.removeStyle(removeStyle); // XXX to remove comment on the selection + //editor.plugins.comments.addComment(); + // Save the undo snapshot after all changes are affected. + setTimeout( function() { + editor.fire('saveSnapshot'); + }, 0 ); + } + }); + + + // Register the toolbar button. + editor.ui.addButton && editor.ui.addButton('UnComment', { + label: 'UNCOMMENT', + command: 'uncomment', + toolbar: 'insert,10' + }); + editor.ui.addButton && editor.ui.addButton('Comment', { + label: 'COMMENT', + command: pluginName, + icon : '/pad/icons/comment.png', + toolbar: 'insert,10' + }); + }, + afterInit: function (editor) { + editor.plugins.comments.removeComment = function () {}; + } + }); + +})(); diff --git a/www/pad/icons/comment.png b/www/pad/icons/comment.png new file mode 100644 index 000000000..02570ded8 Binary files /dev/null and b/www/pad/icons/comment.png differ diff --git a/www/pad/inner.js b/www/pad/inner.js index 632294f43..a5562af91 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -965,6 +965,7 @@ define([ }; Ckeditor.plugins.addExternal('mediatag','/pad/', 'mediatag-plugin.js'); Ckeditor.plugins.addExternal('blockbase64','/pad/', 'disable-base64.js'); + Ckeditor.plugins.addExternal('comments','/pad/', 'comment.js'); Ckeditor.plugins.addExternal('wordcount','/pad/wordcount/', 'plugin.js'); module.ckeditor = editor = Ckeditor.replace('editor1', { customConfig: '/customize/ckeditor-config.js', @@ -973,6 +974,9 @@ define([ }).nThen(function () { editor.plugins.mediatag.import = function ($mt) { framework._.sfCommon.importMediaTag($mt); + }; + editor.plugins.comments.addComment = function (uid, cb) { + }; Links.addSupportForOpeningLinksInNewTab(Ckeditor)({editor: editor}); }).nThen(function () {