2 Copyright (c) 2003-2011, 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.getNextId();
\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
79 '<div class="', editor.skinClass ,'"' +
\r
80 ' lang="', editor.langCode, '"' +
\r
81 ' role="presentation"' +
\r
82 // iframe loading need sometime, keep the panel hidden(#4186).
\r
83 ' style="display:none;z-index:' + ( editor.config.baseFloatZIndex + 1 ) + '">' +
\r
86 ' dir=', editor.lang.dir,
\r
87 ' role="presentation"' +
\r
88 ' class="cke_panel cke_', editor.lang.dir );
\r
90 if ( this.className )
\r
91 output.push( ' ', this.className );
\r
96 if ( this.forceIFrame || this.css.length )
\r
99 '<iframe id="', id, '_frame"' +
\r
100 ' frameborder="0"' +
\r
101 ' role="application" src="javascript:void(' );
\r
104 // Support for custom document.domain in IE.
\r
105 CKEDITOR.env.isCustomDomain() ?
\r
107 'document.open();' +
\r
108 'document.domain=\'' + document.domain + '\';' +
\r
109 'document.close();' +
\r
125 getHolderElement : function()
\r
127 var holder = this._.holder;
\r
131 if ( this.forceIFrame || this.css.length )
\r
133 var iframe = this.document.getById( this.id + '_frame' ),
\r
134 parentDiv = iframe.getParent(),
\r
135 dir = parentDiv.getAttribute( 'dir' ),
\r
136 className = parentDiv.getParent().getAttribute( 'class' ),
\r
137 langCode = parentDiv.getParent().getAttribute( 'lang' ),
\r
138 doc = iframe.getFrameDocument();
\r
140 var onLoad = CKEDITOR.tools.addFunction( CKEDITOR.tools.bind( function( ev )
\r
142 this.isLoaded = true;
\r
148 '<!DOCTYPE html>' +
\r
149 '<html dir="' + dir + '" class="' + className + '_container" lang="' + langCode + '">' +
\r
151 '<style>.' + className + '_container{visibility:hidden}</style>' +
\r
153 '<body class="cke_' + dir + ' cke_panel_frame ' + CKEDITOR.env.cssClass + '" style="margin:0;padding:0"' +
\r
154 ' onload="( window.CKEDITOR || window.parent.CKEDITOR ).tools.callFunction(' + onLoad + ');"></body>' +
\r
155 // It looks strange, but for FF2, the styles must go
\r
156 // after <body>, so it (body) becames immediatelly
\r
157 // available. (#3031)
\r
158 CKEDITOR.tools.buildStyleHtml( this.css ) +
\r
163 var win = doc.getWindow();
\r
165 // Register the CKEDITOR global.
\r
166 win.$.CKEDITOR = CKEDITOR;
\r
168 // Arrow keys for scrolling is only preventable with 'keypress' event in Opera (#4534).
\r
169 doc.on( 'key' + ( CKEDITOR.env.opera? 'press':'down' ), function( evt )
\r
171 var keystroke = evt.data.getKeystroke(),
\r
172 dir = this.document.getById( this.id ).getAttribute( 'dir' );
\r
174 // Delegate key processing to block.
\r
175 if ( this._.onKeyDown && this._.onKeyDown( keystroke ) === false )
\r
177 evt.data.preventDefault();
\r
181 // ESC/ARROW-LEFT(ltr) OR ARROW-RIGHT(rtl)
\r
182 if ( keystroke == 27 || keystroke == ( dir == 'rtl' ? 39 : 37 ) )
\r
184 if ( this.onEscape && this.onEscape( keystroke ) === false )
\r
185 evt.data.preventDefault();
\r
190 holder = doc.getBody();
\r
191 holder.unselectable();
\r
192 CKEDITOR.env.air && CKEDITOR.tools.callFunction( onLoad );
\r
195 holder = this.document.getById( this.id );
\r
197 this._.holder = holder;
\r
203 addBlock : function( name, block )
\r
205 block = this._.blocks[ name ] = block instanceof CKEDITOR.ui.panel.block ? block
\r
206 : new CKEDITOR.ui.panel.block( this.getHolderElement(), block );
\r
208 if ( !this._.currentBlock )
\r
209 this.showBlock( name );
\r
214 getBlock : function( name )
\r
216 return this._.blocks[ name ];
\r
219 showBlock : function( name )
\r
221 var blocks = this._.blocks,
\r
222 block = blocks[ name ],
\r
223 current = this._.currentBlock,
\r
224 holder = this.forceIFrame ?
\r
225 this.document.getById( this.id + '_frame' )
\r
228 // Disable context menu for block panel.
\r
229 holder.getParent().getParent().disableContextMenu();
\r
233 // Clean up the current block's effects on holder.
\r
234 holder.removeAttributes( current.attributes );
\r
238 this._.currentBlock = block;
\r
240 holder.setAttributes( block.attributes );
\r
241 CKEDITOR.fire( 'ariaWidget', holder );
\r
243 // Reset the focus index, so it will always go into the first one.
\r
244 block._.focusIndex = -1;
\r
246 this._.onKeyDown = block.onKeyDown && CKEDITOR.tools.bind( block.onKeyDown, block );
\r
248 block.onMark = function( item )
\r
250 holder.setAttribute( 'aria-activedescendant', item.getId() + '_option' );
\r
253 block.onUnmark = function()
\r
255 holder.removeAttribute( 'aria-activedescendant' );
\r
263 destroy : function()
\r
265 this.element && this.element.remove();
\r
269 CKEDITOR.ui.panel.block = CKEDITOR.tools.createClass(
\r
271 $ : function( blockHolder, blockDefinition )
\r
273 this.element = blockHolder.append(
\r
274 blockHolder.getDocument().createElement( 'div',
\r
279 'class' : 'cke_panel_block',
\r
280 'role' : 'presentation'
\r
288 // Copy all definition properties to this object.
\r
289 if ( blockDefinition )
\r
290 CKEDITOR.tools.extend( this, blockDefinition );
\r
292 if ( !this.attributes.title )
\r
293 this.attributes.title = this.attributes[ 'aria-label' ];
\r
297 this._.focusIndex = -1;
\r
299 // Disable context menu for panels.
\r
300 this.element.disableContextMenu();
\r
306 * Mark the item specified by the index as current activated.
\r
308 markItem: function( index )
\r
312 var links = this.element.getElementsByTag( 'a' );
\r
313 var item = links.getItem( this._.focusIndex = index );
\r
315 // Safari need focus on the iframe window first(#3389), but we need
\r
316 // lock the blur to avoid hiding the panel.
\r
317 if ( CKEDITOR.env.webkit || CKEDITOR.env.opera )
\r
318 item.getDocument().getWindow().focus();
\r
321 this.onMark && this.onMark( item );
\r
329 this.element.setStyle( 'display', '' );
\r
334 if ( !this.onHide || this.onHide.call( this ) !== true )
\r
335 this.element.setStyle( 'display', 'none' );
\r
338 onKeyDown : function( keystroke )
\r
340 var keyAction = this.keys[ keystroke ];
\r
341 switch ( keyAction )
\r
345 var index = this._.focusIndex,
\r
346 links = this.element.getElementsByTag( 'a' ),
\r
349 while ( ( link = links.getItem( ++index ) ) )
\r
351 // Move the focus only if the element is marked with
\r
352 // the _cke_focus and it it's visible (check if it has
\r
354 if ( link.getAttribute( '_cke_focus' ) && link.$.offsetWidth )
\r
356 this._.focusIndex = index;
\r
365 index = this._.focusIndex;
\r
366 links = this.element.getElementsByTag( 'a' );
\r
368 while ( index > 0 && ( link = links.getItem( --index ) ) )
\r
370 // Move the focus only if the element is marked with
\r
371 // the _cke_focus and it it's visible (check if it has
\r
373 if ( link.getAttribute( '_cke_focus' ) && link.$.offsetWidth )
\r
375 this._.focusIndex = index;
\r
383 index = this._.focusIndex;
\r
384 link = index >= 0 && this.element.getElementsByTag( 'a' ).getItem( index );
\r
387 link.$.click ? link.$.click() : link.$.onclick();
\r
398 * Fired when a panel is added to the document
\r
399 * @name CKEDITOR#ariaWidget
\r
401 * @param {Object} holder The element wrapping the panel
\r