mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 16:44:51 +00:00
4192cbc4d5
Changes: * Cleanup the window API to use more consistent and intuitive methods - we now use initialize/setup/teardown instead of initialize/onSetup/onOpen/onClose as methods which are overridden, and use open/close methods to control the window * Change events around to have opening/open and closing/close events which act as before/after points during the opening/closing process * Make WindowSet and Context respond to windows being opened, rather than opening them directly * Fix a LinkInspector creation mode bug where the initial text doesn't get reset * Move inspector, a VisualEditor concept, back to VE * Cleanup naming of SurfaceDialog, SurfaceToolbar, etc. to use shorter names, they were given Surface* names when the generic ones were also in VE, but now the generic ones are in OO, so they can return to their original names Change-Id: I82c4fed8bcb3fb5630938c8bc4dd9b2d5f1a8c1d
109 lines
2.3 KiB
JavaScript
109 lines
2.3 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface SurfaceWidget class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an ve.ui.SurfaceWidget object.
|
|
*
|
|
* @class
|
|
* @abstract
|
|
* @extends OO.ui.Widget
|
|
*
|
|
* @constructor
|
|
* @param {ve.dm.ElementLinearData} data Content data
|
|
* @param {Object} [config] Configuration options
|
|
* @cfg {Object[]} [tools] Toolbar configuration
|
|
* @cfg {string[]} [commands] List of supported commands
|
|
*/
|
|
ve.ui.SurfaceWidget = function VeUiSurfaceWidget( data, config ) {
|
|
// Config intialization
|
|
config = config || {};
|
|
|
|
// Parent constructor
|
|
OO.ui.Widget.call( this, config );
|
|
|
|
// Properties
|
|
this.surface = new ve.ui.Surface( data, { '$': this.$ } );
|
|
this.toolbar = new ve.ui.Toolbar( this.surface, { '$': this.$ } );
|
|
|
|
// Initialization
|
|
this.surface.$element.addClass( 've-ui-surfaceWidget-surface' );
|
|
this.toolbar.$element.addClass( 've-ui-surfaceWidget-toolbar' );
|
|
this.$element
|
|
.addClass( 've-ui-surfaceWidget' )
|
|
.append( this.toolbar.$element, this.surface.$element );
|
|
if ( config.tools ) {
|
|
this.toolbar.setup( config.tools );
|
|
}
|
|
if ( config.commands ) {
|
|
this.surface.addCommands( config.commands );
|
|
}
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.SurfaceWidget, OO.ui.Widget );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Get surface.
|
|
*
|
|
* @method
|
|
* @returns {ve.ui.Surface} Surface
|
|
*/
|
|
ve.ui.SurfaceWidget.prototype.getSurface = function () {
|
|
return this.surface;
|
|
};
|
|
|
|
/**
|
|
* Get toolbar.
|
|
*
|
|
* @method
|
|
* @returns {OO.ui.Toolbar} Toolbar
|
|
*/
|
|
ve.ui.SurfaceWidget.prototype.getToolbar = function () {
|
|
return this.toolbar;
|
|
};
|
|
|
|
/**
|
|
* Get content data.
|
|
*
|
|
* @method
|
|
* @returns {ve.dm.ElementLinearData} Content data
|
|
*/
|
|
ve.ui.SurfaceWidget.prototype.getContent = function () {
|
|
return this.surface.getModel().getDocument().getData();
|
|
};
|
|
|
|
/**
|
|
* Initialize surface and toolbar.
|
|
*
|
|
* Widget must be attached to DOM before initializing.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.SurfaceWidget.prototype.initialize = function () {
|
|
this.toolbar.initialize();
|
|
this.surface.initialize();
|
|
this.surface.view.documentView.documentNode.$element.focus();
|
|
};
|
|
|
|
/**
|
|
* Destroy surface and toolbar.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.SurfaceWidget.prototype.destroy = function () {
|
|
if ( this.surface ) {
|
|
this.surface.destroy();
|
|
}
|
|
if ( this.toolbar ) {
|
|
this.toolbar.destroy();
|
|
}
|
|
this.$element.remove();
|
|
};
|