Nation Notes module contributed by Z&H Healthcare.
[openemr.git] / library / custom_template / ckeditor / _source / plugins / richcombo / plugin.js
blob72509eea3fc0cdefd2d0f11e7be923ef60051d6e
1 /*
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
6 CKEDITOR.plugins.add( 'richcombo',
8         requires : [ 'floatpanel', 'listblock', 'button' ],
10         beforeInit : function( editor )
11         {
12                 editor.ui.addHandler( CKEDITOR.UI_RICHCOMBO, CKEDITOR.ui.richCombo.handler );
13         }
14 });
16 /**
17  * Button UI element.
18  * @constant
19  * @example
20  */
21 CKEDITOR.UI_RICHCOMBO = 3;
23 CKEDITOR.ui.richCombo = CKEDITOR.tools.createClass(
25         $ : function( definition )
26         {
27                 // Copy all definition properties to this object.
28                 CKEDITOR.tools.extend( this, definition,
29                         // Set defaults.
30                         {
31                                 title : definition.label,
32                                 modes : { wysiwyg : 1 }
33                         });
35                 // We don't want the panel definition in this object.
36                 var panelDefinition = this.panel || {};
37                 delete this.panel;
39                 this.id = CKEDITOR.tools.getNextNumber();
41                 this.document = ( panelDefinition
42                                                         && panelDefinition.parent
43                                                         && panelDefinition.parent.getDocument() )
44                                                 || CKEDITOR.document;
46                 panelDefinition.className = ( panelDefinition.className || '' ) + ' cke_rcombopanel';
47                 panelDefinition.block =
48                 {
49                         multiSelect : panelDefinition.multiSelect,
50                         attributes : panelDefinition.attributes
51                 };
53                 this._ =
54                 {
55                         panelDefinition : panelDefinition,
56                         items : {},
57                         state : CKEDITOR.TRISTATE_OFF
58                 };
59         },
61         statics :
62         {
63                 handler :
64                 {
65                         create : function( definition )
66                         {
67                                 return new CKEDITOR.ui.richCombo( definition );
68                         }
69                 }
70         },
72         proto :
73         {
74                 renderHtml : function( editor )
75                 {
76                         var output = [];
77                         this.render( editor, output );
78                         return output.join( '' );
79                 },
81                 /**
82                  * Renders the combo.
83                  * @param {CKEDITOR.editor} editor The editor instance which this button is
84                  *              to be used by.
85                  * @param {Array} output The output array to which append the HTML relative
86                  *              to this button.
87                  * @example
88                  */
89                 render : function( editor, output )
90                 {
91                         var env = CKEDITOR.env;
93                         var id = 'cke_' + this.id;
94                         var clickFn = CKEDITOR.tools.addFunction( function( $element )
95                                 {
96                                         var _ = this._;
98                                         if ( _.state == CKEDITOR.TRISTATE_DISABLED )
99                                                 return;
101                                         this.createPanel( editor );
103                                         if ( _.on )
104                                         {
105                                                 _.panel.hide();
106                                                 return;
107                                         }
109                                         this.commit();
110                                         var value = this.getValue();
111                                         if ( value )
112                                                 _.list.mark( value );
113                                         else
114                                                 _.list.unmarkAll();
116                                         _.panel.showBlock( this.id, new CKEDITOR.dom.element( $element ), 4 );
117                                 },
118                                 this );
120                         var instance = {
121                                 id : id,
122                                 combo : this,
123                                 focus : function()
124                                 {
125                                         var element = CKEDITOR.document.getById( id ).getChild( 1 );
126                                         element.focus();
127                                 },
128                                 clickFn : clickFn
129                         };
131                         editor.on( 'mode', function()
132                                 {
133                                         this.setState( this.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
134                                         this.setValue( '' );
135                                 },
136                                 this );
138                         var keyDownFn = CKEDITOR.tools.addFunction( function( ev, element )
139                                 {
140                                         ev = new CKEDITOR.dom.event( ev );
142                                         var keystroke = ev.getKeystroke();
143                                         switch ( keystroke )
144                                         {
145                                                 case 13 :       // ENTER
146                                                 case 32 :       // SPACE
147                                                 case 40 :       // ARROW-DOWN
148                                                         // Show panel
149                                                         CKEDITOR.tools.callFunction( clickFn, element );
150                                                         break;
151                                                 default :
152                                                         // Delegate the default behavior to toolbar button key handling.
153                                                         instance.onkey( instance,  keystroke );
154                                         }
156                                         // Avoid subsequent focus grab on editor document.
157                                         ev.preventDefault();
158                                 });
160                         // For clean up
161                         instance.keyDownFn = keyDownFn;
163                         output.push(
164                                 '<span class="cke_rcombo">',
165                                 '<span id=', id );
167                         if ( this.className )
168                                 output.push( ' class="', this.className, ' cke_off"');
170                         output.push(
171                                 '>',
172                                         '<span id="' + id+ '_label" class=cke_label>', this.label, '</span>',
173                                         '<a hidefocus=true title="', this.title, '" tabindex="-1"',
174                                                 env.gecko && env.version >= 10900 && !env.hc ? '' : ' href="javascript:void(\'' + this.label + '\')"',
175                                                 ' role="button" aria-labelledby="', id , '_label" aria-describedby="', id, '_text" aria-haspopup="true"' );
177                         // Some browsers don't cancel key events in the keydown but in the
178                         // keypress.
179                         // TODO: Check if really needed for Gecko+Mac.
180                         if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
181                         {
182                                 output.push(
183                                         ' onkeypress="return false;"' );
184                         }
186                         // With Firefox, we need to force it to redraw, otherwise it
187                         // will remain in the focus state.
188                         if ( CKEDITOR.env.gecko )
189                         {
190                                 output.push(
191                                         ' onblur="this.style.cssText = this.style.cssText;"' );
192                         }
194                         output.push(
195                                         ' onkeydown="CKEDITOR.tools.callFunction( ', keyDownFn, ', event, this );"' +
196                                         ' onclick="CKEDITOR.tools.callFunction(', clickFn, ', this); return false;">' +
197                                                 '<span>' +
198                                                         '<span id="' + id + '_text" class="cke_text cke_inline_label">' + this.label + '</span>' +
199                                                 '</span>' +
200                                                 '<span class=cke_openbutton>' + ( CKEDITOR.env.hc ? '<span>&#9660;</span>' : CKEDITOR.env.air ?  '&nbsp;' : '' ) + '</span>' +  // BLACK DOWN-POINTING TRIANGLE
201                                         '</a>' +
202                                 '</span>' +
203                                 '</span>' );
205                         if ( this.onRender )
206                                 this.onRender();
208                         return instance;
209                 },
211                 createPanel : function( editor )
212                 {
213                         if ( this._.panel )
214                                 return;
216                         var panelDefinition = this._.panelDefinition,
217                                 panelBlockDefinition = this._.panelDefinition.block,
218                                 panelParentElement = panelDefinition.parent || CKEDITOR.document.getBody(),
219                                 panel = new CKEDITOR.ui.floatPanel( editor, panelParentElement, panelDefinition ),
220                                 list = panel.addListBlock( this.id, panelBlockDefinition ),
221                                 me = this;
223                         panel.onShow = function()
224                                 {
225                                         if ( me.className )
226                                                 this.element.getFirst().addClass( me.className + '_panel' );
228                                         me.setState( CKEDITOR.TRISTATE_ON );
230                                         list.focus( !me.multiSelect && me.getValue() );
232                                         me._.on = 1;
234                                         if ( me.onOpen )
235                                                 me.onOpen();
236                                 };
238                         panel.onHide = function( preventOnClose )
239                                 {
240                                         if ( me.className )
241                                                 this.element.getFirst().removeClass( me.className + '_panel' );
243                                         me.setState( me.modes && me.modes[ editor.mode ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
245                                         me._.on = 0;
247                                         if ( !preventOnClose && me.onClose )
248                                                 me.onClose();
249                                 };
251                         panel.onEscape = function()
252                                 {
253                                         panel.hide();
254                                         me.document.getById( 'cke_' + me.id ).getFirst().getNext().focus();
255                                 };
257                         list.onClick = function( value, marked )
258                                 {
259                                         // Move the focus to the main windows, otherwise it will stay
260                                         // into the floating panel, even if invisible, and Safari and
261                                         // Opera will go a bit crazy.
262                                         me.document.getWindow().focus();
264                                         if ( me.onClick )
265                                                 me.onClick.call( me, value, marked );
267                                         if ( marked )
268                                                 me.setValue( value, me._.items[ value ] );
269                                         else
270                                                 me.setValue( '' );
272                                         panel.hide();
273                                 };
275                         this._.panel = panel;
276                         this._.list = list;
278                         panel.getBlock( this.id ).onHide = function()
279                                 {
280                                         me._.on = 0;
281                                         me.setState( CKEDITOR.TRISTATE_OFF );
282                                 };
284                         if ( this.init )
285                                 this.init();
286                 },
288                 setValue : function( value, text )
289                 {
290                         this._.value = value;
292                         var textElement = this.document.getById( 'cke_' + this.id + '_text' );
293                         if ( textElement )
294                         {
295                                 if ( !( value || text ) )
296                                 {
297                                         text = this.label;
298                                         textElement.addClass( 'cke_inline_label' );
299                                 }
300                                 else
301                                         textElement.removeClass( 'cke_inline_label' );
303                                 textElement.setHtml( typeof text != 'undefined' ? text : value );
304                         }
305                 },
307                 getValue : function()
308                 {
309                         return this._.value || '';
310                 },
312                 unmarkAll : function()
313                 {
314                         this._.list.unmarkAll();
315                 },
317                 mark : function( value )
318                 {
319                         this._.list.mark( value );
320                 },
322                 hideItem : function( value )
323                 {
324                         this._.list.hideItem( value );
325                 },
327                 hideGroup : function( groupTitle )
328                 {
329                         this._.list.hideGroup( groupTitle );
330                 },
332                 showAll : function()
333                 {
334                         this._.list.showAll();
335                 },
337                 add : function( value, html, text )
338                 {
339                         this._.items[ value ] = text || value;
340                         this._.list.add( value, html, text );
341                 },
343                 startGroup : function( title )
344                 {
345                         this._.list.startGroup( title );
346                 },
348                 commit : function()
349                 {
350                         if ( !this._.committed )
351                         {
352                                 this._.list.commit();
353                                 this._.committed = 1;
354                                 CKEDITOR.ui.fire( 'ready', this );
355                         }
356                         this._.committed = 1;
357                 },
359                 setState : function( state )
360                 {
361                         if ( this._.state == state )
362                                 return;
364                         this.document.getById( 'cke_' + this.id ).setState( state );
366                         this._.state = state;
367                 }
368         }
371 CKEDITOR.ui.prototype.addRichCombo = function( name, definition )
373         this.add( name, CKEDITOR.UI_RICHCOMBO, definition );