X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.special.contributions.js;h=275e96a8d4bb74221e7388ece0e6b43d97d907e9;hp=f65a2579b8cf77cddbca610a926d7f0974011e30;hb=6f3d5a5204770b7e9076ec0c956631c32a9e1114;hpb=399d9c24a85b7e108ccfc51140af225c458f00b9 diff --git a/resources/src/mediawiki.special.contributions.js b/resources/src/mediawiki.special.contributions.js index f65a2579b8..275e96a8d4 100644 --- a/resources/src/mediawiki.special.contributions.js +++ b/resources/src/mediawiki.special.contributions.js @@ -1,12 +1,38 @@ -( function ( mw, $ ) { +( function () { + + // Return a promise that is resolved when the element is blurred (loses focus). + // If it already is blurred, resolved immediately. + function whenBlurred( $elem ) { + var deferred = $.Deferred(); + if ( $elem.is( ':focus' ) ) { + $elem.one( 'blur', deferred.resolve ); + } else { + deferred.resolve(); + } + return deferred.promise(); + } + $( function () { - var startInput = mw.widgets.DateInputWidget.static.infuse( 'mw-date-start' ), - endInput = mw.widgets.DateInputWidget.static.infuse( 'mw-date-end' ); + var startReady, endReady; + + // Do not infuse the date input while it has user focus. + // This is especially important on Firefox, where hiding the native date input while the native + // date picker is open will cause the date picker to remain visible (but non-functional), but + // not replacing the interface while the user is working with it is probably a good idea anyway. + startReady = whenBlurred( $( '#mw-date-start .oo-ui-inputWidget-input' ) ).then( function () { + return mw.widgets.DateInputWidget.static.infuse( 'mw-date-start' ); + } ); + endReady = whenBlurred( $( '#mw-date-end .oo-ui-inputWidget-input' ) ).then( function () { + return mw.widgets.DateInputWidget.static.infuse( 'mw-date-end' ); + } ); - startInput.on( 'deactivate', function ( userSelected ) { - if ( userSelected ) { - endInput.focus(); - } + $.when( startReady, endReady ).then( function ( startInput, endInput ) { + startInput.on( 'deactivate', function ( userSelected ) { + if ( userSelected ) { + endInput.focus(); + } + } ); } ); } ); -}( mediaWiki, jQuery ) ); + +}() );