mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-02 01:46:47 +00:00
db9f941fa6
Objectives: * Rename this.$ to this.$element * Rename this.$$ to this.$ * Get rid of the need to use this.frame.$$ * Rename OO.ui.Element.get$$ to OO.ui.Element.getJQuery Changes: (using Sublime Text regex patterns) * Replace "get$$" with "getJQuery" * Replace "\.(\$)([^\$a-zA-Z])" with ".$element$2" * Replace "\.(\$\$)" with ".$" * Replace "'$$'" with "'$'" * Set this.$ to null in constructor of OO.ui.Window * Set this.$ to this.frame.$ in initialize method of OO.ui.Window * Replace "\.(frame.\$)([^\$a-zA-Z])" with ".\$$2" Bonus: * Use this.$() in a bunch of places where $() was erroneously used Change-Id: If3d870124ab8d10f8223532cda95c2b2b075db94
111 lines
2.7 KiB
JavaScript
111 lines
2.7 KiB
JavaScript
/*!
|
|
* ObjectOriented UserInterface TextInputMenuWidget class.
|
|
*
|
|
* @copyright 2011-2013 OOJS Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an OO.ui.TextInputMenuWidget object.
|
|
*
|
|
* @class
|
|
* @extends OO.ui.MenuWidget
|
|
*
|
|
* @constructor
|
|
* @param {OO.ui.TextInputWidget} input Text input widget to provide menu for
|
|
* @param {Object} [config] Configuration options
|
|
* @cfg {jQuery} [$container=input.$element] Element to render menu under
|
|
*/
|
|
OO.ui.TextInputMenuWidget = function OoUiTextInputMenuWidget( input, config ) {
|
|
// Parent constructor
|
|
OO.ui.MenuWidget.call( this, config );
|
|
|
|
// Properties
|
|
this.input = input;
|
|
this.$container = config.$container || this.input.$element;
|
|
this.onWindowResizeHandler = OO.ui.bind( this.onWindowResize, this );
|
|
|
|
// Initialization
|
|
this.$element.addClass( 'oo-ui-textInputMenuWidget' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( OO.ui.TextInputMenuWidget, OO.ui.MenuWidget );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle window resize event.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Window resize event
|
|
*/
|
|
OO.ui.TextInputMenuWidget.prototype.onWindowResize = function () {
|
|
this.position();
|
|
};
|
|
|
|
/**
|
|
* Shows the menu.
|
|
*
|
|
* @method
|
|
* @chainable
|
|
*/
|
|
OO.ui.TextInputMenuWidget.prototype.show = function () {
|
|
// Parent method
|
|
OO.ui.MenuWidget.prototype.show.call( this );
|
|
|
|
this.position();
|
|
this.$( this.getElementWindow() ).on( 'resize', this.onWindowResizeHandler );
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Hides the menu.
|
|
*
|
|
* @method
|
|
* @chainable
|
|
*/
|
|
OO.ui.TextInputMenuWidget.prototype.hide = function () {
|
|
// Parent method
|
|
OO.ui.MenuWidget.prototype.hide.call( this );
|
|
|
|
this.$( this.getElementWindow() ).off( 'resize', this.onWindowResizeHandler );
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Positions the menu.
|
|
*
|
|
* @method
|
|
* @chainable
|
|
*/
|
|
OO.ui.TextInputMenuWidget.prototype.position = function () {
|
|
var frameOffset,
|
|
$container = this.$container,
|
|
dimensions = $container.offset();
|
|
|
|
// Position under input
|
|
dimensions.top += $container.height();
|
|
dimensions.width = $container.width();
|
|
|
|
// Compensate for frame position if in a differnt frame
|
|
if ( this.input.$.frame && this.input.$.context !== this.$element[0].ownerDocument ) {
|
|
frameOffset = OO.ui.Element.getRelativePosition(
|
|
this.input.$.frame.$element, this.$element.offsetParent()
|
|
);
|
|
dimensions.left += frameOffset.left;
|
|
dimensions.top += frameOffset.top;
|
|
} else {
|
|
// Fix for RTL (for some reason, no need to fix if the frameoffset is set)
|
|
if ( this.$element.css( 'direction' ) === 'rtl' ) {
|
|
dimensions.right = this.$element.parent().position().left - dimensions.width - dimensions.left;
|
|
// Erase the value for 'left':
|
|
delete dimensions.left;
|
|
}
|
|
}
|
|
|
|
this.$element.css( dimensions );
|
|
return this;
|
|
};
|