mw.widgets.DateInputWidget: Close calendar after a date is picked
authorPrateek Saxena <prtksxna@gmail.com>
Thu, 8 Oct 2015 12:07:57 +0000 (17:37 +0530)
committerPrateek Saxena <prtksxna@gmail.com>
Thu, 8 Oct 2015 15:44:36 +0000 (21:14 +0530)
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

resources/src/mediawiki.widgets/mw.widgets.DateInputWidget.js

index 9231fcc..b1e5151 100644 (file)
                        focusout: this.onBlur.bind( this )
                } );
                this.calendar.$element.on( {
+                       click: this.onCalendarClick.bind( this ),
                        keypress: this.onCalendarKeyPress.bind( this )
                } );
                this.$handle.on( {
                }
        };
 
+       /**
+        * 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.
         *