From: Aleksander Ɓukasz Date: Thu, 24 Oct 2013 08:45:20 +0000 (+0200) Subject: smartxml: changing TextNode text emits nodeTextChange event X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/9a93c89991001d4ed088bee3b20cea374aa91d37?ds=inline smartxml: changing TextNode text emits nodeTextChange event --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 53eefed..6e00a7d 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -211,14 +211,22 @@ $.extend(TextNode.prototype, DocumentNode.prototype, { setText: function(text) { this.nativeNode.data = text; + this.triggerTextChangeEvent(); }, appendText: function(text) { this.nativeNode.data = this.nativeNode.data + text; + this.triggerTextChangeEvent(); }, prependText: function(text) { this.nativeNode.data = text + this.nativeNode.data; + this.triggerTextChangeEvent(); + }, + + triggerTextChangeEvent: function() { + var event = new events.ChangeEvent('nodeTextChange', {node: this}); + this.document.trigger('change', event); } }); diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index b33ef1f..15fe394 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -166,6 +166,18 @@ describe('smartxml', function() { textNode.setText('Cat'); expect(textNode.getText()).to.equal('Cat'); }); + + it('emits nodeTextChange', function() { + var node = elementNodeFromXML('
Alice
'), + textNode = node.contents()[0], + spy = sinon.spy(); + + textNode.document.on('change', spy); + textNode.setText('Cat'); + + var event = spy.args[0][0]; + expect(event.type).to.equal('nodeTextChange'); + }); }); describe('Manipulations', function() {