From 6fa89637e5cca74188791ec182bfd2dac28349e6 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 16 May 2014 18:16:59 +0000 Subject: [PATCH] DFW: fix closing only the wpLink or media modal when pressing Esc. git-svn-id: https://develop.svn.wordpress.org/trunk@28455 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/wp-fullscreen.js | 3 +- .../js/tinymce/plugins/wpfullscreen/plugin.js | 32 +++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/wp-admin/js/wp-fullscreen.js b/src/wp-admin/js/wp-fullscreen.js index a00940cd66..de73060ae5 100644 --- a/src/wp-admin/js/wp-fullscreen.js +++ b/src/wp-admin/js/wp-fullscreen.js @@ -510,10 +510,11 @@ } }); - $( window ).on( 'keyup', function( event ) { + $( window ).on( 'keydown.wp-fullscreen', function( event ) { // Turn fullscreen off when Esc is pressed. if ( 27 === event.keyCode && s.visible ) { api.off(); + event.stopImmediatePropagation(); } }); diff --git a/src/wp-includes/js/tinymce/plugins/wpfullscreen/plugin.js b/src/wp-includes/js/tinymce/plugins/wpfullscreen/plugin.js index 52f981198a..8119a21736 100644 --- a/src/wp-includes/js/tinymce/plugins/wpfullscreen/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpfullscreen/plugin.js @@ -63,27 +63,33 @@ tinymce.PluginManager.add( 'wpfullscreen', function( editor ) { editor.addCommand( 'wpFullScreenOn', fullscreenOn ); editor.addCommand( 'wpFullScreenOff', fullscreenOff ); - function toggleFullscreen() { - // Toggle DFW mode. For use from inside the editor. - if ( typeof wp === 'undefined' || ! wp.editor || ! wp.editor.fullscreen ) { - return; - } + function getExtAPI() { + return ( typeof wp !== 'undefined' && wp.editor && wp.editor.fullscreen ); + } - if ( editor.getParam('wp_fullscreen') ) { - wp.editor.fullscreen.off(); - } else { - wp.editor.fullscreen.on(); + // Toggle DFW mode. For use from inside the editor. + function toggleFullscreen() { + var fullscreen = getExtAPI(); + + if ( fullscreen ) { + if ( editor.getParam('wp_fullscreen') ) { + fullscreen.off(); + } else { + fullscreen.on(); + } } } editor.addCommand( 'wpFullScreen', toggleFullscreen ); - editor.on( 'keyup', function( event ) { + editor.on( 'keydown', function( event ) { + var fullscreen; + // Turn fullscreen off when Esc is pressed. - if ( event.keyCode === 27 && wp.editor.fullscreen.settings.visible ) { - wp.editor.fullscreen.off(); + if ( event.keyCode === 27 && ( fullscreen = getExtAPI() ) && fullscreen.settings.visible ) { + fullscreen.off(); } - } ); + }); editor.on( 'init', function() { // Set the editor when initializing from whitin DFW