mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
- extend surface model and surface view with event emitter
- added surface view base methods - enabled toolbar in ve.Surface Change-Id: Ib6a62ef2509712f812f262283c45bb30c8f97ef1
This commit is contained in:
parent
4e8a9d75ea
commit
da65ad48c8
|
@ -275,6 +275,6 @@
|
|||
}
|
||||
|
||||
#es-warning-dismiss:after {
|
||||
content: ' ✖';
|
||||
content: ' x';
|
||||
color: black;
|
||||
}
|
||||
|
|
|
@ -546,7 +546,7 @@ $(document).ready( function() {
|
|||
$( '<a href="#"></a>' )
|
||||
.text( title )
|
||||
.click( function() {
|
||||
var newDocumentModel = ve.dm.DocumentNode.newFromPlainObject( wikidom );
|
||||
var newDocumentModel = new ve.dm.Document( [{ 'type': 'paragraph' }, '', { 'type': '/paragraph' }] );
|
||||
documentModel.data.splice( 0, documentModel.data.length );
|
||||
ve.insertIntoArray( documentModel.data, 0, newDocumentModel.data );
|
||||
surfaceModel.select( new ve.Range( 1, 1 ) );
|
||||
|
|
|
@ -6,9 +6,15 @@
|
|||
* @param model {ve.dm.Surface} Model to observe
|
||||
*/
|
||||
ve.ce.Surface = function( $container, model ) {
|
||||
// Inheritance
|
||||
ve.EventEmitter.call( this );
|
||||
// Properties
|
||||
this.surfaceModel = model;
|
||||
this.documentView = new ve.ce.Document( model.documentModel );
|
||||
$container.append(this.documentView.documentNode.$);
|
||||
this.documentView.documentNode.render();
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
ve.extendClass( ve.ce.Surface, ve.EventEmitter );
|
||||
|
|
|
@ -3,9 +3,91 @@
|
|||
*
|
||||
* @class
|
||||
* @constructor
|
||||
* @extends {ve.EventEmitter}
|
||||
* @param {ve.dm.Document} doc Document model to create surface for
|
||||
*/
|
||||
ve.dm.Surface = function( doc ) {
|
||||
// Inheritance
|
||||
ve.EventEmitter.call( this );
|
||||
// Properties
|
||||
this.documentModel = doc;
|
||||
this.selection = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the document model of the surface.
|
||||
*
|
||||
* @method
|
||||
* @returns {ve.dm.DocumentNode} Document model of the surface
|
||||
*/
|
||||
ve.dm.Surface.prototype.getDocument = function() {
|
||||
return this.doc;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the selection
|
||||
*
|
||||
* @method
|
||||
* @returns {ve.Range} Current selection
|
||||
*/
|
||||
ve.dm.Surface.prototype.getSelection = function() {
|
||||
return this.selection;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the selection
|
||||
*
|
||||
* @method
|
||||
*/
|
||||
ve.dm.Surface.prototype.setSelection = function( selection ) {
|
||||
this.selection = selection;
|
||||
};
|
||||
|
||||
/**
|
||||
* Changes the selection.
|
||||
*
|
||||
* If changing the selection at a high frequency (such as while dragging) use the combine argument
|
||||
* to avoid them being split up into multiple history items
|
||||
*
|
||||
* @method
|
||||
* @param {ve.Range} selection
|
||||
* @param {Boolean} isManual Whether this selection was the result of a user action, and thus should
|
||||
* be recorded in history...?
|
||||
*/
|
||||
ve.dm.Surface.prototype.select = function( selection, isManual ) {
|
||||
selection.normalize();
|
||||
/*if (
|
||||
( ! this.selection ) || ( ! this.selection.equals( selection ) )
|
||||
) {*/
|
||||
if ( isManual ) {
|
||||
this.breakpoint();
|
||||
}
|
||||
// check if the last thing is a selection, if so, swap it.
|
||||
this.selection = selection;
|
||||
this.emit( 'select', this.selection.clone() );
|
||||
//}
|
||||
};
|
||||
|
||||
/**
|
||||
* Applies a series of transactions to the content data.
|
||||
*
|
||||
* If committing multiple transactions which are the result of a single user action and need to be
|
||||
* part of a single history item, use the isPartial argument for all but the last one to avoid them
|
||||
* being split up into multple history items.
|
||||
*
|
||||
* @method
|
||||
* @param {ve.dm.Transaction} transactions Tranasction to apply to the document
|
||||
* @param {boolean} isPartial whether this transaction is part of a larger logical grouping of
|
||||
* transactions (such as when replacing - delete, then insert)
|
||||
*/
|
||||
ve.dm.Surface.prototype.transact = function( transaction ) {
|
||||
//this.bigStack = this.bigStack.slice( 0, this.bigStack.length - this.undoIndex );
|
||||
//this.undoIndex = 0;
|
||||
//this.smallStack.push( transaction );
|
||||
this.doc.commit( transaction );
|
||||
this.emit( 'transact', transaction );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
ve.extendClass( ve.dm.Surface, ve.EventEmitter );
|
||||
|
|
|
@ -94,7 +94,7 @@ ve.Surface = function( parent, data, options ) {
|
|||
//this.context = new ve.ui.Context( this.view );
|
||||
|
||||
// Setup toolbars based on this.options
|
||||
//this.setupToolbars();
|
||||
this.setupToolbars();
|
||||
|
||||
// Setup various toolbar modes and panels
|
||||
//this.setupModes();
|
||||
|
|
Loading…
Reference in a new issue