2 Copyright (c) 2003-2010, 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 // Floating panels are off by (-1px, 0px) in RTL mode. (#3438)
\r
119 if ( rtl && ( corner == 1 || corner == 4 ) )
\r
120 left += offsetParent.$.offsetWidth;
\r
121 else if ( !rtl && ( corner == 2 || corner == 3 ) )
\r
122 left += offsetParent.$.offsetWidth - 1;
\r
124 if ( corner == 3 || corner == 4 )
\r
125 top += offsetParent.$.offsetHeight - 1;
\r
127 // Memorize offsetParent by it's ID.
\r
128 this._.panel._.offsetParentId = offsetParent.getId();
\r
134 opacity : '0', // FF3 is ignoring "visibility"
\r
138 // To allow the context menu to decrease back their width
\r
139 element.getFirst().removeStyle('width');
\r
141 // Configure the IFrame blur event. Do that only once.
\r
142 if ( !this._.blurSet )
\r
144 // Non IE prefer the event into a window object.
\r
145 var focused = CKEDITOR.env.ie ? iframe : new CKEDITOR.dom.window( iframe.$.contentWindow );
\r
147 // With addEventListener compatible browsers, we must
\r
148 // useCapture when registering the focus/blur events to
\r
149 // guarantee they will be firing in all situations. (#3068, #3222 )
\r
150 CKEDITOR.event.useCapture = true;
\r
152 focused.on( 'blur', function( ev )
\r
154 if ( !this.allowBlur() )
\r
157 // As we are using capture to register the listener,
\r
158 // the blur event may get fired even when focusing
\r
159 // inside the window itself, so we must ensure the
\r
160 // target is out of it.
\r
161 var target = ev.data.getTarget(),
\r
162 targetWindow = target.getWindow && target.getWindow();
\r
164 if ( targetWindow && targetWindow.equals( focused ) )
\r
167 if ( this.visible && !this._.activeChild && !isShowing )
\r
172 focused.on( 'focus', function()
\r
174 this._.focused = true;
\r
176 this.allowBlur( true );
\r
180 CKEDITOR.event.useCapture = false;
\r
182 this._.blurSet = 1;
\r
185 panel.onEscape = CKEDITOR.tools.bind( function()
\r
187 this.onEscape && this.onEscape();
\r
191 CKEDITOR.tools.setTimeout( function()
\r
194 left -= element.$.offsetWidth;
\r
196 var panelLoad = CKEDITOR.tools.bind( function ()
\r
198 var target = element.getFirst();
\r
200 if ( block.autoSize )
\r
202 // We must adjust first the width or IE6 could include extra lines in the height computation
\r
203 var widthNode = block.element.$;
\r
205 if ( CKEDITOR.env.gecko || CKEDITOR.env.opera)
\r
206 widthNode = widthNode.parentNode;
\r
208 if ( CKEDITOR.env.ie)
\r
209 widthNode = widthNode.document.body;
\r
211 var width = widthNode.scrollWidth;
\r
212 // Account for extra height needed due to IE quirks box model bug:
\r
213 // http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug
\r
215 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && width > 0 )
\r
216 width += ( target.$.offsetWidth || 0 ) - ( target.$.clientWidth || 0 );
\r
217 // A little extra at the end.
\r
218 // If not present, IE6 might break into the next line, but also it looks better this way
\r
221 target.setStyle( 'width', width + 'px' );
\r
223 // IE doesn't compute the scrollWidth if a filter is applied previously
\r
224 block.element.addClass( 'cke_frameLoaded' );
\r
226 var height = block.element.$.scrollHeight;
\r
228 // Account for extra height needed due to IE quirks box model bug:
\r
229 // http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug
\r
231 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && height > 0 )
\r
232 height += ( target.$.offsetHeight || 0 ) - ( target.$.clientHeight || 0 );
\r
234 target.setStyle( 'height', height + 'px' );
\r
236 // Fix IE < 8 visibility.
\r
237 panel._.currentBlock.element.setStyle( 'display', 'none' ).removeStyle( 'display' );
\r
240 target.removeStyle( 'height' );
\r
242 var panelElement = panel.element,
\r
243 panelWindow = panelElement.getWindow(),
\r
244 windowScroll = panelWindow.getScrollPosition(),
\r
245 viewportSize = panelWindow.getViewPaneSize(),
\r
248 'height' : panelElement.$.offsetHeight,
\r
249 'width' : panelElement.$.offsetWidth
\r
252 // If the menu is horizontal off, shift it toward
\r
253 // the opposite language direction.
\r
254 if ( rtl ? left < 0 : left + panelSize.width > viewportSize.width + windowScroll.x )
\r
255 left += ( panelSize.width * ( rtl ? 1 : -1 ) );
\r
257 // Vertical off screen is simpler.
\r
258 if ( top + panelSize.height > viewportSize.height + windowScroll.y )
\r
259 top -= panelSize.height;
\r
264 left : left + 'px',
\r
270 panel.isLoaded ? panelLoad() : panel.onLoad = panelLoad;
\r
272 // Set the panel frame focus, so the blur event gets fired.
\r
273 CKEDITOR.tools.setTimeout( function()
\r
275 if ( definition.voiceLabel )
\r
277 if ( CKEDITOR.env.gecko )
\r
279 var container = iframe.getParent();
\r
280 container.setAttribute( 'role', 'region' );
\r
281 container.setAttribute( 'title', definition.voiceLabel );
\r
282 iframe.setAttribute( 'role', 'region' );
\r
283 iframe.setAttribute( 'title', ' ' );
\r
287 iframe.$.contentWindow.focus();
\r
288 // We need this get fired manually because of unfired focus() function.
\r
289 this.allowBlur( true );
\r
296 this.onShow.call( this );
\r
303 if ( this.visible && ( !this.onHide || this.onHide.call( this ) !== true ) )
\r
306 this.element.setStyle( 'display', 'none' );
\r
311 allowBlur : function( allow ) // Prevent editor from hiding the panel. #3222.
\r
313 var panel = this._.panel;
\r
314 if ( allow != undefined )
\r
315 panel.allowBlur = allow;
\r
317 return panel.allowBlur;
\r
320 showAsChild : function( panel, blockName, offsetParent, corner, offsetX, offsetY )
\r
322 // Skip reshowing of child which is already visible.
\r
323 if ( this._.activeChild == panel && panel._.panel._.offsetParentId == offsetParent.getId() )
\r
328 panel.onHide = CKEDITOR.tools.bind( function()
\r
330 // Use a timeout, so we give time for this menu to get
\r
331 // potentially focused.
\r
332 CKEDITOR.tools.setTimeout( function()
\r
334 if ( !this._.focused )
\r
341 this._.activeChild = panel;
\r
342 this._.focused = false;
\r
344 panel.showBlock( blockName, offsetParent, corner, offsetX, offsetY );
\r
346 /* #3767 IE: Second level menu may not have borders */
\r
347 if ( CKEDITOR.env.ie7Compat || ( CKEDITOR.env.ie8 && CKEDITOR.env.ie6Compat ) )
\r
349 setTimeout(function()
\r
351 panel.element.getChild( 0 ).$.style.cssText += '';
\r
356 hideChild : function()
\r
358 var activeChild = this._.activeChild;
\r
362 delete activeChild.onHide;
\r
363 delete this._.activeChild;
\r
364 activeChild.hide();
\r
370 CKEDITOR.on( 'instanceDestroyed', function()
\r
372 var isLastInstance = CKEDITOR.tools.isEmpty( CKEDITOR.instances );
\r
374 for ( var i in panels )
\r
376 var panel = panels[ i ];
\r
377 // Safe to destroy it since there're no more instances.(#4241)
\r
378 if ( isLastInstance )
\r
380 // Panel might be used by other instances, just hide them.(#4552)
\r
382 panel.element.hide();
\r
384 // Remove the registration.
\r
385 isLastInstance && ( panels = {} );
\r