Ticket #3804: 3804_3.patch

File 3804_3.patch, 4.5 KB (added by Martin Kou, 15 years ago)
  • _source/tests/core/dom/element.html

     
    506506                        var element = new CKEDITOR.dom.element( document.getElementsByTagName( 'small' )[0] );
    507507                        assert.isTrue( element.hasAttributes() );
    508508                },
    509 
     509               
     510                test_getDocumentPosition : function()
     511                {
     512                        // Assign the page location of the element.
     513                        YAHOO.util.Dom.setXY('DocPositionTarget', [ 350, 450 ] );
     514                        var pos = CKEDITOR.document.getById( 'DocPositionTarget' ).getDocumentPosition();
     515                        if ( !CKEDITOR.env.ie )
     516                        {
     517                                assert.areEqual( 350, pos.x, 'Position coordinates:x relative to document doesn\'t match.' );
     518                                assert.areEqual( 450, pos.y, 'Position coordinates:y relative to document doesn\'t match.' );
     519                        }
     520                        else
     521                        {
     522                                assert.isTrue( pos.x == 348 || pos.x == 349, 'Position coordinates:x relative to document doesn\'t match.' );
     523                                assert.areEqual( 448, pos.y, 'Position coordinates:y relative to document doesn\'t match.' );
     524                        }
     525                },
     526               
    510527                name : document.title
    511528        };
    512529})() );
    513530
    514531        //]]>
    515532        </script>
     533        <style type="text/css" media="screen">
     534                #test-computed {
     535                    width:50%;
     536                    margin:auto;
     537                    padding:10px;
     538                    z-index: 2;
     539                }
     540                .scroll
     541                {
     542                        overflow: visible;
     543                }
     544                .block1
     545                {
     546                        width: 100%;
     547                        height: 100px;
     548                        background-color: blue;
     549                        text-align: center;
     550                }
     551                .block2
     552                {
     553                        margin: auto;
     554                        width: 200px;
     555                        height: 200px;
     556                        background-color: green;
     557                        position : relative;
     558                }
     559                .block3
     560                {
     561                        position: absolute;
     562                        float:right;
     563                        width: 300px;
     564                        height: 300px;
     565                        background-color: black;
     566                }
     567                .block4
     568                {
     569                        position: absolute;
     570                        left: 50px;
     571                        right: 50px;
     572                        width: 400px;
     573                        height: 400px;
     574                        background-color: pink;
     575                }
     576                #DocPositionTarget
     577                {
     578                        background-color: red;
     579                }
     580        </style>
    516581</head>
    517582<body>
    518583        <textarea id="test1" rows="10" cols="80"></textarea>
     
    536601B</div>
    537602        <big>Test</big>
    538603        <small title="Testing">Test</small>
     604       
     605        <div class="block1 scroll" id="block1"><div class="block2 scroll" id="block2"><div class="block3 scroll" id="block3"><div class="block4 scroll" id="block4"><div id="DocPositionTarget">target</div></div></div></div></div>
     606       
    539607</body>
    540608</html>
  • _source/core/dom/element.js

     
    10991099                getDocumentPosition : function( refDocument )
    11001100                {
    11011101                        var x = 0, y = 0,
    1102                                 body = this.getDocument().getBody();
     1102                                body = this.getDocument().getBody(),
     1103                                quirks = this.getDocument().$.compatMode == 'BackCompat';
    11031104
     1105                        var doc = this.getDocument();
     1106
    11041107                        if ( document.documentElement[ "getBoundingClientRect" ] )
    11051108                        {
    11061109                                var box  = this.$.getBoundingClientRect(),
    1107                                         doc = this.getDocument().$,
    1108                                         docElem = doc.documentElement,
    1109                                         clientTop = docElem.clientTop || body.$.clientTop || 0,
    1110                                         clientLeft = docElem.clientLeft || body.$.clientLeft || 0;
     1110                                        $doc = doc.$,
     1111                                        $docElem = $doc.documentElement;
    11111112
    1112                                 x = box.left + ( !CKEDITOR.env.quirks && docElem.scrollLeft || body.$.scrollLeft );
    1113                                 x -= clientLeft;
    1114                                 y = box.top  + ( !CKEDITOR.env.quirks && docElem.scrollTop || body.$.scrollTop );
    1115                                 y -= clientTop;
     1113                                var clientTop = $docElem.clientTop || body.$.clientTop || 0,
     1114                                        clientLeft = $docElem.clientLeft || body.$.clientLeft || 0,
     1115                                        needAdjustScrollAndBorders = true;
     1116
     1117                                if ( CKEDITOR.env.ie )
     1118                                {
     1119                                        var inDocElem = doc.getDocumentElement().contains( this ),
     1120                                                inBody = doc.getBody().contains( this );
     1121
     1122                                        needAdjustScrollAndBorders = ( quirks && inBody ) || ( !quirks && inDocElem );
     1123                                }
     1124
     1125                                if ( needAdjustScrollAndBorders )
     1126                                {
     1127                                        x = box.left + ( !quirks && $docElem.scrollLeft || body.$.scrollLeft );
     1128                                        x -= clientLeft;
     1129                                        y = box.top  + ( !quirks && $docElem.scrollTop || body.$.scrollTop );
     1130                                        y -= clientTop;
     1131                                }
    11161132                        }
    11171133                        else
    11181134                        {
     
    11611177                        {
    11621178                                // In Firefox, we'll endup one pixel before the element positions,
    11631179                                // so we must add it here.
    1164                                 if ( CKEDITOR.env.gecko && !CKEDITOR.env.quirks )
     1180                                if ( CKEDITOR.env.gecko && !quirks )
    11651181                                {
    11661182                                        x += this.$.clientLeft ? 1 : 0;
    11671183                                        y += this.$.clientTop ? 1 : 0;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy