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 // Configure the IFrame blur event. Do that only once.
\r
139 if ( !this._.blurSet )
\r
141 // Non IE prefer the event into a window object.
\r
142 var focused = CKEDITOR.env.ie ? iframe : new CKEDITOR.dom.window( iframe.$.contentWindow );
\r
144 // With addEventListener compatible browsers, we must
\r
145 // useCapture when registering the focus/blur events to
\r
146 // guarantee they will be firing in all situations. (#3068, #3222 )
\r
147 CKEDITOR.event.useCapture = true;
\r
149 focused.on( 'blur', function( ev )
\r
151 if ( !this.allowBlur() )
\r
154 // As we are using capture to register the listener,
\r
155 // the blur event may get fired even when focusing
\r
156 // inside the window itself, so we must ensure the
\r
157 // target is out of it.
\r
158 var target = ev.data.getTarget(),
\r
159 targetWindow = target.getWindow && target.getWindow();
\r
161 if ( targetWindow && targetWindow.equals( focused ) )
\r
164 if ( this.visible && !this._.activeChild && !isShowing )
\r
169 focused.on( 'focus', function()
\r
171 this._.focused = true;
\r
173 this.allowBlur( true );
\r
177 CKEDITOR.event.useCapture = false;
\r
179 this._.blurSet = 1;
\r
182 panel.onEscape = CKEDITOR.tools.bind( function()
\r
184 this.onEscape && this.onEscape();
\r
188 CKEDITOR.tools.setTimeout( function()
\r
191 left -= element.$.offsetWidth;
\r
193 var panelLoad = CKEDITOR.tools.bind( function ()
\r
195 if ( block.autoSize )
\r
197 var target = element.getFirst();
\r
198 var height = block.element.$.scrollHeight;
\r
200 // Account for extra height needed due to IE quirks box model bug:
\r
201 // http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug
\r
203 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && height > 0 )
\r
204 height += ( target.$.offsetHeight || 0 ) - ( target.$.clientHeight || 0 );
\r
206 target.setStyle( 'height', height + 'px' );
\r
208 // Fix IE < 8 visibility.
\r
209 panel._.currentBlock.element.setStyle( 'display', 'none' ).removeStyle( 'display' );
\r
212 element.getFirst().removeStyle( 'height' );
\r
214 var panelElement = panel.element,
\r
215 panelWindow = panelElement.getWindow(),
\r
216 windowScroll = panelWindow.getScrollPosition(),
\r
217 viewportSize = panelWindow.getViewPaneSize(),
\r
220 'height' : panelElement.$.offsetHeight,
\r
221 'width' : panelElement.$.offsetWidth
\r
224 // If the menu is horizontal off, shift it toward
\r
225 // the opposite language direction.
\r
226 if ( rtl ? left < 0 : left + panelSize.width > viewportSize.width + windowScroll.x )
\r
227 left += ( panelSize.width * ( rtl ? 1 : -1 ) );
\r
229 // Vertical off screen is simpler.
\r
230 if( top + panelSize.height > viewportSize.height + windowScroll.y )
\r
231 top -= panelSize.height;
\r
236 left : left + 'px',
\r
242 panel.isLoaded ? panelLoad() : panel.onLoad = panelLoad;
\r
244 // Set the panel frame focus, so the blur event gets fired.
\r
245 CKEDITOR.tools.setTimeout( function()
\r
247 if ( definition.voiceLabel )
\r
249 if ( CKEDITOR.env.gecko )
\r
251 var container = iframe.getParent();
\r
252 container.setAttribute( 'role', 'region' );
\r
253 container.setAttribute( 'title', definition.voiceLabel );
\r
254 iframe.setAttribute( 'role', 'region' );
\r
255 iframe.setAttribute( 'title', ' ' );
\r
259 iframe.$.contentWindow.focus();
\r
260 // We need this get fired manually because of unfired focus() function.
\r
261 this.allowBlur( true );
\r
268 this.onShow.call( this );
\r
275 if ( this.visible && ( !this.onHide || this.onHide.call( this ) !== true ) )
\r
278 this.element.setStyle( 'display', 'none' );
\r
283 allowBlur : function( allow ) // Prevent editor from hiding the panel. #3222.
\r
285 var panel = this._.panel;
\r
286 if ( allow != undefined )
\r
287 panel.allowBlur = allow;
\r
289 return panel.allowBlur;
\r
292 showAsChild : function( panel, blockName, offsetParent, corner, offsetX, offsetY )
\r
294 // Skip reshowing of child which is already visible.
\r
295 if ( this._.activeChild == panel && panel._.panel._.offsetParentId == offsetParent.getId() )
\r
300 panel.onHide = CKEDITOR.tools.bind( function()
\r
302 // Use a timeout, so we give time for this menu to get
\r
303 // potentially focused.
\r
304 CKEDITOR.tools.setTimeout( function()
\r
306 if ( !this._.focused )
\r
313 this._.activeChild = panel;
\r
314 this._.focused = false;
\r
316 panel.showBlock( blockName, offsetParent, corner, offsetX, offsetY );
\r
318 /* #3767 IE: Second level menu may not have borders */
\r
319 if ( CKEDITOR.env.ie7Compat || ( CKEDITOR.env.ie8 && CKEDITOR.env.ie6Compat ) )
\r
321 setTimeout(function()
\r
323 panel.element.getChild( 0 ).$.style.cssText += '';
\r
328 hideChild : function()
\r
330 var activeChild = this._.activeChild;
\r
334 delete activeChild.onHide;
\r
335 delete this._.activeChild;
\r
336 activeChild.hide();
\r
342 CKEDITOR.on( 'instanceDestroyed', function()
\r
344 var isLastInstance = CKEDITOR.tools.isEmpty( CKEDITOR.instances );
\r
346 for( var i in panels )
\r
348 var panel = panels[ i ];
\r
349 // Safe to destroy it since there're no more instances.(#4241)
\r
350 if( isLastInstance )
\r
352 // Panel might be used by other instances, just hide them.(#4552)
\r
354 panel.element.hide();
\r
356 // Remove the registration.
\r
357 isLastInstance && ( panels = {} );
\r