Merge "user: Allow "CAS update failed" exceptions to be normalised"
[lhc/web/wiklou.git] / resources / src / mediawiki.special.contributions.js
1 ( function () {
2
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 var deferred = $.Deferred();
7 if ( $elem.is( ':focus' ) ) {
8 $elem.one( 'blur', deferred.resolve );
9 } else {
10 deferred.resolve();
11 }
12 return deferred.promise();
13 }
14
15 $( function () {
16 var startReady, endReady;
17
18 // Do not infuse the date input while it has user focus.
19 // This is especially important on Firefox, where hiding the native date input while the native
20 // date picker is open will cause the date picker to remain visible (but non-functional), but
21 // not replacing the interface while the user is working with it is probably a good idea anyway.
22 startReady = whenBlurred( $( '#mw-date-start .oo-ui-inputWidget-input' ) ).then( function () {
23 return mw.widgets.DateInputWidget.static.infuse( 'mw-date-start' );
24 } );
25 endReady = whenBlurred( $( '#mw-date-end .oo-ui-inputWidget-input' ) ).then( function () {
26 return mw.widgets.DateInputWidget.static.infuse( 'mw-date-end' );
27 } );
28
29 $.when( startReady, endReady ).then( function ( startInput, endInput ) {
30 startInput.on( 'deactivate', function ( userSelected ) {
31 if ( userSelected ) {
32 endInput.focus();
33 }
34 } );
35 } );
36 } );
37
38 }() );