From: jenkins-bot Date: Mon, 17 Jul 2017 19:47:01 +0000 (+0000) Subject: Merge "DateInputWidget: Unbreak closing the calendar when selecting a date" X-Git-Tag: 1.31.0-rc.0~2698 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/modifier.php?a=commitdiff_plain;h=ab14aaee1a0b2a400a96cd9240fce61fa6b0cd46;hp=419075a0205868eb13a319917668d2bd9a308068;p=lhc%2Fweb%2Fwiklou.git Merge "DateInputWidget: Unbreak closing the calendar when selecting a date" --- diff --git a/resources/src/mediawiki.widgets/mw.widgets.DateInputWidget.js b/resources/src/mediawiki.widgets/mw.widgets.DateInputWidget.js index 50a84f8b05..d41a147666 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.DateInputWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.DateInputWidget.js @@ -130,6 +130,7 @@ } ); this.inCalendar = 0; this.inTextInput = 0; + this.closing = false; this.inputFormat = config.inputFormat; this.displayFormat = config.displayFormat; this.longDisplayFormat = config.longDisplayFormat; @@ -173,7 +174,7 @@ this.$handle.on( { click: this.onClick.bind( this ), keypress: this.onKeyPress.bind( this ), - focus: this.activate.bind( this ) + focus: this.onFocus.bind( this ) } ); // Initialization @@ -521,6 +522,17 @@ } }; + /** + * Handle focus events. + * + * @private + */ + mw.widgets.DateInputWidget.prototype.onFocus = function () { + if ( !this.closing ) { + this.activate(); + } + }; + /** * Handle calendar key press events. * @@ -530,8 +542,13 @@ */ mw.widgets.DateInputWidget.prototype.onCalendarKeyPress = function ( e ) { if ( !this.isDisabled() && e.which === OO.ui.Keys.ENTER ) { + // Prevent focusing the handle from reopening the calendar + this.closing = true; + this.deactivate(); this.$handle.focus(); + + this.closing = false; return false; } }; @@ -547,10 +564,18 @@ if ( !this.isDisabled() && e.which === 1 && - $( e.target ).hasClass( 'mw-widget-calendarWidget-day' ) + ( + $( e.target ).hasClass( 'mw-widget-calendarWidget-day' ) || + $( e.target ).hasClass( 'mw-widget-calendarWidget-month' ) + ) ) { + // Prevent focusing the handle from reopening the calendar + this.closing = true; + this.deactivate(); this.$handle.focus(); + + this.closing = false; return false; } }; @@ -561,8 +586,13 @@ * @private */ mw.widgets.DateInputWidget.prototype.onEnter = function () { + // Prevent focusing the handle from reopening the calendar + this.closing = true; + this.deactivate(); this.$handle.focus(); + + this.closing = false; }; /**