2011-11-02 21:00:55 +00:00
|
|
|
/**
|
2012-02-06 23:50:56 +00:00
|
|
|
* Creates an ve.es.LeafNode 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.LeafNode}
|
|
|
|
* @extends {ve.es.Node}
|
|
|
|
* @param model {ve.ModelNode} Model to observe
|
2011-11-02 21:00:55 +00:00
|
|
|
* @param {jQuery} [$element] Element to use as a container
|
|
|
|
*/
|
2012-02-23 01:18:01 +00:00
|
|
|
ve.es.LeafNode = function( model, $element, options ) {
|
2011-11-02 21:00:55 +00:00
|
|
|
// Inheritance
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.LeafNode.call( this );
|
|
|
|
ve.es.Node.call( this, model, $element );
|
2011-11-02 21:00:55 +00:00
|
|
|
|
|
|
|
// Properties
|
2011-11-02 22:42:30 +00:00
|
|
|
this.$content = $( '<div class="es-contentView"></div>' ).appendTo( this.$ );
|
2012-02-23 01:18:01 +00:00
|
|
|
this.contentView = new ve.es.Content( this.$content, model, options );
|
2011-11-16 00:24:46 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.contentView.on( 'update', this.emitUpdate );
|
2011-11-02 21:00:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render content.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.LeafNode.prototype.renderContent = function() {
|
2011-11-02 21:00:55 +00:00
|
|
|
this.contentView.render();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw selection around a given range.
|
|
|
|
*
|
|
|
|
* @method
|
2012-02-06 23:50:56 +00:00
|
|
|
* @param {ve.Range} range Range of content to draw selection around
|
2011-11-02 21:00:55 +00:00
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.LeafNode.prototype.drawSelection = function( range ) {
|
2011-11-02 21:00:55 +00:00
|
|
|
this.contentView.drawSelection( range );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear selection.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.LeafNode.prototype.clearSelection = function() {
|
2011-11-02 21:00:55 +00:00
|
|
|
this.contentView.clearSelection();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the nearest offset of a rendered position.
|
|
|
|
*
|
|
|
|
* @method
|
2012-02-06 23:50:56 +00:00
|
|
|
* @param {ve.Position} position Position to get offset for
|
2011-11-02 21:00:55 +00:00
|
|
|
* @returns {Integer} Offset of position
|
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.LeafNode.prototype.getOffsetFromRenderedPosition = function( position ) {
|
2011-11-02 21:00:55 +00:00
|
|
|
return this.contentView.getOffsetFromRenderedPosition( position );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets rendered position of offset within content.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Integer} offset Offset to get position for
|
2012-02-06 23:50:56 +00:00
|
|
|
* @returns {ve.Position} Position of offset
|
2011-11-02 21:00:55 +00:00
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.LeafNode.prototype.getRenderedPositionFromOffset = function( offset, leftBias ) {
|
2011-11-02 21:00:55 +00:00
|
|
|
var position = this.contentView.getRenderedPositionFromOffset( offset, leftBias ),
|
2011-11-02 22:28:05 +00:00
|
|
|
contentPosition = this.$content.offset();
|
|
|
|
position.top += contentPosition.top;
|
|
|
|
position.left += contentPosition.left;
|
|
|
|
position.bottom += contentPosition.top;
|
2011-11-02 21:00:55 +00:00
|
|
|
return position;
|
|
|
|
};
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.LeafNode.prototype.getRenderedLineRangeFromOffset = function( offset ) {
|
2011-11-02 21:00:55 +00:00
|
|
|
return this.contentView.getRenderedLineRangeFromOffset( offset );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.extendClass( ve.es.LeafNode, ve.LeafNode );
|
|
|
|
ve.extendClass( ve.es.LeafNode, ve.es.Node );
|