diff --git a/spec/core-api.spec.js b/spec/core-api.spec.js index d9181b926..cddfb672f 100644 --- a/spec/core-api.spec.js +++ b/spec/core-api.spec.js @@ -1,4 +1,5 @@ -/*global fireEvent, selectElementContents */ +/*global fireEvent, selectElementContents, + selectElementContentsAndFire */ describe('Core-API', function () { 'use strict'; @@ -101,4 +102,49 @@ describe('Core-API', function () { expect(exportedSelection.editableElementIndex).toEqual(1); }); }); + + describe('checkContentChanged', function () { + it('should trigger editableInput when called after the html has changed', function () { + var editor = this.newMediumEditor('.editor', { + toolbar: { + buttons: ['italic', 'underline', 'strikethrough'] + } + }), + spy = jasmine.createSpy('handler'); + + editor.subscribe('editableInput', spy); + expect(spy).not.toHaveBeenCalled(); + + selectElementContentsAndFire(this.el.firstChild); + jasmine.clock().tick(1); + + this.el.innerHTML = 'lorem ipsum'; + expect(spy).not.toHaveBeenCalled(); + + var obj = { target: this.el, currentTarget: this.el }; + editor.checkContentChanged(); + expect(spy).toHaveBeenCalledWith(obj, this.el); + }); + + it('should not trigger editableInput when called after the html has not changed', function () { + var editor = this.newMediumEditor('.editor', { + toolbar: { + buttons: ['italic', 'underline', 'strikethrough'] + } + }), + spy = jasmine.createSpy('handler'); + + editor.subscribe('editableInput', spy); + expect(spy).not.toHaveBeenCalled(); + + selectElementContentsAndFire(this.el.firstChild); + jasmine.clock().tick(1); + + this.el.innerHTML = 'lore ipsum'; + expect(spy).not.toHaveBeenCalled(); + + editor.checkContentChanged(); + expect(spy).not.toHaveBeenCalled(); + }); + }); }); diff --git a/src/js/core.js b/src/js/core.js index af8c0929a..3a10c8415 100644 --- a/src/js/core.js +++ b/src/js/core.js @@ -1103,7 +1103,7 @@ }, checkContentChanged: function (editable) { - editable = editable || MediumEditor.selection.getSelectionElement(this.window); + editable = editable || MediumEditor.selection.getSelectionElement(this.options.contentWindow); this.events.updateInput(editable, { target: editable, currentTarget: editable }); } };