mediawiki-extensions-Visual.../modules/oojs-ui/OO.ui.Widget.js
Trevor Parscal db9f941fa6 Rename this.$ to this.$element, and this.$$ to this.$
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
2013-11-03 23:03:49 -08:00

74 lines
1.5 KiB
JavaScript

/*!
* ObjectOriented UserInterface Widget class.
*
* @copyright 2011-2013 OOJS Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* User interface control.
*
* @class
* @abstract
* @extends OO.ui.Element
* @mixin OO.EventEmitter
*
* @constructor
* @param {Object} [config] Configuration options
* @cfg {boolean} [disabled=false] Disable
*/
OO.ui.Widget = function OoUiWidget( config ) {
// Initialize config
config = $.extend( { 'disabled': false }, config );
// Parent constructor
OO.ui.Element.call( this, config );
// Mixin constructors
OO.EventEmitter.call( this );
// Properties
this.disabled = config.disabled;
// Initialization
this.$element.addClass( 'oo-ui-widget' );
this.setDisabled( this.disabled );
};
/* Inheritance */
OO.inheritClass( OO.ui.Widget, OO.ui.Element );
OO.mixinClass( OO.ui.Widget, OO.EventEmitter );
/* Methods */
/**
* Check if the widget is disabled.
*
* @method
* @param {boolean} Button is disabled
*/
OO.ui.Widget.prototype.isDisabled = function () {
return this.disabled;
};
/**
* Set the disabled state of the widget.
*
* This should probably change the widgets's appearance and prevent it from being used.
*
* @method
* @param {boolean} disabled Disable button
* @chainable
*/
OO.ui.Widget.prototype.setDisabled = function ( disabled ) {
this.disabled = !!disabled;
if ( this.disabled ) {
this.$element.addClass( 'oo-ui-widget-disabled' );
} else {
this.$element.removeClass( 'oo-ui-widget-disabled' );
}
return this;
};