/* Static properties */
- mw.widgets.datetime.DateTimeInputWidget[ 'static' ].supportsSimpleLabel = false;
+ mw.widgets.datetime.DateTimeInputWidget.static.supportsSimpleLabel = false;
/* Events */
/* Methods */
+ /**
+ * Get the currently focused field, if any
+ *
+ * @private
+ * @return {jQuery}
+ */
+ mw.widgets.datetime.DateTimeInputWidget.prototype.getFocusedField = function () {
+ return this.$fields.find( this.getElementDocument().activeElement );
+ };
+
/**
* Convert a date string to a Date
*
$field = $( '<span>' )
.width( sz )
.data( 'mw-widgets-datetime-dateTimeInputWidget-placeholder', placeholder );
+ if ( spec.type !== 'static' ) {
+ $field.prop( 'tabIndex', -1 );
+ $field.on( 'focus', this.onFieldFocus.bind( this, $field ) );
+ }
if ( spec.type === 'static' ) {
$field.text( spec.value );
} else {
this.clearButton = new OO.ui.ButtonWidget( {
classes: [ 'mw-widgets-datetime-dateTimeInputWidget-field', 'mw-widgets-datetime-dateTimeInputWidget-clearButton' ],
framed: false,
- icon: 'remove',
+ icon: 'trash',
disabled: disabled
} ).connect( this, {
click: 'onClearClick'
* @private
* @param {jQuery} $field
* @param {jQuery.Event} e Key down event
+ * @return {boolean} False to cancel the default event
*/
mw.widgets.datetime.DateTimeInputWidget.prototype.onFieldKeyDown = function ( $field, e ) {
var spec = $field.data( 'mw-widgets-datetime-dateTimeInputWidget-fieldSpec' );
* @param {jQuery.Event} e Focus event
*/
mw.widgets.datetime.DateTimeInputWidget.prototype.onFieldFocus = function ( $field ) {
+ var spec = $field.data( 'mw-widgets-datetime-dateTimeInputWidget-fieldSpec' );
+
if ( !this.isDisabled() ) {
if ( this.getValueAsDate() === null ) {
this.setValue( this.formatter.getDefaultDate() );
}
if ( this.calendar ) {
- this.calendar.toggle( true );
+ this.calendar.toggle( !!spec.calendarComponent );
}
}
};
* @private
* @param {jQuery} $field
* @param {jQuery.Event} e Change event
+ * @return {boolean} False to cancel the default event
*/
mw.widgets.datetime.DateTimeInputWidget.prototype.onFieldWheel = function ( $field, e ) {
var delta = 0,
spec = $field.data( 'mw-widgets-datetime-dateTimeInputWidget-fieldSpec' );
- if ( this.isDisabled() ) {
+ if ( this.isDisabled() || !this.getFocusedField().length ) {
return;
}
* @inheritdoc
*/
mw.widgets.datetime.DateTimeInputWidget.prototype.focus = function () {
- if ( !this.$fields.find( document.activeElement ).length ) {
+ if ( !this.getFocusedField().length ) {
this.$fields.find( '.mw-widgets-datetime-dateTimeInputWidget-editField' ).first().focus();
}
return this;
* @inheritdoc
*/
mw.widgets.datetime.DateTimeInputWidget.prototype.blur = function () {
- this.$fields.find( document.activeElement ).blur();
+ this.getFocusedField().blur();
return this;
};