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( 'panel',
\r
8 beforeInit : function( editor )
\r
10 editor.ui.addHandler( CKEDITOR.UI_PANEL, CKEDITOR.ui.panel.handler );
\r
19 CKEDITOR.UI_PANEL = 2;
\r
21 CKEDITOR.ui.panel = function( document, definition )
\r
23 // Copy all definition properties to this object.
\r
25 CKEDITOR.tools.extend( this, definition );
\r
28 CKEDITOR.tools.extend( this,
\r
34 this.id = CKEDITOR.tools.getNextNumber();
\r
35 this.document = document;
\r
44 * Transforms a rich combo definition in a {@link CKEDITOR.ui.richCombo}
\r
49 CKEDITOR.ui.panel.handler =
\r
51 create : function( definition )
\r
53 return new CKEDITOR.ui.panel( definition );
\r
57 CKEDITOR.ui.panel.prototype =
\r
59 renderHtml : function( editor )
\r
62 this.render( editor, output );
\r
63 return output.join( '' );
\r
67 * Renders the combo.
\r
68 * @param {CKEDITOR.editor} editor The editor instance which this button is
\r
70 * @param {Array} output The output array to which append the HTML relative
\r
74 render : function( editor, output )
\r
76 var id = 'cke_' + this.id;
\r
79 '<div class="', editor.skinClass ,'"' +
\r
80 ' lang="', editor.langCode, '"' +
\r
81 // iframe loading need sometime, keep the panel hidden(#4186).
\r
82 ' style="display:none;z-index:' + ( editor.config.baseFloatZIndex + 1 ) + '">' +
\r
85 ' dir=', editor.lang.dir,
\r
86 ' class="cke_panel cke_', editor.lang.dir );
\r
88 if ( this.className )
\r
89 output.push( ' ', this.className );
\r
94 if ( this.forceIFrame || this.css.length )
\r
97 '<iframe id="', id, '_frame"' +
\r
98 ' frameborder="0"' +
\r
99 ' src="javascript:void(' );
\r
102 // Support for custom document.domain in IE.
\r
103 CKEDITOR.env.isCustomDomain() ?
\r
105 'document.open();' +
\r
106 'document.domain=\'' + document.domain + '\';' +
\r
107 'document.close();' +
\r
123 getHolderElement : function()
\r
125 var holder = this._.holder;
\r
129 if ( this.forceIFrame || this.css.length )
\r
131 var iframe = this.document.getById( 'cke_' + this.id + '_frame' ),
\r
132 parentDiv = iframe.getParent(),
\r
133 dir = parentDiv.getAttribute( 'dir' ),
\r
134 className = parentDiv.getParent().getAttribute( 'class' ),
\r
135 langCode = parentDiv.getParent().getAttribute( 'lang' ),
\r
136 doc = iframe.getFrameDocument();
\r
137 // Initialize the IFRAME document body.
\r
140 // Support for custom document.domain in IE.
\r
141 if ( CKEDITOR.env.isCustomDomain() )
\r
142 doc.$.domain = document.domain;
\r
144 var onLoad = CKEDITOR.tools.addFunction( CKEDITOR.tools.bind( function( ev )
\r
146 this.isLoaded = true;
\r
152 '<!DOCTYPE html>' +
\r
153 '<html dir="' + dir + '" class="' + className + '_container" lang="' + langCode + '">' +
\r
155 '<style>.' + className + '_container{visibility:hidden}</style>' +
\r
157 '<body class="cke_' + dir + ' cke_panel_frame ' + CKEDITOR.env.cssClass + '" style="margin:0;padding:0"' +
\r
158 ' onload="( window.CKEDITOR || window.parent.CKEDITOR ).tools.callFunction(' + onLoad + ');">' +
\r
160 // It looks strange, but for FF2, the styles must go
\r
161 // after <body>, so it (body) becames immediatelly
\r
162 // available. (#3031)
\r
163 '<link type="text/css" rel=stylesheet href="' + this.css.join( '"><link type="text/css" rel="stylesheet" href="' ) + '">' +
\r
167 var win = doc.getWindow();
\r
169 // Register the CKEDITOR global.
\r
170 win.$.CKEDITOR = CKEDITOR;
\r
172 doc.on( 'keydown', function( evt )
\r
174 var keystroke = evt.data.getKeystroke();
\r
176 // Delegate key processing to block.
\r
177 if ( this._.onKeyDown && this._.onKeyDown( keystroke ) === false )
\r
179 evt.data.preventDefault();
\r
183 if ( keystroke == 27 ) // ESC
\r
184 this.onEscape && this.onEscape();
\r
188 holder = doc.getBody();
\r
191 holder = this.document.getById( 'cke_' + this.id );
\r
193 this._.holder = holder;
\r
199 addBlock : function( name, block )
\r
201 block = this._.blocks[ name ] = block || new CKEDITOR.ui.panel.block( this.getHolderElement() );
\r
203 if ( !this._.currentBlock )
\r
204 this.showBlock( name );
\r
209 getBlock : function( name )
\r
211 return this._.blocks[ name ];
\r
214 showBlock : function( name )
\r
216 var blocks = this._.blocks,
\r
217 block = blocks[ name ],
\r
218 current = this._.currentBlock;
\r
223 this._.currentBlock = block;
\r
225 // Reset the focus index, so it will always go into the first one.
\r
226 block._.focusIndex = -1;
\r
228 this._.onKeyDown = block.onKeyDown && CKEDITOR.tools.bind( block.onKeyDown, block );
\r
236 CKEDITOR.ui.panel.block = CKEDITOR.tools.createClass(
\r
238 $ : function( blockHolder )
\r
240 this.element = blockHolder.append(
\r
241 blockHolder.getDocument().createElement( 'div',
\r
245 'class' : 'cke_panel_block'
\r
255 this._.focusIndex = -1;
\r
257 // Disable context menu for panels.
\r
258 this.element.disableContextMenu();
\r
267 this.element.setStyle( 'display', '' );
\r
272 if ( !this.onHide || this.onHide.call( this ) !== true )
\r
273 this.element.setStyle( 'display', 'none' );
\r
276 onKeyDown : function( keystroke )
\r
278 var keyAction = this.keys[ keystroke ];
\r
279 switch ( keyAction )
\r
283 var index = this._.focusIndex,
\r
284 links = this.element.getElementsByTag( 'a' ),
\r
287 while ( ( link = links.getItem( ++index ) ) )
\r
289 // Move the focus only if the element is marked with
\r
290 // the _cke_focus and it it's visible (check if it has
\r
292 if ( link.getAttribute( '_cke_focus' ) && link.$.offsetWidth )
\r
294 this._.focusIndex = index;
\r
303 index = this._.focusIndex;
\r
304 links = this.element.getElementsByTag( 'a' );
\r
306 while ( index > 0 && ( link = links.getItem( --index ) ) )
\r
308 // Move the focus only if the element is marked with
\r
309 // the _cke_focus and it it's visible (check if it has
\r
311 if ( link.getAttribute( '_cke_focus' ) && link.$.offsetWidth )
\r
313 this._.focusIndex = index;
\r
321 index = this._.focusIndex;
\r
322 link = index >= 0 && this.element.getElementsByTag( 'a' ).getItem( index );
\r
325 link.$.click ? link.$.click() : link.$.onclick();
\r