From fa16ce209454fc1dd160e0d18044335684210e2d Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 3 Jun 2020 15:42:16 -0400 Subject: [PATCH] disallow changing media-tag's attributes while in read-only mode --- www/pad/mediatag-plugin-dialog.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/www/pad/mediatag-plugin-dialog.js b/www/pad/mediatag-plugin-dialog.js index 472525edd..44503af9b 100644 --- a/www/pad/mediatag-plugin-dialog.js +++ b/www/pad/mediatag-plugin-dialog.js @@ -1,5 +1,19 @@ CKEDITOR.dialog.add('mediatag', function (editor) { var Messages = CKEDITOR._mediatagTranslations; + var isReadOnly = function (el) { + if (!el) { return; } + var parent = el; + while (parent) { + if (parent.nodeName.toUpperCase() === 'BODY') { + // I'm not sure why "false" is a string and not a boolean here + // but that's how it is and I'm scared to touch it + // --ansuz + return parent.getAttribute("contenteditable") === 'false'; + } + parent = parent.parentElement; + } + }; + return { title: Messages.title, minWidth: 400, @@ -118,6 +132,14 @@ CKEDITOR.dialog.add('mediatag', function (editor) { update(); }); + // disable all of the dialog's inputs if it is opened while in read-only mode + if (isReadOnly(element && element.$)) { + Array.prototype.slice.call(inputs).forEach(function (node) { + node.setAttribute('disabled', true); + }); + return; + } + setTimeout(update); }, onOk: function() {