DateTimeInputWidget: Ignore wheel when not focused
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 14 Jul 2017 12:42:47 +0000 (08:42 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Fri, 14 Jul 2017 12:59:13 +0000 (08:59 -0400)
Much like I6c9f4679, it's probably best that the widget only use wheel
input when it's focused so it won't accidentally trigger when scrolling
through a form.

Bug: T170607
Change-Id: I46dc3eb01733be939c62e7e7f3f044f21ef1e6d8

resources/src/mediawiki.widgets.datetime/DateTimeInputWidget.js

index e42ab25..9233eef 100644 (file)
 
        /* Methods */
 
+       /**
+        * Get the currently focused field, if any
+        *
+        * @private
+        * @return {jQuery}
+        */
+       mw.widgets.datetime.DateTimeInputWidget.prototype.getFocusedField = function () {
+               return this.$fields.find( this.getElementDocument().activeElement );
+       };
+
        /**
         * Convert a date string to a Date
         *
                var delta = 0,
                        spec = $field.data( 'mw-widgets-datetime-dateTimeInputWidget-fieldSpec' );
 
-               if ( this.isDisabled() ) {
+               if ( this.isDisabled() || !this.getFocusedField().length ) {
                        return;
                }
 
         * @inheritdoc
         */
        mw.widgets.datetime.DateTimeInputWidget.prototype.focus = function () {
-               if ( !this.$fields.find( document.activeElement ).length ) {
+               if ( !this.getFocusedField().length ) {
                        this.$fields.find( '.mw-widgets-datetime-dateTimeInputWidget-editField' ).first().focus();
                }
                return this;
         * @inheritdoc
         */
        mw.widgets.datetime.DateTimeInputWidget.prototype.blur = function () {
-               this.$fields.find( document.activeElement ).blur();
+               this.getFocusedField().blur();
                return this;
        };