From 9a93c89991001d4ed088bee3b20cea374aa91d37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 24 Oct 2013 10:45:20 +0200 Subject: [PATCH] smartxml: changing TextNode text emits nodeTextChange event --- src/smartxml/smartxml.js | 8 ++++++++ src/smartxml/smartxml.test.js | 12 ++++++++++++ 2 files changed, 20 insertions(+) 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() { -- 2.20.1