mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
/**
|
|
* Creates an ve.es.Surface object.
|
|
*
|
|
* @class
|
|
* @constructor
|
|
* @param {jQuery} $container DOM Container to render surface into
|
|
* @param {ve.dm.Surface} model Surface model to view
|
|
*/
|
|
ve.es.Surface = function( $container, model ) {
|
|
// Inheritance
|
|
ve.EventEmitter.call( this );
|
|
|
|
// References for use in closures
|
|
var _this = this,
|
|
$document = $( document ),
|
|
$window = $( window );
|
|
|
|
// Properties
|
|
this.model = model;
|
|
this.documentView = new ve.es.DocumentNode( this.model.getDocument(), this );
|
|
this.contextView = null;
|
|
this.$ = $container
|
|
.addClass( 'es-surfaceView' )
|
|
.append( this.documentView.$ );
|
|
this.emitUpdateTimeout = undefined;
|
|
|
|
// Events
|
|
this.model.getDocument().on( 'update', function() {
|
|
_this.emitUpdate( 25 );
|
|
} );
|
|
|
|
// Initialization
|
|
this.documentView.renderContent();
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
ve.es.Surface.prototype.attachContextView = function( contextView ) {
|
|
this.contextView = contextView;
|
|
};
|
|
|
|
ve.es.Surface.prototype.getModel = function() {
|
|
return this.model;
|
|
};
|
|
|
|
ve.es.Surface.prototype.emitUpdate = function( delay ) {
|
|
if ( delay ) {
|
|
if ( this.emitUpdateTimeout !== undefined ) {
|
|
return;
|
|
}
|
|
var _this = this;
|
|
this.emitUpdateTimeout = setTimeout( function() {
|
|
_this.emit( 'update' );
|
|
_this.emitUpdateTimeout = undefined;
|
|
}, delay );
|
|
} else {
|
|
this.emit( 'update' );
|
|
}
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.extendClass( ve.es.Surface, ve.EventEmitter );
|