2011-11-04 17:07:34 +00:00
|
|
|
/**
|
|
|
|
* Creates an es.DocumentNode object.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
|
|
|
* @constructor
|
|
|
|
* @extends {es.EventEmitter}
|
|
|
|
*/
|
|
|
|
es.DocumentNode = function() {
|
|
|
|
// Inheritance
|
|
|
|
es.EventEmitter.call( this );
|
|
|
|
|
|
|
|
// Reusable function for passing update events upstream
|
|
|
|
var _this = this;
|
|
|
|
this.emitUpdate = function() {
|
|
|
|
_this.emit( 'update' );
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the content length.
|
|
|
|
*
|
|
|
|
* @method
|
2011-11-10 19:26:02 +00:00
|
|
|
* @abstract
|
2011-11-04 17:07:34 +00:00
|
|
|
* @returns {Integer} Length of content
|
|
|
|
*/
|
|
|
|
es.DocumentNode.prototype.getContentLength = function() {
|
|
|
|
throw 'DocumentNode.getContentLength not implemented in this subclass:' + this.constructor;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the element length.
|
|
|
|
*
|
|
|
|
* @method
|
2011-11-10 19:26:02 +00:00
|
|
|
* @abstract
|
2011-11-04 17:07:34 +00:00
|
|
|
* @returns {Integer} Length of content
|
|
|
|
*/
|
|
|
|
es.DocumentNode.prototype.getElementLength = function() {
|
|
|
|
throw 'DocumentNode.getElementLength not implemented in this subclass:' + this.constructor;
|
|
|
|
};
|
|
|
|
|
2011-11-10 19:26:02 +00:00
|
|
|
/**
|
|
|
|
* Checks if this node has child nodes.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @abstract
|
|
|
|
* @returns {Boolean} Whether this node has children
|
|
|
|
*/
|
|
|
|
es.DocumentNode.prototype.hasChildren = function() {
|
|
|
|
throw 'DocumentNode.hasChildren not implemented in this subclass:' + this.constructor;
|
|
|
|
};
|
|
|
|
|
2011-11-18 05:18:48 +00:00
|
|
|
/**
|
|
|
|
* Traverse tree of nodes (model or view) upstream and for each traversed node call callback function passing traversed node as a parameter.
|
|
|
|
* Callback function is called for node passed as node paramter as well.
|
|
|
|
*
|
|
|
|
* @param {es.DocumentNode} node Node from which to start traversing
|
|
|
|
* @param {function} callback Callback method to be called for every traversed node
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
es.DocumentNode.traverseUpstream = function( node, callback ) {
|
|
|
|
while ( node ) {
|
|
|
|
if ( callback ( node ) === false ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
node = node.getParent();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-11-04 17:07:34 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2011-11-22 22:56:49 +00:00
|
|
|
es.extendClass( es.DocumentNode, es.EventEmitter );
|