-contextTransformations['split'] = createContextTransformation({
- impl: function(args) {
- return this.split({offset: args.offset});
- }//,
- // getChangeRoot: function() {
- // return this.context.parent().parent();
- // }
-});
-
-// var TRANSFORMATION2 = function(f, getChangeRoot, undo) {
-// var context = this,
-
-
-// var transformation = createContextTransformation({
-// impl: f,
-// getChangeRoot: getChangeRoot,
-
-// });
-
-// var toret = function() {
-// var
-// f.apply(context, createArgs ? createArgs(arguments) : arguments)
-// };
-// return toret;
-// }
-
-transformations['detach2'] = createTransformation({
- // impl: function() {
- // //this.setAttr('class', 'cite'); //
- // },
- impl: ElementNode.prototype.detach,
- getRoot: function(node) {
- return node.parent();
- }
-
-});
-
-transformations['setText-old'] = createTransformation({
- impl: function(args) {
- this.setText(args.text)
- },
- getRoot: function(node) {
- return node;
- }
-
-});
-
-transformations['setClass-old'] = createTransformation({
- impl: function(args) {
- this.setClass(args.klass);
- },
- getRoot: function(node) {
- return node;
- }
-})
-
-//3. detach z pełnym własnym redo
-
-var Detach3NodeTransformation = function(args) {
- this.node = args.node;
- this.document = this.node.document;
-};
-$.extend(Detach3NodeTransformation.prototype, {
- run: function() {
- //this.index = this.node.getIndex();
- //this.parent = this.node.parent();
-
- this.path = this.node.getPath();
- if(this.node.isSurroundedByTextElements()) {
- this.prevText = this.node.prev().getText();
- this.nextText = this.node.next().getText();
- this.merge = true;
- } else {
- this.prevText = this.nextText = null;
- this.merge = false;
- }
-
- this.node.detach();
- },
- undo: function() {
- var parent = this.document.getNodeByPath(this.path.slice(0,-1)),
- idx = _.last(this.path);
- var inserted = parent.insertAtIndex(this.node, idx);
- if(this.merge) {
- if(inserted.next()) {
- inserted.before({text: this.prevText});
- inserted.next().setText(this.nextText);
- } else {
- inserted.prev().setText(this.prevText);
- inserted.after({text: this.nextText});
- }
- }
- }
-});
-transformations['detach3'] = Detach3NodeTransformation;
-
-
-var registerTransformationsFromObject = function(object) {
- _.pairs(object).filter(function(pair) {
- var property = pair[1];
- return typeof property === 'function' && property._isTransformation;
- })
- .forEach(function(pair) {
- var name = pair[0],
- method = pair[1];
- object.registerTransformation(name, createContextTransformation(method));
- });
-};
-registerTransformationsFromObject(ElementNode.prototype);
-registerTransformationsFromObject(TextNode.prototype);
-registerTransformationsFromObject(Document.prototype);