Ticket #5441: ie_destroy_bug.2.patch

File ie_destroy_bug.2.patch, 1.1 KB (added by Marcos Wright Kuhns, 13 years ago)

A better patch for this bug that also stops unexpected window scrolling.

  • .js

    old new  
    240240                        {
    241241                                container.setStyle( 'display', 'none' );
    242242
    243                                 var $range = document.body.createTextRange();
    244                                 $range.moveToElementText( container.$ );
     243        // We need to record & reset the scroll position because if we focus on
     244        // the document.body the window will scroll to the top.
     245                                var $range = document.body.createTextRange(),
     246                  horizontalScroll = document.documentElement.scrollLeft,
     247                  verticalScroll = document.documentElement.scrollTop;
     248                                try
     249        {
     250          // This will fail if document.body is not a parentNode of container.$
     251                  $range.moveToElementText( container.$ );
     252                }
     253                catch ( e )
     254                {
     255                  $range.moveToElementText( document.body );
     256                }
    245257                                try
    246258                                {
    247259                                        // Putting the selection to a display:none element - this will certainly
     
    250262                                        $range.select();
    251263                                }
    252264                                catch ( e ) {}
     265
     266        document.documentElement.scrollLeft = horizontalScroll;
     267        document.documentElement.scrollTop = verticalScroll;
    253268                        }
    254269
    255270                        if ( container )
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy