From 73e8795a3d19b7221f34353799d39808d57a4d05 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 6 Dec 2013 15:55:39 +0100 Subject: [PATCH] wip: extracting core cont'd - seems to be working --- src/editor/modules/documentCanvas/canvas/canvas.js | 2 +- src/editor/modules/documentCanvas/commands.js | 3 ++- src/smartxml/core.js | 9 +++++---- src/smartxml/smartxml.js | 8 +++----- src/smartxml/smartxml.test.js | 4 +++- src/smartxml/transformations.js | 4 ++-- src/wlxml/extensions/list/list.js | 8 ++++---- 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index d13e2ea..01cb14e 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -39,7 +39,7 @@ $.extend(TextHandler.prototype, { }, setText: function(text, node) { //this.canvas.wlxmlDocument.transform('setText', {node:node, text: text}); - node.transform('smartxml.setText', {text: text}); + node.setText(text); } diff --git a/src/editor/modules/documentCanvas/commands.js b/src/editor/modules/documentCanvas/commands.js index df21cff..2801af8 100644 --- a/src/editor/modules/documentCanvas/commands.js +++ b/src/editor/modules/documentCanvas/commands.js @@ -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}), - 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}); diff --git a/src/smartxml/core.js b/src/smartxml/core.js index bab584e..dd472ce 100644 --- a/src/smartxml/core.js +++ b/src/smartxml/core.js @@ -3,7 +3,8 @@ define([ ], function() { 'use strict'; - +/* globals Node */ +var TEXT_NODE = Node.TEXT_NODE; var INSERTION = function(implementation) { var toret = function(node) { @@ -81,7 +82,7 @@ var elementNodeTransformations = { this.prev().appendText(next.getText()); next.detach(); } - return DocumentNode.prototype.detach.call(this); + return this.__super__.detach(); }, setTag: function(tagName) { @@ -210,7 +211,7 @@ var textNodeTransformations = { _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(); - defineDocumentProperties(this, insertion.ofNode._$); + this._defineDocumentProperties(insertion.ofNode._$); insertion.ofNode.triggerChangeEvent('nodeAdded'); return insertion.ofNode; } diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 6f12667..47c527f 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -10,9 +10,6 @@ define([ 'use strict'; /* globals Node */ -var TEXT_NODE = Node.TEXT_NODE; - - var DocumentNode = function(nativeNode, document) { if(!document) { @@ -51,7 +48,7 @@ $.extend(DocumentNode.prototype, { if(!(this.document.containsNode(this))) { return null; } - + 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.registerExtension(coreTransformations); }; $.extend(Document.prototype, Backbone.Events, { @@ -481,7 +480,6 @@ $.extend(Document.prototype, Backbone.Events, { return { documentFromXML: function(xml) { var doc = new Document(xml); - doc.registerExtension(coreTransformations); return doc; }, diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index 683e9b6..08598aa 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -769,7 +769,9 @@ describe('smartxml', function() { 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; }); }); diff --git a/src/smartxml/transformations.js b/src/smartxml/transformations.js index 5f0756c..a78c9c9 100644 --- a/src/smartxml/transformations.js +++ b/src/smartxml/transformations.js @@ -43,11 +43,11 @@ toret.createGenericTransformation = function(desc, name) { // 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() { - if(transformation.hasRun) { + if(transformation.hasRun && path) { return transformation.document.getNodeByPath(path); } else { return arg; diff --git a/src/wlxml/extensions/list/list.js b/src/wlxml/extensions/list/list.js index 6cac91b..02fe08d 100644 --- a/src/wlxml/extensions/list/list.js +++ b/src/wlxml/extensions/list/list.js @@ -65,10 +65,10 @@ extension.document.transformations.createList = { }); }, getChangeRoot: function() { - return this.args.node1.parent(); + return this.args[0].node1.parent(); }, 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() { - 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()); } }; -- 2.20.1