From: Prateek Saxena Date: Thu, 8 Oct 2015 12:07:57 +0000 (+0530) Subject: mw.widgets.DateInputWidget: Close calendar after a date is picked X-Git-Tag: 1.31.0-rc.0~9471^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=a2bc0241d26e17bdfbb8d3b791b2decb330580fb;p=lhc%2Fweb%2Fwiklou.git mw.widgets.DateInputWidget: Close calendar after a date is picked It guess it makes sense to do this. I can't think on any use case in which the user would want to keep clicking on random dates on an open calendar. It could be helpful if it were a filter for some visualization, but in that case we should probably have a config to keep the calendar always open. Bug: T114942 Change-Id: I1c81464a1835eb488a75920334a3cf3b92ef34fc --- diff --git a/resources/src/mediawiki.widgets/mw.widgets.DateInputWidget.js b/resources/src/mediawiki.widgets/mw.widgets.DateInputWidget.js index 9231fcca5d..b1e5151bc5 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.DateInputWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.DateInputWidget.js @@ -158,6 +158,7 @@ focusout: this.onBlur.bind( this ) } ); this.calendar.$element.on( { + click: this.onCalendarClick.bind( this ), keypress: this.onCalendarKeyPress.bind( this ) } ); this.$handle.on( { @@ -503,6 +504,24 @@ } }; + /** + * Handle calendar click events. + * + * @private + * @param {jQuery.Event} e Mouse click event + */ + mw.widgets.DateInputWidget.prototype.onCalendarClick = function ( e ) { + if ( + !this.isDisabled() && + e.which === 1 && + $( e.target ).hasClass( 'mw-widget-calendarWidget-day' ) + ) { + this.deactivate(); + this.$handle.focus(); + return false; + } + }; + /** * Handle text input enter events. *