2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
6 CKEDITOR.plugins.add( 'panel',
8 beforeInit : function( editor )
10 editor.ui.addHandler( CKEDITOR.UI_PANEL, CKEDITOR.ui.panel.handler );
19 CKEDITOR.UI_PANEL = 'panel';
21 CKEDITOR.ui.panel = function( document, definition )
23 // Copy all definition properties to this object.
25 CKEDITOR.tools.extend( this, definition );
28 CKEDITOR.tools.extend( this,
34 this.id = CKEDITOR.tools.getNextId();
35 this.document = document;
44 * Transforms a rich combo definition in a {@link CKEDITOR.ui.richCombo}
49 CKEDITOR.ui.panel.handler =
51 create : function( definition )
53 return new CKEDITOR.ui.panel( definition );
57 CKEDITOR.ui.panel.prototype =
59 renderHtml : function( editor )
62 this.render( editor, output );
63 return output.join( '' );
68 * @param {CKEDITOR.editor} editor The editor instance which this button is
70 * @param {Array} output The output array to which append the HTML relative
74 render : function( editor, output )
79 '<div class="', editor.skinClass ,'"' +
80 ' lang="', editor.langCode, '"' +
81 ' role="presentation"' +
82 // iframe loading need sometime, keep the panel hidden(#4186).
83 ' style="display:none;z-index:' + ( editor.config.baseFloatZIndex + 1 ) + '">' +
86 ' dir=', editor.lang.dir,
87 ' role="presentation"' +
88 ' class="cke_panel cke_', editor.lang.dir );
91 output.push( ' ', this.className );
96 if ( this.forceIFrame || this.css.length )
99 '<iframe id="', id, '_frame"' +
101 ' role="application" src="javascript:void(' );
104 // Support for custom document.domain in IE.
105 CKEDITOR.env.isCustomDomain() ?
108 'document.domain=\'' + document.domain + '\';' +
109 'document.close();' +
125 getHolderElement : function()
127 var holder = this._.holder;
131 if ( this.forceIFrame || this.css.length )
133 var iframe = this.document.getById( this.id + '_frame' ),
134 parentDiv = iframe.getParent(),
135 dir = parentDiv.getAttribute( 'dir' ),
136 className = parentDiv.getParent().getAttribute( 'class' ),
137 langCode = parentDiv.getParent().getAttribute( 'lang' ),
138 doc = iframe.getFrameDocument();
140 // Make it scrollable on iOS. (#8308)
141 CKEDITOR.env.iOS && parentDiv.setStyles(
143 'overflow' : 'scroll',
144 '-webkit-overflow-scrolling' : 'touch'
147 var onLoad = CKEDITOR.tools.addFunction( CKEDITOR.tools.bind( function( ev )
149 this.isLoaded = true;
156 '<html dir="' + dir + '" class="' + className + '_container" lang="' + langCode + '">' +
158 '<style>.' + className + '_container{visibility:hidden}</style>' +
160 '<body class="cke_' + dir + ' cke_panel_frame ' + CKEDITOR.env.cssClass + '" style="margin:0;padding:0"' +
161 ' onload="( window.CKEDITOR || window.parent.CKEDITOR ).tools.callFunction(' + onLoad + ');"></body>' +
162 // It looks strange, but for FF2, the styles must go
163 // after <body>, so it (body) becames immediatelly
164 // available. (#3031)
165 CKEDITOR.tools.buildStyleHtml( this.css ) +
170 var win = doc.getWindow();
172 // Register the CKEDITOR global.
173 win.$.CKEDITOR = CKEDITOR;
175 // Arrow keys for scrolling is only preventable with 'keypress' event in Opera (#4534).
176 doc.on( 'key' + ( CKEDITOR.env.opera? 'press':'down' ), function( evt )
178 var keystroke = evt.data.getKeystroke(),
179 dir = this.document.getById( this.id ).getAttribute( 'dir' );
181 // Delegate key processing to block.
182 if ( this._.onKeyDown && this._.onKeyDown( keystroke ) === false )
184 evt.data.preventDefault();
188 // ESC/ARROW-LEFT(ltr) OR ARROW-RIGHT(rtl)
189 if ( keystroke == 27 || keystroke == ( dir == 'rtl' ? 39 : 37 ) )
191 if ( this.onEscape && this.onEscape( keystroke ) === false )
192 evt.data.preventDefault();
197 holder = doc.getBody();
198 holder.unselectable();
199 CKEDITOR.env.air && CKEDITOR.tools.callFunction( onLoad );
202 holder = this.document.getById( this.id );
204 this._.holder = holder;
210 addBlock : function( name, block )
212 block = this._.blocks[ name ] = block instanceof CKEDITOR.ui.panel.block ? block
213 : new CKEDITOR.ui.panel.block( this.getHolderElement(), block );
215 if ( !this._.currentBlock )
216 this.showBlock( name );
221 getBlock : function( name )
223 return this._.blocks[ name ];
226 showBlock : function( name )
228 var blocks = this._.blocks,
229 block = blocks[ name ],
230 current = this._.currentBlock,
231 holder = this.forceIFrame ?
232 this.document.getById( this.id + '_frame' )
235 // Disable context menu for block panel.
236 holder.getParent().getParent().disableContextMenu();
240 // Clean up the current block's effects on holder.
241 holder.removeAttributes( current.attributes );
245 this._.currentBlock = block;
247 holder.setAttributes( block.attributes );
248 CKEDITOR.fire( 'ariaWidget', holder );
250 // Reset the focus index, so it will always go into the first one.
251 block._.focusIndex = -1;
253 this._.onKeyDown = block.onKeyDown && CKEDITOR.tools.bind( block.onKeyDown, block );
262 this.element && this.element.remove();
266 CKEDITOR.ui.panel.block = CKEDITOR.tools.createClass(
268 $ : function( blockHolder, blockDefinition )
270 this.element = blockHolder.append(
271 blockHolder.getDocument().createElement( 'div',
276 'class' : 'cke_panel_block',
277 'role' : 'presentation'
285 // Copy all definition properties to this object.
286 if ( blockDefinition )
287 CKEDITOR.tools.extend( this, blockDefinition );
289 if ( !this.attributes.title )
290 this.attributes.title = this.attributes[ 'aria-label' ];
294 this._.focusIndex = -1;
296 // Disable context menu for panels.
297 this.element.disableContextMenu();
303 * Mark the item specified by the index as current activated.
305 markItem: function( index )
309 var links = this.element.getElementsByTag( 'a' );
310 var item = links.getItem( this._.focusIndex = index );
312 // Safari need focus on the iframe window first(#3389), but we need
313 // lock the blur to avoid hiding the panel.
314 if ( CKEDITOR.env.webkit || CKEDITOR.env.opera )
315 item.getDocument().getWindow().focus();
318 this.onMark && this.onMark( item );
326 this.element.setStyle( 'display', '' );
331 if ( !this.onHide || this.onHide.call( this ) !== true )
332 this.element.setStyle( 'display', 'none' );
335 onKeyDown : function( keystroke )
337 var keyAction = this.keys[ keystroke ];
342 var index = this._.focusIndex,
343 links = this.element.getElementsByTag( 'a' ),
346 while ( ( link = links.getItem( ++index ) ) )
348 // Move the focus only if the element is marked with
349 // the _cke_focus and it it's visible (check if it has
351 if ( link.getAttribute( '_cke_focus' ) && link.$.offsetWidth )
353 this._.focusIndex = index;
362 index = this._.focusIndex;
363 links = this.element.getElementsByTag( 'a' );
365 while ( index > 0 && ( link = links.getItem( --index ) ) )
367 // Move the focus only if the element is marked with
368 // the _cke_focus and it it's visible (check if it has
370 if ( link.getAttribute( '_cke_focus' ) && link.$.offsetWidth )
372 this._.focusIndex = index;
381 index = this._.focusIndex;
382 link = index >= 0 && this.element.getElementsByTag( 'a' ).getItem( index );
385 link.$[ keyAction ] ? link.$[ keyAction ]() : link.$[ 'on' + keyAction ]();
396 * Fired when a panel is added to the document
397 * @name CKEDITOR#ariaWidget
399 * @param {Object} holder The element wrapping the panel