Consolidate "close on Escape" in the media modal, DFW, wpLink and Thickbox. Props kovshenin, fixes #26854.

git-svn-id: https://develop.svn.wordpress.org/trunk@27080 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2014-02-03 05:30:12 +00:00
parent 33b079b036
commit 9fd8c54ef9
5 changed files with 17 additions and 48 deletions

View File

@ -701,15 +701,4 @@ $(document).ready( function() {
}
})();
// internal use
$(document).bind( 'wp_CloseOnEscape', function( e, data ) {
if ( typeof(data.cb) != 'function' )
return;
if ( typeof(data.condition) != 'function' || data.condition() )
data.cb();
return true;
});
}( jQuery, window ));

View File

@ -477,23 +477,6 @@
a = e.altKey; // Alt key for Win & Linux
}
if ( 27 == c ) { // Esc
data = {
event: e,
what: 'dfw',
cb: api.off,
condition: function(){
if ( $('#TB_window').is(':visible') || $('.wp-dialog').is(':visible') )
return false;
return true;
}
};
if ( ! $(document).triggerHandler( 'wp_CloseOnEscape', [data] ) ) {
api.off();
}
}
if ( a && (61 == c || 107 == c || 187 == c) ) { // +
api.dfwWidth( 25 );
e.preventDefault();
@ -510,6 +493,13 @@
}
});
$document.on( 'keydown.wp-fullscreen', function( event ) {
if ( 27 === event.which && s.visible ) { // Esc
api.off();
event.stopImmediatePropagation();
}
});
toolbar.on( 'mouseenter', function() {
toggleUI('show');
}).on( 'mouseleave', function() {

View File

@ -2347,10 +2347,9 @@
*/
keydown: function( event ) {
// Close the modal when escape is pressed.
if ( 27 === event.which ) {
event.preventDefault();
if ( 27 === event.which && this.$el.is(':visible') ) {
this.escape();
return;
event.stopImmediatePropagation();
}
}
});

View File

@ -156,11 +156,8 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
}
jQuery(document).bind('keydown.thickbox', function(e){
e.stopImmediatePropagation();
if ( e.which == 27 ){ // close
if ( ! jQuery(document).triggerHandler( 'wp_CloseOnEscape', [{ event: e, what: 'thickbox', cb: tb_remove }] ) )
tb_remove();
tb_remove();
} else if ( e.which == 190 ){ // display previous image
if(!(TB_NextHTML == "")){
@ -244,13 +241,9 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
}
if(!params['modal']){
jQuery(document).bind('keyup.thickbox', function(e){
jQuery(document).bind('keydown.thickbox', function(e){
if ( e.which == 27 ){ // close
e.stopImmediatePropagation();
if ( ! jQuery(document).triggerHandler( 'wp_CloseOnEscape', [{ event: e, what: 'thickbox', cb: tb_remove }] ) )
tb_remove();
tb_remove();
return false;
}
});

View File

@ -304,6 +304,11 @@ var wpLink;
keydown: function( event ) {
var fn, key = $.ui.keyCode;
if ( key.ESCAPE === event.which ) {
wpLink.close();
event.stopImmediatePropagation();
}
if ( event.which !== key.UP && event.which !== key.DOWN ) {
return;
}
@ -318,13 +323,6 @@ var wpLink;
keyup: function( event ) {
var key = $.ui.keyCode;
if ( event.which === key.ESCAPE ) {
event.stopImmediatePropagation();
if ( ! $(document).triggerHandler( 'wp_CloseOnEscape', [{ event: event, what: 'wplink', cb: wpLink.close }] ) )
wpLink.close();
return false;
}
if ( event.which === key.UP || event.which === key.DOWN ) {
clearInterval( wpLink.keyInterval );
event.preventDefault();