jenkins-bot has submitted this change and it was merged.
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 cannot be canceled or prevented from bubbling
up, the only way to prevent the scrolling is to cancel the actual key
and mouse wheel events.
PhantomJs -= 2
Change-Id: I540738459181c37d11caf5db07345703e7000ef9
---
M modules/ve/ui/ve.ui.Dialog.js
1 file changed, 54 insertions(+), 2 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/ui/ve.ui.Dialog.js b/modules/ve/ui/ve.ui.Dialog.js
index 20d710c..3b99e8e 100644
--- a/modules/ve/ui/ve.ui.Dialog.js
+++ b/modules/ve/ui/ve.ui.Dialog.js
@@ -22,6 +22,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' );
@@ -53,10 +55,57 @@
};
/**
+ * 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 ) {
+ switch ( e.which ) {
+ case ve.Keys.PAGEUP:
+ case ve.Keys.PAGEDOWN:
+ case ve.Keys.END:
+ case ve.Keys.HOME:
+ case ve.Keys.LEFT:
+ case ve.Keys.UP:
+ case ve.Keys.RIGHT:
+ case ve.Keys.DOWN:
+ // Prevent any key events that might cause scrolling
+ 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
@@ -69,6 +118,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: merged
Gerrit-Change-Id: I540738459181c37d11caf5db07345703e7000ef9
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits