X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e1f340cca43eafb33256f439cac74689d783f292..0c978bca67983e93096a8e744b53e50861a9333d:/src/smartxml/smartxml.js diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 4e8e575..7b59b18 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -383,6 +383,7 @@ $.extend(TextNode.prototype, { }, setText: function(text) { + console.log('smartxml: ' + text); this.nativeNode.data = text; this.triggerTextChangeEvent(); }, @@ -641,12 +642,14 @@ $.extend(Document.prototype, Backbone.Events, { }, transform: function(transformationName, args) { + console.log('transform'); var Transformation = transformations[transformationName], transformation; if(Transformation) { transformation = new Transformation(args); transformation.run(); this.undoStack.push(transformation); + console.log('clearing redo stack'); this.redoStack = []; } else { throw new Error('Transformation ' + transformationName + ' doesn\'t exist!'); @@ -769,7 +772,60 @@ $.extend(Detach2NodeTransformation.prototype, { this.document.getNodeByPath(this.rootPath).replaceWith(this.oldRoot); } }); -transformations['detach2'] = Detach2NodeTransformation; +//transformations['detach2'] = Detach2NodeTransformation; + +//2a. generyczna transformacja + +var createTransformation = function(desc) { + + var NodeTransformation = function(args) { + this.nodePath = args.node.getPath(); + this.document = args.node.document; + this.args = args; + }; + $.extend(NodeTransformation.prototype, { + run: function() { + var node = this.document.getNodeByPath(this.nodePath), + root; + + if(desc.getRoot) { + root = desc.getRoot(node); + } else { + root = this.document.root; + } + + this.rootPath = root.getPath(); + this.oldRoot = (root).clone(); + desc.impl.call(node, this.args); + }, + undo: function() { + this.document.getNodeByPath(this.rootPath).replaceWith(this.oldRoot); + } + }); + + return NodeTransformation; +} + +transformations['detach2'] = createTransformation({ + // impl: function() { + // //this.setAttr('class', 'cite'); // + // }, + impl: ElementNode.prototype.detach, + getRoot: function(node) { + return node.parent(); + } + +}); + +transformations['setText'] = createTransformation({ + impl: function(args) { + this.setText(args.text) + }, + getRoot: function(node) { + return node; + } + +}); //3. detach z pełnym własnym redo