From f0b2c1a92e8ab4a8d5a0b151bdc09bddcb8b94a5 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 15 Nov 2011 09:59:32 +0000 Subject: [PATCH] (bug 32241) Fix flickering behavior in IE. Patch by Lupo. See also r102948 --- resources/jquery/jquery.textSelection.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/resources/jquery/jquery.textSelection.js b/resources/jquery/jquery.textSelection.js index 9ba78d2d45..443722f2df 100644 --- a/resources/jquery/jquery.textSelection.js +++ b/resources/jquery/jquery.textSelection.js @@ -37,6 +37,19 @@ function rangeForElementIE( e ) { } } +/** + * Helper function for IE for activating the textarea. Called only in the + * IE-specific code paths below; makes use of IE-specific non-standard + * function setActive() if possible to avoid screen flicker. + */ +function activateElementOnIE( element ) { + if ( element.setActive ) { + element.setActive(); // bug 32241: doesn't scroll + } else { + $( element ).focus(); // may scroll (but we patched it above) + } +} + var fn = { /** * Get the contents of the textarea @@ -54,7 +67,7 @@ getSelection: function() { if ( $(e).is( ':hidden' ) ) { // Do nothing } else if ( document.selection && document.selection.createRange ) { - $(e).focus(); + activateElementOnIE( e ); var range = document.selection.createRange(); retval = range.text; } else if ( e.selectionStart || e.selectionStart == '0' ) { @@ -171,7 +184,7 @@ encapsulateSelection: function( options ) { } } else if ( document.selection && document.selection.createRange ) { // IE - $(this).focus(); + activateElementOnIE( this ); if ( context ) { context.fn.restoreCursorAndScrollTop(); } @@ -240,7 +253,7 @@ encapsulateSelection: function( options ) { // the selection ranges when textarea isn't focused. This can // lead to saving a bogus empty selection, which then screws up // whatever we do later (bug 31847). - $(e).focus(); + activateElementOnIE( e ); // IE Support var preFinished = false; -- 2.20.1