2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.plugins.add( 'floatpanel',
\r
8 requires : [ 'panel' ]
\r
14 var isShowing = false;
\r
16 function getPanel( editor, doc, parentElement, definition, level )
\r
18 // Generates the panel key: docId-eleId-skinName-langDir[-uiColor][-CSSs][-level]
\r
21 '-' + parentElement.getUniqueId() +
\r
22 '-' + editor.skinName +
\r
23 '-' + editor.lang.dir +
\r
24 ( ( editor.uiColor && ( '-' + editor.uiColor ) ) || '' ) +
\r
25 ( ( definition.css && ( '-' + definition.css ) ) || '' ) +
\r
26 ( ( level && ( '-' + level ) ) || '' );
\r
28 var panel = panels[ key ];
\r
32 panel = panels[ key ] = new CKEDITOR.ui.panel( doc, definition );
\r
33 panel.element = parentElement.append( CKEDITOR.dom.element.createFromHtml( panel.renderHtml( editor ), doc ) );
\r
35 panel.element.setStyles(
\r
38 position : 'absolute'
\r
45 CKEDITOR.ui.floatPanel = CKEDITOR.tools.createClass(
\r
47 $ : function( editor, parentElement, definition, level )
\r
49 definition.forceIFrame = true;
\r
51 var doc = parentElement.getDocument(),
\r
52 panel = getPanel( editor, doc, parentElement, definition, level || 0 ),
\r
53 element = panel.element,
\r
54 iframe = element.getFirst().getFirst();
\r
56 this.element = element;
\r
60 // The panel that will be floating.
\r
62 parentElement : parentElement,
\r
63 definition : definition,
\r
67 dir : editor.lang.dir
\r
73 addBlock : function( name, block )
\r
75 return this._.panel.addBlock( name, block );
\r
78 addListBlock : function( name, multiSelect )
\r
80 return this._.panel.addListBlock( name, multiSelect );
\r
83 getBlock : function( name )
\r
85 return this._.panel.getBlock( name );
\r
101 showBlock : function( name, offsetParent, corner, offsetX, offsetY )
\r
103 var panel = this._.panel,
\r
104 block = panel.showBlock( name );
\r
106 this.allowBlur( false );
\r
109 var element = this.element,
\r
110 iframe = this._.iframe,
\r
111 definition = this._.definition,
\r
112 position = offsetParent.getDocumentPosition( element.getDocument() ),
\r
113 rtl = this._.dir == 'rtl';
\r
115 var left = position.x + ( offsetX || 0 ),
\r
116 top = position.y + ( offsetY || 0 );
\r
118 if ( ( rtl && ( corner == 1 || corner == 4 ) ) || ( !rtl && ( corner == 2 || corner == 3 ) ) )
\r
119 left += offsetParent.$.offsetWidth - 1;
\r
121 if ( corner == 3 || corner == 4 )
\r
122 top += offsetParent.$.offsetHeight - 1;
\r
124 // Memorize offsetParent by it's ID.
\r
125 this._.panel._.offsetParentId = offsetParent.getId();
\r
131 visibility : 'hidden',
\r
132 opacity : '0', // FF3 is ignoring "visibility"
\r
136 // Configure the IFrame blur event. Do that only once.
\r
137 if ( !this._.blurSet )
\r
139 // Non IE prefer the event into a window object.
\r
140 var focused = CKEDITOR.env.ie ? iframe : new CKEDITOR.dom.window( iframe.$.contentWindow );
\r
142 // With addEventListener compatible browsers, we must
\r
143 // useCapture when registering the focus/blur events to
\r
144 // guarantee they will be firing in all situations. (#3068, #3222 )
\r
145 CKEDITOR.event.useCapture = true;
\r
147 focused.on( 'blur', function( ev )
\r
149 if ( CKEDITOR.env.ie && !this.allowBlur() )
\r
152 // As we are using capture to register the listener,
\r
153 // the blur event may get fired even when focusing
\r
154 // inside the window itself, so we must ensure the
\r
155 // target is out of it.
\r
156 var target = ev.data.getTarget(),
\r
157 targetWindow = target.getWindow && target.getWindow();
\r
159 if ( targetWindow && targetWindow.equals( focused ) )
\r
162 if ( this.visible && !this._.activeChild && !isShowing )
\r
167 focused.on( 'focus', function()
\r
169 this._.focused = true;
\r
171 this.allowBlur( true );
\r
175 CKEDITOR.event.useCapture = false;
\r
177 this._.blurSet = 1;
\r
180 panel.onEscape = CKEDITOR.tools.bind( function()
\r
182 this.onEscape && this.onEscape();
\r
186 CKEDITOR.tools.setTimeout( function()
\r
189 left -= element.$.offsetWidth;
\r
193 left : left + 'px',
\r
195 opacity : '1' // FF3 is ignoring "visibility"
\r
198 if ( block.autoSize )
\r
200 function setHeight()
\r
202 var target = element.getFirst();
\r
203 var height = block.element.$.scrollHeight;
\r
205 // Account for extra height needed due to IE quirks box model bug:
\r
206 // http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug
\r
208 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && height > 0 )
\r
209 height += ( target.$.offsetHeight || 0 ) - ( target.$.clientHeight || 0 );
\r
211 target.setStyle( 'height', height + 'px' );
\r
213 // Fix IE < 8 visibility.
\r
214 panel._.currentBlock.element.setStyle( 'display', 'none' ).removeStyle( 'display' );
\r
217 if ( panel.isLoaded )
\r
220 panel.onLoad = setHeight;
\r
223 element.getFirst().removeStyle( 'height' );
\r
225 // Set the IFrame focus, so the blur event gets fired.
\r
226 CKEDITOR.tools.setTimeout( function()
\r
228 if ( definition.voiceLabel )
\r
230 if ( CKEDITOR.env.gecko )
\r
232 var container = iframe.getParent();
\r
233 container.setAttribute( 'role', 'region' );
\r
234 container.setAttribute( 'title', definition.voiceLabel );
\r
235 iframe.setAttribute( 'role', 'region' );
\r
236 iframe.setAttribute( 'title', ' ' );
\r
239 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks )
\r
242 iframe.$.contentWindow.focus();
\r
244 // We need this get fired manually because of unfired focus() function.
\r
245 if ( CKEDITOR.env.ie && !CKEDITOR.env.quirks )
\r
246 this.allowBlur( true );
\r
252 this.onShow.call( this );
\r
259 if ( this.visible && ( !this.onHide || this.onHide.call( this ) !== true ) )
\r
262 this.element.setStyle( 'display', 'none' );
\r
267 allowBlur : function( allow ) // Prevent editor from hiding the panel. #3222.
\r
269 var panel = this._.panel;
\r
270 if ( allow != undefined )
\r
271 panel.allowBlur = allow;
\r
273 return panel.allowBlur;
\r
276 showAsChild : function( panel, blockName, offsetParent, corner, offsetX, offsetY )
\r
278 // Skip reshowing of child which is already visible.
\r
279 if ( this._.activeChild == panel && panel._.panel._.offsetParentId == offsetParent.getId() )
\r
284 panel.onHide = CKEDITOR.tools.bind( function()
\r
286 // Use a timeout, so we give time for this menu to get
\r
287 // potentially focused.
\r
288 CKEDITOR.tools.setTimeout( function()
\r
290 if ( !this._.focused )
\r
297 this._.activeChild = panel;
\r
298 this._.focused = false;
\r
300 panel.showBlock( blockName, offsetParent, corner, offsetX, offsetY );
\r
302 /* #3767 IE: Second level menu may not have borders */
\r
303 if ( CKEDITOR.env.ie7Compat || ( CKEDITOR.env.ie8 && CKEDITOR.env.ie6Compat ) )
\r
305 setTimeout(function()
\r
307 panel.element.getChild( 0 ).$.style.cssText += '';
\r
312 hideChild : function()
\r
314 var activeChild = this._.activeChild;
\r
318 delete activeChild.onHide;
\r
319 delete this._.activeChild;
\r
320 activeChild.hide();
\r