Index: trunk/phase3/resources/jquery/jquery.textSelection.js |
— | — | @@ -37,6 +37,19 @@ |
38 | 38 | } |
39 | 39 | } |
40 | 40 | |
| 41 | +/** |
| 42 | + * Helper function for IE for activating the textarea. Called only in the |
| 43 | + * IE-specific code paths below; makes use of IE-specific non-standard |
| 44 | + * function setActive() if possible to avoid screen flicker. |
| 45 | + */ |
| 46 | +function activateElementOnIE( element ) { |
| 47 | + if ( element.setActive ) { |
| 48 | + element.setActive(); // bug 32241: doesn't scroll |
| 49 | + } else { |
| 50 | + $( element ).focus(); // may scroll (but we patched it above) |
| 51 | + } |
| 52 | +} |
| 53 | + |
41 | 54 | var fn = { |
42 | 55 | /** |
43 | 56 | * Get the contents of the textarea |
— | — | @@ -54,7 +67,7 @@ |
55 | 68 | if ( $(e).is( ':hidden' ) ) { |
56 | 69 | // Do nothing |
57 | 70 | } else if ( document.selection && document.selection.createRange ) { |
58 | | - $(e).focus(); |
| 71 | + activateElementOnIE( e ); |
59 | 72 | var range = document.selection.createRange(); |
60 | 73 | retval = range.text; |
61 | 74 | } else if ( e.selectionStart || e.selectionStart == '0' ) { |
— | — | @@ -171,7 +184,7 @@ |
172 | 185 | } |
173 | 186 | } else if ( document.selection && document.selection.createRange ) { |
174 | 187 | // IE |
175 | | - $(this).focus(); |
| 188 | + activateElementOnIE( this ); |
176 | 189 | if ( context ) { |
177 | 190 | context.fn.restoreCursorAndScrollTop(); |
178 | 191 | } |
— | — | @@ -240,7 +253,7 @@ |
241 | 254 | // the selection ranges when textarea isn't focused. This can |
242 | 255 | // lead to saving a bogus empty selection, which then screws up |
243 | 256 | // whatever we do later (bug 31847). |
244 | | - $(e).focus(); |
| 257 | + activateElementOnIE( e ); |
245 | 258 | |
246 | 259 | // IE Support |
247 | 260 | var preFinished = false; |