2012-04-30 23:58:41 +00:00
|
|
|
/**
|
|
|
|
* Generic ContentEditable node.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.Node}
|
2012-05-05 00:50:54 +00:00
|
|
|
* @param {String} type Symbolic name of node type
|
2012-04-30 23:58:41 +00:00
|
|
|
* @param {ve.dm.Node} model Model to observe
|
2012-05-01 02:38:42 +00:00
|
|
|
* @param {jQuery} [$element] Element to use as a container
|
2012-04-30 23:58:41 +00:00
|
|
|
*/
|
2012-05-05 00:50:54 +00:00
|
|
|
ve.ce.Node = function( type, model, $element ) {
|
2012-04-30 23:58:41 +00:00
|
|
|
// Inheritance
|
2012-05-05 00:50:54 +00:00
|
|
|
ve.Node.call( this, type );
|
2012-04-30 23:58:41 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.model = model;
|
2012-05-01 02:38:42 +00:00
|
|
|
this.$ = $element || $( '<div></div>' );
|
2012-04-30 23:58:41 +00:00
|
|
|
this.parent = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2012-05-05 00:50:54 +00:00
|
|
|
/**
|
|
|
|
* Checks if this node can have child nodes.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {Boolean} Whether this node can have children
|
|
|
|
*/
|
|
|
|
ve.ce.Node.prototype.canHaveChildren = function() {
|
|
|
|
return ve.ce.factory.canNodeHaveChildren( this.type );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if this node can have child nodes which can also have child nodes.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {Boolean} Whether this node can have grandchildren
|
|
|
|
*/
|
|
|
|
ve.ce.Node.prototype.canHaveGrandchildren = function() {
|
|
|
|
return ve.ce.factory.canNodeHaveGrandchildren( this.type );
|
|
|
|
};
|
|
|
|
|
2012-04-30 23:58:41 +00:00
|
|
|
/**
|
|
|
|
* Gets a reference to the model this node observes.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {ve.dm.Node} Reference to the model this node observes
|
|
|
|
*/
|
|
|
|
ve.ce.Node.prototype.getModel = function() {
|
|
|
|
return this.model;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a reference to this node's parent.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {ve.ce.Node} Reference to this node's parent
|
|
|
|
*/
|
|
|
|
ve.ce.Node.prototype.getParent = function() {
|
|
|
|
return this.parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attaches node as a child to another node.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.ce.Node} parent Node to attach to
|
|
|
|
* @emits attach (parent)
|
|
|
|
*/
|
|
|
|
ve.ce.Node.prototype.attach = function( parent ) {
|
|
|
|
this.parent = parent;
|
|
|
|
this.emit( 'attach', parent );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detaches node from it's parent.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @emits detach (parent)
|
|
|
|
*/
|
|
|
|
ve.ce.Node.prototype.detach = function() {
|
|
|
|
var parent = this.parent;
|
|
|
|
this.parent = null;
|
|
|
|
this.emit( 'detach', parent );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.extendClass( ve.ce.Node, ve.Node );
|