450 | | currentSelection; |
| 450 | currentSelection, |
| 451 | wpAdminbar = document.getElementById( 'wpadminbar' ), |
| 452 | mceIframe, mceToolbar, mceStatusbar, wpStatusbar; |
| 453 | |
| 454 | editor.on( 'init', function() { |
| 455 | mceIframe = document.getElementById( editor.id + '_ifr' ); |
| 456 | mceToolbar = tinymce.$( '.mce-toolbar-grp', editor.getContainer() )[0]; |
| 457 | mceStatusbar = tinymce.$( '.mce-statusbar', editor.getContainer() )[0]; |
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(), |
| 595 | var pageYOffset = window.pageYOffset || document.documentElement.scrollTop, |
| 596 | windowWidth = window.innerWidth, |
| 597 | windowHeight = window.innerHeight, |
| 598 | iframePos = DOM.getPos( mceIframe ), |
| 599 | iframeWidth = mceIframe.offsetWidth, |
| 600 | toolbar = this.getEl(), |
| 601 | toolbarWidth = toolbar.offsetWidth, |
| 602 | toolbarHeight = toolbar.offsetHeight, |
| 603 | selection = currentSelection.getBoundingClientRect(), |
| 604 | selectionMiddle = ( selection.left + selection.right ) / 2, |
590 | | adminbarHeight = 0; |
591 | | |
592 | | if ( ! currentSelection ) { |
593 | | return; |
594 | | } |
595 | | |
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 ) { |
615 | | className = ' mce-arrow-down'; |
616 | | top = boundary.top + iframePos.y - toolbarNodeHeight - margin; |
617 | | } else if ( spaceBottom >= verticalSpaceNeeded ) { |
618 | | className = ' mce-arrow-up'; |
619 | | top = boundary.bottom + iframePos.y; |
620 | | } else { |
621 | | top = buffer; |
| 607 | spaceNeeded = toolbarHeight + margin + buffer, |
| 608 | wpAdminbarBottom = wpAdminbar ? wpAdminbar.getBoundingClientRect().bottom : 0, |
| 609 | mceToolbarBottom = mceToolbar ? mceToolbar.getBoundingClientRect().bottom : 0, |
| 610 | mceStatusbarTop = mceStatusbar ? windowHeight - mceStatusbar.getBoundingClientRect().top : 0, |
| 611 | wpStatusbarTop = wpStatusbar ? windowHeight - wpStatusbar.getBoundingClientRect().top : 0, |
| 612 | blockedTop = Math.max( 0, wpAdminbarBottom, mceToolbarBottom ), |
| 613 | blockedBottom = Math.max( 0, mceStatusbarTop, wpStatusbarTop ), |
| 614 | spaceTop = selection.top + iframePos.y - pageYOffset - blockedTop, |
| 615 | spaceBottom = pageYOffset + windowHeight - iframePos.y - selection.bottom - blockedBottom, |
| 616 | editorHeight = windowHeight - blockedTop - blockedBottom, |
| 617 | className = '', |
| 618 | top, left; |
634 | | minTop = iframePos.y; |
635 | | } |
636 | | |
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; |
| 629 | if ( spaceTop >= spaceNeeded ) { |
| 630 | className = ' mce-arrow-down'; |
| 631 | top = selection.top + iframePos.y - toolbarHeight - margin; |
| 632 | } else if ( spaceBottom >= spaceNeeded && editorHeight / 2 > selection.bottom + iframePos.y - pageYOffset - blockedTop ) { |
| 633 | className = ' mce-arrow-up'; |
| 634 | top = selection.bottom + iframePos.y; |