From a989ce280b2f9d1fc6b0f7aa91441c64e45af03e Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sat, 29 Nov 2014 02:44:37 +0000 Subject: [PATCH] Editor: fix fading out on Escape in DFW v2. props adamsilverstein, fixes #30528. git-svn-id: https://develop.svn.wordpress.org/trunk@30625 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/editor-expand.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/wp-admin/js/editor-expand.js b/src/wp-admin/js/editor-expand.js index 5657ff6e90..af771c9ac7 100644 --- a/src/wp-admin/js/editor-expand.js +++ b/src/wp-admin/js/editor-expand.js @@ -876,7 +876,7 @@ // fadeIn and return on Escape and keyboard shortcut Alt+Shift+W. if ( key === 27 || ( key === 87 && event.altKey && event.shiftKey ) ) { - fadeIn(); + fadeIn( event ); return; } @@ -994,7 +994,7 @@ fadeOutSlug(); } - function fadeIn() { + function fadeIn( event ) { if ( faded ) { faded = false; @@ -1008,11 +1008,18 @@ $overlay.off( 'mouseenter.focus mouseleave.focus mousemove.focus touchstart.focus' ); - $editor.on( 'mouseenter.focus', function() { - if ( $.contains( $editor.get( 0 ), document.activeElement ) || editorHasFocus ) { - fadeOut(); - } - } ); + /* + * When fading in, temporarily watch for refocus and fade back out - helps + * with 'accidental' editor exits with the mouse. When fading in and the event + * is a key event (Escape or Alt+Shift+W) don't watch for refocus. + */ + if ( 'undefined' === typeof event ) { + $editor.on( 'mouseenter.focus', function() { + if ( $.contains( $editor.get( 0 ), document.activeElement ) || editorHasFocus ) { + fadeOut(); + } + } ); + } focusLostTimer = setTimeout( function() { focusLostTimer = null;