X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Ffloatpanel%2Fplugin.js;h=8940192d46e197deaad9d2cd665b3444139e7086;hb=039a051ccf3901311661022a30afd60fc38130c9;hp=0a935284b499fc98caa4b5fe23935a9b954dbe97;hpb=8761695d9b70afe75905deaac88f78c1f8aeb32d;p=ckeditor.git diff --git a/_source/plugins/floatpanel/plugin.js b/_source/plugins/floatpanel/plugin.js index 0a93528..8940192 100644 --- a/_source/plugins/floatpanel/plugin.js +++ b/_source/plugins/floatpanel/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -16,14 +16,8 @@ CKEDITOR.plugins.add( 'floatpanel', function getPanel( editor, doc, parentElement, definition, level ) { // Generates the panel key: docId-eleId-skinName-langDir[-uiColor][-CSSs][-level] - var key = - doc.getUniqueId() + - '-' + parentElement.getUniqueId() + - '-' + editor.skinName + - '-' + editor.lang.dir + - ( ( editor.uiColor && ( '-' + editor.uiColor ) ) || '' ) + - ( ( definition.css && ( '-' + definition.css ) ) || '' ) + - ( ( level && ( '-' + level ) ) || '' ); + var key = CKEDITOR.tools.genKey( doc.getUniqueId(), parentElement.getUniqueId(), editor.skinName, editor.lang.dir, + editor.uiColor || '', definition.css || '', level || '' ); var panel = panels[ key ]; @@ -46,7 +40,7 @@ CKEDITOR.plugins.add( 'floatpanel', { $ : function( editor, parentElement, definition, level ) { - definition.forceIFrame = true; + definition.forceIFrame = 1; var doc = parentElement.getDocument(), panel = getPanel( editor, doc, parentElement, definition, level || 0 ), @@ -55,10 +49,6 @@ CKEDITOR.plugins.add( 'floatpanel', this.element = element; - // Register panels to editor for easy destroying ( #4241 ). - editor.panels ? editor.panels.push( element ) : editor.panels = [ element ]; - - this._ = { // The panel that will be floating. @@ -108,7 +98,7 @@ CKEDITOR.plugins.add( 'floatpanel', block = panel.showBlock( name ); this.allowBlur( false ); - isShowing = true; + isShowing = 1; var element = this.element, iframe = this._.iframe, @@ -133,12 +123,16 @@ CKEDITOR.plugins.add( 'floatpanel', element.setStyles( { - top : top + 'px', - left : '-3000px', - visibility : 'hidden', - opacity : '0', // FF3 is ignoring "visibility" + top : 0, + left: 0, display : '' }); + // Don't use display or visibility style because we need to + // calculate the rendering layout later and focus the element. + element.setOpacity( 0 ); + + // To allow the context menu to decrease back their width + element.getFirst().removeStyle( 'width' ); // Configure the IFrame blur event. Do that only once. if ( !this._.blurSet ) @@ -153,17 +147,17 @@ CKEDITOR.plugins.add( 'floatpanel', focused.on( 'blur', function( ev ) { - if ( CKEDITOR.env.ie && !this.allowBlur() ) + if ( !this.allowBlur() ) return; // As we are using capture to register the listener, // the blur event may get fired even when focusing // inside the window itself, so we must ensure the // target is out of it. - var target = ev.data.getTarget(), - targetWindow = target.getWindow && target.getWindow(); - - if ( targetWindow && targetWindow.equals( focused ) ) + var target; + if ( CKEDITOR.env.ie && !this.allowBlur() + || ( target = ev.data.getTarget() ) + && target.getName && target.getName() != 'iframe' ) return; if ( this.visible && !this._.activeChild && !isShowing ) @@ -184,9 +178,10 @@ CKEDITOR.plugins.add( 'floatpanel', this._.blurSet = 1; } - panel.onEscape = CKEDITOR.tools.bind( function() + panel.onEscape = CKEDITOR.tools.bind( function( keystroke ) { - this.onEscape && this.onEscape(); + if ( this.onEscape && this.onEscape( keystroke ) === false ) + return false; }, this ); @@ -195,18 +190,36 @@ CKEDITOR.plugins.add( 'floatpanel', if ( rtl ) left -= element.$.offsetWidth; - element.setStyles( - { - left : left + 'px', - visibility : '', - opacity : '1' // FF3 is ignoring "visibility" - }); - - if ( block.autoSize ) + var panelLoad = CKEDITOR.tools.bind( function () { - function setHeight() + var target = element.getFirst(); + + if ( block.autoSize ) { - var target = element.getFirst(); + // 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; + + 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) + if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && width > 0 ) + width += ( target.$.offsetWidth || 0 ) - ( target.$.clientWidth || 0 ); + // A little extra at the end. + // If not present, IE6 might break into the next line, but also it looks better this way + width += 4 ; + + target.setStyle( 'width', width + 'px' ); + + // IE doesn't compute the scrollWidth if a filter is applied previously + block.element.addClass( 'cke_frameLoaded' ); + var height = block.element.$.scrollHeight; // Account for extra height needed due to IE quirks box model bug: @@ -220,45 +233,82 @@ CKEDITOR.plugins.add( 'floatpanel', // Fix IE < 8 visibility. panel._.currentBlock.element.setStyle( 'display', 'none' ).removeStyle( 'display' ); } - - if ( panel.isLoaded ) - setHeight(); else - panel.onLoad = setHeight; - } - else - element.getFirst().removeStyle( 'height' ); + target.removeStyle( 'height' ); - // Set the IFrame focus, so the blur event gets fired. - CKEDITOR.tools.setTimeout( function() + var panelElement = panel.element, + panelWindow = panelElement.getWindow(), + windowScroll = panelWindow.getScrollPosition(), + viewportSize = panelWindow.getViewPaneSize(), + panelSize = + { + '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; + + // If IE is in RTL, we have troubles with absolute + // position and horizontal scrolls. Here we have a + // series of hacks to workaround it. (#6146) + if ( CKEDITOR.env.ie ) { - if ( definition.voiceLabel ) + var offsetParent = new CKEDITOR.dom.element( element.$.offsetParent ), + scrollParent = offsetParent; + + // Quirks returns , but standards returns . + if ( scrollParent.getName() == 'html' ) + scrollParent = scrollParent.getDocument().getBody(); + + if ( scrollParent.getComputedStyle( 'direction' ) == 'rtl' ) { - if ( CKEDITOR.env.gecko ) - { - var container = iframe.getParent(); - container.setAttribute( 'role', 'region' ); - container.setAttribute( 'title', definition.voiceLabel ); - iframe.setAttribute( 'role', 'region' ); - iframe.setAttribute( 'title', ' ' ); - } + // For IE8, there is not much logic on this, but it works. + if ( CKEDITOR.env.ie8Compat ) + left -= element.getDocument().getDocumentElement().$.scrollLeft * 2; + else + left -= ( offsetParent.$.scrollWidth - offsetParent.$.clientWidth ); } - if ( CKEDITOR.env.ie && CKEDITOR.env.quirks ) - iframe.focus(); - else - iframe.$.contentWindow.focus(); - - // We need this get fired manually because of unfired focus() function. - if ( CKEDITOR.env.ie && !CKEDITOR.env.quirks ) - this.allowBlur( true ); - }, 0, this); + } + + // Trigger the onHide event of the previously active panel to prevent + // incorrect styles from being applied (#6170) + var innerElement = element.getFirst(), + activePanel; + if ( ( activePanel = innerElement.getCustomData( 'activePanel' ) ) ) + activePanel.onHide && activePanel.onHide.call( this, 1 ); + innerElement.setCustomData( 'activePanel', this ); + + element.setStyles( + { + top : top + 'px', + left : left + 'px' + } ); + element.setOpacity( 1 ); + } , this ); + + panel.isLoaded ? panelLoad() : panel.onLoad = panelLoad; + + // Set the panel frame focus, so the blur event gets fired. + CKEDITOR.tools.setTimeout( function() + { + iframe.$.contentWindow.focus(); + // We need this get fired manually because of unfired focus() function. + this.allowBlur( true ); + }, 0, this); }, 0, this); this.visible = 1; if ( this.onShow ) this.onShow.call( this ); - isShowing = false; + isShowing = 0; }, hide : function() @@ -268,6 +318,7 @@ CKEDITOR.plugins.add( 'floatpanel', this.hideChild(); this.element.setStyle( 'display', 'none' ); this.visible = 0; + this.element.getFirst().removeCustomData( 'activePanel' ); } }, @@ -329,4 +380,23 @@ CKEDITOR.plugins.add( 'floatpanel', } } }); + + CKEDITOR.on( 'instanceDestroyed', function() + { + var isLastInstance = CKEDITOR.tools.isEmpty( CKEDITOR.instances ); + + for ( var i in panels ) + { + var panel = panels[ i ]; + // Safe to destroy it since there're no more instances.(#4241) + if ( isLastInstance ) + panel.destroy(); + // Panel might be used by other instances, just hide them.(#4552) + else + panel.element.hide(); + } + // Remove the registration. + isLastInstance && ( panels = {} ); + + } ); })();