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

Revision: 102948
Author:   catrope
Date:     2011-11-14 08:37:38 +0000 (Mon, 14 Nov 2011)
Log Message:
-----------
(bug 32241) WikiEditor scrolls the browser and does not insert in IE7, IE8, IE9 
if the textarea doesn't fit on the screen. Patch by Lupo

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

Modified: trunk/phase3/CREDITS
===================================================================
--- trunk/phase3/CREDITS        2011-11-14 08:19:55 UTC (rev 102947)
+++ trunk/phase3/CREDITS        2011-11-14 08:37:38 UTC (rev 102948)
@@ -118,6 +118,7 @@
 * Louperivois
 * Lucas Garczewski
 * Luigi Corsaro
+* Lupo
 * Manuel Menal
 * Marcin Cieślak
 * Marcus Buck

Modified: trunk/phase3/resources/jquery/jquery.textSelection.js
===================================================================
--- trunk/phase3/resources/jquery/jquery.textSelection.js       2011-11-14 
08:19:55 UTC (rev 102947)
+++ trunk/phase3/resources/jquery/jquery.textSelection.js       2011-11-14 
08:37:38 UTC (rev 102948)
@@ -2,6 +2,26 @@
  * These plugins provide extra functionality for interaction with textareas.
  */
 ( function( $ ) {
+
+if (document.selection && document.selection.createRange) {
+       // On IE, patch the focus() method to restore the windows' scroll 
position
+       // (bug 32241)
+       $.fn.extend({
+               focus : (function ( _focus ) {
+                       return function () {
+                               if ( arguments.length == 0 ) {
+                                       var $w = $( window );
+                                       var state = {top: $w.scrollTop(), left: 
$w.scrollLeft()};
+                                       var result = _focus.apply( this, 
arguments );
+                                       window.scrollTo( state.top, state.left 
);
+                                       return result;
+                               }
+                               return _focus.apply( this, arguments );
+                       };
+               })( $.fn.focus )
+       });
+}
+
 $.fn.textSelection = function( command, options ) {
 
 /**
@@ -34,7 +54,7 @@
        if ( $(e).is( ':hidden' ) ) {
                // Do nothing
        } else if ( document.selection && document.selection.createRange ) {
-               e.focus();
+               $(e).focus();
                var range = document.selection.createRange();
                retval = range.text;
        } else if ( e.selectionStart || e.selectionStart == '0' ) {
@@ -215,12 +235,12 @@
  getCaretPosition: function( options ) {
        function getCaret( e ) {
                var caretPos = 0, endPos = 0;
-               if ( $.browser.msie ) {
+               if ( document.selection && document.selection.createRange ) {
                        // IE doesn't properly report non-selected caret 
position through
                        // the selection ranges when textarea isn't focused. 
This can
                        // lead to saving a bogus empty selection, which then 
screws up
                        // whatever we do later (bug 31847).
-                       e.focus();
+                       $(e).focus();
 
                        // IE Support
                        var preFinished = false;


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to