diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index f6fb3d7249..36d17b6ab1 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -545,7 +545,7 @@ ve.ce.Surface.prototype.onDocumentKeyPress = function ( e ) { */ ve.ce.Surface.prototype.onDocumentKeyUp = function ( e ) { // Detect end of selecting by letting go of shift - if ( !this.dragging && this.selecting && e.keyCode === 16 ) { + if ( !this.dragging && this.selecting && e.keyCode === ve.Keys.SHIFT ) { this.selecting = false; this.emit( 'selectionEnd' ); } diff --git a/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js b/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js index 8bdf07f4d4..9ef0463528 100644 --- a/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js +++ b/modules/ve/init/mw/targets/ve.init.mw.ViewPageTarget.js @@ -1466,7 +1466,7 @@ ve.init.mw.ViewPageTarget.prototype.showSaveDialog = function () { $( document ).on( 'keydown.ve-savedialog', function ( e ) { // Escape - if ( e.which === 27 ) { + if ( e.which === ve.Keys.ESCAPE ) { viewPage.onSaveDialogCloseButtonClick(); } } ); diff --git a/modules/ve/ui/ve.ui.Dialog.js b/modules/ve/ui/ve.ui.Dialog.js index a9faa93a57..3178297c09 100644 --- a/modules/ve/ui/ve.ui.Dialog.js +++ b/modules/ve/ui/ve.ui.Dialog.js @@ -85,6 +85,19 @@ ve.ui.Dialog.prototype.onDocumentKeyDown = function ( e ) { } }; +/** + * Handle frame document key down events. + * + * @method + * @param {jQuery.Event} e Key down event + */ +ve.ui.Dialog.prototype.onFrameDocumentKeyDown = function ( e ) { + if ( e.which === ve.Keys.ESCAPE ) { + this.close( 'cancel' ); + return false; + } +}; + /** * Open window. * @@ -139,6 +152,7 @@ ve.ui.Dialog.prototype.initialize = function () { // Events this.closeButton.connect( this, { 'click': 'onCloseButtonClick' } ); this.applyButton.connect( this, { 'click': 'onApplyButtonClick' } ); + this.frame.$document.on( 'keydown', ve.bind( this.onFrameDocumentKeyDown, this ) ); // Initialization this.closeButton.$.addClass( 've-ui-window-closeButton' ); diff --git a/modules/ve/ui/ve.ui.Frame.js b/modules/ve/ui/ve.ui.Frame.js index 4d6b33f808..0699e9c66f 100644 --- a/modules/ve/ui/ve.ui.Frame.js +++ b/modules/ve/ui/ve.ui.Frame.js @@ -119,6 +119,7 @@ ve.ui.Frame.prototype.load = function () { // Properties this.$$ = ve.Element.static.get$$( doc, this ); this.$content = this.$$( '.ve-ui-frame-content' ); + this.$document = this.$$( doc ); }; /** diff --git a/modules/ve/ui/ve.ui.Inspector.js b/modules/ve/ui/ve.ui.Inspector.js index dc956368f3..572a0ca78e 100644 --- a/modules/ve/ui/ve.ui.Inspector.js +++ b/modules/ve/ui/ve.ui.Inspector.js @@ -107,7 +107,7 @@ ve.ui.Inspector.prototype.onFormSubmit = function () { */ ve.ui.Inspector.prototype.onFormKeyDown = function ( e ) { // Escape - if ( e.which === 27 ) { + if ( e.which === ve.Keys.ESCAPE ) { this.close( 'back' ); return false; } diff --git a/modules/ve/ui/ve.ui.Window.js b/modules/ve/ui/ve.ui.Window.js index a108918422..c93a3061b1 100644 --- a/modules/ve/ui/ve.ui.Window.js +++ b/modules/ve/ui/ve.ui.Window.js @@ -301,6 +301,7 @@ ve.ui.Window.prototype.open = function () { this.emit( 'setup' ); this.$.show(); this.visible = true; + this.frame.$.focus(); this.frame.run( ve.bind( function () { this.onOpen(); this.opening = false; diff --git a/modules/ve/ui/widgets/ve.ui.MenuWidget.js b/modules/ve/ui/widgets/ve.ui.MenuWidget.js index e33c213304..a0b7daaf92 100644 --- a/modules/ve/ui/widgets/ve.ui.MenuWidget.js +++ b/modules/ve/ui/widgets/ve.ui.MenuWidget.js @@ -57,23 +57,19 @@ ve.ui.MenuWidget.prototype.onKeyDown = function ( e ) { if ( !this.disabled && this.visible ) { switch ( e.keyCode ) { - // Enter - case 13: + case ve.Keys.ENTER: this.selectItem( highlightItem ); handled = true; break; - // Up arrow - case 38: + case ve.Keys.UP: this.highlightItem( this.getRelativeSelectableItem( highlightItem, -1 ) ); handled = true; break; - // Down arrow - case 40: + case ve.Keys.DOWN: this.highlightItem( this.getRelativeSelectableItem( highlightItem, 1 ) ); handled = true; break; - // Escape - case 27: + case ve.Keys.ESCAPE: if ( highlightItem ) { highlightItem.setHighlighted( false ); } diff --git a/modules/ve/ve.js b/modules/ve/ve.js index efb9c4091e..9743b493ab 100644 --- a/modules/ve/ve.js +++ b/modules/ve/ve.js @@ -917,7 +917,9 @@ 'HOME': 36, 'TAB': 9, 'PAGEUP': 33, - 'PAGEDOWN': 34 + 'PAGEDOWN': 34, + 'ESCAPE': 27, + 'SHIFT': 16 }; // Expose