mediawiki-extensions-Visual.../modules/ve/ui/ve.ui.WindowSet.js

141 lines
2.8 KiB
JavaScript
Raw Normal View History

Context, frame, window, dialog and inspector refactor This is a major refactor of user interface context, frame, dialog and inspector classes, including adding several new classes which generalize managing inspectors/dialogs (which are now subclasses of window). New classes: * ve.ui.Window.js - base class for inspector and dialog classes * ve.ui.WindowSet.js - manages mutually exclusive windows, used by surface and context for dialogs and inspectors respectively * ve.ui.DialogFactory - generates dialogs * ve.ui.IconButtonWidget - used in inspector for buttons in the head Refactored classes: * ve.ui.Context - moved inspector management to window set * ve.ui.Frame - made iframes initialize asynchronously * ve.ui.Dialog and ve.ui.Inspector - moved initialization to async initialize method Other interesting bits: ve.ui.*Icons*.css, *.svg, *.png, *.ai * Merged icon stylesheets so all icons are available inside windows * Renamed inspector icon to window ve.ui.*.css * Reorganized styles so that different windows can include only what they need * Moved things to where they belonged (some things were in strange places) ve.init.Target.js, ve.init.mw.ViewPageTarget.js, ve.init.sa.Target.js * Removed dialog management - dialogs are managed by the surface now ve.ui.*Dialog.js * Renamed title message static property * Added registration ve.ui.*Inspector.js * Switch to accept surface object rather than context, which conforms to the more general window class without losing any functionality (in fact, most of the time the surface was what we actually wanted) ve.ui.MenuWidget.js, ve.ui.MWLinkTargetInputWidget.js * Using surface overly rather than passing an overlay around through constructors Change-Id: Ifd16a1003ff44c48ee7b2c66928cf9cc858b2564
2013-03-13 00:06:57 +00:00
/*!
* 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 {boolean} accept Changes have been accepted
*/
/* Methods */
/**
* Handle a window being setup.
*
* @method
* @param {ve.ui.Window} win Window that's been setup
* @emits setup
Context, frame, window, dialog and inspector refactor This is a major refactor of user interface context, frame, dialog and inspector classes, including adding several new classes which generalize managing inspectors/dialogs (which are now subclasses of window). New classes: * ve.ui.Window.js - base class for inspector and dialog classes * ve.ui.WindowSet.js - manages mutually exclusive windows, used by surface and context for dialogs and inspectors respectively * ve.ui.DialogFactory - generates dialogs * ve.ui.IconButtonWidget - used in inspector for buttons in the head Refactored classes: * ve.ui.Context - moved inspector management to window set * ve.ui.Frame - made iframes initialize asynchronously * ve.ui.Dialog and ve.ui.Inspector - moved initialization to async initialize method Other interesting bits: ve.ui.*Icons*.css, *.svg, *.png, *.ai * Merged icon stylesheets so all icons are available inside windows * Renamed inspector icon to window ve.ui.*.css * Reorganized styles so that different windows can include only what they need * Moved things to where they belonged (some things were in strange places) ve.init.Target.js, ve.init.mw.ViewPageTarget.js, ve.init.sa.Target.js * Removed dialog management - dialogs are managed by the surface now ve.ui.*Dialog.js * Renamed title message static property * Added registration ve.ui.*Inspector.js * Switch to accept surface object rather than context, which conforms to the more general window class without losing any functionality (in fact, most of the time the surface was what we actually wanted) ve.ui.MenuWidget.js, ve.ui.MWLinkTargetInputWidget.js * Using surface overly rather than passing an overlay around through constructors Change-Id: Ifd16a1003ff44c48ee7b2c66928cf9cc858b2564
2013-03-13 00:06:57 +00:00
*/
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
Context, frame, window, dialog and inspector refactor This is a major refactor of user interface context, frame, dialog and inspector classes, including adding several new classes which generalize managing inspectors/dialogs (which are now subclasses of window). New classes: * ve.ui.Window.js - base class for inspector and dialog classes * ve.ui.WindowSet.js - manages mutually exclusive windows, used by surface and context for dialogs and inspectors respectively * ve.ui.DialogFactory - generates dialogs * ve.ui.IconButtonWidget - used in inspector for buttons in the head Refactored classes: * ve.ui.Context - moved inspector management to window set * ve.ui.Frame - made iframes initialize asynchronously * ve.ui.Dialog and ve.ui.Inspector - moved initialization to async initialize method Other interesting bits: ve.ui.*Icons*.css, *.svg, *.png, *.ai * Merged icon stylesheets so all icons are available inside windows * Renamed inspector icon to window ve.ui.*.css * Reorganized styles so that different windows can include only what they need * Moved things to where they belonged (some things were in strange places) ve.init.Target.js, ve.init.mw.ViewPageTarget.js, ve.init.sa.Target.js * Removed dialog management - dialogs are managed by the surface now ve.ui.*Dialog.js * Renamed title message static property * Added registration ve.ui.*Inspector.js * Switch to accept surface object rather than context, which conforms to the more general window class without losing any functionality (in fact, most of the time the surface was what we actually wanted) ve.ui.MenuWidget.js, ve.ui.MWLinkTargetInputWidget.js * Using surface overly rather than passing an overlay around through constructors Change-Id: Ifd16a1003ff44c48ee7b2c66928cf9cc858b2564
2013-03-13 00:06:57 +00:00
*/
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
Context, frame, window, dialog and inspector refactor This is a major refactor of user interface context, frame, dialog and inspector classes, including adding several new classes which generalize managing inspectors/dialogs (which are now subclasses of window). New classes: * ve.ui.Window.js - base class for inspector and dialog classes * ve.ui.WindowSet.js - manages mutually exclusive windows, used by surface and context for dialogs and inspectors respectively * ve.ui.DialogFactory - generates dialogs * ve.ui.IconButtonWidget - used in inspector for buttons in the head Refactored classes: * ve.ui.Context - moved inspector management to window set * ve.ui.Frame - made iframes initialize asynchronously * ve.ui.Dialog and ve.ui.Inspector - moved initialization to async initialize method Other interesting bits: ve.ui.*Icons*.css, *.svg, *.png, *.ai * Merged icon stylesheets so all icons are available inside windows * Renamed inspector icon to window ve.ui.*.css * Reorganized styles so that different windows can include only what they need * Moved things to where they belonged (some things were in strange places) ve.init.Target.js, ve.init.mw.ViewPageTarget.js, ve.init.sa.Target.js * Removed dialog management - dialogs are managed by the surface now ve.ui.*Dialog.js * Renamed title message static property * Added registration ve.ui.*Inspector.js * Switch to accept surface object rather than context, which conforms to the more general window class without losing any functionality (in fact, most of the time the surface was what we actually wanted) ve.ui.MenuWidget.js, ve.ui.MWLinkTargetInputWidget.js * Using surface overly rather than passing an overlay around through constructors Change-Id: Ifd16a1003ff44c48ee7b2c66928cf9cc858b2564
2013-03-13 00:06:57 +00:00
*/
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.
*
* @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 ( !( 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.close();
this.windows[name].open();
return this;
};
/**
* Closes currently open window.
*
* @method
* @param {boolean} accept Changes have been accepted
* @chainable
*/
ve.ui.WindowSet.prototype.close = function ( accept ) {
if ( this.currentWindow ) {
this.currentWindow.close( accept );
}
return this;
};