'use strict';
/* globals Node */
-var TEXT_NODE = Node.TEXT_NODE;
-
-
var DocumentNode = function(nativeNode, document) {
if(!document) {
},
getPath: function(ancestor) {
+ if(!(this.document.containsNode(this))) {
+ return null;
+ }
+
var nodePath = [this].concat(this.parents()),
toret, idx;
ancestor = ancestor || this.document.root;
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);
}
};
this._nodeTransformations = {};
this._textNodeTransformations = {};
this._elementNodeTransformations = {};
+
+ this.registerExtension(coreTransformations);
};
$.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;
},
loadXML: function(xml, options) {
options = options || {};
- defineDocumentProperties(this, $(parseXML(xml)));
+ this._defineDocumentProperties($(parseXML(xml)));
if(!options.silent) {
this.trigger('contentSet');
}
toret = toret.contents()[idx];
});
return toret;
+ },
+
+ _defineDocumentProperties: function($document) {
+ var doc = this;
+ Object.defineProperty(doc, 'root', {get: function() {
+ return doc.createDocumentNode($document[0]);
+ }, configurable: true});
+ Object.defineProperty(doc, 'dom', {get: function() {
+ return $document[0];
+ }, configurable: true});
}
});
-var defineDocumentProperties = function(doc, $document) {
- Object.defineProperty(doc, 'root', {get: function() {
- return doc.createDocumentNode($document[0]);
- }, configurable: true});
- Object.defineProperty(doc, 'dom', {get: function() {
- return $document[0];
- }, configurable: true});
-};
-
return {
documentFromXML: function(xml) {
var doc = new Document(xml);
- doc.registerExtension(coreTransformations);
return doc;
},