mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-28 20:56:44 +00:00
f31dc45da8
Objectives: * Make the link inspector easier to use * Try to resolve a few bugs (bug 43841, bug 43063, bug 42986) * Stop using jquery.multiSuggest (which didn't really understand annotations) * Better divide MediaWiki specifics from generic implementations Changes: VisualEditor.php, modules/ve/test/index.php, demos/ve/index.php * Updated links to files ve.Registry * Fixed mistake where registry was initialized as an array - this didn't cause any errors because you can add arbitrary properties to an array and use it like any other object ve.Factory * Removed duplicate initialization of registry property * Added entries property, which is an array that's appended to for tracking the order of registrations ve.CommandRegistry * Added mwLink command which opens the mwLink inspector ve.ui.TextInputWidget * Added basic widget class for text inputs ve.ui.TextInputMenuWidget * Added widget that provides a menu of options for a text input widget ve.ui.MWLinkTargetInputWidget * Added MediaWiki specific link target widget ve.ui.MenuWidget * Converted ve.ui.Menu into a widget * Moved the body of onSelect to onMouseUp ve.ui.LinkTargetInputWidget * Added link target widget which adds link annotation functionality to a normal text input ve.ui.InputWidget * Added generic input widget which emits reliable and instant change events and synchronizes a value property with the DOM value ve.ui.Widget * Added base widget class * Widgets can be used in any frame ve.ui.Tool * Fixed line length issues ve.ui.InspectorFactory * Made use of new entries property for factories to select the most recently added inspector if more than one match a given annotation ve.ui.Inspector * Added auto-focus on the first visible input element on open * Moved afterClose event to after re-focus on document on close * Added documentation ve.ui.Frame * Adjusted documentation * Added binding of $$ to the frame context so it can be passed around * Added documentation ve.ui.Context * Added ve.ui.Widget.css to iframes * Updated code as per moving of ve.ui.Menu to ve.ui.MenuWidget * Removed unused positionBelowOverlay method * Added CSS settings to set overlay left and width properties according to context size * Added documentation ve.ui.DropdownTool * Updated code as per moving of ve.ui.Menu to ve.ui.MenuWidget ve.ui.FormatDropdownTool * Added documentation ve.ui.MWLinkButtonTool * Added MediaWiki specific version of ve.ui.LinkButtonTool, which opens the mwLink inspector ve.ui.Widget.css * Added styles for all widgets ve.ui.Tool.css, ve.init.sa.css, ve.init.mw.ViewPageTarget.css, ve.init.mw.ViewPageTarget-apex.css * Updated code as per moving of ve.ui.Menu to ve.ui.MenuWidget ve.ui.Menu.css * Deleted (merged into ve.ui.Widget.css) ve.ui.Menu.css * Deleted suggest styles (no longer used) pending.gif, pending.psd * Added diagonal stripe animation to indicate a pending request to the API ve.ui.MWLinkInspector * Added MediaWiki specific inspector which uses MediaWiki specific annotations and widgets ve.ui.LinkInspector * Removed mw global hint (not needed anymore) * Switched from comparing targets to annotations (since the target text is ambiguous in some situations) * Switched to using input widget, which is configured using a static property * Removed use of jquery.multiSuggest * Moved MediaWiki specifics to their own class (ve.ui.MWLinkInspector) ve.init.mw.ViewPageTarget * Added MediaWiki specific toolbar and command options Change-Id: I859b5871a9d2f17d970c002067c8ff24f3513e9f
154 lines
3.8 KiB
JavaScript
154 lines
3.8 KiB
JavaScript
/*!
|
|
* VisualEditor user interface DropdownTool class.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an ve.ui.DropdownTool object.
|
|
*
|
|
* @abstract
|
|
* @class
|
|
* @extends ve.ui.Tool
|
|
* @constructor
|
|
* @param {ve.ui.Toolbar} toolbar
|
|
* @param {Object[]} items
|
|
*/
|
|
ve.ui.DropdownTool = function VeUiDropdownTool( toolbar, items ) {
|
|
// Parent constructor
|
|
ve.ui.Tool.call( this, toolbar );
|
|
|
|
// Properties
|
|
this.menuView = new ve.ui.MenuWidget( items, ve.bind( this.onMenuItemSelect, this ), null, this.$ );
|
|
this.$icon = $( '<div class="ve-ui-dropdownTool-icon ve-ui-icon-down"></div>' );
|
|
this.$label = $( '<div class="ve-ui-dropdownTool-label"></div>' );
|
|
this.$labelText = $( '<span> </span>' );
|
|
|
|
// Events
|
|
$( 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 )
|
|
} );
|
|
|
|
// Initialization
|
|
this.$
|
|
.append( this.$icon, this.$label )
|
|
.addClass( 've-ui-dropdownTool ve-ui-dropdownTool-' + this.constructor.static.name )
|
|
.attr( 'title', ve.msg( this.constructor.static.titleMessage ) );
|
|
this.$label.append( this.$labelText );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.DropdownTool, ve.ui.Tool );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Responds to the mouse button being pressed.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Normalized event
|
|
*/
|
|
ve.ui.DropdownTool.prototype.onMousedown = function ( e ) {
|
|
if ( e.which === 1 ) {
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Responds to the mouse button being released.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Normalized event
|
|
*/
|
|
ve.ui.DropdownTool.prototype.onMouseup = function ( e ) {
|
|
if ( e.which === 1 ) {
|
|
// Don't respond to menu clicks
|
|
var $item = $( e.target ).closest( '.ve-ui-menuWidget' );
|
|
if ( e.which === 1 && $item.length === 0 ) {
|
|
this.menuView.open();
|
|
} else {
|
|
this.menuView.close();
|
|
}
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Responds to 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 Normalized event
|
|
*/
|
|
ve.ui.DropdownTool.prototype.onBlur = function ( e ) {
|
|
if ( e.which === 1 ) {
|
|
this.menuView.close();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Responds to 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 {Object} item Menu item
|
|
*/
|
|
ve.ui.DropdownTool.prototype.onMenuItemSelect = function ( item ) {
|
|
if ( this.toolbar.getSurface().isEnabled() ) {
|
|
this.setLabel( item.label );
|
|
this.onSelect( item );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Responds to dropdown option being selected.
|
|
*
|
|
* This is an abstract method that must be overridden in a concrete subclass.
|
|
*
|
|
* @abstract
|
|
* @method
|
|
* @param {Object} item Menu item
|
|
*/
|
|
ve.ui.DropdownTool.prototype.onSelect = function () {
|
|
throw new Error(
|
|
've.ui.DropdownTool.onSelect not implemented in this subclass:' + this.constructor
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Responds to toolbar state being cleared.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.DropdownTool.prototype.onClearState = function () {
|
|
this.setLabel();
|
|
};
|
|
|
|
/**
|
|
* Sets the label.
|
|
*
|
|
* If the label value is empty, undefined or only contains whitespace an empty label will be used.
|
|
*
|
|
* @method
|
|
* @param {jQuery|string} [value] jQuery HTML node selection or string text value to use for label
|
|
*/
|
|
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( ' ' );
|
|
}
|
|
};
|