From a2bc0241d26e17bdfbb8d3b791b2decb330580fb Mon Sep 17 00:00:00 2001 From: Prateek Saxena Date: Thu, 8 Oct 2015 17:37:57 +0530 Subject: [PATCH] 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 --- .../mw.widgets.DateInputWidget.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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. * -- 2.20.1