diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 0906331f1..b7a0ac270 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -3,6 +3,7 @@ ## 3.3.22 ### BugFix * [#325](https://github.com/xdan/jodit/issues/325) +* [#327](https://github.com/xdan/jodit/issues/327) ### Feature * Added `Dom`.`isTag` method diff --git a/src/Config.ts b/src/Config.ts index 26f74214f..de60a2410 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -1154,3 +1154,7 @@ Config.prototype.controls = { tooltip: 'Insert youtube/vimeo video' } as IControlType }; + +export function configFactory(options?: object): Config { + return new OptionsDefault(options) as Config; +} diff --git a/src/Jodit.ts b/src/Jodit.ts index a3bdfcb03..6e6a6a1b8 100644 --- a/src/Jodit.ts +++ b/src/Jodit.ts @@ -4,9 +4,10 @@ * Copyright (c) 2013-2020 Valeriy Chupurnov. All rights reserved. https://xdsoft.net */ -import { Config, OptionsDefault } from './Config'; +import { Config, configFactory } from './Config'; import * as consts from './constants'; import { Dom } from './modules/Dom'; + import { asArray, css, @@ -80,6 +81,9 @@ export class Jodit extends ViewWithToolbar implements IJodit { 'text' ]); + /** + * HTML value + */ get value(): string { return this.getEditorValue(); } @@ -260,7 +264,13 @@ export class Jodit extends ViewWithToolbar implements IJodit { /** * options All Jodit settings default + second arguments of constructor */ - options: Config; + get options(): Config { + return this.currentPlace.options as Config; + } + + set options(opt: Config) { + this.setPlaceField('options', opt); + } /** * @property {Select} selection @@ -943,7 +953,7 @@ export class Jodit extends ViewWithToolbar implements IJodit { /** @override **/ protected initOptions(options?: object): void { - this.options = new OptionsDefault(options) as Config; + this.options = configFactory(options); } /** @override **/ @@ -990,6 +1000,11 @@ export class Jodit extends ViewWithToolbar implements IJodit { this.initPlugins(); + this.events.on('changePlace', () => { + this.setReadOnly(this.options.readonly); + this.setDisabled(this.options.disabled); + }); + this.places.length = 0; const addPlaceResult = this.addPlace(element, options); @@ -1030,7 +1045,7 @@ export class Jodit extends ViewWithToolbar implements IJodit { ): void | Promise { const element = this.resolveElement(source); - if (!this.places.length) { + if (!this.isReady) { this.id = element.getAttribute('id') || new Date().getTime().toString(); @@ -1125,6 +1140,7 @@ export class Jodit extends ViewWithToolbar implements IJodit { container, workplace, statusbar, + options: this.isReady ? configFactory(options) : this.options, observer: new Observer(this), editorWindow: this.ownerWindow }; @@ -1136,10 +1152,10 @@ export class Jodit extends ViewWithToolbar implements IJodit { this.setNativeEditorValue(this.getElementValue()); // Init value - const opt = this.options; - const initResult = this.initEditor(buffer); + const opt = this.options; + const init = () => { if ( opt.enableDragAndDropFileToEditor && diff --git a/src/plugins/placeholder.ts b/src/plugins/placeholder.ts index 9c21a5167..b24852624 100644 --- a/src/plugins/placeholder.ts +++ b/src/plugins/placeholder.ts @@ -117,7 +117,7 @@ export class placeholder extends Plugin { .off('.placeholder') .on( 'change.placeholder focus.placeholder keyup.placeholder mouseup.placeholder keydown.placeholder ' + - 'mousedown.placeholder afterSetMode.placeholder', + 'mousedown.placeholder afterSetMode.placeholder changePlace.placeholder', this.toggle ) .on(window, 'load', this.toggle); diff --git a/src/plugins/xpath.ts b/src/plugins/xpath.ts index 7e4a34422..150aeee62 100644 --- a/src/plugins/xpath.ts +++ b/src/plugins/xpath.ts @@ -206,6 +206,13 @@ export class xpath extends Plugin { .on( 'afterSetMode.xpath afterInit.xpath changePlace.xpath', () => { + console.log(this.jodit.id, this.jodit.events.current); + + if (!this.jodit.options.showXPathInStatusbar) { + return; + } + console.log(this.jodit.id, this.jodit.events.current); + this.jodit.statusbar.append(this.container); if (this.jodit.getRealMode() === MODE_WYSIWYG) { diff --git a/src/types/jodit.d.ts b/src/types/jodit.d.ts index a8252c205..5ed001860 100644 --- a/src/types/jodit.d.ts +++ b/src/types/jodit.d.ts @@ -21,6 +21,7 @@ interface IWorkPlace { iframe?: HTMLIFrameElement | void; editorWindow: Window; observer: Observer; + options: IViewOptions } interface IJodit extends IViewWithToolbar { diff --git a/test/tests/acceptance/toolbarTest.js b/test/tests/acceptance/toolbarTest.js index 3235e129e..858bc525a 100644 --- a/test/tests/acceptance/toolbarTest.js +++ b/test/tests/acceptance/toolbarTest.js @@ -2662,7 +2662,53 @@ describe('Toolbar', function() { expect(secondEditPlace.innerHTML).equals('second'); expect(thirdEditPlace.innerHTML).equals('third'); }); - }); - afterEach(removeStuff); + describe('For all instances you can set self options', function() { + it('Should change options for all instances', function() { + const toolbarBox = appendTestDiv(), + firstEditPlace = appendTestDiv('firstEditPlace'), + secondEditPlace = appendTestDiv('secondEditPlace'), + thirdEditPlace = appendTestDiv('thirdEditPlace'), + editor = Jodit.make(firstEditPlace); + + editor.setPanel(toolbarBox); + + editor.value = 'first'; + + editor.addPlace(secondEditPlace, { + "readonly": true, + "showCharsCounter": false, + "showWordsCounter": false, + "showXPathInStatusbar": false + }); + + editor.value = 'second'; + + editor.addPlace(thirdEditPlace, { + "readonly": false, + "showCharsCounter": false, + "showWordsCounter": false, + "showXPathInStatusbar": false + }); + + editor.value = 'third'; + + const editPlaces = editor.ownerDocument.querySelectorAll('.jodit_wysiwyg'); + expect(editPlaces.length).equals(3); + + editPlaces[0].focus(); + expect(editor.options.readonly).is.false; + expect(editor.options.showCharsCounter).is.true; + + editPlaces[1].focus(); + expect(editor.options.readonly).is.true; + expect(editor.options.showCharsCounter).is.false; + + editPlaces[2].focus(); + expect(editor.options.readonly).is.false; + expect(editor.options.showCharsCounter).is.false; + + }); + }); + }); });