2011-11-02 21:00:55 +00:00
|
|
|
/**
|
|
|
|
* Creates an es.DocumentViewNode object.
|
|
|
|
*
|
|
|
|
* @class
|
2011-11-03 21:48:40 +00:00
|
|
|
* @abstract
|
2011-11-02 21:00:55 +00:00
|
|
|
* @constructor
|
2011-11-14 19:50:28 +00:00
|
|
|
* @extends {es.DocumentNode}
|
2011-11-04 17:07:44 +00:00
|
|
|
* @param {es.DocumentModelNode} model Model to observe
|
|
|
|
* @param {jQuery} [$element=$( '<div></div>' )] Element to use as a container
|
2011-11-02 21:00:55 +00:00
|
|
|
*/
|
|
|
|
es.DocumentViewNode = function( model, $element ) {
|
|
|
|
// Inheritance
|
2011-11-04 17:07:44 +00:00
|
|
|
es.DocumentNode.call( this );
|
2011-11-02 21:00:55 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.model = model;
|
2011-11-04 17:07:44 +00:00
|
|
|
this.parent = null;
|
2011-11-02 21:00:55 +00:00
|
|
|
this.$ = $element || $( '<div/>' );
|
|
|
|
};
|
|
|
|
|
2011-11-04 17:07:44 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2011-11-02 21:00:55 +00:00
|
|
|
/**
|
2011-11-04 17:07:44 +00:00
|
|
|
* Gets the length of the element in the model.
|
2011-11-02 21:00:55 +00:00
|
|
|
*
|
|
|
|
* @method
|
2011-11-04 17:07:44 +00:00
|
|
|
* @see {es.DocumentNode.prototype.getElementLength}
|
|
|
|
* @returns {Integer} Length of content
|
2011-11-02 21:00:55 +00:00
|
|
|
*/
|
2011-11-04 17:07:44 +00:00
|
|
|
es.DocumentViewNode.prototype.getElementLength = function() {
|
|
|
|
return this.model.getElementLength();
|
2011-11-02 21:00:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2011-11-04 17:07:44 +00:00
|
|
|
* Gets the length of the content in the model.
|
2011-11-02 21:00:55 +00:00
|
|
|
*
|
|
|
|
* @method
|
2011-11-04 17:07:44 +00:00
|
|
|
* @see {es.DocumentNode.prototype.getContentLength}
|
|
|
|
* @returns {Integer} Length of content
|
2011-11-02 21:00:55 +00:00
|
|
|
*/
|
2011-11-04 17:07:44 +00:00
|
|
|
es.DocumentViewNode.prototype.getContentLength = function() {
|
|
|
|
return this.model.getContentLength();
|
2011-11-02 21:00:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attaches node as a child to another node.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {es.DocumentViewNode} parent Node to attach to
|
|
|
|
* @emits attach (parent)
|
|
|
|
*/
|
|
|
|
es.DocumentViewNode.prototype.attach = function( parent ) {
|
|
|
|
this.parent = parent;
|
|
|
|
this.emit( 'attach', parent );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detaches node from it's parent.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @emits detach (parent)
|
|
|
|
*/
|
|
|
|
es.DocumentViewNode.prototype.detach = function() {
|
|
|
|
var parent = this.parent;
|
|
|
|
this.parent = null;
|
|
|
|
this.emit( 'detach', parent );
|
|
|
|
};
|
|
|
|
|
2011-11-02 22:53:14 +00:00
|
|
|
/**
|
2011-11-04 17:07:44 +00:00
|
|
|
* Gets a reference to this node's parent.
|
2011-11-02 22:53:14 +00:00
|
|
|
*
|
|
|
|
* @method
|
2011-11-04 17:07:44 +00:00
|
|
|
* @returns {es.DocumentViewNode} Reference to this node's parent
|
2011-11-02 22:53:14 +00:00
|
|
|
*/
|
2011-11-04 17:07:44 +00:00
|
|
|
es.DocumentViewNode.prototype.getParent = function() {
|
|
|
|
return this.parent;
|
2011-11-02 22:53:14 +00:00
|
|
|
};
|
|
|
|
|
2011-11-02 22:55:02 +00:00
|
|
|
/**
|
2011-11-04 17:07:44 +00:00
|
|
|
* Gets a reference to the model this node observes.
|
2011-11-02 22:55:02 +00:00
|
|
|
*
|
|
|
|
* @method
|
2011-11-04 17:07:44 +00:00
|
|
|
* @returns {es.DocumentModelNode} Reference to the model this node observes
|
2011-11-02 22:55:02 +00:00
|
|
|
*/
|
2011-11-04 17:07:44 +00:00
|
|
|
es.DocumentViewNode.prototype.getModel = function() {
|
|
|
|
return this.model;
|
2011-11-02 22:53:14 +00:00
|
|
|
};
|
|
|
|
|
2011-11-02 21:00:55 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2011-11-04 17:07:44 +00:00
|
|
|
es.extendClass( es.DocumentViewNode, es.DocumentNode );
|