r84384 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84383‎ | r84384 | r84385 >
Date:14:48, 20 March 2011
Author:catrope
Status:ok
Tags:
Comment:
In $.textSelection, treat <input> elements differently from other elements (such as textareas and iframes) in IE, seems to be needed for some reason (oh IE, how I hate you). This fixes a bug causing Narayam's keyboard mappings to not work in <input> elements in IE.
Modified paths:
  • /trunk/phase3/resources/jquery/jquery.textSelection.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.textSelection.js
@@ -3,6 +3,20 @@
44 */
55 ( function( $ ) {
66 $.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+
721 var fn = {
822 /**
923 * Get the contents of the textarea
@@ -152,15 +166,11 @@
153167 // Create range containing text in the selection
154168 var periRange = document.selection.createRange().duplicate();
155169 // Create range containing text before the selection
156 - var preRange = document.body.createTextRange();
157 - // Select all the text
158 - preRange.moveToElementText(e);
 170+ var preRange = rangeForElementIE( e );
159171 // Move the end where we need it
160172 preRange.setEndPoint("EndToStart", periRange);
161173 // Create range containing text after the selection
162 - var postRange = document.body.createTextRange();
163 - // Select all the text
164 - postRange.moveToElementText(e);
 174+ var postRange = rangeForElementIE( e );
165175 // Move the start where we need it
166176 postRange.setEndPoint("StartToEnd", periRange);
167177 // Load the text values we need to compare
@@ -240,8 +250,7 @@
241251 this.selectionEnd = options.end;
242252 }
243253 } else if ( document.body.createTextRange ) {
244 - var selection = document.body.createTextRange();
245 - selection.moveToElementText( this );
 254+ var selection = rangeForElementIE( this );
246255 var length = this.value.length;
247256 // IE doesn't count \n when computing the offset, so we won't either
248257 var newLines = this.value.match( /\n/g );

Follow-up revisions

RevisionCommit summaryAuthorDate
r843851.17wmf1: MFT r84384catrope14:50, 20 March 2011

Status & tagging log