]>
git.immae.eu Git - perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git/blob - sources/plugins/richcombo/plugin.js
2 * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
6 CKEDITOR
.plugins
.add( 'richcombo', {
7 requires: 'floatpanel,listblock,button',
9 beforeInit: function( editor
) {
10 editor
.ui
.addHandler( CKEDITOR
.UI_RICHCOMBO
, CKEDITOR
.ui
.richCombo
.handler
);
15 var template
= '<span id="{id}"' +
16 ' class="cke_combo cke_combo__{name} {cls}"' +
17 ' role="presentation">' +
18 '<span id="{id}_label" class="cke_combo_label">{label}</span>' +
19 '<a class="cke_combo_button" title="{title}" tabindex="-1"' +
20 ( CKEDITOR
.env
.gecko
&& !CKEDITOR
.env
.hc
? '' : ' href="javascript:void(\'{titleJs}\')"' ) +
23 ' aria-labelledby="{id}_label"' +
24 ' aria-haspopup="true"';
26 // Some browsers don't cancel key events in the keydown but in the
28 // TODO: Check if really needed.
29 if ( CKEDITOR
.env
.gecko
&& CKEDITOR
.env
.mac
)
30 template
+= ' onkeypress="return false;"';
32 // With Firefox, we need to force the button to redraw, otherwise it
33 // will remain in the focus state.
34 if ( CKEDITOR
.env
.gecko
)
35 template
+= ' onblur="this.style.cssText = this.style.cssText;"';
38 ' onkeydown="return CKEDITOR.tools.callFunction({keydownFn},event,this);"' +
39 ' onfocus="return CKEDITOR.tools.callFunction({focusFn},event);" ' +
40 ( CKEDITOR
.env
.ie
? 'onclick="return false;" onmouseup' : 'onclick' ) + // http://dev.ckeditor.com/ticket/188
41 '="CKEDITOR.tools.callFunction({clickFn},this);return false;">' +
42 '<span id="{id}_text" class="cke_combo_text cke_combo_inlinelabel">{label}</span>' +
43 '<span class="cke_combo_open">' +
44 '<span class="cke_combo_arrow">' +
45 // BLACK DOWN-POINTING TRIANGLE
46 ( CKEDITOR
.env
.hc
? '▼' : CKEDITOR
.env
.air
? ' ' : '' ) +
52 var rcomboTpl
= CKEDITOR
.addTemplate( 'combo', template
);
58 * @property {String} [='richcombo']
61 CKEDITOR
.UI_RICHCOMBO
= 'richcombo';
67 CKEDITOR
.ui
.richCombo
= CKEDITOR
.tools
.createClass( {
68 $: function( definition
) {
69 // Copy all definition properties to this object.
70 CKEDITOR
.tools
.extend( this, definition
,
73 // The combo won't participate in toolbar grouping.
75 title: definition
.label
,
76 modes: { wysiwyg: 1 },
80 // We don't want the panel definition in this object.
81 var panelDefinition
= this.panel
|| {};
84 this.id
= CKEDITOR
.tools
.getNextNumber();
86 this.document
= ( panelDefinition
.parent
&& panelDefinition
.parent
.getDocument() ) || CKEDITOR
.document
;
88 panelDefinition
.className
= 'cke_combopanel';
89 panelDefinition
.block
= {
90 multiSelect: panelDefinition
.multiSelect
,
91 attributes: panelDefinition
.attributes
93 panelDefinition
.toolbarRelated
= true;
96 panelDefinition: panelDefinition
,
102 renderHtml: function( editor
) {
104 this.render( editor
, output
);
105 return output
.join( '' );
111 * @param {CKEDITOR.editor} editor The editor instance which this button is
113 * @param {Array} output The output array to which append the HTML relative
116 render: function( editor
, output
) {
117 var env
= CKEDITOR
.env
;
119 var id
= 'cke_' + this.id
;
120 var clickFn
= CKEDITOR
.tools
.addFunction( function( el
) {
121 // Restore locked selection in Opera.
123 editor
.unlockSelection( 1 );
126 instance
.execute( el
);
134 var element
= CKEDITOR
.document
.getById( id
).getChild( 1 );
137 execute: function( el
) {
140 if ( _
.state
== CKEDITOR
.TRISTATE_DISABLED
)
143 combo
.createPanel( editor
);
151 var value
= combo
.getValue();
153 _
.list
.mark( value
);
157 _
.panel
.showBlock( combo
.id
, new CKEDITOR
.dom
.element( el
), 4 );
162 function updateState() {
163 // Don't change state while richcombo is active (http://dev.ckeditor.com/ticket/11793).
164 if ( this.getState() == CKEDITOR
.TRISTATE_ON
)
167 var state
= this.modes
[ editor
.mode
] ? CKEDITOR
.TRISTATE_OFF : CKEDITOR
.TRISTATE_DISABLED
;
169 if ( editor
.readOnly
&& !this.readOnly
)
170 state
= CKEDITOR
.TRISTATE_DISABLED
;
172 this.setState( state
);
175 // Let plugin to disable button.
176 if ( state
!= CKEDITOR
.TRISTATE_DISABLED
&& this.refresh
)
180 // Update status when activeFilter, mode, selection or readOnly changes.
181 editor
.on( 'activeFilterChange', updateState
, this );
182 editor
.on( 'mode', updateState
, this );
183 editor
.on( 'selectionChange', updateState
, this );
184 // If this combo is sensitive to readOnly state, update it accordingly.
185 !this.readOnly
&& editor
.on( 'readOnly', updateState
, this );
187 var keyDownFn
= CKEDITOR
.tools
.addFunction( function( ev
, element
) {
188 ev
= new CKEDITOR
.dom
.event( ev
);
190 var keystroke
= ev
.getKeystroke();
192 switch ( keystroke
) {
195 case 40: // ARROW-DOWN
197 CKEDITOR
.tools
.callFunction( clickFn
, element
);
200 // Delegate the default behavior to toolbar button key handling.
201 instance
.onkey( instance
, keystroke
);
204 // Avoid subsequent focus grab on editor document.
208 var focusFn
= CKEDITOR
.tools
.addFunction( function() {
209 instance
.onfocus
&& instance
.onfocus();
215 instance
.keyDownFn
= keyDownFn
;
219 name: this.name
|| this.command
,
222 cls: this.className
|| '',
223 titleJs: env
.gecko
&& !env
.hc
? '' : ( this.title
|| '' ).replace( "'", '' ),
224 keydownFn: keyDownFn
,
229 rcomboTpl
.output( params
, output
);
237 createPanel: function( editor
) {
241 var panelDefinition
= this._
.panelDefinition
,
242 panelBlockDefinition
= this._
.panelDefinition
.block
,
243 panelParentElement
= panelDefinition
.parent
|| CKEDITOR
.document
.getBody(),
244 namedPanelCls
= 'cke_combopanel__' + this.name
,
245 panel
= new CKEDITOR
.ui
.floatPanel( editor
, panelParentElement
, panelDefinition
),
246 list
= panel
.addListBlock( this.id
, panelBlockDefinition
),
249 panel
.onShow = function() {
250 this.element
.addClass( namedPanelCls
);
252 me
.setState( CKEDITOR
.TRISTATE_ON
);
256 me
.editorFocus
&& !editor
.focusManager
.hasFocus
&& editor
.focus();
262 panel
.onHide = function( preventOnClose
) {
263 this.element
.removeClass( namedPanelCls
);
265 me
.setState( me
.modes
&& me
.modes
[ editor
.mode
] ? CKEDITOR
.TRISTATE_OFF : CKEDITOR
.TRISTATE_DISABLED
);
269 if ( !preventOnClose
&& me
.onClose
)
273 panel
.onEscape = function() {
274 // Hide drop-down with focus returned.
278 list
.onClick = function( value
, marked
) {
281 me
.onClick
.call( me
, value
, marked
);
286 this._
.panel
= panel
;
289 panel
.getBlock( this.id
).onHide = function() {
291 me
.setState( CKEDITOR
.TRISTATE_OFF
);
298 setValue: function( value
, text
) {
299 this._
.value
= value
;
301 var textElement
= this.document
.getById( 'cke_' + this.id
+ '_text' );
303 if ( !( value
|| text
) ) {
305 textElement
.addClass( 'cke_combo_inlinelabel' );
307 textElement
.removeClass( 'cke_combo_inlinelabel' );
310 textElement
.setText( typeof text
!= 'undefined' ? text : value
);
314 getValue: function() {
315 return this._
.value
|| '';
318 unmarkAll: function() {
319 this._
.list
.unmarkAll();
322 mark: function( value
) {
323 this._
.list
.mark( value
);
326 hideItem: function( value
) {
327 this._
.list
.hideItem( value
);
330 hideGroup: function( groupTitle
) {
331 this._
.list
.hideGroup( groupTitle
);
334 showAll: function() {
335 this._
.list
.showAll();
338 add: function( value
, html
, text
) {
339 this._
.items
[ value
] = text
|| value
;
340 this._
.list
.add( value
, html
, text
);
343 startGroup: function( title
) {
344 this._
.list
.startGroup( title
);
348 if ( !this._
.committed
) {
349 this._
.list
.commit();
350 this._
.committed
= 1;
351 CKEDITOR
.ui
.fire( 'ready', this );
353 this._
.committed
= 1;
356 setState: function( state
) {
357 if ( this._
.state
== state
)
360 var el
= this.document
.getById( 'cke_' + this.id
);
361 el
.setState( state
, 'cke_combo' );
363 state
== CKEDITOR
.TRISTATE_DISABLED
?
364 el
.setAttribute( 'aria-disabled', true ) :
365 el
.removeAttribute( 'aria-disabled' );
367 this._
.state
= state
;
370 getState: function() {
375 if ( this._
.state
== CKEDITOR
.TRISTATE_DISABLED
)
376 this.setState( this._
.lastState
);
379 disable: function() {
380 if ( this._
.state
!= CKEDITOR
.TRISTATE_DISABLED
) {
381 this._
.lastState
= this._
.state
;
382 this.setState( CKEDITOR
.TRISTATE_DISABLED
);
388 * Represents richCombo handler object.
390 * @class CKEDITOR.ui.richCombo.handler
392 * @extends CKEDITOR.ui.handlerDefinition
397 * Transforms a richCombo definition in a {@link CKEDITOR.ui.richCombo} instance.
399 * @param {Object} definition
400 * @returns {CKEDITOR.ui.richCombo}
402 create: function( definition
) {
403 return new CKEDITOR
.ui
.richCombo( definition
);
410 * @param {String} name
411 * @param {Object} definition
412 * @member CKEDITOR.ui
415 CKEDITOR
.ui
.prototype.addRichCombo = function( name
, definition
) {
416 this.add( name
, CKEDITOR
.UI_RICHCOMBO
, definition
);