From f3e921d7a5ed76a1bdef6e563fccdd853f5299a4 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 24 Apr 2020 12:49:21 +0200 Subject: [PATCH] Comment from context menu --- www/pad/comment.js | 52 ++++++++++++++++++++++++++++++++++++---------- www/pad/inner.js | 4 ++++ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/www/pad/comment.js b/www/pad/comment.js index 7240b880d..ccab47a74 100644 --- a/www/pad/comment.js +++ b/www/pad/comment.js @@ -23,6 +23,7 @@ 'comment * { background-color: transparent !important; }'); }, init: function (editor) { + var Messages = CKEDITOR._commentsTranslations; var pluginName = 'comment'; var styleDef = { @@ -48,7 +49,7 @@ if (isComment) { return; } // We can't comment on empty text! - if (!editor.getSelection().getSelectedText()) { return; } + if (!editor.getSelection().getSelectedText()) { console.warn('there');return; } var uid = CKEDITOR.tools.getUniqueId(); editor.plugins.comments.addComment(uid, function () { @@ -104,12 +105,12 @@ }, 0 ); }; + // Uncomment from context menu, disabled for now... editor.addCommand('uncomment', { exec: function (editor, data) { if (editor.readOnly) { return; } editor.fire('saveSnapshot'); if (!data || !data.id) { - // XXX Uncomment the selection, remove on prod, only used for dev editor.focus(); editor.removeStyle(removeStyle); setTimeout( function() { @@ -121,22 +122,51 @@ }); // Register the toolbar button. - // XXX Uncomment selection, remove on prod, only used for dev - if (editor.ui.addButton) { - editor.ui.addButton('UnComment', { - label: 'UNCOMMENT', - command: 'uncomment', - toolbar: 'insert,10' - }); - } if (editor.ui.addButton) { editor.ui.addButton('Comment', { - label: 'COMMENT', + label: Messages.comment, command: 'comment', icon : '/pad/icons/comment.png', toolbar: 'insert,10' }); } + + if (editor.addMenuItems) { + editor.addMenuGroup('comments'); + editor.addMenuItem('comment', { + label: Messages.comment, + icon : '/pad/icons/comment.png', + command: 'comment', + group: 'comments' + }); + /* + editor.addMenuItem('uncomment', { + label: Messages.uncomment, + icon : '/pad/icons/uncomment.png', + command: 'uncomment', + group: 'comments' + }); + */ + } + if (editor.contextMenu) { + /* + editor.contextMenu.addListener(function (element, sel, path) { + var isComment = removeStyle.checkActive(path, editor); + if (!isComment) { return; } + return { + uncomment: CKEDITOR.TRISTATE_OFF, + }; + }); + */ + editor.contextMenu.addListener(function (element, sel, path) { + var applicable = removeStyle.checkApplicable(path, editor); + var empty = !sel.getSelectedText(); + if (!applicable || empty) { return; } + return { + comment: CKEDITOR.TRISTATE_OFF, + }; + }); + } } }); diff --git a/www/pad/inner.js b/www/pad/inner.js index 683b62b7e..a8fc98924 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -1007,6 +1007,10 @@ define([ 'import': Messages.pad_mediatagImport, options: Messages.pad_mediatagOptions }; + Messages.comments_comment = "COMMENT"; // XXX + Ckeditor._commentsTranslations = { + comment: Messages.comments_comment, + }; Ckeditor.plugins.addExternal('mediatag','/pad/', 'mediatag-plugin.js'); Ckeditor.plugins.addExternal('blockbase64','/pad/', 'disable-base64.js'); Ckeditor.plugins.addExternal('comments','/pad/', 'comment.js');