X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Ffloatpanel%2Fplugin.js;h=4a24dfa4d31a5781af7cb6a8ed9646cc4b18885f;hb=3fe9cac293e090ea459a3ee10d78cbe9e1dd0e03;hp=5569e5eb98e83257af3a006a4ee669379fa8d634;hpb=f0610347140239143439a511ee2bd48cb784f470;p=ckeditor.git diff --git a/_source/plugins/floatpanel/plugin.js b/_source/plugins/floatpanel/plugin.js index 5569e5e..4a24dfa 100644 --- a/_source/plugins/floatpanel/plugin.js +++ b/_source/plugins/floatpanel/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -47,6 +47,9 @@ CKEDITOR.plugins.add( 'floatpanel', element = panel.element, iframe = element.getFirst().getFirst(); + // Disable native browser menu. (#4825) + element.disableContextMenu(); + this.element = element; this._ = @@ -198,25 +201,15 @@ CKEDITOR.plugins.add( 'floatpanel', CKEDITOR.tools.setTimeout( function() { - if ( rtl ) - left -= element.$.offsetWidth; - var panelLoad = CKEDITOR.tools.bind( function () { var target = element.getFirst(); if ( block.autoSize ) { - // We must adjust first the width or IE6 could include extra lines in the height computation - var widthNode = block.element.$; - - if ( CKEDITOR.env.gecko || CKEDITOR.env.opera ) - widthNode = widthNode.parentNode; + var panelDoc = block.element.getDocument(); + var width = ( CKEDITOR.env.webkit? block.element : panelDoc.getBody() )[ '$' ].scrollWidth; - if ( CKEDITOR.env.ie ) - widthNode = widthNode.document.body; - - var width = widthNode.scrollWidth; // Account for extra height needed due to IE quirks box model bug: // http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug // (#3426) @@ -247,24 +240,72 @@ CKEDITOR.plugins.add( 'floatpanel', else target.removeStyle( 'height' ); + // Flip panel layout horizontally in RTL with known width. + if ( rtl ) + left -= element.$.offsetWidth; + + // Pop the style now for measurement. + element.setStyle( 'left', left + 'px' ); + + /* panel layout smartly fit the viewport size. */ var panelElement = panel.element, panelWindow = panelElement.getWindow(), - windowScroll = panelWindow.getScrollPosition(), - viewportSize = panelWindow.getViewPaneSize(), - panelSize = + rect = element.$.getBoundingClientRect(), + viewportSize = panelWindow.getViewPaneSize(); + + // Compensation for browsers that dont support "width" and "height". + var rectWidth = rect.width || rect.right - rect.left, + rectHeight = rect.height || rect.bottom - rect.top; + + // Check if default horizontal layout is impossible. + var spaceAfter = rtl ? rect.right : viewportSize.width - rect.left, + spaceBefore = rtl ? viewportSize.width - rect.right : rect.left; + + if ( rtl ) + { + if ( spaceAfter < rectWidth ) { - 'height' : panelElement.$.offsetHeight, - 'width' : panelElement.$.offsetWidth - }; - - // If the menu is horizontal off, shift it toward - // the opposite language direction. - if ( rtl ? left < 0 : left + panelSize.width > viewportSize.width + windowScroll.x ) - left += ( panelSize.width * ( rtl ? 1 : -1 ) ); - - // Vertical off screen is simpler. - if ( top + panelSize.height > viewportSize.height + windowScroll.y ) - top -= panelSize.height; + // Flip to show on right. + if ( spaceBefore > rectWidth ) + left += rectWidth; + // Align to window left. + else if ( viewportSize.width > rectWidth ) + left = left - rect.left; + // Align to window right, never cutting the panel at right. + else + left = left - rect.right + viewportSize.width; + } + } + else if ( spaceAfter < rectWidth ) + { + // Flip to show on left. + if ( spaceBefore > rectWidth ) + left -= rectWidth; + // Align to window right. + else if ( viewportSize.width > rectWidth ) + left = left - rect.right + viewportSize.width; + // Align to window left, never cutting the panel at left. + else + left = left - rect.left; + } + + + // Check if the default vertical layout is possible. + var spaceBelow = viewportSize.height - rect.top, + spaceAbove = rect.top; + + if ( spaceBelow < rectHeight ) + { + // Flip to show above. + if ( spaceAbove > rectHeight ) + top -= rectHeight; + // Align to window bottom. + else if ( viewportSize.height > rectHeight ) + top = top - rect.bottom + viewportSize.height; + // Align to top, never cutting the panel at top. + else + top = top - rect.top; + } // If IE is in RTL, we have troubles with absolute // position and horizontal scrolls. Here we have a