3 // Return a promise that is resolved when the element is blurred (loses focus).
4 // If it already is blurred, resolved immediately.
5 function whenBlurred( $elem ) {
6 const deferred = $.Deferred();
7 if ( $elem.is( ':focus' ) ) {
8 $elem.one( 'blur', deferred.resolve );
12 return deferred.promise();
16 // Do not infuse the date input while it has user focus.
17 // This is especially important on Firefox, where hiding the native date input while the native
18 // date picker is open will cause the date picker to remain visible (but non-functional), but
19 // not replacing the interface while the user is working with it is probably a good idea anyway.
20 const startReady = whenBlurred( $( '#mw-date-start .oo-ui-inputWidget-input' ) ).then( () => mw.widgets.DateInputWidget.static.infuse( $( '#mw-date-start' ) ) );
21 const endReady = whenBlurred( $( '#mw-date-end .oo-ui-inputWidget-input' ) ).then( () => mw.widgets.DateInputWidget.static.infuse( $( '#mw-date-end' ) ) );
23 $.when( startReady, endReady ).then( ( startInput, endInput ) => {
24 startInput.on( 'deactivate', ( userSelected ) => {