https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113775

Revision: 113775
Author:   brion
Date:     2012-03-13 22:38:14 +0000 (Tue, 13 Mar 2012)
Log Message:
-----------
* (bug 35201) Edit buttons no longer cause jump in IE 9

Changed order of feature-detection checks so we prefer the IE method over the 
Mozilla method in encapsulateSelection. Fixes a problem where IE9 triggered the 
Mozilla mode, then mysteriously scrolled to the top of the page.

(IE9 and IE10 add a lot of standard and semi-standard HTML APIs, so this sort 
of thing happens from time to time. :)

Modified Paths:
--------------
    trunk/phase3/resources/jquery/jquery.textSelection.js

Modified: trunk/phase3/resources/jquery/jquery.textSelection.js
===================================================================
--- trunk/phase3/resources/jquery/jquery.textSelection.js       2012-03-13 
22:35:03 UTC (rev 113774)
+++ trunk/phase3/resources/jquery/jquery.textSelection.js       2012-03-13 
22:38:14 UTC (rev 113775)
@@ -131,8 +131,58 @@
                var isSample = false;
                if ( this.style.display == 'none' ) {
                        // Do nothing
+               } else if ( document.selection && 
document.selection.createRange ) {
+                       // IE
+
+                       // Note that IE9 will trigger the next section unless 
we check this first.
+                       // See bug 35201.
+
+                       activateElementOnIE( this );
+                       if ( context ) {
+                               context.fn.restoreCursorAndScrollTop();
+                       }
+                       if ( options.selectionStart !== undefined ) {
+                               $(this).textSelection( 'setSelection', { 
'start': options.selectionStart, 'end': options.selectionEnd } );
+                       }
+
+                       var selText = $(this).textSelection( 'getSelection' );
+                       var scrollTop = this.scrollTop;
+                       var range = document.selection.createRange();
+
+                       checkSelectedText();
+                       var insertText = pre + selText + post;
+                       if ( options.splitlines ) {
+                               insertText = doSplitLines( selText, pre, post );
+                       }
+                       if ( options.ownline && range.moveStart ) {
+                               var range2 = document.selection.createRange();
+                               range2.collapse();
+                               range2.moveStart( 'character', -1 );
+                               // FIXME: Which check is correct?
+                               if ( range2.text != "\r" && range2.text != "\n" 
&& range2.text != "" ) {
+                                       insertText = "\n" + insertText;
+                                       pre += "\n";
+                               }
+                               var range3 = document.selection.createRange();
+                               range3.collapse( false );
+                               range3.moveEnd( 'character', 1 );
+                               if ( range3.text != "\r" && range3.text != "\n" 
&& range3.text != "" ) {
+                                       insertText += "\n";
+                                       post += "\n";
+                               }
+                       }
+
+                       range.text = insertText;
+                       if ( isSample && options.selectPeri && range.moveStart 
) {
+                               range.moveStart( 'character', - post.length - 
selText.length );
+                               range.moveEnd( 'character', - post.length );
+                       }
+                       range.select();
+                       // Restore the scroll position
+                       this.scrollTop = scrollTop;
                } else if ( this.selectionStart || this.selectionStart == '0' ) 
{
                        // Mozilla/Opera
+
                        $(this).focus();
                        if ( options.selectionStart !== undefined ) {
                                $(this).textSelection( 'setSelection', { 
'start': options.selectionStart, 'end': options.selectionEnd } );
@@ -182,51 +232,6 @@
                                this.selectionStart = startPos + 
insertText.length;
                                this.selectionEnd = this.selectionStart;
                        }
-               } else if ( document.selection && 
document.selection.createRange ) {
-                       // IE
-                       activateElementOnIE( this );
-                       if ( context ) {
-                               context.fn.restoreCursorAndScrollTop();
-                       }
-                       if ( options.selectionStart !== undefined ) {
-                               $(this).textSelection( 'setSelection', { 
'start': options.selectionStart, 'end': options.selectionEnd } );
-                       }
-                       
-                       var selText = $(this).textSelection( 'getSelection' );
-                       var scrollTop = this.scrollTop;
-                       var range = document.selection.createRange();
-
-                       checkSelectedText();
-                       var insertText = pre + selText + post;
-                       if ( options.splitlines ) {
-                               insertText = doSplitLines( selText, pre, post );
-                       }
-                       if ( options.ownline && range.moveStart ) {
-                               var range2 = document.selection.createRange();
-                               range2.collapse();
-                               range2.moveStart( 'character', -1 );
-                               // FIXME: Which check is correct?
-                               if ( range2.text != "\r" && range2.text != "\n" 
&& range2.text != "" ) {
-                                       insertText = "\n" + insertText;
-                                       pre += "\n";
-                               }
-                               var range3 = document.selection.createRange();
-                               range3.collapse( false );
-                               range3.moveEnd( 'character', 1 );
-                               if ( range3.text != "\r" && range3.text != "\n" 
&& range3.text != "" ) {
-                                       insertText += "\n";
-                                       post += "\n";
-                               }
-                       }
-
-                       range.text = insertText;
-                       if ( isSample && options.selectPeri && range.moveStart 
) {
-                               range.moveStart( 'character', - post.length - 
selText.length );
-                               range.moveEnd( 'character', - post.length );
-                       }
-                       range.select();
-                       // Restore the scroll position
-                       this.scrollTop = scrollTop;
                }
                $(this).trigger( 'encapsulateSelection', [ options.pre, 
options.peri, options.post, options.ownline,
                        options.replace, options.spitlines ] );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to