X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/324bfe12fcbabe4da96256dd98bc16da5be3ab82..a30654944f1af2db12a3fc1b7b1bfbd223f4f76c:/src/smartxml/smartxml.js diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 477166b..bac53af 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -1,6 +1,8 @@ define([ - 'libs/jquery' -], function($) { + 'libs/jquery', + 'libs/backbone', + 'smartxml/events' +], function($, Backbone, events) { 'use strict'; @@ -38,6 +40,11 @@ $.extend(DocumentNode.prototype, { } node.append(this); }, + + triggerChangeEvent: function(type, metaData) { + var event = new events.ChangeEvent(type, $.extend({node: this}, metaData || {})); + this.document.trigger('change', event); + }, }); var ElementNode = function(nativeNode, document) { @@ -74,7 +81,9 @@ $.extend(ElementNode.prototype, DocumentNode.prototype, { }, setAttr: function(name, value) { + var oldVal = this.getAttr(name); this._$.attr(name, value); + this.triggerChangeEvent('nodeAttrChange', {attr: name, oldVal: oldVal, newVal: value}); }, getAttrs: function() { @@ -178,7 +187,7 @@ var Document = function(xml) { return $document[0]; }}); }; -$.extend(Document.prototype, { +$.extend(Document.prototype, Backbone.Events, { ElementNodeFactory: ElementNode, TextNodeFactory: TextNode,