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
47 panelDefinition.block =
\r
49 multiSelect : panelDefinition.multiSelect,
\r
50 attributes : panelDefinition.attributes
\r
55 panelDefinition : panelDefinition,
\r
57 state : CKEDITOR.TRISTATE_OFF
\r
65 create : function( definition )
\r
67 return new CKEDITOR.ui.richCombo( definition );
\r
74 renderHtml : function( editor )
\r
77 this.render( editor, output );
\r
78 return output.join( '' );
\r
82 * Renders the combo.
\r
83 * @param {CKEDITOR.editor} editor The editor instance which this button is
\r
85 * @param {Array} output The output array to which append the HTML relative
\r
89 render : function( editor, output )
\r
91 var env = CKEDITOR.env;
\r
93 var id = 'cke_' + this.id;
\r
94 var clickFn = CKEDITOR.tools.addFunction( function( $element )
\r
98 if ( _.state == CKEDITOR.TRISTATE_DISABLED )
\r
101 this.createPanel( editor );
\r
110 var value = this.getValue();
\r
112 _.list.mark( value );
\r
114 _.list.unmarkAll();
\r
116 _.panel.showBlock( this.id, new CKEDITOR.dom.element( $element ), 4 );
\r
125 var element = CKEDITOR.document.getById( id ).getChild( 1 );
\r
131 editor.on( 'mode', function()
\r
133 this.setState( this.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
\r
137 var keyDownFn = CKEDITOR.tools.addFunction( function( ev, element )
\r
139 ev = new CKEDITOR.dom.event( ev );
\r
141 var keystroke = ev.getKeystroke();
\r
142 switch ( keystroke )
\r
146 case 40 : // ARROW-DOWN
\r
148 CKEDITOR.tools.callFunction( clickFn, element );
\r
151 // Delegate the default behavior to toolbar button key handling.
\r
152 instance.onkey( instance, keystroke );
\r
155 // Avoid subsequent focus grab on editor document.
\r
156 ev.preventDefault();
\r
160 instance.keyDownFn = keyDownFn;
\r
163 '<span class="cke_rcombo">',
\r
166 if ( this.className )
\r
167 output.push( ' class="', this.className, ' cke_off"');
\r
171 '<span id="' + id+ '_label" class=cke_label>', this.label, '</span>',
\r
172 '<a hidefocus=true title="', this.title, '" tabindex="-1"',
\r
173 env.gecko && env.version >= 10900 && !env.hc ? '' : ' href="javascript:void(\'' + this.label + '\')"',
\r
174 ' role="button" aria-labelledby="', id , '_label" aria-describedby="', id, '_text" aria-haspopup="true"' );
\r
176 // Some browsers don't cancel key events in the keydown but in the
\r
178 // TODO: Check if really needed for Gecko+Mac.
\r
179 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
182 ' onkeypress="return false;"' );
\r
185 // With Firefox, we need to force it to redraw, otherwise it
\r
186 // will remain in the focus state.
\r
187 if ( CKEDITOR.env.gecko )
\r
190 ' onblur="this.style.cssText = this.style.cssText;"' );
\r
194 ' onkeydown="CKEDITOR.tools.callFunction( ', keyDownFn, ', event, this );"' +
\r
195 ' onclick="CKEDITOR.tools.callFunction(', clickFn, ', this); return false;">' +
\r
197 '<span id="' + id + '_text" class="cke_text cke_inline_label">' + this.label + '</span>' +
\r
199 '<span class=cke_openbutton>' + ( CKEDITOR.env.hc ? '<span>▼</span>' : CKEDITOR.env.air ? ' ' : '' ) + '</span>' + // BLACK DOWN-POINTING TRIANGLE
\r
204 if ( this.onRender )
\r
210 createPanel : function( editor )
\r
212 if ( this._.panel )
\r
215 var panelDefinition = this._.panelDefinition,
\r
216 panelBlockDefinition = this._.panelDefinition.block,
\r
217 panelParentElement = panelDefinition.parent || CKEDITOR.document.getBody(),
\r
218 panel = new CKEDITOR.ui.floatPanel( editor, panelParentElement, panelDefinition ),
\r
219 list = panel.addListBlock( this.id, panelBlockDefinition ),
\r
222 panel.onShow = function()
\r
224 if ( me.className )
\r
225 this.element.getFirst().addClass( me.className + '_panel' );
\r
227 me.setState( CKEDITOR.TRISTATE_ON );
\r
229 list.focus( !me.multiSelect && me.getValue() );
\r
237 panel.onHide = function( preventOnClose )
\r
239 if ( me.className )
\r
240 this.element.getFirst().removeClass( me.className + '_panel' );
\r
242 me.setState( me.modes && me.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
\r
246 if ( !preventOnClose && me.onClose )
\r
250 panel.onEscape = function()
\r
253 me.document.getById( 'cke_' + me.id ).getFirst().getNext().focus();
\r
256 list.onClick = function( value, marked )
\r
258 // Move the focus to the main windows, otherwise it will stay
\r
259 // into the floating panel, even if invisible, and Safari and
\r
260 // Opera will go a bit crazy.
\r
261 me.document.getWindow().focus();
\r
264 me.onClick.call( me, value, marked );
\r
267 me.setValue( value, me._.items[ value ] );
\r
274 this._.panel = panel;
\r
275 this._.list = list;
\r
277 panel.getBlock( this.id ).onHide = function()
\r
280 me.setState( CKEDITOR.TRISTATE_OFF );
\r
287 setValue : function( value, text )
\r
289 this._.value = value;
\r
291 var textElement = this.document.getById( 'cke_' + this.id + '_text' );
\r
293 if ( !( value || text ) )
\r
296 textElement.addClass( 'cke_inline_label' );
\r
299 textElement.removeClass( 'cke_inline_label' );
\r
301 textElement.setHtml( typeof text != 'undefined' ? text : value );
\r
304 getValue : function()
\r
306 return this._.value || '';
\r
309 unmarkAll : function()
\r
311 this._.list.unmarkAll();
\r
314 mark : function( value )
\r
316 this._.list.mark( value );
\r
319 hideItem : function( value )
\r
321 this._.list.hideItem( value );
\r
324 hideGroup : function( groupTitle )
\r
326 this._.list.hideGroup( groupTitle );
\r
329 showAll : function()
\r
331 this._.list.showAll();
\r
334 add : function( value, html, text )
\r
336 this._.items[ value ] = text || value;
\r
337 this._.list.add( value, html, text );
\r
340 startGroup : function( title )
\r
342 this._.list.startGroup( title );
\r
345 commit : function()
\r
347 if ( !this._.committed )
\r
349 this._.list.commit();
\r
350 this._.committed = 1;
\r
351 CKEDITOR.ui.fire( 'ready', this );
\r
353 this._.committed = 1;
\r
356 setState : function( state )
\r
358 if ( this._.state == state )
\r
361 this.document.getById( 'cke_' + this.id ).setState( state );
\r
363 this._.state = state;
\r
368 CKEDITOR.ui.prototype.addRichCombo = function( name, definition )
\r
370 this.add( name, CKEDITOR.UI_RICHCOMBO, definition );
\r