Index: branches/wmf/1.17wmf1/resources/jquery/jquery.textSelection.js |
— | — | @@ -3,6 +3,20 @@ |
4 | 4 | */ |
5 | 5 | ( function( $ ) { |
6 | 6 | $.fn.textSelection = function( command, options ) { |
| 7 | + |
| 8 | +/** |
| 9 | + * Helper function to get an IE TextRange object for an element |
| 10 | + */ |
| 11 | +function rangeForElementIE( e ) { |
| 12 | + if ( e.nodeName.toLowerCase() == 'input' ) { |
| 13 | + return e.createTextRange(); |
| 14 | + } else { |
| 15 | + var sel = document.body.createTextRange(); |
| 16 | + sel.moveToElementText( e ); |
| 17 | + return sel; |
| 18 | + } |
| 19 | +} |
| 20 | + |
7 | 21 | var fn = { |
8 | 22 | /** |
9 | 23 | * Get the contents of the textarea |
— | — | @@ -148,15 +162,11 @@ |
149 | 163 | // Create range containing text in the selection |
150 | 164 | var periRange = document.selection.createRange().duplicate(); |
151 | 165 | // Create range containing text before the selection |
152 | | - var preRange = document.body.createTextRange(); |
153 | | - // Select all the text |
154 | | - preRange.moveToElementText(e); |
| 166 | + var preRange = rangeForElementIE( e ); |
155 | 167 | // Move the end where we need it |
156 | 168 | preRange.setEndPoint("EndToStart", periRange); |
157 | 169 | // Create range containing text after the selection |
158 | | - var postRange = document.body.createTextRange(); |
159 | | - // Select all the text |
160 | | - postRange.moveToElementText(e); |
| 170 | + var postRange = rangeForElementIE( e ); |
161 | 171 | // Move the start where we need it |
162 | 172 | postRange.setEndPoint("StartToEnd", periRange); |
163 | 173 | // Load the text values we need to compare |
— | — | @@ -233,8 +243,7 @@ |
234 | 244 | this.selectionEnd = options.end; |
235 | 245 | } |
236 | 246 | } else if ( document.body.createTextRange ) { |
237 | | - var selection = document.body.createTextRange(); |
238 | | - selection.moveToElementText( this ); |
| 247 | + var selection = rangeForElementIE( this ); |
239 | 248 | var length = this.value.length; |
240 | 249 | // IE doesn't count \n when computing the offset, so we won't either |
241 | 250 | var newLines = this.value.match( /\n/g ); |
Property changes on: branches/wmf/1.17wmf1/resources/jquery/jquery.textSelection.js |
___________________________________________________________________ |
Added: svn:mergeinfo |
242 | 251 | Merged /branches/sqlite/resources/jquery/jquery.textSelection.js:r58211-58321 |
243 | 252 | Merged /trunk/phase3/resources/jquery/jquery.textSelection.js:r79828,79830,79848,79853,79950-79951,79954,79989,80006-80007,80013,80016,80080,80083,80124,80128,80238,81833,83212,83590,84384 |
244 | 253 | Merged /branches/new-installer/phase3/resources/jquery/jquery.textSelection.js:r43664-66004 |
245 | 254 | Merged /branches/wmf-deployment/resources/jquery/jquery.textSelection.js:r60970 |
246 | 255 | Merged /branches/REL1_15/phase3/resources/jquery/jquery.textSelection.js:r51646 |
247 | 256 | Merged /branches/wmf/1.16wmf4/resources/jquery/jquery.textSelection.js:r67177,69199,76243,77266 |