2012-05-03 20:21:13 +00:00
|
|
|
/**
|
|
|
|
* DataModel surface.
|
2012-05-03 23:02:21 +00:00
|
|
|
*
|
2012-05-03 20:21:13 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
2012-05-03 23:02:21 +00:00
|
|
|
* @extends {ve.EventEmitter}
|
2012-05-03 20:21:13 +00:00
|
|
|
* @param {ve.dm.Document} doc Document model to create surface for
|
|
|
|
*/
|
|
|
|
ve.dm.Surface = function( doc ) {
|
2012-05-03 23:02:21 +00:00
|
|
|
// Inheritance
|
|
|
|
ve.EventEmitter.call( this );
|
2012-05-03 20:21:13 +00:00
|
|
|
// Properties
|
|
|
|
this.documentModel = doc;
|
2012-05-03 23:02:21 +00:00
|
|
|
this.selection = null;
|
2012-05-03 20:21:13 +00:00
|
|
|
};
|
2012-05-03 23:02:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the document model of the surface.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {ve.dm.DocumentNode} Document model of the surface
|
|
|
|
*/
|
|
|
|
ve.dm.Surface.prototype.getDocument = function() {
|
2012-05-04 22:20:14 +00:00
|
|
|
return this.documentModel;
|
2012-05-03 23:02:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the selection
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {ve.Range} Current selection
|
|
|
|
*/
|
|
|
|
ve.dm.Surface.prototype.getSelection = function() {
|
|
|
|
return this.selection;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the selection
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.Range} selection
|
|
|
|
*/
|
2012-05-04 22:29:47 +00:00
|
|
|
ve.dm.Surface.prototype.setSelection = function( selection ) {
|
2012-05-03 23:02:21 +00:00
|
|
|
selection.normalize();
|
2012-05-04 22:29:47 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
( !this.selection ) ||
|
|
|
|
( !this.selection.equals ( selection ) )
|
|
|
|
)
|
|
|
|
{
|
2012-05-03 23:02:21 +00:00
|
|
|
this.selection = selection;
|
2012-05-04 22:29:47 +00:00
|
|
|
this.emit ('select', this.selection.clone() );
|
|
|
|
}
|
2012-05-03 23:02:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies a series of transactions to the content data.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.Transaction} transactions Tranasction to apply to the document
|
|
|
|
*/
|
|
|
|
ve.dm.Surface.prototype.transact = function( transaction ) {
|
2012-05-04 22:29:47 +00:00
|
|
|
this.documentModel.commit( transaction );
|
2012-05-03 23:02:21 +00:00
|
|
|
this.emit( 'transact', transaction );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.extendClass( ve.dm.Surface, ve.EventEmitter );
|