Skip to content

Commit

Permalink
Added disablePlugins options. Fix bug in setEditorValue when value wa…
Browse files Browse the repository at this point in the history
…s set twice
  • Loading branch information
xdan committed Sep 28, 2017
1 parent 773cac6 commit 3a2a00a
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 544 deletions.
33 changes: 31 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
};
}
editor = new Jodit('#area_editor', {
// disablePlugins: ['source'],
// useAceEditor: false,
// theme: 'dark',
// textIcons: true,
Expand All @@ -89,7 +90,7 @@
height: 300,
// defaultMode: Jodit.MODE_SPLIT,
observer: {
timeout: 100
timeout: 0
},
uploader: {
url: 'https://xdsoft.net/jodit/connector/index.php?action=upload'
Expand Down Expand Up @@ -132,6 +133,34 @@
editor.editor.addEventListener('mouseup', callback)
editor.editor.addEventListener('input', callback);

editor.setEditorValue('<ul>' +
'<li>1</li>' +
'<li>2</li>' +
'<li>asd</li>' +
'</ul>');

editor.selection.focus();

var range = editor.doc.createRange();


// set cursor in start of element

range.setStartAfter(editor.editor.firstChild.lastChild.firstChild);
range.collapse(true);
editor.win.getSelection().removeAllRanges();
editor.win.getSelection().addRange(range);

// debugger
// simulateEvent('keydown', Jodit.KEY_ENTER, editor.editor);
//
// editor.selection.insertNode(editor.doc.createTextNode('split '));

// expect(editor.getEditorValue()).to.be.equal('<ul>' +
// '<li>1</li>' +
// '<li>2</li>' +
// '</ul>' + '<p>split <img src="https://xdsoft.net/jodit/images/artio.jpg"></p>');


// editor.setEditorValue('<table><tbody>' +
// '<tr><td>3</td></tr>' +
Expand All @@ -141,5 +170,5 @@
// var dialogs = document.querySelectorAll('.jodit.jodit_dialog_box.jodit_text_icons.active');
// expect(dialogs.length).toWYSIWYG.equal(1);

callback();
callback();
</script>
17 changes: 16 additions & 1 deletion src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,21 @@ export class Config {
*/
removeButtons: string[] = [];

/**
* Do not init these plugins
* @example
* ```typescript
* var editor = new Jodit('.editor', {
* disablePlugins: 'table,iframe'
* });
* //or
* var editor = new Jodit('.editor', {
* disablePlugins: ['table', 'iframe']
* });
* ```
*/
disablePlugins: string[]|string = [];

/**
* This buttons list will be added to option.buttons
*/
Expand Down Expand Up @@ -547,7 +562,7 @@ Config.prototype.controls = {
return ImageSelectorWidget(editor, {
filebrowser: (data: FileBrowserCallBcackData) => {
if (data.files && data.files.length) {
let i;
let i: number;
for (i = 0; i < data.files.length; i += 1) {
insertImage(data.baseurl + data.files[i]);
}
Expand Down
10 changes: 8 additions & 2 deletions src/Jodit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,14 @@ export default class Jodit extends Component{
__plugins: {[key: string]: JoditPlugin} = {};

initPlugines() {
const disable: string[] = Array.isArray(this.options.disablePlugins) ? this.options.disablePlugins.map((pluginName: string) => {
return pluginName.toLowerCase();
}) : this.options.disablePlugins.toLowerCase().split(/[\s,]+/);

Object.keys(Jodit.plugins).forEach((key: string) => {
this.__plugins[key] = new Jodit.plugins[key](this);
if (disable.indexOf(key.toLowerCase()) === -1) {
this.__plugins[key] = new Jodit.plugins[key](this);
}
})
}

Expand Down Expand Up @@ -450,7 +456,7 @@ export default class Jodit extends Component{
throw new Error('value must be string');
}

if (value !== undefined) {
if (value !== undefined && this.editor.innerHTML !== value) {
this.editor.innerHTML = value;
}

Expand Down
Loading

0 comments on commit 3a2a00a

Please sign in to comment.