mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
fb22e4df50
Objective: Refactor menu widgets so that the majority of their code can be reused, and then add an outline widget which shares the same base classes. ve.ui.Dialog.css * Make dialog a fixed width and have a minimum and maximum height while always being centered in the window. * Add style for the outline panel * Add border below the title * Move font-size adjustment to child elements to preserve layout scale ve.ui.Inspector.css * Make inspectors fade in when being opened (will happen after the size transition is complete) * Add initial size for inspector to prevent the default size of the unfinished contents from making it too large while loading ve.ui.Tool.css * Update classes according to changes in labeled widgets ve.ui.Widget.css * Add display: block to widget labels to support use of autoEllipsis on them * Update classes according to changes in labeled widgets * Add styles for new select, option and outline item widgets * Remove unused group and items classes for menu widgets (which are now subclasses of the select widget and no longer have grouping built-in) ve.ui.Window.css.js * Moved selection disabling rules up to the head to prevent selection drawing around the title ve.ui.GroupWidget.js * New widget that manages "items", allowing getting, adding, removing and clearing ve.ui.MenuSectionItemWidget.js * New widget that can be used inside a menu to create an unselectable, unhighlightable item that describes a section of the menu ve.ui.OptionWidget.js * New widget to be used with select widgets, provides select and highlight functionality ve.ui.OutlineItemWidget.js * New widget to be used with outline widgets, extends option and adds support for an icon to be rendered to the left of the label ve.ui.OutlineWidget.js * New widget that provides a vertically stacked list of mutually exclusive options, extends select ve.ui.SelectWidget.js * New widget that implements most of what menu once did, only now it also handles all the events for it's child elements internally ve.ui.MetaDialog.js * Hacked in support for an outline widget in the outline pane * Added classes for styling purposes ve.ui.FormatDropDownTool.js * Modified call to menu item constructor as per changes therein * Reorganized options config to make construction simpler * Changed to setLabel after selecting the item to prevent the label from being changed to the wrong value as a side-effect of setting the item ve.ui.DropDownTool.js * Added $$ in config for menu widget - just in case later on we use a drop-down inside of a frame * Using jQuery .text() method to propagate the selected item's text to the label rather than keeping around a plain text copy of the label in a property ve.ui.Context.js * Improve context/inspector behavior in regards to initial sizing ve.ui.js * Added context property to $$ returned by get$$ so it's easy to get the document object (for event binding) wherever you have a $$ ve.ui.Window.js * Fixed incorrect case for boolean type in comment * Added getFrame method ve.ui.ButtonWidget.js * Removed extra class being set on label ve.ui.LabeledWidget.js * Added class on label * Added fitLabel method which uses autoEllipsis internally ve.ui.MenuItemWidget.js * Moved nearly all of the implementation to option so it could be reused ve.ui.Menu.js * Moved most of the implementation to select and group ve.ui.MWLinkTargetInputWidget * Prevent aborting and re-querying if the value hasn't actually changed * Updated populateMenu method as per changes in menu class *.php * Added links to new files Change-Id: I2271b5cc0554973b13cfbff94caf16901c02caa5
293 lines
6 KiB
JavaScript
293 lines
6 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface Window class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* UserInterface window.
|
|
*
|
|
* @class
|
|
* @abstract
|
|
* @extends ve.EventEmitter
|
|
*
|
|
* @constructor
|
|
* @param {ve.Surface} surface
|
|
* @emits initialize
|
|
*/
|
|
ve.ui.Window = function VeUiWindow( surface ) {
|
|
// Inheritance
|
|
ve.EventEmitter.call( this );
|
|
|
|
// Properties
|
|
this.surface = surface;
|
|
this.visible = false;
|
|
this.opening = false;
|
|
this.closing = false;
|
|
this.frame = null;
|
|
this.$ = $( '<div>' );
|
|
this.$frame = $( '<div>' );
|
|
|
|
// Initialization
|
|
this.$
|
|
.addClass( 've-ui-window' )
|
|
.append( this.$frame );
|
|
this.frame = new ve.ui.Frame( { 'stylesheets': this.constructor.static.stylesheets } );
|
|
this.$frame
|
|
.addClass( 've-ui-window-frame' )
|
|
.append( this.frame.$ );
|
|
|
|
// Events
|
|
this.frame.on( 'initialize', ve.bind( function () {
|
|
this.initialize();
|
|
this.emit( 'initialize' );
|
|
}, this ) );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.Window, ve.EventEmitter );
|
|
|
|
/* Events */
|
|
|
|
/**
|
|
* @event initialize
|
|
*/
|
|
|
|
/**
|
|
* @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
|
|
*/
|
|
|
|
/* Static Properties */
|
|
|
|
/**
|
|
* @static
|
|
* @property
|
|
* @inheritable
|
|
*/
|
|
ve.ui.Window.static = {};
|
|
|
|
/**
|
|
* Options for frame.
|
|
*
|
|
* @see ve.ui.Frame
|
|
*
|
|
* @static
|
|
* @property
|
|
* @type {Object}
|
|
*/
|
|
ve.ui.Window.static.stylesheets = [
|
|
've.ui.Frame.css',
|
|
've.ui.Window.css',
|
|
've.ui.Layout.css',
|
|
've.ui.Widget.css',
|
|
( window.devicePixelRatio > 1 ? 've.ui.Icons-vector.css' : 've.ui.Icons-raster.css' )
|
|
];
|
|
|
|
/**
|
|
* Symbolic name of icon.
|
|
*
|
|
* @static
|
|
* @property
|
|
* @type {string}
|
|
*/
|
|
ve.ui.Window.static.icon = 'window';
|
|
|
|
/**
|
|
* Localized message for title.
|
|
*
|
|
* @static
|
|
* @property
|
|
* @type {string}
|
|
*/
|
|
ve.ui.Window.static.titleMessage = null;
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle the window being initialized.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.Window.prototype.initialize = function () {
|
|
// Properties
|
|
this.$$ = this.frame.$$;
|
|
this.$title = this.$$( '<div class="ve-ui-window-title"></div>' );
|
|
if ( this.constructor.static.titleMessage ) {
|
|
this.$title.text( ve.msg( this.constructor.static.titleMessage ) );
|
|
}
|
|
this.$icon = this.$$( '<div class="ve-ui-window-icon"></div>' )
|
|
.addClass( 've-ui-icon-' + this.constructor.static.icon );
|
|
this.$head = this.$$( '<div class="ve-ui-window-head"></div>' );
|
|
this.$body = this.$$( '<div class="ve-ui-window-body"></div>' );
|
|
|
|
// Initialization
|
|
this.frame.$content.append(
|
|
this.$head.append( this.$icon, this.$title ),
|
|
this.$body
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Handle the window being opened.
|
|
*
|
|
* Any changes to the document in that need to be done prior to opening should be made here.
|
|
*
|
|
* To be notified after this method is called, listen to the `setup` event.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.Window.prototype.onSetup = function () {
|
|
// This is a stub, override functionality in child classes
|
|
};
|
|
|
|
/**
|
|
* Handle the window being opened.
|
|
*
|
|
* Any changes to the window that need to be done prior to opening should be made here.
|
|
*
|
|
* To be notified after this method is called, listen to the `open` event.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.Window.prototype.onOpen = function () {
|
|
// This is a stub, override functionality in child classes
|
|
};
|
|
|
|
/**
|
|
* Handle the window being closed.
|
|
*
|
|
* Any changes to the document that need to be done prior to closing should be made here.
|
|
*
|
|
* To be notified after this method is called, listen to the `close` event.
|
|
*
|
|
* @method
|
|
* @param {boolean} accept Changes have been accepted
|
|
*/
|
|
ve.ui.Window.prototype.onClose = function () {
|
|
// This is a stub, override functionality in child classes
|
|
};
|
|
|
|
/**
|
|
* Check if window is visible.
|
|
*
|
|
* @method
|
|
* @returns {boolean} Window is visible
|
|
*/
|
|
ve.ui.Window.prototype.isVisible = function () {
|
|
return this.visible;
|
|
};
|
|
|
|
/**
|
|
* Get the window frame.
|
|
*
|
|
* @method
|
|
* @returns {ve.ui.Frame} Frame of window
|
|
*/
|
|
ve.ui.Window.prototype.getFrame = function () {
|
|
return this.frame;
|
|
};
|
|
|
|
/**
|
|
*
|
|
*/
|
|
ve.ui.Window.prototype.setSize = function ( width, height ) {
|
|
if ( !this.frame.$content ) {
|
|
return;
|
|
}
|
|
|
|
this.frame.$.css( {
|
|
'width': width === undefined ? 'auto' : width,
|
|
'height': height === undefined ? 'auto' : height
|
|
} );
|
|
};
|
|
|
|
/**
|
|
*
|
|
*/
|
|
ve.ui.Window.prototype.fitHeightToContents = function ( min, max ) {
|
|
var height = this.frame.$content.outerHeight();
|
|
|
|
this.frame.$.css(
|
|
'height', Math.max( min || 0, max === undefined ? height : Math.min( max, height ) )
|
|
);
|
|
};
|
|
|
|
/**
|
|
*
|
|
*/
|
|
ve.ui.Window.prototype.fitWidthToContents = function ( min, max ) {
|
|
var width = this.frame.$content.outerWidth();
|
|
|
|
this.frame.$.css(
|
|
'width', Math.max( min || 0, max === undefined ? width : Math.min( max, width ) )
|
|
);
|
|
};
|
|
|
|
/**
|
|
*
|
|
*/
|
|
ve.ui.Window.prototype.setPosition = function ( left, top ) {
|
|
this.$.css( { 'left': left, 'top': top } );
|
|
};
|
|
|
|
/**
|
|
* Open window.
|
|
*
|
|
* @method
|
|
* @emits setup
|
|
* @emits open
|
|
*/
|
|
ve.ui.Window.prototype.open = function () {
|
|
if ( !this.opening ) {
|
|
this.opening = true;
|
|
this.onSetup();
|
|
this.emit( 'setup' );
|
|
this.$.show();
|
|
this.visible = true;
|
|
this.frame.run( ve.bind( function () {
|
|
this.frame.$.focus();
|
|
this.onOpen();
|
|
this.opening = false;
|
|
this.emit( 'open' );
|
|
}, this ) );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Close window.
|
|
*
|
|
* This method guards against recursive calling internally. This protects against changes made while
|
|
* closing the window which themselves would cause the window to be closed from causing an infinate
|
|
* loop.
|
|
*
|
|
* @method
|
|
* @param {boolean} accept Changes have been accepted
|
|
* @emits close
|
|
*/
|
|
ve.ui.Window.prototype.close = function ( remove ) {
|
|
if ( !this.closing ) {
|
|
this.closing = true;
|
|
this.$.hide();
|
|
this.visible = false;
|
|
this.onClose( remove );
|
|
this.closing = false;
|
|
this.frame.$content.find( ':focus' ).blur();
|
|
this.surface.getView().getDocument().getDocumentNode().$.focus();
|
|
this.emit( 'close', remove );
|
|
}
|
|
};
|