mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 14:56:20 +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
153 lines
3.7 KiB
JavaScript
153 lines
3.7 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface DropdownTool class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* UserInterface dropdown tool.
|
|
*
|
|
* @abstract
|
|
* @class
|
|
* @extends ve.ui.Tool
|
|
* @constructor
|
|
* @param {ve.ui.Toolbar} toolbar
|
|
* @param {Object} [config] Config options
|
|
*/
|
|
ve.ui.DropdownTool = function VeUiDropdownTool( toolbar, config ) {
|
|
// Parent constructor
|
|
ve.ui.Tool.call( this, toolbar, config );
|
|
|
|
// Properties
|
|
this.menu = new ve.ui.MenuWidget( { '$$': this.$$ } );
|
|
this.$icon = this.$$( '<div class="ve-ui-dropdownTool-icon ve-ui-icon-down"></div>' );
|
|
this.$label = this.$$( '<div class="ve-ui-dropdownTool-label"></div>' );
|
|
this.$labelText = this.$$( '<span> </span>' );
|
|
|
|
// Events
|
|
this.$$( document )
|
|
.add( this.toolbar.getSurface().getView().$ )
|
|
.mousedown( ve.bind( this.onBlur, this ) );
|
|
this.$.on( {
|
|
'mousedown': ve.bind( this.onMouseDown, this ),
|
|
'mouseup': ve.bind( this.onMouseUp, this )
|
|
} );
|
|
this.menu.on( 'select', ve.bind( this.onMenuItemSelect, this ) );
|
|
|
|
// Initialization
|
|
this.$
|
|
.append( this.$icon, this.$label, this.menu.$ )
|
|
.addClass(
|
|
've-ui-dropdownTool ve-ui-dropdownTool-' +
|
|
( this.constructor.static.cssName || this.constructor.static.name )
|
|
);
|
|
if ( this.constructor.static.titleMessage ) {
|
|
this.$.attr( 'title', ve.msg( this.constructor.static.titleMessage ) );
|
|
}
|
|
this.$label.append( this.$labelText );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.DropdownTool, ve.ui.Tool );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle the mouse button being pressed.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Mouse down event
|
|
*/
|
|
ve.ui.DropdownTool.prototype.onMouseDown = function ( e ) {
|
|
if ( e.which === 1 ) {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Handle the mouse button being released.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Mouse up event
|
|
*/
|
|
ve.ui.DropdownTool.prototype.onMouseUp = function ( e ) {
|
|
if ( e.which === 1 ) {
|
|
// Toggle menu
|
|
if ( this.menu.isVisible() ) {
|
|
this.menu.hide();
|
|
} else {
|
|
this.menu.show();
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
/**
|
|
* Handle focus being lost.
|
|
*
|
|
* The event is actually generated from a mousedown on an element outside the menu, so it is not
|
|
* a normal blur event object.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Mouse down event
|
|
*/
|
|
ve.ui.DropdownTool.prototype.onBlur = function ( e ) {
|
|
if ( e.which === 1 ) {
|
|
this.menu.hide();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Handle one of the items in the menu being selected.
|
|
*
|
|
* This should not be overridden in subclasses, it simple connects events from the internal menu
|
|
* to the onSelect method.
|
|
*
|
|
* @method
|
|
* @param {ve.ui.MenuItemWidget|null} item Selected menu item, null if none is selected
|
|
*/
|
|
ve.ui.DropdownTool.prototype.onMenuItemSelect = function ( item ) {
|
|
|
|
if ( this.toolbar.getSurface().isEnabled() ) {
|
|
this.setLabel( item && item.$label.text() );
|
|
this.onSelect( item );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Handle dropdown option being selected.
|
|
*
|
|
* This is an abstract method that must be overridden in a concrete subclass.
|
|
*
|
|
* @abstract
|
|
* @method
|
|
* @param {ve.ui.MenuItemWidget} item Menu item
|
|
*/
|
|
ve.ui.DropdownTool.prototype.onSelect = function () {
|
|
throw new Error(
|
|
've.ui.DropdownTool.onSelect not implemented in this subclass:' + this.constructor
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Set the label.
|
|
*
|
|
* If the label value is empty, undefined or only contains whitespace an empty label will be used.
|
|
*
|
|
* @method
|
|
* @param {jQuery|string} [value] Label text
|
|
* @chainable
|
|
*/
|
|
ve.ui.DropdownTool.prototype.setLabel = function ( value ) {
|
|
if ( typeof value === 'string' && value.length && /[^\s]*/.test( value ) ) {
|
|
this.$labelText.text( value );
|
|
} else if ( value instanceof jQuery ) {
|
|
this.$labelText.empty().append( value );
|
|
} else {
|
|
this.$labelText.html( ' ' );
|
|
}
|
|
return this;
|
|
};
|