wip: extracting core cont'd - seems to be working
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 6 Dec 2013 14:55:39 +0000 (15:55 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sun, 15 Dec 2013 21:32:48 +0000 (22:32 +0100)
src/editor/modules/documentCanvas/canvas/canvas.js
src/editor/modules/documentCanvas/commands.js
src/smartxml/core.js
src/smartxml/smartxml.js
src/smartxml/smartxml.test.js
src/smartxml/transformations.js
src/wlxml/extensions/list/list.js

index d13e2ea..01cb14e 100644 (file)
@@ -39,7 +39,7 @@ $.extend(TextHandler.prototype, {
     },
     setText: function(text, node) {
         //this.canvas.wlxmlDocument.transform('setText', {node:node, text: text});
     },
     setText: function(text, node) {
         //this.canvas.wlxmlDocument.transform('setText', {node:node, text: text});
-        node.transform('smartxml.setText', {text: text});
+        node.setText(text);
 
     }
 
 
     }
 
index df21cff..2801af8 100644 (file)
@@ -125,7 +125,8 @@ commands.register('newNodeRequested', function(canvas, params) {
                 var wlxmlNode = selectionStart.element.data('wlxmlNode'),
                     caretTo = selectionStart.offset < selectionEnd.offset ? 'start' : 'end',
                     //wrapper = wlxmlNode.wrapWith({tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}, start: selectionStart.offset, end: selectionEnd.offset}),
                 var wlxmlNode = selectionStart.element.data('wlxmlNode'),
                     caretTo = selectionStart.offset < selectionEnd.offset ? 'start' : 'end',
                     //wrapper = wlxmlNode.wrapWith({tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}, start: selectionStart.offset, end: selectionEnd.offset}),
-                    wrapper = wlxmlNode.transform('smartxml.wrapWith', {tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}, start: selectionStart.offset, end: selectionEnd.offset})
+                    //wrapper = wlxmlNode.transform('smartxml.wrapWith', {tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}, start: selectionStart.offset, end: selectionEnd.offset})
+                    wrapper = wlxmlNode.wrapWith({tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}, start: selectionStart.offset, end: selectionEnd.offset});
                     ;
                 var wrapperCanvasElement = utils.findCanvasElement(wrapper);
                 canvas.setCurrentElement(wrapperCanvasElement.children()[0], {caretTo: caretTo});
                     ;
                 var wrapperCanvasElement = utils.findCanvasElement(wrapper);
                 canvas.setCurrentElement(wrapperCanvasElement.children()[0], {caretTo: caretTo});
index bab584e..dd472ce 100644 (file)
@@ -3,7 +3,8 @@ define([
 ], function() {
     
 'use strict';
 ], function() {
     
 'use strict';
-
+/* globals Node */
+var TEXT_NODE = Node.TEXT_NODE;
 
 var INSERTION = function(implementation) {
     var toret = function(node) {
 
 var INSERTION = function(implementation) {
     var toret = function(node) {
@@ -81,7 +82,7 @@ var elementNodeTransformations = {
             this.prev().appendText(next.getText());
             next.detach();
         }
             this.prev().appendText(next.getText());
             next.detach();
         }
-        return DocumentNode.prototype.detach.call(this);
+        return this.__super__.detach();
     },
 
     setTag: function(tagName) {
     },
 
     setTag: function(tagName) {
@@ -210,7 +211,7 @@ var textNodeTransformations = {
                 _with: {tagName: desc.tagName, attrs: desc.attrs}
             });
         } else {
                 _with: {tagName: desc.tagName, attrs: desc.attrs}
             });
         } else {
-            return DocumentNode.prototype.wrapWith.call(this, desc);
+            return this.__super__.wrapWith.call(this, desc);
         }
     },
 
         }
     },
 
