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 12:32:47 +0000 |
| commit | fe304be167d0306d9e5161ed504b107117b59841 (patch) | |
| tree | 398c5b201e9b70c40aacb8d36d71c05bcf905ff9 /resources | |
| parent | 8681967f770ff6beef0b4296bf372a3ee3fef9f0 (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
Diffstat (limited to 'resources')
| -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 09ad477..1cc90e0 100644 --- a/resources/assets/javascripts/lib/wysiwyg.js +++ b/resources/assets/javascripts/lib/wysiwyg.js @@ -39,6 +39,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); @@ -54,6 +75,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'); |
