X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/6b6d2a8c7dfde855e81a9b02ca38f69d6dfb9440..becdfc02dc816d594bcad03cbcbab7aac550da5f:/src/smartxml/transformations.js?ds=inline diff --git a/src/smartxml/transformations.js b/src/smartxml/transformations.js index 3f4b65f..053ed10 100644 --- a/src/smartxml/transformations.js +++ b/src/smartxml/transformations.js @@ -90,19 +90,15 @@ toret.createGenericTransformation = function(desc, name) { run: function(options) { var changeRoot; if(!desc.undo && options.beUndoable) { - if(desc.getChangeRoot) { - changeRoot = desc.getChangeRoot.call(this); - if(!changeRoot) { - throw new Error( - 'Transformation {name} returned invalid change root value' - .replace('{name}', name) - ); - } - } else { - changeRoot = this.document.root; + changeRoot = this.getChangeRoot(); + if(!changeRoot) { + throw new Error( + 'Transformation {name} returned invalid change root value' + .replace('{name}', name) + ); } - this.snapshot = changeRoot.clone(); this.changeRootPath = changeRoot.getPath(); + this.snapshot = changeRoot.clone(); } var argsToPass = desc.undo ? [this].concat(this.args) : this.args; var toret = desc.impl.apply(this.context, argsToPass); @@ -116,6 +112,9 @@ toret.createGenericTransformation = function(desc, name) { this.document.getNodeByPath(this.changeRootPath).replaceWith(this.snapshot); } }, + getChangeRoot: desc.getChangeRoot || function() { + return this.document.root; + } }); return GenericTransformation;