Skip to content

Commit 9f16c7c

Browse files
TINY-11911: Modified the behavior so that the 'disabled' option does not do anything with versions below 7.6
1 parent 0fe72cd commit 9f16c7c

File tree

1 file changed

+22
-35
lines changed

1 file changed

+22
-35
lines changed

src/main/ts/component/Editor.ts

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Resolve, Obj, Fun, Global } from '@ephox/katamari';
22
import { TinyMCE, Editor } from 'tinymce';
33
import { ScriptLoader } from '../utils/ScriptLoader';
4+
import { TinyVer } from '@tinymce/miniature';
45
type EditorOptions = Parameters<TinyMCE['init']>[0];
56
type EventHandler = Parameters<Editor['on']>[1];
67

@@ -80,10 +81,7 @@ const configRenames: Record<string, string> = {};
8081

8182
// Function that checks if the disabled option is supported with the version used
8283
const isDisabledOptionSupported = (tinymce: TinyMCE): boolean => {
83-
const major = parseFloat(tinymce.majorVersion);
84-
const minor = parseFloat(tinymce.minorVersion);
85-
const version = major + minor / 10;
86-
return version >= 7.6;
84+
return (!TinyVer.isLessThan(tinymce, '7.6.0'))
8785
};
8886

8987
class TinyMceEditor extends HTMLElement {
@@ -258,18 +256,11 @@ class TinyMceEditor extends HTMLElement {
258256
editor.on("init", (_e: unknown) => {
259257
const tinymce = this._getTinymce();
260258
const isDisableSupported = isDisabledOptionSupported(tinymce);
261-
if (isDisableSupported) {
262-
if (this.hasAttribute('readonly')) {
263-
this.setAttribute('readonly', '');
264-
} else {
265-
this.removeAttribute('readonly');
266-
}
267-
} else {
268-
if (!this.hasAttribute('disabled')) {
269-
this.setAttribute('disabled', '');
270-
} else {
271-
this.removeAttribute('disabled');
272-
}
259+
if (isDisableSupported && this.hasAttribute('disabled')) {
260+
editor.options.set('disabled', true);
261+
}
262+
if (this.hasAttribute('readonly')) {
263+
editor.options.set('readonly', true);
273264
}
274265
this._status = Status.Ready;
275266
});
@@ -358,46 +349,42 @@ class TinyMceEditor extends HTMLElement {
358349

359350
get readonly(): boolean {
360351
if (this._editor) {
361-
return this._editor.mode.get() === "readonly";
352+
return this._editor.mode.get() === 'readonly';
362353
} else {
363-
return this.hasAttribute("readonly");
354+
return this.hasAttribute('readonly');
364355
}
365356
}
366357

367358
set readonly(value: boolean) {
368359
if (value) {
369-
if (this._editor && this._editor.mode.get() !== "readonly") {
370-
this._editor.mode.set("readonly");
360+
if (this._editor && this._editor.mode.get() !== 'readonly') {
361+
this._editor.mode.set('readonly');
371362
}
372-
if (!this.hasAttribute("readonly")) {
373-
this.setAttribute("readonly", "");
363+
if (!this.hasAttribute('readonly')) {
364+
this.setAttribute('readonly', '');
374365
}
375366
} else {
376-
if (this._editor && this._editor.mode.get() === "readonly") {
377-
this._editor.mode.set("design");
367+
if (this._editor && this._editor.mode.get() === 'readonly') {
368+
this._editor.mode.set('design');
378369
}
379-
if (this.hasAttribute("readonly")) {
380-
this.removeAttribute("readonly");
370+
if (this.hasAttribute('readonly')) {
371+
this.removeAttribute('readonly');
381372
}
382373
}
383374
}
384375

385376
get disabled(): boolean {
386377
return this._editor
387-
? this._editor.options.get("disabled")
388-
: this.hasAttribute("disabled");
378+
? this._editor.options.get('disabled')
379+
: this.hasAttribute('disabled');
389380
}
390381

391382
set disabled(value: boolean) {
392383
const tinymce = this._getTinymce?.();
393-
const isNew = tinymce ? isDisabledOptionSupported(tinymce) : true;
384+
const isVersionNewer = tinymce ? isDisabledOptionSupported(tinymce) : true;
394385

395-
if (this._editor && this._status === Status.Ready) {
396-
if (isNew) {
397-
this._editor.options.set('disabled', value);
398-
} else {
399-
this._editor.mode.set(value ? 'readonly' : 'design');
400-
}
386+
if (this._editor && this._status === Status.Ready && isVersionNewer) {
387+
this._editor.options.set('disabled', value);
401388
}
402389

403390
if (value && !this.hasAttribute('disabled')) {

0 commit comments

Comments
 (0)