Index: branches/wmf/1.18wmf1/CREDITS |
— | — | @@ -111,6 +111,7 @@ |
112 | 112 | * Louperivois |
113 | 113 | * Lucas Garczewski |
114 | 114 | * Luigi Corsaro |
| 115 | +* Lupo |
115 | 116 | * Manuel Menal |
116 | 117 | * Marcin Cieślak |
117 | 118 | * Marcus Buck |
Index: branches/wmf/1.18wmf1/resources/jquery/jquery.textSelection.js |
— | — | @@ -2,6 +2,26 @@ |
3 | 3 | * These plugins provide extra functionality for interaction with textareas. |
4 | 4 | */ |
5 | 5 | ( function( $ ) { |
| 6 | + |
| 7 | +if (document.selection && document.selection.createRange) { |
| 8 | + // On IE, patch the focus() method to restore the windows' scroll position |
| 9 | + // (bug 32241) |
| 10 | + $.fn.extend({ |
| 11 | + focus : (function ( _focus ) { |
| 12 | + return function () { |
| 13 | + if ( arguments.length == 0 ) { |
| 14 | + var $w = $( window ); |
| 15 | + var state = {top: $w.scrollTop(), left: $w.scrollLeft()}; |
| 16 | + var result = _focus.apply( this, arguments ); |
| 17 | + window.scrollTo( state.top, state.left ); |
| 18 | + return result; |
| 19 | + } |
| 20 | + return _focus.apply( this, arguments ); |
| 21 | + }; |
| 22 | + })( $.fn.focus ) |
| 23 | + }); |
| 24 | +} |
| 25 | + |
6 | 26 | $.fn.textSelection = function( command, options ) { |
7 | 27 | |
8 | 28 | /** |
— | — | @@ -17,6 +37,19 @@ |
18 | 38 | } |
19 | 39 | } |
20 | 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 | + |
21 | 54 | var fn = { |
22 | 55 | /** |
23 | 56 | * Get the contents of the textarea |
— | — | @@ -34,7 +67,7 @@ |
35 | 68 | if ( $(e).is( ':hidden' ) ) { |
36 | 69 | // Do nothing |
37 | 70 | } else if ( document.selection && document.selection.createRange ) { |
38 | | - e.focus(); |
| 71 | + activateElementOnIE( e ); |
39 | 72 | var range = document.selection.createRange(); |
40 | 73 | retval = range.text; |
41 | 74 | } else if ( e.selectionStart || e.selectionStart == '0' ) { |
— | — | @@ -150,7 +183,7 @@ |
151 | 184 | } |
152 | 185 | } else if ( document.selection && document.selection.createRange ) { |
153 | 186 | // IE |
154 | | - $(this).focus(); |
| 187 | + activateElementOnIE( this ); |
155 | 188 | if ( context ) { |
156 | 189 | context.fn.restoreCursorAndScrollTop(); |
157 | 190 | } |
— | — | @@ -212,12 +245,12 @@ |
213 | 246 | getCaretPosition: function( options ) { |
214 | 247 | function getCaret( e ) { |
215 | 248 | var caretPos = 0, endPos = 0; |
216 | | - if ( $.browser.msie ) { |
| 249 | + if ( document.selection && document.selection.createRange ) { |
217 | 250 | // IE doesn't properly report non-selected caret position through |
218 | 251 | // the selection ranges when textarea isn't focused. This can |
219 | 252 | // lead to saving a bogus empty selection, which then screws up |
220 | 253 | // whatever we do later (bug 31847). |
221 | | - e.focus(); |
| 254 | + activateElementOnIE( e ); |
222 | 255 | |
223 | 256 | // IE Support |
224 | 257 | var preFinished = false; |
Property changes on: branches/wmf/1.18wmf1 |
___________________________________________________________________ |
Modified: svn:mergeinfo |
225 | 258 | Merged /trunk/phase3:r102948,103138 |