mw.widgets.DateTimeInputWidget: Simplify code for hiding reused $input when infusing
authorBartosz Dziewoński <matma.rex@gmail.com>
Sat, 8 Oct 2016 17:33:21 +0000 (19:33 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Sat, 8 Oct 2016 17:33:21 +0000 (19:33 +0200)
This is the standard solution, used also in OO.ui.DropdownInputWidget.

Change-Id: I42993bfade56b0461d4dd1a65fb110d605f1acf2

resources/src/mediawiki.widgets.datetime/DateTimeInputWidget.js

index 91f797d..a3088ec 100644 (file)
                        calendar: {}
                }, config );
 
+               // See InputWidget#reusePreInfuseDOM about config.$input
+               if ( config.$input ) {
+                       config.$input.addClass( 'oo-ui-element-hidden' );
+               }
+
                if ( $.isPlainObject( config.formatter ) && config.formatter.format === undefined ) {
                        config.formatter.format = '@' + config.type;
                }
                        } );
                }
 
-               // Our form input *should* be type="hidden". But if we're infusing from
-               // PHP, it's not.
-               if ( this.$input.attr( 'type' ) !== 'hidden' ) {
-                       try {
-                               this.$input.attr( 'type', 'hidden' );
-                       } catch ( e ) {
-                       }
-                       // IE <= 8, and IE 9 in quirks mode, doesn't allow changing the
-                       // type, so just hide the field with CSS. IE 9 in quirks mode
-                       // doesn't even throw an error, so do that unconditionally. Sigh.
-                       this.$input.css( 'display', 'none' );
-               }
-
                // Initialization
                this.setTabIndex( -1 );