Ticket #3045: 3045.patch
File 3045.patch, 4.5 KB (added by , 14 years ago) |
---|
-
editor/_source/internals/fcktools.js
514 514 515 515 FCKTools.GetDocumentPosition = function( w, node ) 516 516 { 517 var x = 0 ;518 var y = 0 ;519 var curNode = node ;520 var prevNode = null;521 var curWindow = FCKTools.GetElementWindow( curNode ) ; 522 while ( curNode && !( curWindow == w && ( curNode == w.document.body || curNode == w.document.documentElement ) ))517 var x = 0, y = 0, 518 doc = this.GetElementDocument( node ), 519 body = doc.body, 520 quirks = ( doc.compatMode == 'BackCompat' ) ; 521 522 if ( document.documentElement[ 'getBoundingClientRect' ] ) 523 523 { 524 x += curNode.offsetLeft - curNode.scrollLeft ;525 y += curNode.offsetTop - curNode.scrollTop;524 var box = node.getBoundingClientRect(), 525 docElem = doc.documentElement ; 526 526 527 if ( ! FCKBrowserInfo.IsOpera ) 527 var clientTop = docElem.clientTop || body.clientTop || 0, 528 clientLeft = docElem.clientLeft || body.clientLeft || 0, 529 needAdjustScrollAndBorders = true; 530 531 /* 532 * #3804: getBoundingClientRect() works differently on IE and non-IE 533 * browsers, regarding scroll positions. 534 * 535 * On IE, the top position of the <html> element is always 0, no matter 536 * how much you scrolled down. 537 * 538 * On other browsers, the top position of the <html> element is negative 539 * scrollTop. 540 */ 541 if ( FCKBrowserInfo.IsIE ) 528 542 { 529 var scrollNode = prevNode ; 530 while ( scrollNode && scrollNode != curNode ) 531 { 532 x -= scrollNode.scrollLeft ; 533 y -= scrollNode.scrollTop ; 534 scrollNode = scrollNode.parentNode ; 535 } 543 var inDocElem = FCKDomTools.Contains( docElem, node ), 544 inBody = FCKDomTools.Contains( body, node ) ; 545 546 needAdjustScrollAndBorders = ( quirks && inBody ) || ( !quirks && inDocElem ) ; 536 547 } 537 548 538 prevNode = curNode ; 539 if ( curNode.offsetParent ) 540 curNode = curNode.offsetParent ; 541 else 549 if ( needAdjustScrollAndBorders ) 542 550 { 543 if ( curWindow != w ) 551 x = box.left + ( !quirks && docElem.scrollLeft || body.scrollLeft ) ; 552 x -= clientLeft ; 553 y = box.top + ( !quirks && docElem.scrollTop || body.scrollTop ) ; 554 y -= clientTop ; 555 } 556 } 557 else 558 { 559 var current = node, previous = null ; 560 var currentName = current.nodeName ; 561 while ( current && !( currentName.IEquals( 'body' ) || currentName.IEquals( 'html' ) ) ) 562 { 563 x += current.offsetLeft - current.scrollLeft ; 564 y += current.offsetTop - current.scrollTop ; 565 566 // Opera includes clientTop|Left into offsetTop|Left. 567 if ( current != node ) 544 568 { 545 curNode = curWindow.frameElement ; 546 prevNode = null ; 547 if ( curNode ) 548 curWindow = curNode.contentWindow.parent ; 569 x += current.clientLeft || 0 ; 570 y += current.clientTop || 0 ; 549 571 } 550 else 551 curNode = null ; 572 573 var scrollElement = previous ; 574 while ( scrollElement && scrollElement != current ) 575 { 576 x -= scrollElement.scrollLeft ; 577 y -= scrollElement.scrollTop ; 578 scrollElement = scrollElement.parentNode ; 579 } 580 581 previous = current ; 582 current = current.offsetParent ; 552 583 } 553 584 } 554 585 555 // document.body is a special case when it comes to offsetTop and offsetLeft values. 556 // 1. It matters if document.body itself is a positioned element; 557 // 2. It matters is when we're in IE and the element has no positioned ancestor. 558 // Otherwise the values should be ignored. 559 if ( FCKDomTools.GetCurrentElementStyle( w.document.body, 'position') != 'static' 560 || ( FCKBrowserInfo.IsIE && FCKDomTools.GetPositionedAncestor( node ) == null ) ) 586 if ( w ) 561 587 { 562 x += w.document.body.offsetLeft ; 563 y += w.document.body.offsetTop ; 588 var currentWindow = this.GetDocumentWindow( doc ) ; 589 590 if ( currentWindow != w && currentWindow.frameElement ) 591 { 592 var iframePosition = this.GetDocumentPosition( this.GetElementWindow( currentWindow.frameElement ), currentWindow.frameElement ); 593 594 x += iframePosition.x ; 595 y += iframePosition.y ; 596 } 564 597 } 565 598 566 return { "x" : x, "y" : y } ; 599 if ( !document.documentElement[ 'getBoundingClientRect' ] ) 600 { 601 // In Firefox, we'll end up one pixel before the element positions, 602 // so we must add it here. 603 if ( CKEDITOR.env.gecko && !quirks ) 604 { 605 x += node.clientLeft ? 1 : 0 ; 606 y += node.clientTop ? 1 : 0 ; 607 } 608 } 609 610 console.log( 'x:', x, 'y:', y ); 611 return { x : x, y : y } ; 567 612 } 568 613 569 614 FCKTools.GetWindowPosition = function( w, node )