mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-30 00:55:00 +00:00
a56e795f58
Objectives: * Split ve.Surface into ve.Editor and ve.ui.Surface * Move actions, triggers and commands to ve.ui * Move toolbar wrapping, floating, shadow and actions functionality to configurable options of ve.ui.Toolbar * Make ve.ce.Surface and ve.ui.Surface inherit ve.Element and use this.$$ for iframe friendliness * Make the toolbar separately initialized so it's possible to have a surface without one, as well as control where the toolbar is Some change notes: VisualEditor.php * Added standalone module for mediawiki integrated unit testing ve.ce.Surface.js * Remove requirement to pass in an attached container to construct object * Inherit ve.Element and use this.$$ instead of $ * Make getSelectionRect iframe friendly * Move most of the initialize stuff to a new initialize method to be called after the surface is attached to the DOM ve.init.mw.ViewPageTarget.js * Merge toolbar functions into setup/teardown methods * Add toolbar manually (since it's not added by the surface anymore) ve.init.sa.Target.js * Update new init procedure for editor, surface and toolbar separately * Move toolbar floating stuff to ve.Toolbar Change-Id: If91a9d6e76a8be8d1b5a2566394765a37d29a8a7
134 lines
2.7 KiB
JavaScript
134 lines
2.7 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface WindowSet class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* UserInterface window set.
|
|
*
|
|
* @class
|
|
* @mixins ve.EventEmitter
|
|
*
|
|
* @constructor
|
|
* @param {ve.ui.Surface} surface
|
|
*/
|
|
ve.ui.WindowSet = function VeUiWindowSet( surface, factory ) {
|
|
// Mixin constructors
|
|
ve.EventEmitter.call( this );
|
|
|
|
// Properties
|
|
this.surface = surface;
|
|
this.factory = factory;
|
|
this.$ = $( '<div>' );
|
|
this.windows = {};
|
|
this.currentWindow = null;
|
|
|
|
// Initialization
|
|
this.$.addClass( 've-ui-windowSet' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.mixinClass( ve.ui.WindowSet, ve.EventEmitter );
|
|
|
|
/* Events */
|
|
|
|
/**
|
|
* @event setup
|
|
* @param {ve.ui.Window} win Window that's been setup
|
|
*/
|
|
|
|
/**
|
|
* @event open
|
|
* @param {ve.ui.Window} win Window that's been opened
|
|
*/
|
|
|
|
/**
|
|
* @event close
|
|
* @param {ve.ui.Window} win Window that's been closed
|
|
* @param {string} action Action that caused the window to be closed
|
|
*/
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle a window being setup.
|
|
*
|
|
* @method
|
|
* @param {ve.ui.Window} win Window that's been setup
|
|
* @emits setup
|
|
*/
|
|
ve.ui.WindowSet.prototype.onWindowSetup = function ( win ) {
|
|
this.emit( 'setup', win );
|
|
};
|
|
|
|
/**
|
|
* Handle a window being opened.
|
|
*
|
|
* @method
|
|
* @param {ve.ui.Window} win Window that's been opened
|
|
* @emits open
|
|
*/
|
|
ve.ui.WindowSet.prototype.onWindowOpen = function ( win ) {
|
|
this.currentWindow = win;
|
|
this.emit( 'open', win );
|
|
};
|
|
|
|
/**
|
|
* Handle a window being closed.
|
|
*
|
|
* @method
|
|
* @param {ve.ui.Window} win Window that's been opened
|
|
* @param {boolean} accept Changes have been accepted
|
|
* @emits close
|
|
*/
|
|
ve.ui.WindowSet.prototype.onWindowClose = function ( win, accept ) {
|
|
this.currentWindow = null;
|
|
this.emit( 'close', win, accept );
|
|
};
|
|
|
|
/**
|
|
* Get the current window.
|
|
*
|
|
* @method
|
|
* @returns {ve.ui.Window} Current window
|
|
*/
|
|
ve.ui.WindowSet.prototype.getCurrent = function () {
|
|
return this.currentWindow;
|
|
};
|
|
|
|
/**
|
|
* Opens a given window.
|
|
*
|
|
* Any already open dialog will be closed.
|
|
*
|
|
* @method
|
|
* @param {string} name Symbolic name of window
|
|
* @chainable
|
|
*/
|
|
ve.ui.WindowSet.prototype.open = function ( name ) {
|
|
var win;
|
|
|
|
if ( !this.factory.lookup( name ) ) {
|
|
throw new Error( 'Unknown window: ' + name );
|
|
}
|
|
if ( this.currentWindow ) {
|
|
throw new Error( 'Cannot open another window while another one is active' );
|
|
}
|
|
if ( !( name in this.windows ) ) {
|
|
win = this.windows[name] = this.factory.create( name, this.surface );
|
|
win.connect( this, {
|
|
'setup': ['onWindowSetup', win],
|
|
'open': ['onWindowOpen', win],
|
|
'close': ['onWindowClose', win]
|
|
} );
|
|
this.$.append( win.$ );
|
|
}
|
|
|
|
this.windows[name].open();
|
|
|
|
return this;
|
|
};
|