mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-01 17:36:35 +00:00
7ac32bc0f6
window.close( true ) thing sucked, and was being named and used inconsistently throughout the code. The new approach uses an action string, so it looks more like window.close( 'accept' ) or window.close( 'back' ). This makes it easy to steer the behavior at any point in the window close code path. Most importantly for the link inspector, this allows us to now restore the previous selection when the user presses escape or clicks the back button, while still moving the cursor to the end and collapsing the selection upon pressing enter and allowing removal by clicking the trash can. This commit also cleans some things up, like the various ways we have to close an inspector which all seem useless because we wouldn't want to just randomly close an inspector on someone. An inspector should be closed only when the user has dealt with it. ve.InspectorAction.js * Removed close method ve.ui.LinkInspector.js * Updated documentation * Passing action to parent method * Updated logic to deal with change from "remove" to "action" argument * Added selection restauration on "back" action ve.ui.Context.js * Added action to call to close * Removed closeInspector method ve.ui.Dialog.js * Moved event handlers to the top * Added actions to calls to close * Added click block event handler to prevent focus changes ve.ui.Inspector.js * Added actions to calls to close * Added storing of previous selection - this is different from initialSelection because it's captured before the selection is modified by setup ve.ui.Window.js * Updated documentation * Updated argument name from "remove" to "action" ve.ui.WindowSet.js * Updated documentation * Removed auto-close, replaced it with error if trying to open a window when another is already open * Removed close method Change-Id: Ie8f72504177dd6ba169fdddbb776fd5397b831c4
132 lines
2.7 KiB
JavaScript
132 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
|
|
* @extends ve.EventEmitter
|
|
*
|
|
* @constructor
|
|
* @param {ve.Surface} surface
|
|
*/
|
|
ve.ui.WindowSet = function VeUiWindowSet( surface, factory ) {
|
|
// Inheritance
|
|
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.inheritClass( 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.on( 'setup', ve.bind( this.onWindowSetup, this, win ) );
|
|
win.on( 'open', ve.bind( this.onWindowOpen, this, win ) );
|
|
win.on( 'close', ve.bind( this.onWindowClose, this, win ) );
|
|
this.$.append( win.$ );
|
|
}
|
|
|
|
this.windows[name].open();
|
|
|
|
return this;
|
|
};
|