Merge "selenium: invoke jobs to enforce eventual consistency"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets.datetime / DateTimeInputWidget.js
index e42ab25..21aecd6 100644 (file)
@@ -1,9 +1,9 @@
-( function ( $, mw ) {
+( function () {
 
        /**
         * DateTimeInputWidgets can be used to input a date, a time, or a date and
         * time, in either UTC or the user's local timezone.
-        * Please see the [OOjs UI documentation on MediaWiki] [1] for more information and examples.
+        * Please see the [OOUI documentation on MediaWiki] [1] for more information and examples.
         *
         * This widget can be used inside a HTML form, such as a OO.ui.FormLayout.
         *
@@ -12,7 +12,7 @@
         *     var dateTimeInput = new mw.widgets.datetime.DateTimeInputWidget( {} )
         *     $( 'body' ).append( dateTimeInput.$element );
         *
-        * [1]: https://www.mediawiki.org/wiki/OOjs_UI/Widgets/Inputs
+        * [1]: https://www.mediawiki.org/wiki/OOUI/Widgets/Inputs
         *
         * @class
         * @extends OO.ui.InputWidget
 
        /* 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
         *
                                sz = ( spec.size * 1.15 ) + 'ch';
                        } else {
                                // Add a little for padding
-                               sz = ( spec.size * 1.15 ) + 'ch';
+                               sz = ( spec.size * 1.25 ) + 'ch';
                        }
                        if ( spec.editable && spec.type !== 'static' ) {
                                if ( spec.type === 'boolean' || spec.type === 'toggleLocal' ) {
                                } else {
                                        maxlength = spec.size;
                                        if ( spec.intercalarySize ) {
+                                               // eslint-disable-next-line no-restricted-properties
                                                $.each( spec.intercalarySize, reduceFunc );
                                        }
                                        $field = $( '<input>' ).attr( 'type', 'text' )
                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;
        };
 
                this.focus();
        };
 
-}( jQuery, mediaWiki ) );
+}() );