Trevor Parscal has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/65246


Change subject: Prevent scrolling in top-level window while dialog is open
......................................................................

Prevent scrolling in top-level window while dialog is open

Because scroll events can not be cancelled or prevented from bubbling up, the 
only way to prevent the scrolling is to cancel the actual key and mouse wheel 
events.

Change-Id: I540738459181c37d11caf5db07345703e7000ef9
---
M modules/ve/ui/ve.ui.Dialog.js
1 file changed, 45 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/46/65246/1

diff --git a/modules/ve/ui/ve.ui.Dialog.js b/modules/ve/ui/ve.ui.Dialog.js
index 85d8feb..b70ee88 100644
--- a/modules/ve/ui/ve.ui.Dialog.js
+++ b/modules/ve/ui/ve.ui.Dialog.js
@@ -21,6 +21,8 @@
 
        // Properties
        this.visible = false;
+       this.onWindowMouseWheelHandler = ve.bind( this.onWindowMouseWheel, this 
);
+       this.onDocumentKeyDownHandler = ve.bind( this.onDocumentKeyDown, this );
 
        // Initialization
        this.$.addClass( 've-ui-dialog' );
@@ -52,10 +54,48 @@
 };
 
 /**
+ * Handle window mouse wheel events.
+ *
+ * @method
+ * @param {jQuery.Event} e Mouse wheel event
+ */
+ve.ui.Dialog.prototype.onWindowMouseWheel = function () {
+       return false;
+};
+
+/**
+ * Handle document key down events.
+ *
+ * @method
+ * @param {jQuery.Event} e Key down event
+ */
+ve.ui.Dialog.prototype.onDocumentKeyDown = function ( e ) {
+       if ( e.which >= 33 && e.which <= 40 ) {
+               return false;
+       }
+};
+
+/**
+ * Open window.
+ *
+ * Wraps the parent open method. Disables native top-level window scrolling 
behavior.
+ *
+ * @method
+ * @emits setup
+ * @emits open
+ */
+ve.ui.Dialog.prototype.open = function () {
+       ve.ui.Window.prototype.open.call( this );
+       // Prevent scrolling in top-level window
+       $( window ).on( 'mousewheel', this.onWindowMouseWheelHandler );
+       $( document ).on( 'keydown', this.onDocumentKeyDownHandler );
+};
+
+/**
  * Close dialog.
  *
- * This method overrides the parent close method to allow animation, but still 
provides the same
- * recursion blocking and eventually calls the parent method.
+ * Wraps the parent close method. Allows animation by delaying parent close 
call, while still
+ * providing the same recursion blocking. Restores native top-level window 
scrolling behavior.
  *
  * @method
  * @param {boolean} action Action that caused the window to be closed
@@ -68,6 +108,9 @@
                        ve.ui.Window.prototype.close.call( this, action );
                        this.$.removeClass( 've-ui-dialog-closing' );
                }, this ), 250 );
+               // Allow scrolling in top-level window
+               $( window ).off( 'mousewheel', this.onWindowMouseWheelHandler );
+               $( document ).off( 'keydown', this.onDocumentKeyDownHandler );
        }
 };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/65246
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I540738459181c37d11caf5db07345703e7000ef9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to