wip: extracting core cont'd - seems to be working
[fnpeditor.git] / src / smartxml / smartxml.js
index 2ed9c47..47c527f 100644 (file)
@@ -10,9 +10,6 @@ define([
 'use strict';
 /* globals Node */
 
-var TEXT_NODE = Node.TEXT_NODE;
-
-
 
 var DocumentNode = function(nativeNode, document) {
     if(!document) {
@@ -48,6 +45,10 @@ $.extend(DocumentNode.prototype, {
     },
 
     getPath: function(ancestor) {
+        if(!(this.document.containsNode(this))) {
+            return null;
+        }
+
         var nodePath = [this].concat(this.parents()),
             toret, idx;
         ancestor = ancestor || this.document.root;
@@ -235,8 +236,9 @@ var registerTransformation = function(desc, name, target) {
     var Transformation = transformations.createContextTransformation(desc, name);
     //+ to sie powinna nazywac registerTransformationFromDesc or sth
     //+ ew. spr czy nie override (tylko jesli powyzej sa prototypy to trudno do nich dojsc)
-    target[name] = function(args) {
-        var instance = this;
+    target[name] = function() {
+        var instance = this,
+            args = Array.prototype.slice.call(arguments, 0);
         return instance.transform(Transformation, args);
     }
 };
@@ -264,6 +266,8 @@ var Document = function(xml) {
     this._nodeTransformations = {};
     this._textNodeTransformations = {};
     this._elementNodeTransformations = {};
+    
+    this.registerExtension(coreTransformations);
 };
 
 $.extend(Document.prototype, Backbone.Events, {
@@ -298,8 +302,15 @@ $.extend(Document.prototype, Backbone.Events, {
         var toret = new Factory(from, this);
         _.extend(toret, this._nodeMethods);
         _.extend(toret, typeMethods);
+        
         _.extend(toret, this._nodeTransformations);
         _.extend(toret, typeTransformations);
+        
+        toret.__super__ = _.extend({}, this._nodeMethods, this._nodeTransformations);
+        _.keys(toret.__super__).forEach(function(key) {
+            toret.__super__[key] = _.bind(toret.__super__[key], toret);
+        });
+
         return toret;
     },
 
@@ -469,7 +480,6 @@ $.extend(Document.prototype, Backbone.Events, {
 return {
     documentFromXML: function(xml) {
         var doc = new Document(xml);
-        doc.registerExtension(coreTransformations);
         return doc;
     },