From: Roan Kattouw Date: Mon, 14 Nov 2011 08:37:38 +0000 (+0000) Subject: (bug 32241) WikiEditor scrolls the browser and does not insert in IE7, IE8, IE9 if... X-Git-Tag: 1.31.0-rc.0~26525 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=fc3b1648de93e211ad6d44d95a2d5052764a382b;p=lhc%2Fweb%2Fwiklou.git (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 --- diff --git a/CREDITS b/CREDITS index 40753c0890..d6677dc64c 100644 --- a/CREDITS +++ b/CREDITS @@ -118,6 +118,7 @@ following names for their contribution to the product. * Louperivois * Lucas Garczewski * Luigi Corsaro +* Lupo * Manuel Menal * Marcin Cieślak * Marcus Buck diff --git a/resources/jquery/jquery.textSelection.js b/resources/jquery/jquery.textSelection.js index 158f205c63..9ba78d2d45 100644 --- a/resources/jquery/jquery.textSelection.js +++ b/resources/jquery/jquery.textSelection.js @@ -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 @@ getSelection: function() { 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 @@ encapsulateSelection: function( options ) { 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;