Skip to content

Commit

Permalink
Fixed issue xdan/jodit#18
Browse files Browse the repository at this point in the history
  • Loading branch information
vinhtranchau committed Feb 10, 2018
1 parent c427e8f commit a8be766
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 26 deletions.
7 changes: 5 additions & 2 deletions src/modules/EventsNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class EventsNative {
* });
* ```
*/
current: string = '';
current: string[] = [];

private doc: Document = document;
constructor(doc?: Document){
Expand Down Expand Up @@ -474,15 +474,18 @@ export class EventsNative {
} else {
const blocks: EventHandlerBlock[] | void = store.get(event, namespace);
if (blocks) {
this.current = event;


try {
blocks.every((block: EventHandlerBlock): boolean => {
if (this.isStopped(blocks)) {
return false;
}

this.current.push(event);
result_value = block.syntheticCallback.apply(subject, argumentsList);
this.current.pop();

if (result_value !== undefined) {
result = result_value;
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/fullsize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export function fullsize(editor: Jodit) {
condition = !editor.container.classList.contains('jodit_fullsize');
}

editor.options.fullsize = !!condition;

shown = condition;

editor.container.classList.toggle('jodit_fullsize', condition);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ export class search extends Component {
}
})
.on('searchNext searchPrevious', () => {
return self.findAndSelect(editor.selection.current() || editor.editor.firstChild, self.queryInput.value, editor.events.current === 'searchNext');
return self.findAndSelect(editor.selection.current() || editor.editor.firstChild, self.queryInput.value, editor.events.current[editor.events.current.length - 1] === 'searchNext');
})
.on('search', (value: string, next: boolean = true) => {
editor.execCommand('search', value, next);
Expand Down
23 changes: 11 additions & 12 deletions src/plugins/size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import {Jodit} from "../Jodit";
import {css, dom, throttle} from "../modules/Helpers";
import {css, debounce, dom, throttle} from "../modules/Helpers";
import {Config} from '../Config'

declare module "../Config" {
Expand Down Expand Up @@ -55,11 +55,13 @@ export function size(editor: Jodit) {
});
}

const resizeWorkspace = () => {
css(editor.workplace, {
height: editor.container.offsetHeight - editor.toolbar.container.offsetHeight
});
};
const resizeWorkspace = debounce(() => {
if (editor.options.height !== 'auto' || editor.options.fullsize) {
css(editor.workplace, {
height: editor.container.offsetHeight - editor.toolbar.container.offsetHeight
});
}
}, editor.options.observer.timeout);

editor.events
.on('afterInit', () => {
Expand Down Expand Up @@ -94,11 +96,8 @@ export function size(editor: Jodit) {
width: editor.options.width,
});
}
}, undefined, undefined,true);
}, undefined, undefined,true)
.on(window, 'load', resizeWorkspace)
.on('afterInit resize updateToolbar scroll afterResize', resizeWorkspace)

if (editor.options.height !== 'auto') {
editor.events
.on(window, 'load', resizeWorkspace)
.on('afterInit resize updateToolbar scroll', resizeWorkspace)
}
}
47 changes: 36 additions & 11 deletions test/tests/editorTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,45 @@ describe('Jodit Editor Tests', function() {
simulateEvent('resize', 0, window);
expect(editor.container.offsetHeight).to.be.equal(300);
});
it('Should restore size after fullsized mode', function () {
var area = appendTestArea();
var editor = new Jodit(area, {
height: 300



describe('Fullsize mode', function () {
it('Should set heights of workplace to 100% - toolbar\'s height', function () {
var area = appendTestArea();
var editor = new Jodit(area, {
fullsize: true
});

expect(editor.workplace.offsetHeight).to.be.above(300);

});
editor.setEditorValue('<p>test</p>'.repeat(20))
expect(editor.container.offsetHeight).to.be.equal(300);
it('Should restore size after fullsized mode', function () {
var area = appendTestArea();
var editor = new Jodit(area, {
height: 300
});
editor.setEditorValue('<p>test</p>'.repeat(20))
expect(editor.container.offsetHeight).to.be.equal(300);

editor.events.fire('toggleFullsize', true);
expect(editor.container.offsetHeight).to.be.above(300);
editor.events.fire('toggleFullsize', true);
expect(editor.container.offsetHeight).to.be.above(300);

editor.events.fire('toggleFullsize', false);
expect(editor.container.offsetHeight).to.be.equal(300);
expect(editor.container.offsetWidth).to.be.above(300);
editor.events.fire('toggleFullsize', false);
expect(editor.container.offsetHeight).to.be.equal(300);
expect(editor.container.offsetWidth).to.be.above(300);
});

it('Should hide resizer', function () {
var area = appendTestArea();
var editor = new Jodit(area, {
height: 300,
iframe: true
});
expect(editor.container.querySelectorAll('.jodit_editor_resize').length).to.be.equal(1);
editor.events.fire('toggleFullsize', true);

});
});
it('Should add resize handle', function () {
var area = appendTestArea();
Expand Down

0 comments on commit a8be766

Please sign in to comment.