Merge "Close dialogs on escape"

This commit is contained in:
jenkins-bot 2013-06-28 00:10:36 +00:00 committed by Gerrit Code Review
commit c6fceaa1e2
8 changed files with 26 additions and 12 deletions

View file

@ -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' );
}

View file

@ -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();
}
} );

View file

@ -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' );

View file

@ -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 );
};
/**

View file

@ -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;
}

View file

@ -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;

View file

@ -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 );
}

View file

@ -917,7 +917,9 @@
'HOME': 36,
'TAB': 9,
'PAGEUP': 33,
'PAGEDOWN': 34
'PAGEDOWN': 34,
'ESCAPE': 27,
'SHIFT': 16
};
// Expose