diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2024-12-09 12:32:47 +0000 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2024-12-09 13:34:40 +0100 |
| commit | f5b858ab2bf3f7fa005e67d30d2b47f0681e3de2 (patch) | |
| tree | bb76bf7f553c1bff78bb1e2698b2617ce9711df3 | |
| parent | 915d9af4531c364df241d1be3c433022ebbabdd4 (diff) | |
set wysiwyg editor to readonly mode when disabled or readonly attribute is set and let ir react to dynamic changes of these attributes, fixes #4979
Closes #4979
Merge request studip/studip!3738
| -rw-r--r-- | resources/assets/javascripts/lib/wysiwyg.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/resources/assets/javascripts/lib/wysiwyg.js b/resources/assets/javascripts/lib/wysiwyg.js index f9acb81..ca6a343 100644 --- a/resources/assets/javascripts/lib/wysiwyg.js +++ b/resources/assets/javascripts/lib/wysiwyg.js @@ -38,6 +38,27 @@ const wysiwyg = { export default wysiwyg; +const observeTextarea = (() => { + const observer = new MutationObserver(mutations => { + mutations.forEach(mutation => { + const editor = getEditor(mutation.target); + const disabledFromAttributes = mutation.target.matches('[readonly],[disabled]'); + const disabledFromEditor = editor.isReadOnly; + + if (disabledFromAttributes && !disabledFromEditor) { + editor.enableReadOnlyMode('studip'); + } else if (!disabledFromAttributes && disabledFromEditor) { + editor.disableReadOnlyMode('studip'); + } + }); + }); + + return textarea => observer.observe(textarea, { + attributes: true, + attributeFilter: ['disabled', 'readonly'], + }); +})(); + async function replaceTextarea(textarea) { if (hasEditor(textarea)) { return getEditor(textarea); @@ -53,6 +74,11 @@ async function replaceTextarea(textarea) { const editor = await createEditor(chunk, textarea, editorType, options); enhanceEditor($textarea, editor); + if ($textarea[0].matches('[readonly],[disabled]')) { + editor.enableReadOnlyMode('studip'); + } + observeTextarea($textarea[0]); + setEditor(textarea, editor); $textarea.trigger('load.wysiwyg'); |
