mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-01 09:26:37 +00:00
e962373e83
It was discovered that nested iframes inside firefox do not fire load events: http://osdir.com/ml/dev-apps-firefox/2010-03/msg00134.html Since we no longer care when the iframe is loaded, changing the frame onLoad method name to load and manually calling it was sufficient. Bug: 50115 Change-Id: I65c0c404a2a384566701b1c6b1bb978e0b99c90d
142 lines
2.9 KiB
JavaScript
142 lines
2.9 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.Element
|
|
* @mixins ve.EventEmitter
|
|
*
|
|
* @constructor
|
|
* @param {ve.ui.Surface} surface
|
|
* @param {ve.Factory} factory Window factory
|
|
* @param {Object} [config] Config options
|
|
*/
|
|
ve.ui.WindowSet = function VeUiWindowSet( surface, factory, config ) {
|
|
// Parent constructor
|
|
ve.Element.call( this, config );
|
|
|
|
// Mixin constructors
|
|
ve.EventEmitter.call( this );
|
|
|
|
// Properties
|
|
this.surface = surface;
|
|
this.factory = factory;
|
|
this.windows = {};
|
|
this.currentWindow = null;
|
|
|
|
// Initialization
|
|
this.$.addClass( 've-ui-windowSet' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.WindowSet, ve.Element );
|
|
|
|
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.$ );
|
|
win.getFrame().load();
|
|
}
|
|
|
|
this.windows[name].open();
|
|
|
|
return this;
|
|
};
|