'use strict';
/* globals Node */
-var TEXT_NODE = Node.TEXT_NODE;
-
-
var DocumentNode = function(nativeNode, document) {
if(!document) {
},
getPath: function(ancestor) {
+ if(!(this.document.containsNode(this))) {
+ return null;
+ }
+
var nodePath = [this].concat(this.parents()),
toret, idx;
ancestor = ancestor || this.document.root;
this._nodeTransformations = {};
this._textNodeTransformations = {};
this._elementNodeTransformations = {};
+
+ this.registerExtension(coreTransformations);
};
$.extend(Document.prototype, Backbone.Events, {
transform: function(Transformation, args) {
//console.log('transform');
var toret, transformation;
+ //debugger;
// ref: odrebnie przygotowanie transformacji, odrebnie jej wykonanie (to pierwsze to analog transform z node)
}
if(transformation) {
this._transformationLevel++;
- toret = transformation.run();
- if(this._transformationLevel === 1) {
+ toret = transformation.run({beUndoable:this._transformationLevel === 1});
+ if(this._transformationLevel === 1 && !this._undoInProgress) {
this.undoStack.push(transformation);
}
this._transformationLevel--;
//console.log('clearing redo stack');
- this.redoStack = [];
+ if(!this._undoInProgress) {
+ this.redoStack = [];
+ }
return toret;
} else {
throw new Error('Transformation ' + transformation + ' doesn\'t exist!');
undo: function() {
var transformation = this.undoStack.pop();
if(transformation) {
+ this._undoInProgress = true;
transformation.undo();
+ this._undoInProgress = false;
this.redoStack.push(transformation);
}
},
redo: function() {
var transformation = this.redoStack.pop();
if(transformation) {
- transformation.run();
+ this._transformationLevel++;
+ transformation.run({beUndoable: true});
+ this._transformationLevel--;
this.undoStack.push(transformation);
+
}
},
return {
documentFromXML: function(xml) {
var doc = new Document(xml);
- doc.registerExtension(coreTransformations);
return doc;
},