2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 /** @fileoverview The "dialogui" plugin. */
\r
8 CKEDITOR.plugins.add( 'dialogui' );
\r
12 var initPrivateObject = function( elementDefinition )
\r
14 this._ || ( this._ = {} );
\r
15 this._['default'] = this._.initValue = elementDefinition['default'] || '';
\r
16 var args = [ this._ ];
\r
17 for ( var i = 1 ; i < arguments.length ; i++ )
\r
18 args.push( arguments[i] );
\r
20 CKEDITOR.tools.extend.apply( CKEDITOR.tools, args );
\r
25 build : function( dialog, elementDefinition, output )
\r
27 return new CKEDITOR.ui.dialog.textInput( dialog, elementDefinition, output );
\r
32 build : function( dialog, elementDefinition, output )
\r
34 return new CKEDITOR.ui.dialog[elementDefinition.type]( dialog, elementDefinition, output );
\r
39 isChanged : function()
\r
41 return this.getValue() != this.getInitValue();
\r
46 this.setValue( this.getInitValue() );
\r
49 setInitValue : function()
\r
51 this._.initValue = this.getValue();
\r
54 resetInitValue : function()
\r
56 this._.initValue = this._['default'];
\r
59 getInitValue : function()
\r
61 return this._.initValue;
\r
64 commonEventProcessors = CKEDITOR.tools.extend( {}, CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
\r
66 onChange : function( dialog, func )
\r
68 if ( !this._.domOnChangeRegistered )
\r
70 dialog.on( 'load', function()
\r
72 this.getInputElement().on( 'change', function(){ this.fire( 'change', { value : this.getValue() } ); }, this );
\r
74 this._.domOnChangeRegistered = true;
\r
77 this.on( 'change', func );
\r
80 eventRegex = /^on([A-Z]\w+)/,
\r
81 cleanInnerDefinition = function( def )
\r
83 // An inner UI element should not have the parent's type, title or events.
\r
84 for ( var i in def )
\r
86 if ( eventRegex.test( i ) || i == 'title' || i == 'type' )
\r
92 CKEDITOR.tools.extend( CKEDITOR.ui.dialog,
\r
93 /** @lends CKEDITOR.ui.dialog */
\r
96 * Base class for all dialog elements with a textual label on the left.
\r
99 * @extends CKEDITOR.ui.dialog.uiElement
\r
100 * @param {CKEDITOR.dialog} dialog
\r
101 * Parent dialog object.
\r
102 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
103 * The element definition. Accepted fields:
\r
105 * <li><strong>label</strong> (Required) The label string.</li>
\r
106 * <li><strong>labelLayout</strong> (Optional) Put 'horizontal' here if the
\r
107 * label element is to be layed out horizontally. Otherwise a vertical
\r
108 * layout will be used.</li>
\r
109 * <li><strong>widths</strong> (Optional) This applies only for horizontal
\r
110 * layouts - an 2-element array of lengths to specify the widths of the
\r
111 * label and the content element.</li>
\r
113 * @param {Array} htmlList
\r
114 * List of HTML code to output to.
\r
115 * @param {Function} contentHtml
\r
116 * A function returning the HTML code string to be added inside the content
\r
119 labeledElement : function( dialog, elementDefinition, htmlList, contentHtml )
\r
121 if ( arguments.length < 4 )
\r
124 var _ = initPrivateObject.call( this, elementDefinition );
\r
125 _.labelId = CKEDITOR.tools.getNextNumber() + '_label';
\r
126 var children = this._.children = [];
\r
128 var innerHTML = function()
\r
131 if ( elementDefinition.labelLayout != 'horizontal' )
\r
132 html.push( '<div class="cke_dialog_ui_labeled_label" id="',
\r
135 elementDefinition.label,
\r
137 '<div class="cke_dialog_ui_labeled_content">',
\r
138 contentHtml( dialog, elementDefinition ),
\r
142 var hboxDefinition = {
\r
144 widths : elementDefinition.widths,
\r
150 html : '<span class="cke_dialog_ui_labeled_label" ' +
\r
151 'id="' + _.labelId + '">' + CKEDITOR.tools.htmlEncode( elementDefinition.label ) +
\r
156 html : '<span class="cke_dialog_ui_labeled_content">' +
\r
157 contentHtml( dialog, elementDefinition ) +
\r
162 CKEDITOR.dialog._.uiElementBuilders.hbox.build( dialog, hboxDefinition, html );
\r
164 return html.join( '' );
\r
166 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition, htmlList, 'div', null, null, innerHTML );
\r
170 * A text input with a label. This UI element class represents both the
\r
171 * single-line text inputs and password inputs in dialog boxes.
\r
174 * @extends CKEDITOR.ui.dialog.labeledElement
\r
175 * @param {CKEDITOR.dialog} dialog
\r
176 * Parent dialog object.
\r
177 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
178 * The element definition. Accepted fields:
\r
180 * <li><strong>default</strong> (Optional) The default value.</li>
\r
181 * <li><strong>validate</strong> (Optional) The validation function. </li>
\r
182 * <li><strong>maxLength</strong> (Optional) The maximum length of text box
\r
184 * <li><strong>size</strong> (Optional) The size of the text box. This is
\r
185 * usually overridden by the size defined by the skin, however.</li>
\r
187 * @param {Array} htmlList
\r
188 * List of HTML code to output to.
\r
190 textInput : function( dialog, elementDefinition, htmlList )
\r
192 if ( arguments.length < 3 )
\r
195 initPrivateObject.call( this, elementDefinition );
\r
196 var domId = this._.inputId = CKEDITOR.tools.getNextNumber() + '_textInput',
\r
197 attributes = { 'class' : 'cke_dialog_ui_input_' + elementDefinition.type, id : domId, type : 'text' },
\r
200 // Set the validator, if any.
\r
201 if ( elementDefinition.validate )
\r
202 this.validate = elementDefinition.validate;
\r
204 // Set the max length and size.
\r
205 if ( elementDefinition.maxLength )
\r
206 attributes.maxlength = elementDefinition.maxLength;
\r
207 if ( elementDefinition.size )
\r
208 attributes.size = elementDefinition.size;
\r
210 // If user presses Enter in a text box, it implies clicking OK for the dialog.
\r
211 var me = this, keyPressedOnMe = false;
\r
212 dialog.on( 'load', function()
\r
214 me.getInputElement().on( 'keydown', function( evt )
\r
216 if ( evt.data.getKeystroke() == 13 )
\r
217 keyPressedOnMe = true;
\r
220 // Lower the priority this 'keyup' since 'ok' will close the dialog.(#3749)
\r
221 me.getInputElement().on( 'keyup', function( evt )
\r
223 if ( evt.data.getKeystroke() == 13 && keyPressedOnMe )
\r
225 dialog.getButton( 'ok' ) && dialog.getButton( 'ok' ).click();
\r
226 keyPressedOnMe = false;
\r
228 }, null, null, 1000 );
\r
232 var innerHTML = function()
\r
234 // IE BUG: Text input fields in IE at 100% would exceed a <td> or inline
\r
235 // container's width, so need to wrap it inside a <div>.
\r
236 var html = [ '<div class="cke_dialog_ui_input_', elementDefinition.type, '"' ];
\r
238 if ( elementDefinition.width )
\r
239 html.push( 'style="width:'+ elementDefinition.width +'" ' );
\r
241 html.push( '><input ' );
\r
242 for ( var i in attributes )
\r
243 html.push( i + '="' + attributes[i] + '" ' );
\r
244 html.push( ' /></div>' );
\r
245 return html.join( '' );
\r
247 CKEDITOR.ui.dialog.labeledElement.call( this, dialog, elementDefinition, htmlList, innerHTML );
\r
251 * A text area with a label on the top or left.
\r
253 * @extends CKEDITOR.ui.dialog.labeledElement
\r
255 * @param {CKEDITOR.dialog} dialog
\r
256 * Parent dialog object.
\r
257 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
258 * The element definition. Accepted fields:
\r
260 * <li><strong>rows</strong> (Optional) The number of rows displayed.
\r
261 * Defaults to 5 if not defined.</li>
\r
262 * <li><strong>cols</strong> (Optional) The number of cols displayed.
\r
263 * Defaults to 20 if not defined. Usually overridden by skins.</li>
\r
264 * <li><strong>default</strong> (Optional) The default value.</li>
\r
265 * <li><strong>validate</strong> (Optional) The validation function. </li>
\r
267 * @param {Array} htmlList
\r
268 * List of HTML code to output to.
\r
270 textarea : function( dialog, elementDefinition, htmlList )
\r
272 if ( arguments.length < 3 )
\r
275 initPrivateObject.call( this, elementDefinition );
\r
277 domId = this._.inputId = CKEDITOR.tools.getNextNumber() + '_textarea',
\r
280 if ( elementDefinition.validate )
\r
281 this.validate = elementDefinition.validate;
\r
283 // Generates the essential attributes for the textarea tag.
\r
284 attributes.rows = elementDefinition.rows || 5;
\r
285 attributes.cols = elementDefinition.cols || 20;
\r
288 var innerHTML = function()
\r
290 var html = [ '<div class="cke_dialog_ui_input_textarea"><textarea class="cke_dialog_ui_input_textarea" id="', domId, '" ' ];
\r
291 for ( var i in attributes )
\r
292 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '" ' );
\r
293 html.push( '>', CKEDITOR.tools.htmlEncode( me._['default'] ), '</textarea></div>' );
\r
294 return html.join( '' );
\r
296 CKEDITOR.ui.dialog.labeledElement.call( this, dialog, elementDefinition, htmlList, innerHTML );
\r
300 * A single checkbox with a label on the right.
\r
302 * @extends CKEDITOR.ui.dialog.uiElement
\r
304 * @param {CKEDITOR.dialog} dialog
\r
305 * Parent dialog object.
\r
306 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
307 * The element definition. Accepted fields:
\r
309 * <li><strong>checked</strong> (Optional) Whether the checkbox is checked
\r
310 * on instantiation. Defaults to false.</li>
\r
311 * <li><strong>validate</strong> (Optional) The validation function.</li>
\r
312 * <li><strong>label</strong> (Optional) The checkbox label.</li>
\r
314 * @param {Array} htmlList
\r
315 * List of HTML code to output to.
\r
317 checkbox : function( dialog, elementDefinition, htmlList )
\r
319 if ( arguments.length < 3 )
\r
322 var _ = initPrivateObject.call( this, elementDefinition, { 'default' : !!elementDefinition[ 'default' ] } );
\r
324 if ( elementDefinition.validate )
\r
325 this.validate = elementDefinition.validate;
\r
328 var innerHTML = function()
\r
330 var myDefinition = CKEDITOR.tools.extend( {}, elementDefinition,
\r
332 id : elementDefinition.id ? elementDefinition.id + '_checkbox' : CKEDITOR.tools.getNextNumber() + '_checkbox'
\r
335 attributes = { 'class' : 'cke_dialog_ui_checkbox_input', type : 'checkbox' };
\r
336 cleanInnerDefinition( myDefinition );
\r
337 if ( elementDefinition[ 'default' ] )
\r
338 attributes.checked = 'checked';
\r
339 _.checkbox = new CKEDITOR.ui.dialog.uiElement( dialog, myDefinition, html, 'input', null, attributes );
\r
340 html.push( ' <label for="', attributes.id, '">',
\r
341 CKEDITOR.tools.htmlEncode( elementDefinition.label ),
\r
343 return html.join( '' );
\r
346 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition, htmlList, 'span', null, null, innerHTML );
\r
350 * A group of radio buttons.
\r
353 * @extends CKEDITOR.ui.dialog.labeledElement
\r
354 * @param {CKEDITOR.dialog} dialog
\r
355 * Parent dialog object.
\r
356 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
357 * The element definition. Accepted fields:
\r
359 * <li><strong>default</strong> (Required) The default value.</li>
\r
360 * <li><strong>validate</strong> (Optional) The validation function.</li>
\r
361 * <li><strong>items</strong> (Required) An array of options. Each option
\r
362 * is a 1- or 2-item array of format [ 'Description', 'Value' ]. If 'Value'
\r
363 * is missing, then the value would be assumed to be the same as the
\r
364 * description.</li>
\r
366 * @param {Array} htmlList
\r
367 * List of HTML code to output to.
\r
369 radio : function( dialog, elementDefinition, htmlList )
\r
371 if ( arguments.length < 3)
\r
374 initPrivateObject.call( this, elementDefinition );
\r
375 if ( !this._['default'] )
\r
376 this._['default'] = this._.initValue = elementDefinition.items[0][1];
\r
377 if ( elementDefinition.validate )
\r
378 this.validate = elementDefinition.valdiate;
\r
379 var children = [], me = this;
\r
382 var innerHTML = function()
\r
384 var inputHtmlList = [], html = [],
\r
385 commonAttributes = { 'class' : 'cke_dialog_ui_radio_item' },
\r
386 commonName = elementDefinition.id ? elementDefinition.id + '_radio' : CKEDITOR.tools.getNextNumber() + '_radio';
\r
387 for ( var i = 0 ; i < elementDefinition.items.length ; i++ )
\r
389 var item = elementDefinition.items[i],
\r
390 title = item[2] !== undefined ? item[2] : item[0],
\r
391 value = item[1] !== undefined ? item[1] : item[0],
\r
392 inputDefinition = CKEDITOR.tools.extend( {}, elementDefinition,
\r
394 id : CKEDITOR.tools.getNextNumber() + '_radio_input',
\r
398 labelDefinition = CKEDITOR.tools.extend( {}, inputDefinition,
\r
406 'class' : 'cke_dialog_ui_radio_input',
\r
411 if ( me._['default'] == value )
\r
412 inputAttributes.checked = 'checked';
\r
413 cleanInnerDefinition( inputDefinition );
\r
414 cleanInnerDefinition( labelDefinition );
\r
415 children.push( new CKEDITOR.ui.dialog.uiElement( dialog, inputDefinition, inputHtml, 'input', null, inputAttributes ) );
\r
416 inputHtml.push( ' ' );
\r
417 new CKEDITOR.ui.dialog.uiElement( dialog, labelDefinition, inputHtml, 'label', null, { 'for' : inputAttributes.id },
\r
419 inputHtmlList.push( inputHtml.join( '' ) );
\r
421 new CKEDITOR.ui.dialog.hbox( dialog, [], inputHtmlList, html );
\r
422 return html.join( '' );
\r
425 CKEDITOR.ui.dialog.labeledElement.call( this, dialog, elementDefinition, htmlList, innerHTML );
\r
426 this._.children = children;
\r
430 * A button with a label inside.
\r
433 * @extends CKEDITOR.ui.dialog.uiElement
\r
434 * @param {CKEDITOR.dialog} dialog
\r
435 * Parent dialog object.
\r
436 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
437 * The element definition. Accepted fields:
\r
439 * <li><strong>label</strong> (Required) The button label.</li>
\r
440 * <li><strong>disabled</strong> (Optional) Set to true if you want the
\r
441 * button to appear in disabled state.</li>
\r
443 * @param {Array} htmlList
\r
444 * List of HTML code to output to.
\r
446 button : function( dialog, elementDefinition, htmlList )
\r
448 if ( !arguments.length )
\r
451 if ( typeof elementDefinition == 'function' )
\r
452 elementDefinition = elementDefinition( dialog.getParentEditor() );
\r
454 initPrivateObject.call( this, elementDefinition, { disabled : elementDefinition.disabled || false } );
\r
456 // Add OnClick event to this input.
\r
457 CKEDITOR.event.implementOn( this );
\r
461 // Register an event handler for processing button clicks.
\r
462 dialog.on( 'load', function( eventInfo )
\r
464 var element = this.getElement();
\r
468 element.on( 'click', function( evt )
\r
470 me.fire( 'click', { dialog : me.getDialog() } );
\r
471 evt.data.preventDefault();
\r
475 element.unselectable();
\r
478 var outerDefinition = CKEDITOR.tools.extend( {}, elementDefinition );
\r
479 delete outerDefinition.style;
\r
481 CKEDITOR.ui.dialog.uiElement.call(
\r
489 style : elementDefinition.style,
\r
490 href : 'javascript:void(0)',
\r
491 title : elementDefinition.label,
\r
492 hidefocus : 'true',
\r
493 'class' : elementDefinition['class']
\r
495 '<span class="cke_dialog_ui_button">' +
\r
496 CKEDITOR.tools.htmlEncode( elementDefinition.label ) +
\r
502 * @extends CKEDITOR.ui.dialog.uiElement
\r
505 * @param {CKEDITOR.dialog} dialog
\r
506 * Parent dialog object.
\r
507 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
508 * The element definition. Accepted fields:
\r
510 * <li><strong>default</strong> (Required) The default value.</li>
\r
511 * <li><strong>validate</strong> (Optional) The validation function.</li>
\r
512 * <li><strong>items</strong> (Required) An array of options. Each option
\r
513 * is a 1- or 2-item array of format [ 'Description', 'Value' ]. If 'Value'
\r
514 * is missing, then the value would be assumed to be the same as the
\r
515 * description.</li>
\r
516 * <li><strong>multiple</strong> (Optional) Set this to true if you'd like
\r
517 * to have a multiple-choice select box.</li>
\r
518 * <li><strong>size</strong> (Optional) The number of items to display in
\r
519 * the select box.</li>
\r
521 * @param {Array} htmlList
\r
522 * List of HTML code to output to.
\r
524 select : function( dialog, elementDefinition, htmlList )
\r
526 if ( arguments.length < 3 )
\r
529 var _ = initPrivateObject.call( this, elementDefinition );
\r
531 if ( elementDefinition.validate )
\r
532 this.validate = elementDefinition.validate;
\r
535 var innerHTML = function()
\r
537 var myDefinition = CKEDITOR.tools.extend( {}, elementDefinition,
\r
539 id : elementDefinition.id ? elementDefinition.id + '_select' : CKEDITOR.tools.getNextNumber() + '_select'
\r
543 attributes = { 'class' : 'cke_dialog_ui_input_select' };
\r
545 // Add multiple and size attributes from element definition.
\r
546 if ( elementDefinition.size != undefined )
\r
547 attributes.size = elementDefinition.size;
\r
548 if ( elementDefinition.multiple != undefined )
\r
549 attributes.multiple = elementDefinition.multiple;
\r
551 cleanInnerDefinition( myDefinition );
\r
552 for ( var i = 0, item ; i < elementDefinition.items.length && ( item = elementDefinition.items[i] ) ; i++ )
\r
554 innerHTML.push( '<option value="',
\r
555 CKEDITOR.tools.htmlEncode( item[1] !== undefined ? item[1] : item[0] ), '" /> ',
\r
556 CKEDITOR.tools.htmlEncode( item[0] ) );
\r
559 _.select = new CKEDITOR.ui.dialog.uiElement( dialog, myDefinition, html, 'select', null, attributes, innerHTML.join( '' ) );
\r
560 return html.join( '' );
\r
563 CKEDITOR.ui.dialog.labeledElement.call( this, dialog, elementDefinition, htmlList, innerHTML );
\r
567 * A file upload input.
\r
568 * @extends CKEDITOR.ui.dialog.labeledElement
\r
571 * @param {CKEDITOR.dialog} dialog
\r
572 * Parent dialog object.
\r
573 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
574 * The element definition. Accepted fields:
\r
576 * <li><strong>validate</strong> (Optional) The validation function.</li>
\r
578 * @param {Array} htmlList
\r
579 * List of HTML code to output to.
\r
581 file : function( dialog, elementDefinition, htmlList )
\r
583 if ( arguments.length < 3 )
\r
586 if ( elementDefinition['default'] === undefined )
\r
587 elementDefinition['default'] = '';
\r
589 var _ = CKEDITOR.tools.extend( initPrivateObject.call( this, elementDefinition ), { definition : elementDefinition, buttons : [] } );
\r
591 if ( elementDefinition.validate )
\r
592 this.validate = elementDefinition.validate;
\r
595 var innerHTML = function()
\r
597 _.frameId = CKEDITOR.tools.getNextNumber() + '_fileInput';
\r
599 // Support for custom document.domain in IE.
\r
600 var isCustomDomain = CKEDITOR.env.isCustomDomain();
\r
604 ' frameborder="0"' +
\r
605 ' allowtransparency="0"' +
\r
606 ' class="cke_dialog_ui_input_file"' +
\r
607 ' id="', _.frameId, '"' +
\r
608 ' title="', elementDefinition.label, '"' +
\r
609 ' src="javascript:void(' ];
\r
614 'document.open();' +
\r
615 'document.domain=\'' + document.domain + '\';' +
\r
616 'document.close();' +
\r
625 return html.join( '' );
\r
628 // IE BUG: Parent container does not resize to contain the iframe automatically.
\r
629 dialog.on( 'load', function()
\r
631 var iframe = CKEDITOR.document.getById( _.frameId ),
\r
632 contentDiv = iframe.getParent();
\r
633 contentDiv.addClass( 'cke_dialog_ui_input_file' );
\r
636 CKEDITOR.ui.dialog.labeledElement.call( this, dialog, elementDefinition, htmlList, innerHTML );
\r
640 * A button for submitting the file in a file upload input.
\r
641 * @extends CKEDITOR.ui.dialog.button
\r
644 * @param {CKEDITOR.dialog} dialog
\r
645 * Parent dialog object.
\r
646 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
647 * The element definition. Accepted fields:
\r
649 * <li><strong>for</strong> (Required) The file input's page and element Id
\r
650 * to associate to, in a 2-item array format: [ 'page_id', 'element_id' ].
\r
652 * <li><strong>validate</strong> (Optional) The validation function.</li>
\r
654 * @param {Array} htmlList
\r
655 * List of HTML code to output to.
\r
657 fileButton : function( dialog, elementDefinition, htmlList )
\r
659 if ( arguments.length < 3 )
\r
662 var _ = initPrivateObject.call( this, elementDefinition ),
\r
665 if ( elementDefinition.validate )
\r
666 this.validate = elementDefinition.validate;
\r
668 var myDefinition = CKEDITOR.tools.extend( {}, elementDefinition );
\r
669 var onClick = myDefinition.onClick;
\r
670 myDefinition.className = ( myDefinition.className ? myDefinition.className + ' ' : '' ) + 'cke_dialog_ui_button';
\r
671 myDefinition.onClick = function( evt )
\r
673 var target = elementDefinition[ 'for' ]; // [ pageId, elementId ]
\r
674 if ( !onClick || onClick.call( this, evt ) !== false )
\r
676 dialog.getContentElement( target[0], target[1] ).submit();
\r
681 dialog.on( 'load', function()
\r
683 dialog.getContentElement( elementDefinition[ 'for' ][0], elementDefinition[ 'for' ][1] )._.buttons.push( me );
\r
686 CKEDITOR.ui.dialog.button.call( this, dialog, myDefinition, htmlList );
\r
691 var myHtmlRe = /^\s*<[\w:]+\s+([^>]*)?>/,
\r
692 theirHtmlRe = /^(\s*<[\w:]+(?:\s+[^>]*)?)((?:.|\r|\n)+)$/,
\r
693 emptyTagRe = /\/$/;
\r
695 * A dialog element made from raw HTML code.
\r
696 * @extends CKEDITOR.ui.dialog.uiElement
\r
697 * @name CKEDITOR.ui.dialog.html
\r
698 * @param {CKEDITOR.dialog} dialog Parent dialog object.
\r
699 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition Element definition.
\r
702 * <li><strong>html</strong> (Required) HTML code of this element.</li>
\r
704 * @param {Array} htmlList List of HTML code to be added to the dialog's content area.
\r
708 return function( dialog, elementDefinition, htmlList )
\r
710 if ( arguments.length < 3 )
\r
713 var myHtmlList = [],
\r
715 theirHtml = elementDefinition.html,
\r
716 myMatch, theirMatch;
\r
718 // If the HTML input doesn't contain any tags at the beginning, add a <span> tag around it.
\r
719 if ( theirHtml.charAt( 0 ) != '<' )
\r
720 theirHtml = '<span>' + theirHtml + '</span>';
\r
722 // Look for focus function in definition.
\r
723 if ( elementDefinition.focus )
\r
725 var oldFocus = this.focus;
\r
726 this.focus = function()
\r
728 oldFocus.call( this );
\r
729 elementDefinition.focus.call( this );
\r
730 this.fire( 'focus' );
\r
732 if ( elementDefinition.isFocusable )
\r
734 var oldIsFocusable = this.isFocusable;
\r
735 this.isFocusable = oldIsFocusable;
\r
737 this.keyboardFocusable = true;
\r
740 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition, myHtmlList, 'span', null, null, '' );
\r
742 // Append the attributes created by the uiElement call to the real HTML.
\r
743 myHtml = myHtmlList.join( '' );
\r
744 myMatch = myHtml.match( myHtmlRe );
\r
745 theirMatch = theirHtml.match( theirHtmlRe ) || [ '', '', '' ];
\r
747 if ( emptyTagRe.test( theirMatch[1] ) )
\r
749 theirMatch[1] = theirMatch[1].slice( 0, -1 );
\r
750 theirMatch[2] = '/' + theirMatch[2];
\r
753 htmlList.push( [ theirMatch[1], ' ', myMatch[1] || '', theirMatch[2] ].join( '' ) );
\r
758 CKEDITOR.ui.dialog.html.prototype = new CKEDITOR.ui.dialog.uiElement;
\r
760 CKEDITOR.ui.dialog.labeledElement.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
\r
761 /** @lends CKEDITOR.ui.dialog.labeledElement.prototype */
\r
764 * Sets the label text of the element.
\r
765 * @param {String} label The new label text.
\r
766 * @returns {CKEDITOR.ui.dialog.labeledElement} The current labeled element.
\r
769 setLabel : function( label )
\r
771 var node = CKEDITOR.document.getById( this._.labelId );
\r
772 if ( node.getChildCount() < 1 )
\r
773 ( new CKEDITOR.dom.text( label, CKEDITOR.document ) ).appendTo( node );
\r
775 node.getChild( 0 ).$.nodeValue = label;
\r
780 * Retrieves the current label text of the elment.
\r
781 * @returns {String} The current label text.
\r
784 getLabel : function()
\r
786 var node = CKEDITOR.document.getById( this._.labelId );
\r
787 if ( !node || node.getChildCount() < 1 )
\r
790 return node.getChild( 0 ).getText();
\r
794 * Defines the onChange event for UI element definitions.
\r
799 eventProcessors : commonEventProcessors
\r
802 CKEDITOR.ui.dialog.button.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
\r
803 /** @lends CKEDITOR.ui.dialog.button.prototype */
\r
806 * Simulates a click to the button.
\r
808 * @returns {Object} Return value of the 'click' event.
\r
812 if ( !this._.disabled )
\r
813 return this.fire( 'click', { dialog : this._.dialog } );
\r
814 this.getElement().$.blur();
\r
819 * Enables the button.
\r
822 enable : function()
\r
824 this._.disabled = false;
\r
825 var element = this.getElement();
\r
826 element && element.removeClass( 'disabled' );
\r
830 * Disables the button.
\r
833 disable : function()
\r
835 this._.disabled = true;
\r
836 this.getElement().addClass( 'disabled' );
\r
839 isVisible : function()
\r
841 return !!this.getElement().$.firstChild.offsetHeight;
\r
844 isEnabled : function()
\r
846 return !this._.disabled;
\r
850 * Defines the onChange event and onClick for button element definitions.
\r
855 eventProcessors : CKEDITOR.tools.extend( {}, CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
\r
858 onClick : function( dialog, func )
\r
860 this.on( 'click', func );
\r
865 * Handler for the element's access key up event. Simulates a click to
\r
869 accessKeyUp : function()
\r
875 * Handler for the element's access key down event. Simulates a mouse
\r
876 * down to the button.
\r
879 accessKeyDown : function()
\r
884 keyboardFocusable : true
\r
887 CKEDITOR.ui.dialog.textInput.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.labeledElement,
\r
888 /** @lends CKEDITOR.ui.dialog.textInput.prototype */
\r
891 * Gets the text input DOM element under this UI object.
\r
893 * @returns {CKEDITOR.dom.element} The DOM element of the text input.
\r
895 getInputElement : function()
\r
897 return CKEDITOR.document.getById( this._.inputId );
\r
901 * Puts focus into the text input.
\r
906 var me = this.selectParentTab();
\r
908 // GECKO BUG: setTimeout() is needed to workaround invisible selections.
\r
909 setTimeout( function()
\r
911 var element = me.getInputElement();
\r
912 element && element.$.focus();
\r
917 * Selects all the text in the text input.
\r
920 select : function()
\r
922 var me = this.selectParentTab();
\r
924 // GECKO BUG: setTimeout() is needed to workaround invisible selections.
\r
925 setTimeout( function()
\r
927 var e = me.getInputElement();
\r
937 * Handler for the text input's access key up event. Makes a select()
\r
938 * call to the text input.
\r
941 accessKeyUp : function()
\r
947 * Sets the value of this text input object.
\r
948 * @param {Object} value The new value.
\r
949 * @returns {CKEDITOR.ui.dialog.textInput} The current UI element.
\r
951 * uiElement.setValue( 'Blamo' );
\r
953 setValue : function( value )
\r
955 value = value || '';
\r
956 return CKEDITOR.ui.dialog.uiElement.prototype.setValue.call( this, value );
\r
959 keyboardFocusable : true
\r
960 }, commonPrototype, true );
\r
962 CKEDITOR.ui.dialog.textarea.prototype = new CKEDITOR.ui.dialog.textInput();
\r
964 CKEDITOR.ui.dialog.select.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.labeledElement,
\r
965 /** @lends CKEDITOR.ui.dialog.select.prototype */
\r
968 * Gets the DOM element of the select box.
\r
969 * @returns {CKEDITOR.dom.element} The <select> element of this UI
\r
973 getInputElement : function()
\r
975 return this._.select.getElement();
\r
979 * Adds an option to the select box.
\r
980 * @param {String} label Option label.
\r
981 * @param {String} value (Optional) Option value, if not defined it'll be
\r
982 * assumed to be the same as the label.
\r
983 * @param {Number} index (Optional) Position of the option to be inserted
\r
984 * to. If not defined the new option will be inserted to the end of list.
\r
986 * @returns {CKEDITOR.ui.dialog.select} The current select UI element.
\r
988 add : function( label, value, index )
\r
990 var option = new CKEDITOR.dom.element( 'option', this.getDialog().getParentEditor().document ),
\r
991 selectElement = this.getInputElement().$;
\r
992 option.$.text = label;
\r
993 option.$.value = ( value === undefined || value === null ) ? label : value;
\r
994 if ( index === undefined || index === null )
\r
996 if ( CKEDITOR.env.ie )
\r
997 selectElement.add( option.$ );
\r
999 selectElement.add( option.$, null );
\r
1002 selectElement.add( option.$, index );
\r
1007 * Removes an option from the selection list.
\r
1008 * @param {Number} index Index of the option to be removed.
\r
1010 * @returns {CKEDITOR.ui.dialog.select} The current select UI element.
\r
1012 remove : function( index )
\r
1014 var selectElement = this.getInputElement().$;
\r
1015 selectElement.remove( index );
\r
1020 * Clears all options out of the selection list.
\r
1021 * @returns {CKEDITOR.ui.dialog.select} The current select UI element.
\r
1023 clear : function()
\r
1025 var selectElement = this.getInputElement().$;
\r
1026 while ( selectElement.length > 0 )
\r
1027 selectElement.remove( 0 );
\r
1031 keyboardFocusable : true
\r
1032 }, commonPrototype, true );
\r
1034 CKEDITOR.ui.dialog.checkbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
\r
1035 /** @lends CKEDITOR.ui.dialog.checkbox.prototype */
\r
1038 * Gets the checkbox DOM element.
\r
1040 * @returns {CKEDITOR.dom.element} The DOM element of the checkbox.
\r
1042 getInputElement : function()
\r
1044 return this._.checkbox.getElement();
\r
1048 * Sets the state of the checkbox.
\r
1050 * @param {Boolean} true to tick the checkbox, false to untick it.
\r
1052 setValue : function( checked )
\r
1054 this.getInputElement().$.checked = checked;
\r
1055 this.fire( 'change', { value : checked } );
\r
1059 * Gets the state of the checkbox.
\r
1061 * @returns {Boolean} true means the checkbox is ticked, false means it's not ticked.
\r
1063 getValue : function()
\r
1065 return this.getInputElement().$.checked;
\r
1069 * Handler for the access key up event. Toggles the checkbox.
\r
1072 accessKeyUp : function()
\r
1074 this.setValue( !this.getValue() );
\r
1078 * Defines the onChange event for UI element definitions.
\r
1085 onChange : function( dialog, func )
\r
1087 if ( !CKEDITOR.env.ie )
\r
1088 return commonEventProcessors.onChange.apply( this, arguments );
\r
1091 dialog.on( 'load', function()
\r
1093 var element = this._.checkbox.getElement();
\r
1094 element.on( 'propertychange', function( evt )
\r
1097 if ( evt.propertyName == 'checked' )
\r
1098 this.fire( 'change', { value : element.$.checked } );
\r
1101 this.on( 'change', func );
\r
1107 keyboardFocusable : true
\r
1108 }, commonPrototype, true );
\r
1110 CKEDITOR.ui.dialog.radio.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
\r
1111 /** @lends CKEDITOR.ui.dialog.radio.prototype */
\r
1114 * Checks one of the radio buttons in this button group.
\r
1116 * @param {String} value The value of the button to be chcked.
\r
1118 setValue : function( value )
\r
1120 var children = this._.children,
\r
1122 for ( var i = 0 ; ( i < children.length ) && ( item = children[i] ) ; i++ )
\r
1123 item.getElement().$.checked = ( item.getValue() == value );
\r
1124 this.fire( 'change', { value : value } );
\r
1128 * Gets the value of the currently checked radio button.
\r
1130 * @returns {String} The currently checked button's value.
\r
1132 getValue : function()
\r
1134 var children = this._.children;
\r
1135 for ( var i = 0 ; i < children.length ; i++ )
\r
1137 if ( children[i].getElement().$.checked )
\r
1138 return children[i].getValue();
\r
1144 * Handler for the access key up event. Focuses the currently
\r
1145 * selected radio button, or the first radio button if none is
\r
1149 accessKeyUp : function()
\r
1151 var children = this._.children, i;
\r
1152 for ( i = 0 ; i < children.length ; i++ )
\r
1154 if ( children[i].getElement().$.checked )
\r
1156 children[i].getElement().focus();
\r
1160 children[0].getElement().focus();
\r
1164 * Defines the onChange event for UI element definitions.
\r
1171 onChange : function( dialog, func )
\r
1173 if ( !CKEDITOR.env.ie )
\r
1174 return commonEventProcessors.onChange.apply( this, arguments );
\r
1177 dialog.on( 'load', function()
\r
1179 var children = this._.children, me = this;
\r
1180 for ( var i = 0 ; i < children.length ; i++ )
\r
1182 var element = children[i].getElement();
\r
1183 element.on( 'propertychange', function( evt )
\r
1186 if ( evt.propertyName == 'checked' && this.$.checked )
\r
1187 me.fire( 'change', { value : this.getAttribute( 'value' ) } );
\r
1191 this.on( 'change', func );
\r
1197 keyboardFocusable : true
\r
1198 }, commonPrototype, true );
\r
1200 CKEDITOR.ui.dialog.file.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.labeledElement,
\r
1202 /** @lends CKEDITOR.ui.dialog.file.prototype */
\r
1205 * Gets the <input> element of this file input.
\r
1206 * @returns {CKEDITOR.dom.element} The file input element.
\r
1209 getInputElement : function()
\r
1211 var frameDocument = CKEDITOR.document.getById( this._.frameId ).getFrameDocument();
\r
1212 return frameDocument.$.forms.length > 0 ?
\r
1213 new CKEDITOR.dom.element( frameDocument.$.forms[0].elements[0] ) :
\r
1214 this.getElement();
\r
1218 * Uploads the file in the file input.
\r
1219 * @returns {CKEDITOR.ui.dialog.file} This object.
\r
1222 submit : function()
\r
1224 this.getInputElement().getParent().$.submit();
\r
1229 * Get the action assigned to the form.
\r
1230 * @returns {String} The value of the action.
\r
1233 getAction : function( action )
\r
1235 return this.getInputElement().getParent().$.action;
\r
1239 * Redraws the file input and resets the file path in the file input.
\r
1240 * The redraw logic is necessary because non-IE browsers tend to clear
\r
1241 * the <iframe> containing the file input after closing the dialog.
\r
1244 reset : function()
\r
1246 var frameElement = CKEDITOR.document.getById( this._.frameId ),
\r
1247 frameDocument = frameElement.getFrameDocument(),
\r
1248 elementDefinition = this._.definition,
\r
1249 buttons = this._.buttons;
\r
1251 function generateFormField()
\r
1253 frameDocument.$.open();
\r
1255 // Support for custom document.domain in IE.
\r
1256 if ( CKEDITOR.env.isCustomDomain() )
\r
1257 frameDocument.$.domain = document.domain;
\r
1260 if ( elementDefinition.size )
\r
1261 size = elementDefinition.size - ( CKEDITOR.env.ie ? 7 : 0 ); // "Browse" button is bigger in IE.
\r
1263 frameDocument.$.write( [ '<html><head><title></title></head><body style="margin: 0; overflow: hidden; background: transparent;">',
\r
1264 '<form enctype="multipart/form-data" method="POST" action="',
\r
1265 CKEDITOR.tools.htmlEncode( elementDefinition.action ),
\r
1267 '<input type="file" name="',
\r
1268 CKEDITOR.tools.htmlEncode( elementDefinition.id || 'cke_upload' ),
\r
1270 CKEDITOR.tools.htmlEncode( size > 0 ? size : "" ),
\r
1273 '</body></html>' ].join( '' ) );
\r
1275 frameDocument.$.close();
\r
1277 for ( var i = 0 ; i < buttons.length ; i++ )
\r
1278 buttons[i].enable();
\r
1281 // #3465: Wait for the browser to finish rendering the dialog first.
\r
1282 if ( CKEDITOR.env.gecko )
\r
1283 setTimeout( generateFormField, 500 );
\r
1285 generateFormField();
\r
1288 getValue : function()
\r
1290 // The file path returned from the input tag is incomplete anyway, so it's
\r
1291 // safe to ignore it and prevent the confirmation dialog from appearing.
\r
1292 // (Part of #3465)
\r
1297 * Defines the onChange event for UI element definitions.
\r
1302 eventProcessors : commonEventProcessors,
\r
1304 keyboardFocusable : true
\r
1307 CKEDITOR.ui.dialog.fileButton.prototype = new CKEDITOR.ui.dialog.button;
\r
1309 CKEDITOR.dialog.addUIElement( 'text', textBuilder );
\r
1310 CKEDITOR.dialog.addUIElement( 'password', textBuilder );
\r
1311 CKEDITOR.dialog.addUIElement( 'textarea', commonBuilder );
\r
1312 CKEDITOR.dialog.addUIElement( 'checkbox', commonBuilder );
\r
1313 CKEDITOR.dialog.addUIElement( 'radio', commonBuilder );
\r
1314 CKEDITOR.dialog.addUIElement( 'button', commonBuilder );
\r
1315 CKEDITOR.dialog.addUIElement( 'select', commonBuilder );
\r
1316 CKEDITOR.dialog.addUIElement( 'file', commonBuilder );
\r
1317 CKEDITOR.dialog.addUIElement( 'fileButton', commonBuilder );
\r
1318 CKEDITOR.dialog.addUIElement( 'html', commonBuilder );
\r