X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.special.contributions.js;h=6558bda513343b900d6228aba4421e239c0a5bc6;hb=22ff706ce0cfd51b50fb33201f2570a39e87212b;hp=f65a2579b8cf77cddbca610a926d7f0974011e30;hpb=99a57ca021d6e2c7bb25d927d47d8657e60b48e8;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.special.contributions.js b/resources/src/mediawiki.special.contributions.js index f65a2579b8..6558bda513 100644 --- a/resources/src/mediawiki.special.contributions.js +++ b/resources/src/mediawiki.special.contributions.js @@ -1,12 +1,38 @@ ( function ( mw, $ ) { + + // 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 ) );