@@ -342,7 +343,7 @@ var documentTransformations = {
     replaceRoot: function(node) {
         var insertion = this.getNodeInsertion(node);
         this.root.detach();
     replaceRoot: function(node) {
         var insertion = this.getNodeInsertion(node);
         this.root.detach();
-        defineDocumentProperties(this, insertion.ofNode._$);
+        this._defineDocumentProperties(insertion.ofNode._$);
         insertion.ofNode.triggerChangeEvent('nodeAdded');
         return insertion.ofNode;
     }
         insertion.ofNode.triggerChangeEvent('nodeAdded');
         return insertion.ofNode;
     }
index 6f12667..47c527f 100644 (file)
@@ -10,9 +10,6 @@ define([
 'use strict';
 /* globals Node */
 
 'use strict';
 /* globals Node */
 
-var TEXT_NODE = Node.TEXT_NODE;
-
-
 
 var DocumentNode = function(nativeNode, document) {
     if(!document) {
 
 var DocumentNode = function(nativeNode, document) {
     if(!document) {
@@ -51,7 +48,7 @@ $.extend(DocumentNode.prototype, {
         if(!(this.document.containsNode(this))) {
             return null;
         }
         if(!(this.document.containsNode(this))) {
             return null;
         }
-        
+
         var nodePath = [this].concat(this.parents()),
             toret, idx;
         ancestor = ancestor || this.document.root;
         var nodePath = [this].concat(this.parents()),
             toret, idx;
         ancestor = ancestor || this.document.root;
@@ -269,6 +266,8 @@ var Document = function(xml) {
     this._nodeTransformations = {};
     this._textNodeTransformations = {};
     this._elementNodeTransformations = {};
     this._nodeTransformations = {};
     this._textNodeTransformations = {};
     this._elementNodeTransformations = {};
+    
+    this.registerExtension(coreTransformations);
 };
 
 $.extend(Document.prototype, Backbone.Events, {
 };
 
 $.extend(Document.prototype, Backbone.Events, {
@@ -481,7 +480,6 @@ $.extend(Document.prototype, Backbone.Events, {
 return {
     documentFromXML: function(xml) {
         var doc = new Document(xml);
 return {
     documentFromXML: function(xml) {
         var doc = new Document(xml);
-        doc.registerExtension(coreTransformations);
         return doc;
     },
 
         return doc;
     },
 
index 683e9b6..08598aa 100644 (file)
@@ -769,7 +769,9 @@ describe('smartxml', function() {
                     c = b.contents()[0];
 
                 var parents = c.parents();
                     c = b.contents()[0];
 
                 var parents = c.parents();
-                expect(parents).to.eql([b,a]);
+                // @@
+                expect(parents[0].sameNode(b)).to.be.true;
+                expect(parents[1].sameNode(a)).to.be.true;
             });
         });
 
             });
         });
 
index 5f0756c..a78c9c9 100644 (file)
@@ -43,11 +43,11 @@ toret.createGenericTransformation = function(desc, name) {
 
         // potem spr na dotychczasowych undo/redo tests;
         this.args.forEach(function(arg, idx, args) {
 
         // potem spr na dotychczasowych undo/redo tests;
         this.args.forEach(function(arg, idx, args) {
-            if(arg.nodeType) { // ~
+            if(arg && arg.nodeType) { // ~
                 var path = arg.getPath();
                 Object.defineProperty(args, idx, {
                     get: function() {
                 var path = arg.getPath();
                 Object.defineProperty(args, idx, {
                     get: function() {
-                        if(transformation.hasRun) {
+                        if(transformation.hasRun && path) {
                             return transformation.document.getNodeByPath(path);
                         } else {
                             return arg;
                             return transformation.document.getNodeByPath(path);
                         } else {
                             return arg;
index 6cac91b..02fe08d 100644 (file)
@@ -65,10 +65,10 @@ extension.document.transformations.createList = {
         });
     },
     getChangeRoot: function() {
         });
     },
     getChangeRoot: function() {
-        return this.args.node1.parent();
+        return this.args[0].node1.parent();
     },
     isAllowed: function() {
     },
     isAllowed: function() {
-        return this.args.node1.parent().sameNode(this.args.node2.parent());
+        return this.args[0].node1.parent().sameNode(this.args[0].node2.parent());
     }
 };
 
     }
 };
 
@@ -140,8 +140,8 @@ extension.document.transformations.extractItems = {
         return true;
     },
     isAllowed: function() {
         return true;
     },
     isAllowed: function() {
-        var parent = this.args.nodel1.parent();
-        return parent.is('list') && parent.sameNode(this.args.node2.parent());
+        var parent = this.args[0].nodel1.parent();
+        return parent.is('list') && parent.sameNode(this.args[0].node2.parent());
     }
 };
 
     }
 };