| 450 | | currentSelection; |
| | 450 | currentSelection, |
| | 451 | wpAdminbar = document.getElementById( 'wpadminbar' ), |
| | 452 | wpStatusbar = document.getElementById( 'post-status-info' ), |
| | 453 | mceIframe, mceToolbar, mceStatusbar; |
| | 454 | |
| | 455 | editor.on( 'init', function() { |
| | 456 | mceIframe = document.getElementById( editor.id + '_ifr' ); |
| | 457 | mceToolbar = tinymce.$( '.mce-toolbar-grp', editor.getContainer() )[0]; |
| | 458 | mceStatusbar = tinymce.$( '.mce-statusbar', editor.getContainer() )[0]; |
| | 459 | } ); |
| 581 | | var top, left, minTop, className, |
| 582 | | windowPos, adminbar, mceToolbar, boundary, |
| 583 | | boundaryMiddle, boundaryVerticalMiddle, spaceTop, |
| 584 | | spaceBottom, windowWidth, toolbarWidth, toolbarHalf, |
| 585 | | iframe, iframePos, iframeWidth, iframeHeigth, |
| 586 | | toolbarNodeHeight, verticalSpaceNeeded, |
| 587 | | toolbarNode = this.getEl(), |
| | 590 | var windowPos = window.pageYOffset || document.documentElement.scrollTop, |
| | 591 | windowWidth = window.innerWidth, |
| | 592 | windowHeight = window.innerHeight, |
| | 593 | iframePos = DOM.getPos( mceIframe ), |
| | 594 | iframeWidth = mceIframe.offsetWidth, |
| | 595 | toolbar = this.getEl(), |
| | 596 | toolbarWidth = toolbar.offsetWidth, |
| | 597 | toolbarHeight = toolbar.offsetHeight, |
| | 598 | selection = currentSelection.getBoundingClientRect(), |
| | 599 | selectionMiddle = ( selection.left + selection.right ) / 2, |
| 590 | | adminbarHeight = 0; |
| 591 | | |
| 592 | | if ( ! currentSelection ) { |
| 593 | | return; |
| 594 | | } |
| | 602 | spaceNeeded = toolbarHeight + margin + buffer, |
| | 603 | wpAdminbarBottom = wpAdminbar ? wpAdminbar.getBoundingClientRect().bottom : 0, |
| | 604 | mceToolbarBottom = mceToolbar ? mceToolbar.getBoundingClientRect().bottom : 0, |
| | 605 | mceStatusbarTop = mceStatusbar ? mceStatusbar.getBoundingClientRect().top : 0, |
| | 606 | wpStatusbarTop = wpStatusbar ? wpStatusbar.getBoundingClientRect().top : 0, |
| | 607 | blockedTop = Math.max( 0, wpAdminbarBottom, mceToolbarBottom ), |
| | 608 | blockedBottom = Math.max( 0, windowHeight - mceStatusbarTop, windowHeight - wpStatusbarTop ), |
| | 609 | spaceTop = selection.top + iframePos.y - windowPos - blockedTop, |
| | 610 | spaceBottom = windowPos + windowHeight - iframePos.y - selection.bottom - blockedBottom, |
| | 611 | className = '', |
| | 612 | top, left; |
| 596 | | windowPos = window.pageYOffset || document.documentElement.scrollTop; |
| 597 | | adminbar = tinymce.$( '#wpadminbar' )[0]; |
| 598 | | mceToolbar = tinymce.$( '.mce-toolbar-grp', editor.getContainer() )[0]; |
| 599 | | boundary = currentSelection.getBoundingClientRect(); |
| 600 | | boundaryMiddle = ( boundary.left + boundary.right ) / 2; |
| 601 | | boundaryVerticalMiddle = ( boundary.top + boundary.bottom ) / 2; |
| 602 | | spaceTop = boundary.top; |
| 603 | | spaceBottom = iframeHeigth - boundary.bottom; |
| 604 | | windowWidth = window.innerWidth; |
| 605 | | toolbarWidth = toolbarNode.offsetWidth; |
| 606 | | toolbarHalf = toolbarWidth / 2; |
| 607 | | iframe = document.getElementById( editor.id + '_ifr' ); |
| 608 | | iframePos = DOM.getPos( iframe ); |
| 609 | | iframeWidth = iframe.offsetWidth; |
| 610 | | iframeHeigth = iframe.offsetHeight; |
| 611 | | toolbarNodeHeight = toolbarNode.offsetHeight; |
| 612 | | verticalSpaceNeeded = toolbarNodeHeight + margin + buffer; |
| 613 | | |
| 614 | | if ( spaceTop >= verticalSpaceNeeded ) { |
| | 614 | if ( spaceTop >= spaceNeeded ) { |
| 637 | | // Make sure the image toolbar is below the adminbar (if visible) or below the top of the window. |
| 638 | | if ( windowPos ) { |
| 639 | | if ( adminbar && adminbar.getBoundingClientRect().top === 0 ) { |
| 640 | | adminbarHeight = adminbar.clientHeight; |
| 641 | | } |
| 642 | | |
| 643 | | if ( windowPos + adminbarHeight > minTop ) { |
| 644 | | minTop = windowPos + adminbarHeight; |
| 645 | | } |
| 646 | | } |
| 647 | | |
| 648 | | if ( top && minTop && ( minTop + buffer > top ) ) { |
| 649 | | top = minTop + buffer; |
| 650 | | className = ''; |
| 651 | | } |
| 652 | | |
| 653 | | left = boundaryMiddle - toolbarHalf; |
| 654 | | left += iframePos.x; |
| | 624 | left = selectionMiddle - toolbarWidth / 2 + iframePos.x; |