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( 'richcombo',
\r
8 requires : [ 'floatpanel', 'listblock', 'button' ],
\r
10 beforeInit : function( editor )
\r
12 editor.ui.addHandler( CKEDITOR.UI_RICHCOMBO, CKEDITOR.ui.richCombo.handler );
\r
17 * Button UI element.
\r
21 CKEDITOR.UI_RICHCOMBO = 3;
\r
23 CKEDITOR.ui.richCombo = CKEDITOR.tools.createClass(
\r
25 $ : function( definition )
\r
27 // Copy all definition properties to this object.
\r
28 CKEDITOR.tools.extend( this, definition,
\r
31 title : definition.label,
\r
32 modes : { wysiwyg : 1 }
\r
35 // We don't want the panel definition in this object.
\r
36 var panelDefinition = this.panel || {};
\r
39 this.id = CKEDITOR.tools.getNextNumber();
\r
41 this.document = ( panelDefinition
\r
42 && panelDefinition.parent
\r
43 && panelDefinition.parent.getDocument() )
\r
44 || CKEDITOR.document;
\r
46 panelDefinition.className = ( panelDefinition.className || '' ) + ' cke_rcombopanel';
\r
50 panelDefinition : panelDefinition,
\r
52 state : CKEDITOR.TRISTATE_OFF
\r
60 create : function( definition )
\r
62 return new CKEDITOR.ui.richCombo( definition );
\r
69 renderHtml : function( editor )
\r
72 this.render( editor, output );
\r
73 return output.join( '' );
\r
77 * Renders the combo.
\r
78 * @param {CKEDITOR.editor} editor The editor instance which this button is
\r
80 * @param {Array} output The output array to which append the HTML relative
\r
84 render : function( editor, output )
\r
86 var id = 'cke_' + this.id;
\r
87 var clickFn = CKEDITOR.tools.addFunction( function( $element )
\r
91 if ( _.state == CKEDITOR.TRISTATE_DISABLED )
\r
94 this.createPanel( editor );
\r
102 if ( !_.committed )
\r
108 var value = this.getValue();
\r
110 _.list.mark( value );
\r
112 _.list.unmarkAll();
\r
114 _.panel.showBlock( this.id, new CKEDITOR.dom.element( $element ), 4 );
\r
123 var element = CKEDITOR.document.getById( id ).getChild( 1 );
\r
129 editor.on( 'mode', function()
\r
131 this.setState( this.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
\r
135 var keyDownFn = CKEDITOR.tools.addFunction( function( ev, element )
\r
137 ev = new CKEDITOR.dom.event( ev );
\r
139 var keystroke = ev.getKeystroke();
\r
140 switch ( keystroke )
\r
144 case 40 : // ARROW-DOWN
\r
146 CKEDITOR.tools.callFunction( clickFn, element );
\r
149 // Delegate the default behavior to toolbar button key handling.
\r
150 instance.onkey( instance, keystroke );
\r
153 // Avoid subsequent focus grab on editor document.
\r
154 ev.preventDefault();
\r
158 '<span class="cke_rcombo">',
\r
161 if ( this.className )
\r
162 output.push( ' class="', this.className, ' cke_off"');
\r
166 '<span class=cke_label>', this.label, '</span>' +
\r
167 '<a hidefocus=true title="', this.title, '" tabindex="-1" href="javascript:void(\'', this.label, '\')"' );
\r
169 // Some browsers don't cancel key events in the keydown but in the
\r
171 // TODO: Check if really needed for Gecko+Mac.
\r
172 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
175 ' onkeypress="return false;"' );
\r
178 // With Firefox, we need to force it to redraw, otherwise it
\r
179 // will remain in the focus state.
\r
180 if ( CKEDITOR.env.gecko )
\r
183 ' onblur="this.style.cssText = this.style.cssText;"' );
\r
187 ' onkeydown="CKEDITOR.tools.callFunction( ', keyDownFn, ', event, this );"' +
\r
188 ' onclick="CKEDITOR.tools.callFunction(', clickFn, ', this); return false;">' +
\r
190 '<span class="cke_accessibility">' + ( this.voiceLabel ? this.voiceLabel + ' ' : '' ) + '</span>' +
\r
191 '<span id="' + id + '_text" class="cke_text cke_inline_label">' + this.label + '</span>' +
\r
193 '<span class=cke_openbutton></span>' +
\r
198 if ( this.onRender )
\r
204 createPanel : function( editor )
\r
206 if ( this._.panel )
\r
209 var panelDefinition = this._.panelDefinition,
\r
210 panelParentElement = panelDefinition.parent || CKEDITOR.document.getBody(),
\r
211 panel = new CKEDITOR.ui.floatPanel( editor, panelParentElement, panelDefinition ),
\r
212 list = panel.addListBlock( this.id, this.multiSelect ),
\r
215 panel.onShow = function()
\r
217 if ( me.className )
\r
218 this.element.getFirst().addClass( me.className + '_panel' );
\r
220 me.setState( CKEDITOR.TRISTATE_ON );
\r
222 list.focus( !me.multiSelect && me.getValue() );
\r
230 panel.onHide = function()
\r
232 if ( me.className )
\r
233 this.element.getFirst().removeClass( me.className + '_panel' );
\r
235 me.setState( CKEDITOR.TRISTATE_OFF );
\r
243 panel.onEscape = function()
\r
246 me.document.getById( 'cke_' + me.id ).getFirst().getNext().focus();
\r
249 list.onClick = function( value, marked )
\r
251 // Move the focus to the main windows, otherwise it will stay
\r
252 // into the floating panel, even if invisible, and Safari and
\r
253 // Opera will go a bit crazy.
\r
254 me.document.getWindow().focus();
\r
257 me.onClick.call( me, value, marked );
\r
260 me.setValue( value, me._.items[ value ] );
\r
267 this._.panel = panel;
\r
268 this._.list = list;
\r
270 panel.getBlock( this.id ).onHide = function()
\r
273 me.setState( CKEDITOR.TRISTATE_OFF );
\r
280 setValue : function( value, text )
\r
282 this._.value = value;
\r
284 var textElement = this.document.getById( 'cke_' + this.id + '_text' );
\r
286 if ( !( value || text ) )
\r
289 textElement.addClass( 'cke_inline_label' );
\r
292 textElement.removeClass( 'cke_inline_label' );
\r
293 textElement.setHtml( typeof text != 'undefined' ? text : value );
\r
296 getValue : function()
\r
298 return this._.value || '';
\r
301 unmarkAll : function()
\r
303 this._.list.unmarkAll();
\r
306 mark : function( value )
\r
308 this._.list.mark( value );
\r
311 hideItem : function( value )
\r
313 this._.list.hideItem( value );
\r
316 hideGroup : function( groupTitle )
\r
318 this._.list.hideGroup( groupTitle );
\r
321 showAll : function()
\r
323 this._.list.showAll();
\r
326 add : function( value, html, text )
\r
328 this._.items[ value ] = text || value;
\r
329 this._.list.add( value, html, text );
\r
332 startGroup : function( title )
\r
334 this._.list.startGroup( title );
\r
337 commit : function()
\r
339 this._.list.commit();
\r
342 setState : function( state )
\r
344 if ( this._.state == state )
\r
347 this.document.getById( 'cke_' + this.id ).setState( state );
\r
349 this._.state = state;
\r
354 CKEDITOR.ui.prototype.addRichCombo = function( name, definition )
\r
356 this.add( name, CKEDITOR.UI_RICHCOMBO, definition );
\r