From 9a529362778c78f39365d937856673fd9414f7f7 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 25 Aug 2014 17:44:28 +0000 Subject: [PATCH] Media Grid: exit selection mode when Esc is pressed. Fixes #29366. git-svn-id: https://develop.svn.wordpress.org/trunk@29600 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-grid.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/wp-includes/js/media-grid.js b/src/wp-includes/js/media-grid.js index c3edcf182a..ed14c73c81 100644 --- a/src/wp-includes/js/media-grid.js +++ b/src/wp-includes/js/media-grid.js @@ -65,6 +65,7 @@ mode: [ 'grid', 'edit' ] }); + this.$body = $( document.body ); this.$window = $( window ); this.$adminBar = $( '#wpadminbar' ); this.$window.on( 'scroll resize', _.debounce( _.bind( this.fixPosition, this ), 15 ) ); @@ -149,6 +150,24 @@ // Handle a frame-level event for editing an attachment. this.on( 'edit:attachment', this.openEditAttachmentModal, this ); + + this.on( 'select:activate', this.bindKeydown, this ); + this.on( 'select:deactivate', this.unbindKeydown, this ); + }, + + handleKeydown: function( e ) { + if ( 27 === e.which ) { + e.preventDefault(); + this.deactivateMode( 'select' ).activateMode( 'edit' ); + } + }, + + bindKeydown: function() { + this.$body.on( 'keydown.select', _.bind( this.handleKeydown, this ) ); + }, + + unbindKeydown: function() { + this.$body.off( 'keydown.select' ); }, fixPosition: function() {