2011-11-02 21:00:55 +00:00
|
|
|
/**
|
2012-02-06 23:50:56 +00:00
|
|
|
* Creates an ve.es.Node object.
|
2011-11-02 21:00:55 +00:00
|
|
|
*
|
|
|
|
* @class
|
2011-11-03 21:48:40 +00:00
|
|
|
* @abstract
|
2011-11-02 21:00:55 +00:00
|
|
|
* @constructor
|
2012-02-06 23:50:56 +00:00
|
|
|
* @extends {ve.Node}
|
|
|
|
* @param {ve.dm.Node} model Model to observe
|
2011-11-04 17:07:44 +00:00
|
|
|
* @param {jQuery} [$element=$( '<div></div>' )] Element to use as a container
|
2011-11-02 21:00:55 +00:00
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.Node = function( model, $element ) {
|
2011-11-02 21:00:55 +00:00
|
|
|
// Inheritance
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.Node.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
|
2012-02-06 23:50:56 +00:00
|
|
|
* @see {ve.Node.prototype.getElementLength}
|
2011-11-04 17:07:44 +00:00
|
|
|
* @returns {Integer} Length of content
|
2011-11-02 21:00:55 +00:00
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.Node.prototype.getElementLength = function() {
|
2011-11-04 17:07:44 +00:00
|
|
|
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
|
2012-02-06 23:50:56 +00:00
|
|
|
* @see {ve.Node.prototype.getContentLength}
|
2011-11-04 17:07:44 +00:00
|
|
|
* @returns {Integer} Length of content
|
2011-11-02 21:00:55 +00:00
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.Node.prototype.getContentLength = function() {
|
2011-11-04 17:07:44 +00:00
|
|
|
return this.model.getContentLength();
|
2011-11-02 21:00:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attaches node as a child to another node.
|
|
|
|
*
|
|
|
|
* @method
|
2012-02-06 23:50:56 +00:00
|
|
|
* @param {ve.es.Node} parent Node to attach to
|
2011-11-02 21:00:55 +00:00
|
|
|
* @emits attach (parent)
|
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.Node.prototype.attach = function( parent ) {
|
2011-11-02 21:00:55 +00:00
|
|
|
this.parent = parent;
|
|
|
|
this.emit( 'attach', parent );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detaches node from it's parent.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @emits detach (parent)
|
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.Node.prototype.detach = function() {
|
2011-11-02 21:00:55 +00:00
|
|
|
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
|
2012-02-06 23:50:56 +00:00
|
|
|
* @returns {ve.es.Node} Reference to this node's parent
|
2011-11-02 22:53:14 +00:00
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.Node.prototype.getParent = function() {
|
2011-11-04 17:07:44 +00:00
|
|
|
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
|
2012-02-06 23:50:56 +00:00
|
|
|
* @returns {ve.dm.Node} Reference to the model this node observes
|
2011-11-02 22:55:02 +00:00
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.Node.prototype.getModel = function() {
|
2011-11-04 17:07:44 +00:00
|
|
|
return this.model;
|
2011-11-02 22:53:14 +00:00
|
|
|
};
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.Node.getSplitableNode = function( node ) {
|
2011-11-18 06:49:00 +00:00
|
|
|
var splitableNode = null;
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.Node.traverseUpstream( node, function( node ) {
|
2011-11-18 06:49:00 +00:00
|
|
|
var elementType = node.model.getElementType();
|
2012-02-07 01:11:32 +00:00
|
|
|
if ( splitableNode != null && ve.es.DocumentNode.splitRules[ elementType ].children === true ) {
|
2011-11-18 06:49:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-02-07 01:11:32 +00:00
|
|
|
splitableNode = ve.es.DocumentNode.splitRules[ elementType ].self ? node : null
|
2011-11-18 06:49:00 +00:00
|
|
|
} );
|
|
|
|
return splitableNode;
|
|
|
|
};
|
|
|
|
|
2011-11-02 21:00:55 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.extendClass( ve.es.Node, ve.Node );
|