editor: fix - check for success before changing current element
[fnpeditor.git] / src / wlxml / wlxml.js
index fe0636d..034312d 100644 (file)
@@ -17,10 +17,26 @@ AttributesList.prototype.keys = function() {
     return _.keys(this);
 };
 
+var getClassLists = function(klassName) {
+    var toret = [],
+        classParts = [''].concat(klassName.split('.')),
+        classCurrent;
+
+    classParts.forEach(function(part) {
+        classCurrent = classCurrent ? classCurrent + '.' + part : part;
+        toret.push(classCurrent);
+    });
+    return toret;
+};
+
 var installObject = function(instance, klass) {
-    var methods = instance.document.classMethods[klass] || {},
-        transformations = instance.document.classTransformations[klass] || {};
+    var methods = {},
+        transformations = {};
 
+    getClassLists(klass).forEach(function(klassName) {
+        _.extend(methods, instance.document.classMethods[klassName] || {});
+        _.extend(methods, instance.document.classTransformations[klassName] || {});
+    });
     instance.object = Object.create(_.extend({}, methods, transformations));
     _.keys(methods).concat(_.keys(transformations)).forEach(function(key) {
         instance.object[key] = _.bind(instance.object[key], instance);
@@ -281,8 +297,9 @@ $.extend(WLXMLDocument.prototype, {
 
     registerClassTransformation: function(Transformation, className) {
         var thisClassTransformations = (this.classTransformations[className] = this.classTransformations[className] || {});
-        thisClassTransformations[Transformation.prototype.name] = function(args) {
+        thisClassTransformations[Transformation.prototype.name] = function() {
             var nodeInstance = this;
+            var args = Array.prototype.slice.call(arguments, 0);
             return nodeInstance.transform(Transformation, args);
         };
     },
@@ -326,14 +343,17 @@ var wlxmlClasses = {
 
 
 return {
-    WLXMLDocumentFromXML: function(xml, options) {
+    WLXMLDocumentFromXML: function(xml, options, Factory) {
         options = _.extend({wlxmlClasses: wlxmlClasses}, options);
-        return new WLXMLDocument(xml, options);
+        Factory = Factory || WLXMLDocument;
+        return new Factory(xml, options);
     },
 
     WLXMLElementNodeFromXML: function(xml) {
         return this.WLXMLDocumentFromXML(xml).root;
-    }
+    },
+
+    WLXMLDocument: WLXMLDocument
 };
 
 });
\ No newline at end of file