From 4053c4c1a667d777af0980942a38b65e5583b451 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 25 Jun 2020 13:50:05 -0400 Subject: [PATCH] avoid displaying new comment while the document is not editable closes #570 --- www/pad/comments.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/www/pad/comments.js b/www/pad/comments.js index da98ceeb2..1e6f37259 100644 --- a/www/pad/comments.js +++ b/www/pad/comments.js @@ -747,6 +747,14 @@ define([ Env.$contentContainer.append(h('div.cp-comment-bubble', button)); }; + var isEditable = function (document) { + try { + return document.body.getAttribute('contenteditable') === 'true'; + } catch (err) { + return false; + } + }; + var addAddCommentHandler = function(Env) { Env.editor.plugins.comments.addComment = function(uid, addMark) { if (!Env.ready) { return; } @@ -809,7 +817,7 @@ define([ $(Env.ifrWindow.document).on('selectionchange', function() { removeCommentBubble(Env); var applicable = Env.editor.plugins.comments.isApplicable(); - if (!applicable) { return; } + if (!applicable || !isEditable(Env.ifrWindow.document)) { return; } addCommentBubble(Env); }); };