/* globals Node */
+var WLXMLDocumentNodeMethods = {
+ isInside: function(klass) {
+ var parent = this.getParent(klass);
+ return !!parent;
+ },
+ getParent: function(klass) {
+ /* globals Node */
+ var me = this.nodeType === Node.ELEMENT_NODE ? [this] : [],
+ toret;
+ me.concat(this.parents()).some(function(node) {
+ if(node.is(klass)) {
+ toret = node;
+ return true;
+ }
+ });
+ return toret;
+ },
+};
+
var AttributesList = function() {};
AttributesList.prototype = Object.create({});
AttributesList.prototype.keys = function() {
};
WLXMLElementNode.prototype = Object.create(smartxml.ElementNode.prototype);
-$.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, {
+$.extend(WLXMLElementNode.prototype, WLXMLDocumentNodeMethods, smartxml.ElementNode.prototype, {
getClass: function() {
return this.getAttr('class') || '';
},
};
WLXMLDocumentNode.prototype = Object.create(smartxml.DocumentNode.prototype);
+
+var WLXMLTextNode = function() {
+ smartxml.TextNode.apply(this, arguments);
+};
+WLXMLTextNode.prototype = Object.create(smartxml.TextNode.prototype);
+$.extend(WLXMLTextNode.prototype, WLXMLDocumentNodeMethods);
+
var WLXMLDocument = function(xml, options) {
this.classMethods = {};
this.classTransformations = {};
WLXMLDocument.prototype = Object.create(smartxml.Document.prototype);
$.extend(WLXMLDocument.prototype, {
ElementNodeFactory: WLXMLElementNode,
+ TextNodeFactory: WLXMLTextNode,
loadXML: function(xml) {
smartxml.Document.prototype.loadXML.call(this, xml, {silent: true});
this.trigger('contentSet');
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);
};
},
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