Skip to content

Commit

Permalink
Fixed xdan#327
Browse files Browse the repository at this point in the history
  • Loading branch information
xdan committed Feb 9, 2020
1 parent 0e2aa37 commit c4c08fe
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
28 changes: 22 additions & 6 deletions src/Jodit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -80,6 +81,9 @@ export class Jodit extends ViewWithToolbar implements IJodit {
'text'
]);

/**
* HTML value
*/
get value(): string {
return this.getEditorValue();
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 **/
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1030,7 +1045,7 @@ export class Jodit extends ViewWithToolbar implements IJodit {
): void | Promise<any> {
const element = this.resolveElement(source);

if (!this.places.length) {
if (!this.isReady) {
this.id =
element.getAttribute('id') || new Date().getTime().toString();

Expand Down Expand Up @@ -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
};
Expand All @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/xpath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/types/jodit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface IWorkPlace {
iframe?: HTMLIFrameElement | void;
editorWindow: Window;
observer: Observer;
options: IViewOptions
}

interface IJodit extends IViewWithToolbar {
Expand Down
50 changes: 48 additions & 2 deletions test/tests/acceptance/toolbarTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

});
});
});
});

0 comments on commit c4c08fe

Please sign in to comment.