X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/21cd91531dd9c6e88d00da03f6b2f3ad88fb0da0..471fbe0d1628d3f2baabd39e02a4e58f7d9bca5c:/src/smartxml/transformations.js diff --git a/src/smartxml/transformations.js b/src/smartxml/transformations.js index 25c0ec1..053ed10 100644 --- a/src/smartxml/transformations.js +++ b/src/smartxml/transformations.js @@ -90,9 +90,15 @@ toret.createGenericTransformation = function(desc, name) { run: function(options) { var changeRoot; if(!desc.undo && options.beUndoable) { - changeRoot = desc.getChangeRoot ? desc.getChangeRoot.call(this) : this.document.root; - this.snapshot = changeRoot.clone(); + changeRoot = this.getChangeRoot(); + if(!changeRoot) { + throw new Error( + 'Transformation {name} returned invalid change root value' + .replace('{name}', name) + ); + } 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); @@ -106,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;