mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-30 00:55:00 +00:00
cd6b54a4e8
Refactoring of externally sourced suggestions for text inputs. *.php * Added links to new file ve.ui.InputLabelWidget.js * Changed to focus input element, not wrapper div ve.ui.InputWidget.js * Fixed incorrect documentation ve.ui.LookupInputWidget.js * New mixing that abstracts placing a menu of options below a text input and filling it with data from an external source ve.ui.MenuWidget.js * Fixed to get reference to input element, no wrapper div ve.ui.MWLinkTargetInputWidget.js * Moved pending and lookup functionality to mixing * Implemented menu population using only matching pages, rather than a combination of that and page existence checks (fewer API calls) ve.ui.TextInputMenuWidget.js * Added configurable container to render underneath, rather than assuming this.input.$ * Added auto-position-on-window-resize functionality * Fixed frame position correction to ensure that it only is used when the overlay is in a different frame from the container to position underneath ve.ui.TextInputWidget.js * Added placeholder text feature Change-Id: If5ed1b64fd15982807691ce8bb0362970633108a
102 lines
2.3 KiB
JavaScript
102 lines
2.3 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface TextInputMenuWidget class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an ve.ui.TextInputMenuWidget object.
|
|
*
|
|
* @class
|
|
* @extends ve.ui.MenuWidget
|
|
*
|
|
* @constructor
|
|
* @param {ve.ui.TextInputWidget} input Text input widget to provide menu for
|
|
* @param {Object} [config] Config options
|
|
* @cfg {jQuery} [$container=input.$] Element to render menu under
|
|
*/
|
|
ve.ui.TextInputMenuWidget = function VeUiTextInputMenuWidget( input, config ) {
|
|
// Parent constructor
|
|
ve.ui.MenuWidget.call( this, config );
|
|
|
|
// Properties
|
|
this.input = input;
|
|
this.$container = config.$container || this.input.$;
|
|
this.onWindowResizeHandler = ve.bind( this.onWindowResize, this );
|
|
|
|
// Initialization
|
|
this.$.addClass( 've-ui-textInputMenuWidget' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.TextInputMenuWidget, ve.ui.MenuWidget );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle window resize event.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Window resize event
|
|
*/
|
|
ve.ui.TextInputMenuWidget.prototype.onWindowResize = function () {
|
|
this.position();
|
|
};
|
|
|
|
/**
|
|
* Shows the menu.
|
|
*
|
|
* @method
|
|
* @chainable
|
|
*/
|
|
ve.ui.TextInputMenuWidget.prototype.show = function () {
|
|
// Parent method
|
|
ve.ui.MenuWidget.prototype.show.call( this );
|
|
|
|
this.position();
|
|
$( window ).on( 'resize', this.onWindowResizeHandler );
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Hides the menu.
|
|
*
|
|
* @method
|
|
* @chainable
|
|
*/
|
|
ve.ui.TextInputMenuWidget.prototype.hide = function () {
|
|
// Parent method
|
|
ve.ui.MenuWidget.prototype.hide.call( this );
|
|
|
|
$( window ).off( 'resize', this.onWindowResizeHandler );
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Positions the menu.
|
|
*
|
|
* @method
|
|
* @chainable
|
|
*/
|
|
ve.ui.TextInputMenuWidget.prototype.position = function () {
|
|
var frameOffset,
|
|
$container = this.$container,
|
|
dimensions = $container.offset();
|
|
|
|
// Position under input
|
|
dimensions.top += $container.outerHeight( true );
|
|
dimensions.width = $container.outerWidth( true );
|
|
|
|
// Compensate for frame position if in a differnt frame
|
|
if ( this.input.$$.frame && this.input.$$.context !== this.$[0].ownerDocument ) {
|
|
frameOffset = this.input.$$.frame.$.offset();
|
|
dimensions.left += frameOffset.left;
|
|
dimensions.top += frameOffset.top;
|
|
}
|
|
|
|
this.$.css( dimensions );
|
|
return this;
|
|
};
|