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

Built from https://develop.svn.wordpress.org/trunk@27080


git-svn-id: http://core.svn.wordpress.org/trunk@26953 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2014-02-03 05:31:14 +00:00
parent 87c3c8adc0
commit 2f6d9d37cc
9 changed files with 21 additions and 52 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 )); }( jQuery, window ));

File diff suppressed because one or more lines are too long

View File

@ -477,23 +477,6 @@
a = e.altKey; // Alt key for Win & Linux 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) ) { // + if ( a && (61 == c || 107 == c || 187 == c) ) { // +
api.dfwWidth( 25 ); api.dfwWidth( 25 );
e.preventDefault(); 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() { toolbar.on( 'mouseenter', function() {
toggleUI('show'); toggleUI('show');
}).on( 'mouseleave', function() { }).on( 'mouseleave', function() {

File diff suppressed because one or more lines are too long

View File

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

File diff suppressed because one or more lines are too long

View File

@ -156,10 +156,7 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
} }
jQuery(document).bind('keydown.thickbox', function(e){ jQuery(document).bind('keydown.thickbox', function(e){
e.stopImmediatePropagation();
if ( e.which == 27 ){ // close 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 } else if ( e.which == 190 ){ // display previous image
@ -244,13 +241,9 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
} }
if(!params['modal']){ if(!params['modal']){
jQuery(document).bind('keyup.thickbox', function(e){ jQuery(document).bind('keydown.thickbox', function(e){
if ( e.which == 27 ){ // close 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; return false;
} }
}); });

View File

@ -304,6 +304,11 @@ var wpLink;
keydown: function( event ) { keydown: function( event ) {
var fn, key = $.ui.keyCode; var fn, key = $.ui.keyCode;
if ( key.ESCAPE === event.which ) {
wpLink.close();
event.stopImmediatePropagation();
}
if ( event.which !== key.UP && event.which !== key.DOWN ) { if ( event.which !== key.UP && event.which !== key.DOWN ) {
return; return;
} }
@ -318,13 +323,6 @@ var wpLink;
keyup: function( event ) { keyup: function( event ) {
var key = $.ui.keyCode; 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 ) { if ( event.which === key.UP || event.which === key.DOWN ) {
clearInterval( wpLink.keyInterval ); clearInterval( wpLink.keyInterval );
event.preventDefault(); event.preventDefault();

File diff suppressed because one or more lines are too long