From 7acbe4ba2c392342ca9a45f62db94ce067d0ec4d Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 8 Apr 2020 16:16:04 +0200 Subject: [PATCH] Comment plugin --- customize.dist/ckeditor-config.js | 2 +- www/pad/comment.js | 87 ++++++++++++++++++++++++++++++ www/pad/icons/comment.png | Bin 0 -> 3622 bytes www/pad/inner.js | 4 ++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 www/pad/comment.js create mode 100644 www/pad/icons/comment.png 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 0000000000000000000000000000000000000000..02570ded8a4176d5bd96121b5c6b0cb1af1e4cb2 GIT binary patch literal 3622 zcmbtX3sh5A7CkR{A&&qn(LqE-lYZ1#f6V94_fE^vNRoYa;M^Oes&N?TsMYA zY(Wnr`J;m5$F||1aO=F+=Lnl=#?=pgy4$M7xv%Gi1TNiH_pqTpxqhyvK*^oon=Puo zbv{e9V(H5>W4gM6#UH-NeLQogdfdXb!JgNP-(h!TBh>HtF(rKc8f=I>+|tIV_a{d; zyv0&5*EMAh1X%QUl`f@Y^pX_`^ z>(24GYT=vU37G+Mz80#7iMuLv`#9b3PeD~DjG~kvu@Wo&kh7Mi6#;9|&k#@}D$<++ znI&)tfe}}M9GEmEt>4G15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AuHROzaZJ zh1@A2x22EH<7KW>kUZrp@0^Y|5>qN17XgP;ug?~Q%U3_NRvN+c4Z?C z)k*C;vo&@niy>h9D42RDef)=!9lMHGu3G6Kv6Au{oTMx>noEQHBOXngPf3_!!~327 zM|&27_cx`Qu|FjvqLydM>D<$jOc8L?xX#Nh$-E$`fLr)c`1OKYM*p&9=bkh-(C!k; znC6#s*c%<(XB?8YOm-HE;!93$k8Wz?V=pl*chs>UPUFE$g2bxCjUp;-46&d}zMnvE zwM{cs_~mCCAQC` z^2cCfg)sPm;Swkyxai3Uh<(XIg^}#R0pjVF2BZlZZUfSSO|?+WL`-Hg-*=pbmRqQN z%qcWk?Z%lKXLplqyA0=-AXB`QBfB8YJG42spbXFI^oU=KdRedcQ0*ByD!YdYyNzsF z0a&M*ROdek*mC3T=j`RNGBep-#^mHctoJS_x>9F|F(4D9;K`k=90Qi+y{O^=r80YP x`9e;Z2$A(XW(U-K0T14wGiPDt{art-)Gq9$hn(FTG1pFj=FM3ck{hJT_&3x6+}!{G literal 0 HcmV?d00001 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 () {