Editor focus: Don't trigger when typing while the mouse is outside the editor.

props avryl.
fixes #20668.

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


git-svn-id: http://core.svn.wordpress.org/trunk@30807 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2014-12-11 09:34:26 +00:00
parent 0aa0016488
commit 5e3e3d0e0f
2 changed files with 22 additions and 14 deletions

View File

@ -803,6 +803,12 @@
mouseY = event.pageY;
} );
function recalcEditorRect() {
editorRect = $editor.offset();
editorRect.right = editorRect.left + $editor.outerWidth();
editorRect.bottom = editorRect.top + $editor.outerHeight();
}
function activate() {
if ( ! _isActive ) {
_isActive = true;
@ -909,9 +915,7 @@
$overlay
// Always recalculate the editor area entering the overlay with the mouse.
.on( 'mouseenter.focus', function() {
editorRect = $editor.offset();
editorRect.right = editorRect.left + $editor.outerWidth();
editorRect.bottom = editorRect.top + $editor.outerHeight();
recalcEditorRect();
$window.on( 'scroll.focus', function() {
var nScrollY = window.pageYOffset;
@ -937,24 +941,26 @@
} )
// Fade in when the mouse moves away form the editor area.
.on( 'mousemove.focus', function( event ) {
var nx = event.pageX,
ny = event.pageY;
var nx = event.clientX,
ny = event.clientY,
pageYOffset = window.pageYOffset,
pageXOffset = window.pageXOffset;
if ( x && y && ( nx !== x || ny !== y ) ) {
if (
( ny <= y && ny < editorRect.top ) ||
( ny >= y && ny > editorRect.bottom ) ||
( nx <= x && nx < editorRect.left ) ||
( nx >= x && nx > editorRect.right )
( ny <= y && ny < editorRect.top - pageYOffset ) ||
( ny >= y && ny > editorRect.bottom - pageYOffset ) ||
( nx <= x && nx < editorRect.left - pageXOffset ) ||
( nx >= x && nx > editorRect.right - pageXOffset )
) {
traveledX += Math.abs( x - nx );
traveledY += Math.abs( y - ny );
if ( (
ny <= editorRect.top - buffer ||
ny >= editorRect.bottom + buffer ||
nx <= editorRect.left - buffer ||
nx >= editorRect.right + buffer
ny <= editorRect.top - buffer - pageYOffset ||
ny >= editorRect.bottom + buffer - pageYOffset ||
nx <= editorRect.left - buffer - pageXOffset ||
nx >= editorRect.right + buffer - pageXOffset
) && (
traveledX > 10 ||
traveledY > 10
@ -1151,6 +1157,7 @@
editor.on( 'blur', maybeFadeIn );
editor.on( 'focus', focus );
editor.on( 'blur', blur );
editor.on( 'wp-autoresize', recalcEditorRect );
};
mceUnbind = function() {
@ -1158,6 +1165,7 @@
editor.off( 'blur', maybeFadeIn );
editor.off( 'focus', focus );
editor.off( 'blur', blur );
editor.off( 'wp-autoresize', recalcEditorRect );
};
if ( _isOn ) {

File diff suppressed because one or more lines are too long