mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-27 20:26:46 +00:00
59c67e1e94
demos/ve/demo.css, demos/ve/index.php * Style changes for utilities and dump output * Initially disable the log range button, activate when there's a range to log * Make range inputs read-only * Rename some widget variables * Add extra structure and classes to dump output ve.ui.Widget.css * Remove left/right margin for buttons * Simplify opaque white color * Modify selector for disabled buttons - see changes in ve.ui.Widget.js * Added styles for text input widget's readonly and disabled states ve.ui.Widget.js * Added disabled state ve.ui.ButtonWidget.js * Moved click event handler to method ve.ui.InputLabelWidget.js * Moved click event handler to method ve.ui.InputWidget.js * Moved input change event handler to method * Added readOnly state ve.ui.LinkTargetInputWidget.js * Corrected documentation ve.ui.MenuWidget.js * Blocked interaction while widget is disabled ve.ui.MWLinkTargetInputWidget.js * Corrected documentation * Blocked interaction while widget is disabled ve.ui.TextInputMenuWidget.js * Blocked interaction while widget is disabled Change-Id: I7ea89873b50a98d058d1dd1e309e3e8b7c8e7b2e
132 lines
2.8 KiB
JavaScript
132 lines
2.8 KiB
JavaScript
/*!
|
|
* VisualEditor user interface InputWidget class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an ve.ui.InputWidget object.
|
|
*
|
|
* @abstract
|
|
* @class
|
|
* @constructor
|
|
* @extends ve.ui.Widget
|
|
* @param {Function} $$ jQuery for the frame the widget is in
|
|
* @param {string} [type] HTML input type
|
|
* @param {string} [name] HTML input name
|
|
* @param {string} [value] Input value
|
|
*/
|
|
ve.ui.InputWidget = function VeUiInputWidget( $$, type, name, value ) {
|
|
// Parent constructor
|
|
ve.ui.Widget.call( this, $$ );
|
|
|
|
// Properties
|
|
this.$input = this.$$( '<input>' );
|
|
this.value = this.sanitizeValue( value );
|
|
this.readOnly = false;
|
|
|
|
// Events
|
|
this.$input.on(
|
|
'keydown mouseup cut paste change input select', ve.bind( this.onInputChange, this )
|
|
);
|
|
|
|
// Initialization
|
|
this.$input.attr( { 'type': type, 'name': name, 'value': value } );
|
|
this.$
|
|
.addClass( 've-ui-inputWidget' )
|
|
.append( this.$input );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.InputWidget, ve.ui.Widget );
|
|
|
|
/**
|
|
* @event change
|
|
* @param value
|
|
* @param origin
|
|
*/
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handles potentially value-changing events.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Event
|
|
*/
|
|
ve.ui.InputWidget.prototype.onInputChange = function () {
|
|
if ( !this.disabled ) {
|
|
// Allow the stack to clear so the value will be updated
|
|
setTimeout( ve.bind( function () {
|
|
this.setValue( this.$input.val() );
|
|
}, this ), 0 );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Gets the value of the input.
|
|
*
|
|
* @method
|
|
* @returns {string} Input value
|
|
*/
|
|
ve.ui.InputWidget.prototype.getValue = function () {
|
|
return this.value;
|
|
};
|
|
|
|
/**
|
|
* Sets the value of the input.
|
|
*
|
|
* @method
|
|
* @param {string} value New value
|
|
* @param {string} [origin] Origin of change
|
|
* @emits change
|
|
*/
|
|
ve.ui.InputWidget.prototype.setValue = function ( value, origin ) {
|
|
var domValue = this.$input.val();
|
|
value = this.sanitizeValue( value );
|
|
if ( this.value !== value ) {
|
|
this.value = value;
|
|
// Only update the DOM if we must
|
|
if ( domValue !== this.value ) {
|
|
this.$input.val( this.value );
|
|
}
|
|
this.emit( 'change', this.value, origin );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Sanitize incoming value.
|
|
*
|
|
* @method
|
|
* @param {string} value Original value
|
|
* @returns {string} Sanitized value
|
|
*/
|
|
ve.ui.InputWidget.prototype.sanitizeValue = function ( value ) {
|
|
return String( value );
|
|
};
|
|
|
|
/**
|
|
* Check if the widget is read-only.
|
|
*
|
|
* @method
|
|
* @param {boolean} Button is read-only
|
|
*/
|
|
ve.ui.InputWidget.prototype.isReadOnly = function () {
|
|
return this.readOnly;
|
|
};
|
|
|
|
/**
|
|
* Set the disabled state of the widget.
|
|
*
|
|
* This should probably change the widgets's appearance and prevent it from being used.
|
|
*
|
|
* @method
|
|
* @param {boolean} state Disable button
|
|
*/
|
|
ve.ui.InputWidget.prototype.setReadOnly = function ( state ) {
|
|
this.readOnly = !!state;
|
|
this.$input.prop( 'readonly', this.readOnly );
|
|
};
|