mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 16:20:52 +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
180 lines
4.2 KiB
JavaScript
180 lines
4.2 KiB
JavaScript
/*!
|
|
* ObjectOriented UserInterface Dialog class.
|
|
*
|
|
* @copyright 2011-2013 OOJS Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Modal dialog box.
|
|
*
|
|
* @class
|
|
* @abstract
|
|
* @extends OO.ui.Window
|
|
*
|
|
* @constructor
|
|
* @param {OO.ui.WindowSet} windowSet Window set this dialog is part of
|
|
* @param {Object} [config] Configuration options
|
|
* @cfg {boolean} [footless] Hide foot
|
|
* @cfg {boolean} [small] Make the dialog small
|
|
*/
|
|
OO.ui.Dialog = function OoUiDialog( windowSet, config ) {
|
|
// Configuration initialization
|
|
config = config || {};
|
|
|
|
// Parent constructor
|
|
OO.ui.Window.call( this, windowSet, config );
|
|
|
|
// Properties
|
|
this.visible = false;
|
|
this.footless = !!config.footless;
|
|
this.small = !!config.small;
|
|
this.onWindowMouseWheelHandler = OO.ui.bind( this.onWindowMouseWheel, this );
|
|
this.onDocumentKeyDownHandler = OO.ui.bind( this.onDocumentKeyDown, this );
|
|
|
|
// Events
|
|
this.$element.on( 'mousedown', false );
|
|
|
|
// Initialization
|
|
this.$element.addClass( 'oo-ui-dialog' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( OO.ui.Dialog, OO.ui.Window );
|
|
|
|
/* Static Properties */
|
|
|
|
/**
|
|
* Symbolic name of dialog.
|
|
*
|
|
* @abstract
|
|
* @static
|
|
* @property {string}
|
|
* @inheritable
|
|
*/
|
|
OO.ui.Dialog.static.name = '';
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle close button click events.
|
|
*
|
|
* @method
|
|
*/
|
|
OO.ui.Dialog.prototype.onCloseButtonClick = function () {
|
|
this.close( { 'action': 'cancel' } );
|
|
};
|
|
|
|
/**
|
|
* Handle window mouse wheel events.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Mouse wheel event
|
|
*/
|
|
OO.ui.Dialog.prototype.onWindowMouseWheel = function () {
|
|
return false;
|
|
};
|
|
|
|
/**
|
|
* Handle document key down events.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Key down event
|
|
*/
|
|
OO.ui.Dialog.prototype.onDocumentKeyDown = function ( e ) {
|
|
switch ( e.which ) {
|
|
case OO.ui.Keys.PAGEUP:
|
|
case OO.ui.Keys.PAGEDOWN:
|
|
case OO.ui.Keys.END:
|
|
case OO.ui.Keys.HOME:
|
|
case OO.ui.Keys.LEFT:
|
|
case OO.ui.Keys.UP:
|
|
case OO.ui.Keys.RIGHT:
|
|
case OO.ui.Keys.DOWN:
|
|
// Prevent any key events that might cause scrolling
|
|
return false;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Handle frame document key down events.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Key down event
|
|
*/
|
|
OO.ui.Dialog.prototype.onFrameDocumentKeyDown = function ( e ) {
|
|
if ( e.which === OO.ui.Keys.ESCAPE ) {
|
|
this.close( { 'action': 'cancel' } );
|
|
return false;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
OO.ui.Dialog.prototype.initialize = function () {
|
|
// Parent method
|
|
OO.ui.Window.prototype.initialize.call( this );
|
|
|
|
// Properties
|
|
this.closeButton = new OO.ui.IconButtonWidget( {
|
|
'$': this.$, 'title': OO.ui.msg( 'ooui-dialog-action-close' ), 'icon': 'close'
|
|
} );
|
|
|
|
// Events
|
|
this.closeButton.connect( this, { 'click': 'onCloseButtonClick' } );
|
|
this.frame.$document.on( 'keydown', OO.ui.bind( this.onFrameDocumentKeyDown, this ) );
|
|
|
|
// Initialization
|
|
this.frame.$content.addClass( 'oo-ui-dialog-content' );
|
|
if ( this.footless ) {
|
|
this.frame.$content.addClass( 'oo-ui-dialog-content-footless' );
|
|
}
|
|
if ( this.small ) {
|
|
this.$frame.addClass( 'oo-ui-window-frame-small' );
|
|
}
|
|
this.closeButton.$element.addClass( 'oo-ui-window-closeButton' );
|
|
this.$head.append( this.closeButton.$element );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
OO.ui.Dialog.prototype.setup = function ( data ) {
|
|
// Parent method
|
|
OO.ui.Window.prototype.setup.call( this, data );
|
|
|
|
// Prevent scrolling in top-level window
|
|
this.$( window ).on( 'mousewheel', this.onWindowMouseWheelHandler );
|
|
this.$( document ).on( 'keydown', this.onDocumentKeyDownHandler );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
OO.ui.Dialog.prototype.teardown = function ( data ) {
|
|
// Parent method
|
|
OO.ui.Window.prototype.teardown.call( this, data );
|
|
|
|
// Allow scrolling in top-level window
|
|
this.$( window ).off( 'mousewheel', this.onWindowMouseWheelHandler );
|
|
this.$( document ).off( 'keydown', this.onDocumentKeyDownHandler );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
OO.ui.Dialog.prototype.close = function ( data ) {
|
|
if ( !this.opening && !this.closing && this.visible ) {
|
|
// Trigger transition
|
|
this.$element.addClass( 'oo-ui-dialog-closing' );
|
|
// Allow transition to complete before actually closing
|
|
setTimeout( OO.ui.bind( function () {
|
|
this.$element.removeClass( 'oo-ui-dialog-closing' );
|
|
// Parent method
|
|
OO.ui.Window.prototype.close.call( this, data );
|
|
}, this ), 250 );
|
|
}
|
|
};
|