]> git.immae.eu Git - perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git/blob - sources/plugins/dialog/plugin.js
Add oembed
[perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git] / sources / plugins / dialog / plugin.js
1 /**
2 * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
4 */
5
6 /**
7 * @fileOverview The floating dialog plugin.
8 */
9
10 /**
11 * No resize for this dialog.
12 *
13 * @readonly
14 * @property {Number} [=0]
15 * @member CKEDITOR
16 */
17 CKEDITOR.DIALOG_RESIZE_NONE = 0;
18
19 /**
20 * Only allow horizontal resizing for this dialog, disable vertical resizing.
21 *
22 * @readonly
23 * @property {Number} [=1]
24 * @member CKEDITOR
25 */
26 CKEDITOR.DIALOG_RESIZE_WIDTH = 1;
27
28 /**
29 * Only allow vertical resizing for this dialog, disable horizontal resizing.
30 *
31 * @readonly
32 * @property {Number} [=2]
33 * @member CKEDITOR
34 */
35 CKEDITOR.DIALOG_RESIZE_HEIGHT = 2;
36
37 /**
38 * Allow the dialog to be resized in both directions.
39 *
40 * @readonly
41 * @property {Number} [=3]
42 * @member CKEDITOR
43 */
44 CKEDITOR.DIALOG_RESIZE_BOTH = 3;
45
46 /**
47 * Dialog state when idle.
48 *
49 * @readonly
50 * @property {Number} [=1]
51 * @member CKEDITOR
52 */
53 CKEDITOR.DIALOG_STATE_IDLE = 1;
54
55 /**
56 * Dialog state when busy.
57 *
58 * @readonly
59 * @property {Number} [=2]
60 * @member CKEDITOR
61 */
62 CKEDITOR.DIALOG_STATE_BUSY = 2;
63
64 ( function() {
65 var cssLength = CKEDITOR.tools.cssLength;
66
67 function isTabVisible( tabId ) {
68 return !!this._.tabs[ tabId ][ 0 ].$.offsetHeight;
69 }
70
71 function getPreviousVisibleTab() {
72 var tabId = this._.currentTabId,
73 length = this._.tabIdList.length,
74 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId ) + length;
75
76 for ( var i = tabIndex - 1; i > tabIndex - length; i-- ) {
77 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
78 return this._.tabIdList[ i % length ];
79 }
80
81 return null;
82 }
83
84 function getNextVisibleTab() {
85 var tabId = this._.currentTabId,
86 length = this._.tabIdList.length,
87 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId );
88
89 for ( var i = tabIndex + 1; i < tabIndex + length; i++ ) {
90 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
91 return this._.tabIdList[ i % length ];
92 }
93
94 return null;
95 }
96
97
98 function clearOrRecoverTextInputValue( container, isRecover ) {
99 var inputs = container.$.getElementsByTagName( 'input' );
100 for ( var i = 0, length = inputs.length; i < length; i++ ) {
101 var item = new CKEDITOR.dom.element( inputs[ i ] );
102
103 if ( item.getAttribute( 'type' ).toLowerCase() == 'text' ) {
104 if ( isRecover ) {
105 item.setAttribute( 'value', item.getCustomData( 'fake_value' ) || '' );
106 item.removeCustomData( 'fake_value' );
107 } else {
108 item.setCustomData( 'fake_value', item.getAttribute( 'value' ) );
109 item.setAttribute( 'value', '' );
110 }
111 }
112 }
113 }
114
115 // Handle dialog element validation state UI changes.
116 function handleFieldValidated( isValid, msg ) {
117 var input = this.getInputElement();
118 if ( input )
119 isValid ? input.removeAttribute( 'aria-invalid' ) : input.setAttribute( 'aria-invalid', true );
120
121 if ( !isValid ) {
122 if ( this.select )
123 this.select();
124 else
125 this.focus();
126 }
127
128 msg && alert( msg ); // jshint ignore:line
129
130 this.fire( 'validated', { valid: isValid, msg: msg } );
131 }
132
133 function resetField() {
134 var input = this.getInputElement();
135 input && input.removeAttribute( 'aria-invalid' );
136 }
137
138 var templateSource = '<div class="cke_reset_all {editorId} {editorDialogClass} {hidpi}' +
139 '" dir="{langDir}"' +
140 ' lang="{langCode}"' +
141 ' role="dialog"' +
142 ' aria-labelledby="cke_dialog_title_{id}"' +
143 '>' +
144 '<table class="cke_dialog ' + CKEDITOR.env.cssClass + ' cke_{langDir}"' +
145 ' style="position:absolute" role="presentation">' +
146 '<tr><td role="presentation">' +
147 '<div class="cke_dialog_body" role="presentation">' +
148 '<div id="cke_dialog_title_{id}" class="cke_dialog_title" role="presentation"></div>' +
149 '<a id="cke_dialog_close_button_{id}" class="cke_dialog_close_button" href="javascript:void(0)" title="{closeTitle}" role="button"><span class="cke_label">X</span></a>' +
150 '<div id="cke_dialog_tabs_{id}" class="cke_dialog_tabs" role="tablist"></div>' +
151 '<table class="cke_dialog_contents" role="presentation">' +
152 '<tr>' +
153 '<td id="cke_dialog_contents_{id}" class="cke_dialog_contents_body" role="presentation"></td>' +
154 '</tr>' +
155 '<tr>' +
156 '<td id="cke_dialog_footer_{id}" class="cke_dialog_footer" role="presentation"></td>' +
157 '</tr>' +
158 '</table>' +
159 '</div>' +
160 '</td></tr>' +
161 '</table>' +
162 '</div>';
163
164 function buildDialog( editor ) {
165 var element = CKEDITOR.dom.element.createFromHtml( CKEDITOR.addTemplate( 'dialog', templateSource ).output( {
166 id: CKEDITOR.tools.getNextNumber(),
167 editorId: editor.id,
168 langDir: editor.lang.dir,
169 langCode: editor.langCode,
170 editorDialogClass: 'cke_editor_' + editor.name.replace( /\./g, '\\.' ) + '_dialog',
171 closeTitle: editor.lang.common.close,
172 hidpi: CKEDITOR.env.hidpi ? 'cke_hidpi' : ''
173 } ) );
174
175 // TODO: Change this to getById(), so it'll support custom templates.
176 var body = element.getChild( [ 0, 0, 0, 0, 0 ] ),
177 title = body.getChild( 0 ),
178 close = body.getChild( 1 );
179
180 // Don't allow dragging on dialog (http://dev.ckeditor.com/ticket/13184).
181 editor.plugins.clipboard && CKEDITOR.plugins.clipboard.preventDefaultDropOnElement( body );
182
183 // IFrame shim for dialog that masks activeX in IE. (http://dev.ckeditor.com/ticket/7619)
184 if ( CKEDITOR.env.ie && !CKEDITOR.env.quirks && !CKEDITOR.env.edge ) {
185 var src = 'javascript:void(function(){' + encodeURIComponent( 'document.open();(' + CKEDITOR.tools.fixDomain + ')();document.close();' ) + '}())', // jshint ignore:line
186 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +
187 ' frameBorder="0"' +
188 ' class="cke_iframe_shim"' +
189 ' src="' + src + '"' +
190 ' tabIndex="-1"' +
191 '></iframe>' );
192 iframe.appendTo( body.getParent() );
193 }
194
195 // Make the Title and Close Button unselectable.
196 title.unselectable();
197 close.unselectable();
198
199 return {
200 element: element,
201 parts: {
202 dialog: element.getChild( 0 ),
203 title: title,
204 close: close,
205 tabs: body.getChild( 2 ),
206 contents: body.getChild( [ 3, 0, 0, 0 ] ),
207 footer: body.getChild( [ 3, 0, 1, 0 ] )
208 }
209 };
210 }
211
212 /**
213 * This is the base class for runtime dialog objects. An instance of this
214 * class represents a single named dialog for a single editor instance.
215 *
216 * var dialogObj = new CKEDITOR.dialog( editor, 'smiley' );
217 *
218 * @class
219 * @constructor Creates a dialog class instance.
220 * @param {Object} editor The editor which created the dialog.
221 * @param {String} dialogName The dialog's registered name.
222 */
223 CKEDITOR.dialog = function( editor, dialogName ) {
224 // Load the dialog definition.
225 var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
226 defaultDefinition = CKEDITOR.tools.clone( defaultDialogDefinition ),
227 buttonsOrder = editor.config.dialog_buttonsOrder || 'OS',
228 dir = editor.lang.dir,
229 tabsToRemove = {},
230 i, processed, stopPropagation;
231
232 if ( ( buttonsOrder == 'OS' && CKEDITOR.env.mac ) || // The buttons in MacOS Apps are in reverse order (http://dev.ckeditor.com/ticket/4750)
233 ( buttonsOrder == 'rtl' && dir == 'ltr' ) || ( buttonsOrder == 'ltr' && dir == 'rtl' ) )
234 defaultDefinition.buttons.reverse();
235
236
237 // Completes the definition with the default values.
238 definition = CKEDITOR.tools.extend( definition( editor ), defaultDefinition );
239
240 // Clone a functionally independent copy for this dialog.
241 definition = CKEDITOR.tools.clone( definition );
242
243 // Create a complex definition object, extending it with the API
244 // functions.
245 definition = new definitionObject( this, definition );
246
247 var themeBuilt = buildDialog( editor );
248
249 // Initialize some basic parameters.
250 this._ = {
251 editor: editor,
252 element: themeBuilt.element,
253 name: dialogName,
254 contentSize: { width: 0, height: 0 },
255 size: { width: 0, height: 0 },
256 contents: {},
257 buttons: {},
258 accessKeyMap: {},
259
260 // Initialize the tab and page map.
261 tabs: {},
262 tabIdList: [],
263 currentTabId: null,
264 currentTabIndex: null,
265 pageCount: 0,
266 lastTab: null,
267 tabBarMode: false,
268
269 // Initialize the tab order array for input widgets.
270 focusList: [],
271 currentFocusIndex: 0,
272 hasFocus: false
273 };
274
275 this.parts = themeBuilt.parts;
276
277 CKEDITOR.tools.setTimeout( function() {
278 editor.fire( 'ariaWidget', this.parts.contents );
279 }, 0, this );
280
281 // Set the startup styles for the dialog, avoiding it enlarging the
282 // page size on the dialog creation.
283 var startStyles = {
284 position: CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed',
285 top: 0,
286 visibility: 'hidden'
287 };
288
289 startStyles[ dir == 'rtl' ? 'right' : 'left' ] = 0;
290 this.parts.dialog.setStyles( startStyles );
291
292
293 // Call the CKEDITOR.event constructor to initialize this instance.
294 CKEDITOR.event.call( this );
295
296 // Fire the "dialogDefinition" event, making it possible to customize
297 // the dialog definition.
298 this.definition = definition = CKEDITOR.fire( 'dialogDefinition', {
299 name: dialogName,
300 definition: definition
301 }, editor ).definition;
302
303 // Cache tabs that should be removed.
304 if ( !( 'removeDialogTabs' in editor._ ) && editor.config.removeDialogTabs ) {
305 var removeContents = editor.config.removeDialogTabs.split( ';' );
306
307 for ( i = 0; i < removeContents.length; i++ ) {
308 var parts = removeContents[ i ].split( ':' );
309 if ( parts.length == 2 ) {
310 var removeDialogName = parts[ 0 ];
311 if ( !tabsToRemove[ removeDialogName ] )
312 tabsToRemove[ removeDialogName ] = [];
313 tabsToRemove[ removeDialogName ].push( parts[ 1 ] );
314 }
315 }
316 editor._.removeDialogTabs = tabsToRemove;
317 }
318
319 // Remove tabs of this dialog.
320 if ( editor._.removeDialogTabs && ( tabsToRemove = editor._.removeDialogTabs[ dialogName ] ) ) {
321 for ( i = 0; i < tabsToRemove.length; i++ )
322 definition.removeContents( tabsToRemove[ i ] );
323 }
324
325 // Initialize load, show, hide, ok and cancel events.
326 if ( definition.onLoad )
327 this.on( 'load', definition.onLoad );
328
329 if ( definition.onShow )
330 this.on( 'show', definition.onShow );
331
332 if ( definition.onHide )
333 this.on( 'hide', definition.onHide );
334
335 if ( definition.onOk ) {
336 this.on( 'ok', function( evt ) {
337 // Dialog confirm might probably introduce content changes (http://dev.ckeditor.com/ticket/5415).
338 editor.fire( 'saveSnapshot' );
339 setTimeout( function() {
340 editor.fire( 'saveSnapshot' );
341 }, 0 );
342 if ( definition.onOk.call( this, evt ) === false )
343 evt.data.hide = false;
344 } );
345 }
346
347 // Set default dialog state.
348 this.state = CKEDITOR.DIALOG_STATE_IDLE;
349
350 if ( definition.onCancel ) {
351 this.on( 'cancel', function( evt ) {
352 if ( definition.onCancel.call( this, evt ) === false )
353 evt.data.hide = false;
354 } );
355 }
356
357 var me = this;
358
359 // Iterates over all items inside all content in the dialog, calling a
360 // function for each of them.
361 var iterContents = function( func ) {
362 var contents = me._.contents,
363 stop = false;
364
365 for ( var i in contents ) {
366 for ( var j in contents[ i ] ) {
367 stop = func.call( this, contents[ i ][ j ] );
368 if ( stop )
369 return;
370 }
371 }
372 };
373
374 this.on( 'ok', function( evt ) {
375 iterContents( function( item ) {
376 if ( item.validate ) {
377 var retval = item.validate( this ),
378 invalid = ( typeof retval == 'string' ) || retval === false;
379
380 if ( invalid ) {
381 evt.data.hide = false;
382 evt.stop();
383 }
384
385 handleFieldValidated.call( item, !invalid, typeof retval == 'string' ? retval : undefined );
386 return invalid;
387 }
388 } );
389 }, this, null, 0 );
390
391 this.on( 'cancel', function( evt ) {
392 iterContents( function( item ) {
393 if ( item.isChanged() ) {
394 if ( !editor.config.dialog_noConfirmCancel && !confirm( editor.lang.common.confirmCancel ) ) // jshint ignore:line
395 evt.data.hide = false;
396 return true;
397 }
398 } );
399 }, this, null, 0 );
400
401 this.parts.close.on( 'click', function( evt ) {
402 if ( this.fire( 'cancel', { hide: true } ).hide !== false )
403 this.hide();
404 evt.data.preventDefault();
405 }, this );
406
407 // Sort focus list according to tab order definitions.
408 function setupFocus() {
409 var focusList = me._.focusList;
410 focusList.sort( function( a, b ) {
411 // Mimics browser tab order logics;
412 if ( a.tabIndex != b.tabIndex )
413 return b.tabIndex - a.tabIndex;
414 // Sort is not stable in some browsers,
415 // fall-back the comparator to 'focusIndex';
416 else
417 return a.focusIndex - b.focusIndex;
418 } );
419
420 var size = focusList.length;
421 for ( var i = 0; i < size; i++ )
422 focusList[ i ].focusIndex = i;
423 }
424
425 // Expects 1 or -1 as an offset, meaning direction of the offset change.
426 function changeFocus( offset ) {
427 var focusList = me._.focusList;
428 offset = offset || 0;
429
430 if ( focusList.length < 1 )
431 return;
432
433 var startIndex = me._.currentFocusIndex;
434
435 if ( me._.tabBarMode && offset < 0 ) {
436 // If we are in tab mode, we need to mimic that we started tabbing back from the first
437 // focusList (so it will go to the last one).
438 startIndex = 0;
439 }
440
441 // Trigger the 'blur' event of any input element before anything,
442 // since certain UI updates may depend on it.
443 try {
444 focusList[ startIndex ].getInputElement().$.blur();
445 } catch ( e ) {}
446
447 var currentIndex = startIndex,
448 hasTabs = me._.pageCount > 1;
449
450 do {
451 currentIndex = currentIndex + offset;
452
453 if ( hasTabs && !me._.tabBarMode && ( currentIndex == focusList.length || currentIndex == -1 ) ) {
454 // If the dialog was not in tab mode, then focus the first tab (http://dev.ckeditor.com/ticket/13027).
455 me._.tabBarMode = true;
456 me._.tabs[ me._.currentTabId ][ 0 ].focus();
457 me._.currentFocusIndex = -1;
458
459 // Early return, in order to avoid accessing focusList[ -1 ].
460 return;
461 }
462
463 currentIndex = ( currentIndex + focusList.length ) % focusList.length;
464
465 if ( currentIndex == startIndex ) {
466 break;
467 }
468 } while ( offset && !focusList[ currentIndex ].isFocusable() );
469
470 focusList[ currentIndex ].focus();
471
472 // Select whole field content.
473 if ( focusList[ currentIndex ].type == 'text' )
474 focusList[ currentIndex ].select();
475 }
476
477 this.changeFocus = changeFocus;
478
479
480 function keydownHandler( evt ) {
481 // If I'm not the top dialog, ignore.
482 if ( me != CKEDITOR.dialog._.currentTop )
483 return;
484
485 var keystroke = evt.data.getKeystroke(),
486 rtl = editor.lang.dir == 'rtl',
487 arrowKeys = [ 37, 38, 39, 40 ],
488 button;
489
490 processed = stopPropagation = 0;
491
492 if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 ) {
493 var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
494 changeFocus( shiftPressed ? -1 : 1 );
495 processed = 1;
496 } else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode && me.getPageCount() > 1 ) {
497 // Alt-F10 puts focus into the current tab item in the tab bar.
498 me._.tabBarMode = true;
499 me._.tabs[ me._.currentTabId ][ 0 ].focus();
500 me._.currentFocusIndex = -1;
501 processed = 1;
502 } else if ( CKEDITOR.tools.indexOf( arrowKeys, keystroke ) != -1 && me._.tabBarMode ) {
503 // Array with key codes that activate previous tab.
504 var prevKeyCodes = [
505 // Depending on the lang dir: right or left key
506 rtl ? 39 : 37,
507 // Top/bot arrow: actually for both cases it's the same.
508 38
509 ],
510 nextId = CKEDITOR.tools.indexOf( prevKeyCodes, keystroke ) != -1 ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );
511
512 me.selectPage( nextId );
513 me._.tabs[ nextId ][ 0 ].focus();
514 processed = 1;
515 } else if ( ( keystroke == 13 || keystroke == 32 ) && me._.tabBarMode ) {
516 this.selectPage( this._.currentTabId );
517 this._.tabBarMode = false;
518 this._.currentFocusIndex = -1;
519 changeFocus( 1 );
520 processed = 1;
521 }
522 // If user presses enter key in a text box, it implies clicking OK for the dialog.
523 else if ( keystroke == 13 /*ENTER*/ ) {
524 // Don't do that for a target that handles ENTER.
525 var target = evt.data.getTarget();
526 if ( !target.is( 'a', 'button', 'select', 'textarea' ) && ( !target.is( 'input' ) || target.$.type != 'button' ) ) {
527 button = this.getButton( 'ok' );
528 button && CKEDITOR.tools.setTimeout( button.click, 0, button );
529 processed = 1;
530 }
531 stopPropagation = 1; // Always block the propagation (http://dev.ckeditor.com/ticket/4269)
532 } else if ( keystroke == 27 /*ESC*/ ) {
533 button = this.getButton( 'cancel' );
534
535 // If there's a Cancel button, click it, else just fire the cancel event and hide the dialog.
536 if ( button )
537 CKEDITOR.tools.setTimeout( button.click, 0, button );
538 else {
539 if ( this.fire( 'cancel', { hide: true } ).hide !== false )
540 this.hide();
541 }
542 stopPropagation = 1; // Always block the propagation (http://dev.ckeditor.com/ticket/4269)
543 } else {
544 return;
545 }
546
547 keypressHandler( evt );
548 }
549
550 function keypressHandler( evt ) {
551 if ( processed )
552 evt.data.preventDefault( 1 );
553 else if ( stopPropagation )
554 evt.data.stopPropagation();
555 }
556
557 var dialogElement = this._.element;
558
559 editor.focusManager.add( dialogElement, 1 );
560
561 // Add the dialog keyboard handlers.
562 this.on( 'show', function() {
563 dialogElement.on( 'keydown', keydownHandler, this );
564
565 // Some browsers instead, don't cancel key events in the keydown, but in the
566 // keypress. So we must do a longer trip in those cases. (http://dev.ckeditor.com/ticket/4531,http://dev.ckeditor.com/ticket/8985)
567 if ( CKEDITOR.env.gecko )
568 dialogElement.on( 'keypress', keypressHandler, this );
569
570 } );
571 this.on( 'hide', function() {
572 dialogElement.removeListener( 'keydown', keydownHandler );
573 if ( CKEDITOR.env.gecko )
574 dialogElement.removeListener( 'keypress', keypressHandler );
575
576 // Reset fields state when closing dialog.
577 iterContents( function( item ) {
578 resetField.apply( item );
579 } );
580 } );
581 this.on( 'iframeAdded', function( evt ) {
582 var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );
583 doc.on( 'keydown', keydownHandler, this, null, 0 );
584 } );
585
586 // Auto-focus logic in dialog.
587 this.on( 'show', function() {
588 // Setup tabIndex on showing the dialog instead of on loading
589 // to allow dynamic tab order happen in dialog definition.
590 setupFocus();
591
592 var hasTabs = me._.pageCount > 1;
593
594 if ( editor.config.dialog_startupFocusTab && hasTabs ) {
595 me._.tabBarMode = true;
596 me._.tabs[ me._.currentTabId ][ 0 ].focus();
597 me._.currentFocusIndex = -1;
598 } else if ( !this._.hasFocus ) {
599 // http://dev.ckeditor.com/ticket/13114#comment:4.
600 this._.currentFocusIndex = hasTabs ? -1 : this._.focusList.length - 1;
601
602 // Decide where to put the initial focus.
603 if ( definition.onFocus ) {
604 var initialFocus = definition.onFocus.call( this );
605 // Focus the field that the user specified.
606 initialFocus && initialFocus.focus();
607 }
608 // Focus the first field in layout order.
609 else {
610 changeFocus( 1 );
611 }
612 }
613 }, this, null, 0xffffffff );
614
615 // IE6 BUG: Text fields and text areas are only half-rendered the first time the dialog appears in IE6 (http://dev.ckeditor.com/ticket/2661).
616 // This is still needed after [2708] and [2709] because text fields in hidden TR tags are still broken.
617 if ( CKEDITOR.env.ie6Compat ) {
618 this.on( 'load', function() {
619 var outer = this.getElement(),
620 inner = outer.getFirst();
621 inner.remove();
622 inner.appendTo( outer );
623 }, this );
624 }
625
626 initDragAndDrop( this );
627 initResizeHandles( this );
628
629 // Insert the title.
630 ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );
631
632 // Insert the tabs and contents.
633 for ( i = 0; i < definition.contents.length; i++ ) {
634 var page = definition.contents[ i ];
635 page && this.addPage( page );
636 }
637
638 this.parts.tabs.on( 'click', function( evt ) {
639 var target = evt.data.getTarget();
640 // If we aren't inside a tab, bail out.
641 if ( target.hasClass( 'cke_dialog_tab' ) ) {
642 // Get the ID of the tab, without the 'cke_' prefix and the unique number suffix.
643 var id = target.$.id;
644 this.selectPage( id.substring( 4, id.lastIndexOf( '_' ) ) );
645
646 if ( this._.tabBarMode ) {
647 this._.tabBarMode = false;
648 this._.currentFocusIndex = -1;
649 changeFocus( 1 );
650 }
651 evt.data.preventDefault();
652 }
653 }, this );
654
655 // Insert buttons.
656 var buttonsHtml = [],
657 buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this, {
658 type: 'hbox',
659 className: 'cke_dialog_footer_buttons',
660 widths: [],
661 children: definition.buttons
662 }, buttonsHtml ).getChild();
663 this.parts.footer.setHtml( buttonsHtml.join( '' ) );
664
665 for ( i = 0; i < buttons.length; i++ )
666 this._.buttons[ buttons[ i ].id ] = buttons[ i ];
667
668 /**
669 * Current state of the dialog. Use the {@link #setState} method to update it.
670 * See the {@link #event-state} event to know more.
671 *
672 * @readonly
673 * @property {Number} [state=CKEDITOR.DIALOG_STATE_IDLE]
674 */
675 };
676
677 // Focusable interface. Use it via dialog.addFocusable.
678 function Focusable( dialog, element, index ) {
679 this.element = element;
680 this.focusIndex = index;
681 // TODO: support tabIndex for focusables.
682 this.tabIndex = 0;
683 this.isFocusable = function() {
684 return !element.getAttribute( 'disabled' ) && element.isVisible();
685 };
686 this.focus = function() {
687 dialog._.currentFocusIndex = this.focusIndex;
688 this.element.focus();
689 };
690 // Bind events
691 element.on( 'keydown', function( e ) {
692 if ( e.data.getKeystroke() in { 32: 1, 13: 1 } )
693 this.fire( 'click' );
694 } );
695 element.on( 'focus', function() {
696 this.fire( 'mouseover' );
697 } );
698 element.on( 'blur', function() {
699 this.fire( 'mouseout' );
700 } );
701 }
702
703 // Re-layout the dialog on window resize.
704 function resizeWithWindow( dialog ) {
705 var win = CKEDITOR.document.getWindow();
706 function resizeHandler() {
707 dialog.layout();
708 }
709 win.on( 'resize', resizeHandler );
710 dialog.on( 'hide', function() {
711 win.removeListener( 'resize', resizeHandler );
712 } );
713 }
714
715 CKEDITOR.dialog.prototype = {
716 destroy: function() {
717 this.hide();
718 this._.element.remove();
719 },
720
721 /**
722 * Resizes the dialog.
723 *
724 * dialogObj.resize( 800, 640 );
725 *
726 * @method
727 * @param {Number} width The width of the dialog in pixels.
728 * @param {Number} height The height of the dialog in pixels.
729 */
730 resize: ( function() {
731 return function( width, height ) {
732 if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )
733 return;
734
735 CKEDITOR.dialog.fire( 'resize', {
736 dialog: this,
737 width: width,
738 height: height
739 }, this._.editor );
740
741 this.fire( 'resize', {
742 width: width,
743 height: height
744 }, this._.editor );
745
746 var contents = this.parts.contents;
747 contents.setStyles( {
748 width: width + 'px',
749 height: height + 'px'
750 } );
751
752 // Update dialog position when dimension get changed in RTL.
753 if ( this._.editor.lang.dir == 'rtl' && this._.position )
754 this._.position.x = CKEDITOR.document.getWindow().getViewPaneSize().width - this._.contentSize.width - parseInt( this._.element.getFirst().getStyle( 'right' ), 10 );
755
756 this._.contentSize = { width: width, height: height };
757 };
758 } )(),
759
760 /**
761 * Gets the current size of the dialog in pixels.
762 *
763 * var width = dialogObj.getSize().width;
764 *
765 * @returns {Object}
766 * @returns {Number} return.width
767 * @returns {Number} return.height
768 */
769 getSize: function() {
770 var element = this._.element.getFirst();
771 return { width: element.$.offsetWidth || 0, height: element.$.offsetHeight || 0 };
772 },
773
774 /**
775 * Moves the dialog to an `(x, y)` coordinate relative to the window.
776 *
777 * dialogObj.move( 10, 40 );
778 *
779 * @method
780 * @param {Number} x The target x-coordinate.
781 * @param {Number} y The target y-coordinate.
782 * @param {Boolean} save Flag indicate whether the dialog position should be remembered on next open up.
783 */
784 move: function( x, y, save ) {
785
786 // The dialog may be fixed positioned or absolute positioned. Ask the
787 // browser what is the current situation first.
788 var element = this._.element.getFirst(), rtl = this._.editor.lang.dir == 'rtl';
789 var isFixed = element.getComputedStyle( 'position' ) == 'fixed';
790
791 // (http://dev.ckeditor.com/ticket/8888) In some cases of a very small viewport, dialog is incorrectly
792 // positioned in IE7. It also happens that it remains sticky and user cannot
793 // scroll down/up to reveal dialog's content below/above the viewport; this is
794 // cumbersome.
795 // The only way to fix this is to move mouse out of the browser and
796 // go back to see that dialog position is automagically fixed. No events,
797 // no style change - pure magic. This is a IE7 rendering issue, which can be
798 // fixed with dummy style redraw on each move.
799 if ( CKEDITOR.env.ie )
800 element.setStyle( 'zoom', '100%' );
801
802 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
803 return;
804
805 // Save the current position.
806 this._.position = { x: x, y: y };
807
808 // If not fixed positioned, add scroll position to the coordinates.
809 if ( !isFixed ) {
810 var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
811 x += scrollPosition.x;
812 y += scrollPosition.y;
813 }
814
815 // Translate coordinate for RTL.
816 if ( rtl ) {
817 var dialogSize = this.getSize(), viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize();
818 x = viewPaneSize.width - dialogSize.width - x;
819 }
820
821 var styles = { 'top': ( y > 0 ? y : 0 ) + 'px' };
822 styles[ rtl ? 'right' : 'left' ] = ( x > 0 ? x : 0 ) + 'px';
823
824 element.setStyles( styles );
825
826 save && ( this._.moved = 1 );
827 },
828
829 /**
830 * Gets the dialog's position in the window.
831 *
832 * var dialogX = dialogObj.getPosition().x;
833 *
834 * @returns {Object}
835 * @returns {Number} return.x
836 * @returns {Number} return.y
837 */
838 getPosition: function() {
839 return CKEDITOR.tools.extend( {}, this._.position );
840 },
841
842 /**
843 * Shows the dialog box.
844 *
845 * dialogObj.show();
846 */
847 show: function() {
848 // Insert the dialog's element to the root document.
849 var element = this._.element;
850 var definition = this.definition;
851 if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )
852 element.appendTo( CKEDITOR.document.getBody() );
853 else
854 element.setStyle( 'display', 'block' );
855
856 // First, set the dialog to an appropriate size.
857 this.resize(
858 this._.contentSize && this._.contentSize.width || definition.width || definition.minWidth,
859 this._.contentSize && this._.contentSize.height || definition.height || definition.minHeight
860 );
861
862 // Reset all inputs back to their default value.
863 this.reset();
864
865 // Selects the first tab if no tab is already selected.
866 if ( this._.currentTabId === null ) {
867 this.selectPage( this.definition.contents[ 0 ].id );
868 }
869
870 // Set z-index.
871 if ( CKEDITOR.dialog._.currentZIndex === null )
872 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;
873 this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
874
875 // Maintain the dialog ordering and dialog cover.
876 if ( CKEDITOR.dialog._.currentTop === null ) {
877 CKEDITOR.dialog._.currentTop = this;
878 this._.parentDialog = null;
879 showCover( this._.editor );
880
881 } else {
882 this._.parentDialog = CKEDITOR.dialog._.currentTop;
883 var parentElement = this._.parentDialog.getElement().getFirst();
884 parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );
885 CKEDITOR.dialog._.currentTop = this;
886 }
887
888 element.on( 'keydown', accessKeyDownHandler );
889 element.on( 'keyup', accessKeyUpHandler );
890
891 // Reset the hasFocus state.
892 this._.hasFocus = false;
893
894 for ( var i in definition.contents ) {
895 if ( !definition.contents[ i ] )
896 continue;
897
898 var content = definition.contents[ i ],
899 tab = this._.tabs[ content.id ],
900 requiredContent = content.requiredContent,
901 enableElements = 0;
902
903 if ( !tab )
904 continue;
905
906 for ( var j in this._.contents[ content.id ] ) {
907 var elem = this._.contents[ content.id ][ j ];
908
909 if ( elem.type == 'hbox' || elem.type == 'vbox' || !elem.getInputElement() )
910 continue;
911
912 if ( elem.requiredContent && !this._.editor.activeFilter.check( elem.requiredContent ) )
913 elem.disable();
914 else {
915 elem.enable();
916 enableElements++;
917 }
918 }
919
920 if ( !enableElements || ( requiredContent && !this._.editor.activeFilter.check( requiredContent ) ) )
921 tab[ 0 ].addClass( 'cke_dialog_tab_disabled' );
922 else
923 tab[ 0 ].removeClass( 'cke_dialog_tab_disabled' );
924 }
925
926 CKEDITOR.tools.setTimeout( function() {
927 this.layout();
928 resizeWithWindow( this );
929
930 this.parts.dialog.setStyle( 'visibility', '' );
931
932 // Execute onLoad for the first show.
933 this.fireOnce( 'load', {} );
934 CKEDITOR.ui.fire( 'ready', this );
935
936 this.fire( 'show', {} );
937 this._.editor.fire( 'dialogShow', this );
938
939 if ( !this._.parentDialog )
940 this._.editor.focusManager.lock();
941
942 // Save the initial values of the dialog.
943 this.foreach( function( contentObj ) {
944 contentObj.setInitValue && contentObj.setInitValue();
945 } );
946
947 }, 100, this );
948 },
949
950 /**
951 * Rearrange the dialog to its previous position or the middle of the window.
952 *
953 * @since 3.5
954 */
955 layout: function() {
956 var el = this.parts.dialog;
957 var dialogSize = this.getSize();
958 var win = CKEDITOR.document.getWindow(),
959 viewSize = win.getViewPaneSize();
960
961 var posX = ( viewSize.width - dialogSize.width ) / 2,
962 posY = ( viewSize.height - dialogSize.height ) / 2;
963
964 // Switch to absolute position when viewport is smaller than dialog size.
965 if ( !CKEDITOR.env.ie6Compat ) {
966 if ( dialogSize.height + ( posY > 0 ? posY : 0 ) > viewSize.height || dialogSize.width + ( posX > 0 ? posX : 0 ) > viewSize.width ) {
967 el.setStyle( 'position', 'absolute' );
968 } else {
969 el.setStyle( 'position', 'fixed' );
970 }
971 }
972
973 this.move( this._.moved ? this._.position.x : posX, this._.moved ? this._.position.y : posY );
974 },
975
976 /**
977 * Executes a function for each UI element.
978 *
979 * @param {Function} fn Function to execute for each UI element.
980 * @returns {CKEDITOR.dialog} The current dialog object.
981 */
982 foreach: function( fn ) {
983 for ( var i in this._.contents ) {
984 for ( var j in this._.contents[ i ] ) {
985 fn.call( this, this._.contents[i][j] );
986 }
987 }
988
989 return this;
990 },
991
992 /**
993 * Resets all input values in the dialog.
994 *
995 * dialogObj.reset();
996 *
997 * @method
998 * @chainable
999 */
1000 reset: ( function() {
1001 var fn = function( widget ) {
1002 if ( widget.reset )
1003 widget.reset( 1 );
1004 };
1005 return function() {
1006 this.foreach( fn );
1007 return this;
1008 };
1009 } )(),
1010
1011
1012 /**
1013 * Calls the {@link CKEDITOR.dialog.definition.uiElement#setup} method of each
1014 * of the UI elements, with the arguments passed through it.
1015 * It is usually being called when the dialog is opened, to put the initial value inside the field.
1016 *
1017 * dialogObj.setupContent();
1018 *
1019 * var timestamp = ( new Date() ).valueOf();
1020 * dialogObj.setupContent( timestamp );
1021 */
1022 setupContent: function() {
1023 var args = arguments;
1024 this.foreach( function( widget ) {
1025 if ( widget.setup )
1026 widget.setup.apply( widget, args );
1027 } );
1028 },
1029
1030 /**
1031 * Calls the {@link CKEDITOR.dialog.definition.uiElement#commit} method of each
1032 * of the UI elements, with the arguments passed through it.
1033 * It is usually being called when the user confirms the dialog, to process the values.
1034 *
1035 * dialogObj.commitContent();
1036 *
1037 * var timestamp = ( new Date() ).valueOf();
1038 * dialogObj.commitContent( timestamp );
1039 */
1040 commitContent: function() {
1041 var args = arguments;
1042 this.foreach( function( widget ) {
1043 // Make sure IE triggers "change" event on last focused input before closing the dialog. (http://dev.ckeditor.com/ticket/7915)
1044 if ( CKEDITOR.env.ie && this._.currentFocusIndex == widget.focusIndex )
1045 widget.getInputElement().$.blur();
1046
1047 if ( widget.commit )
1048 widget.commit.apply( widget, args );
1049 } );
1050 },
1051
1052 /**
1053 * Hides the dialog box.
1054 *
1055 * dialogObj.hide();
1056 */
1057 hide: function() {
1058 if ( !this.parts.dialog.isVisible() )
1059 return;
1060
1061 this.fire( 'hide', {} );
1062 this._.editor.fire( 'dialogHide', this );
1063 // Reset the tab page.
1064 this.selectPage( this._.tabIdList[ 0 ] );
1065 var element = this._.element;
1066 element.setStyle( 'display', 'none' );
1067 this.parts.dialog.setStyle( 'visibility', 'hidden' );
1068 // Unregister all access keys associated with this dialog.
1069 unregisterAccessKey( this );
1070
1071 // Close any child(top) dialogs first.
1072 while ( CKEDITOR.dialog._.currentTop != this )
1073 CKEDITOR.dialog._.currentTop.hide();
1074
1075 // Maintain dialog ordering and remove cover if needed.
1076 if ( !this._.parentDialog )
1077 hideCover( this._.editor );
1078 else {
1079 var parentElement = this._.parentDialog.getElement().getFirst();
1080 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
1081 }
1082 CKEDITOR.dialog._.currentTop = this._.parentDialog;
1083
1084 // Deduct or clear the z-index.
1085 if ( !this._.parentDialog ) {
1086 CKEDITOR.dialog._.currentZIndex = null;
1087
1088 // Remove access key handlers.
1089 element.removeListener( 'keydown', accessKeyDownHandler );
1090 element.removeListener( 'keyup', accessKeyUpHandler );
1091
1092 var editor = this._.editor;
1093 editor.focus();
1094
1095 // Give a while before unlock, waiting for focus to return to the editable. (http://dev.ckeditor.com/ticket/172)
1096 setTimeout( function() {
1097 editor.focusManager.unlock();
1098
1099 // Fixed iOS focus issue (http://dev.ckeditor.com/ticket/12381).
1100 // Keep in mind that editor.focus() does not work in this case.
1101 if ( CKEDITOR.env.iOS ) {
1102 editor.window.focus();
1103 }
1104 }, 0 );
1105
1106 } else {
1107 CKEDITOR.dialog._.currentZIndex -= 10;
1108 }
1109
1110 delete this._.parentDialog;
1111 // Reset the initial values of the dialog.
1112 this.foreach( function( contentObj ) {
1113 contentObj.resetInitValue && contentObj.resetInitValue();
1114 } );
1115
1116 // Reset dialog state back to IDLE, if busy (http://dev.ckeditor.com/ticket/13213).
1117 this.setState( CKEDITOR.DIALOG_STATE_IDLE );
1118 },
1119
1120 /**
1121 * Adds a tabbed page into the dialog.
1122 *
1123 * @param {Object} contents Content definition.
1124 */
1125 addPage: function( contents ) {
1126 if ( contents.requiredContent && !this._.editor.filter.check( contents.requiredContent ) )
1127 return;
1128
1129 var pageHtml = [],
1130 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
1131 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this, {
1132 type: 'vbox',
1133 className: 'cke_dialog_page_contents',
1134 children: contents.elements,
1135 expand: !!contents.expand,
1136 padding: contents.padding,
1137 style: contents.style || 'width: 100%;'
1138 }, pageHtml );
1139
1140 var contentMap = this._.contents[ contents.id ] = {},
1141 cursor,
1142 children = vbox.getChild(),
1143 enabledFields = 0;
1144
1145 while ( ( cursor = children.shift() ) ) {
1146 // Count all allowed fields.
1147 if ( !cursor.notAllowed && cursor.type != 'hbox' && cursor.type != 'vbox' )
1148 enabledFields++;
1149
1150 contentMap[ cursor.id ] = cursor;
1151 if ( typeof cursor.getChild == 'function' )
1152 children.push.apply( children, cursor.getChild() );
1153 }
1154
1155 // If all fields are disabled (because they are not allowed) hide this tab.
1156 if ( !enabledFields )
1157 contents.hidden = true;
1158
1159 // Create the HTML for the tab and the content block.
1160 var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
1161 page.setAttribute( 'role', 'tabpanel' );
1162
1163 var env = CKEDITOR.env;
1164 var tabId = 'cke_' + contents.id + '_' + CKEDITOR.tools.getNextNumber(),
1165 tab = CKEDITOR.dom.element.createFromHtml( [
1166 '<a class="cke_dialog_tab"',
1167 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),
1168 titleHtml,
1169 ( !!contents.hidden ? ' style="display:none"' : '' ),
1170 ' id="', tabId, '"',
1171 env.gecko && !env.hc ? '' : ' href="javascript:void(0)"',
1172 ' tabIndex="-1"',
1173 ' hidefocus="true"',
1174 ' role="tab">',
1175 contents.label,
1176 '</a>'
1177 ].join( '' ) );
1178
1179 page.setAttribute( 'aria-labelledby', tabId );
1180
1181 // Take records for the tabs and elements created.
1182 this._.tabs[ contents.id ] = [ tab, page ];
1183 this._.tabIdList.push( contents.id );
1184 !contents.hidden && this._.pageCount++;
1185 this._.lastTab = tab;
1186 this.updateStyle();
1187
1188 // Attach the DOM nodes.
1189
1190 page.setAttribute( 'name', contents.id );
1191 page.appendTo( this.parts.contents );
1192
1193 tab.unselectable();
1194 this.parts.tabs.append( tab );
1195
1196 // Add access key handlers if access key is defined.
1197 if ( contents.accessKey ) {
1198 registerAccessKey( this, this, 'CTRL+' + contents.accessKey, tabAccessKeyDown, tabAccessKeyUp );
1199 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;
1200 }
1201 },
1202
1203 /**
1204 * Activates a tab page in the dialog by its id.
1205 *
1206 * dialogObj.selectPage( 'tab_1' );
1207 *
1208 * @param {String} id The id of the dialog tab to be activated.
1209 */
1210 selectPage: function( id ) {
1211 if ( this._.currentTabId == id )
1212 return;
1213
1214 if ( this._.tabs[ id ][ 0 ].hasClass( 'cke_dialog_tab_disabled' ) )
1215 return;
1216
1217 // If event was canceled - do nothing.
1218 if ( this.fire( 'selectPage', { page: id, currentPage: this._.currentTabId } ) === false )
1219 return;
1220
1221 // Hide the non-selected tabs and pages.
1222 for ( var i in this._.tabs ) {
1223 var tab = this._.tabs[ i ][ 0 ],
1224 page = this._.tabs[ i ][ 1 ];
1225 if ( i != id ) {
1226 tab.removeClass( 'cke_dialog_tab_selected' );
1227 page.hide();
1228 }
1229 page.setAttribute( 'aria-hidden', i != id );
1230 }
1231
1232 var selected = this._.tabs[ id ];
1233 selected[ 0 ].addClass( 'cke_dialog_tab_selected' );
1234
1235 // [IE] an invisible input[type='text'] will enlarge it's width
1236 // if it's value is long when it shows, so we clear it's value
1237 // before it shows and then recover it (http://dev.ckeditor.com/ticket/5649)
1238 if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat ) {
1239 clearOrRecoverTextInputValue( selected[ 1 ] );
1240 selected[ 1 ].show();
1241 setTimeout( function() {
1242 clearOrRecoverTextInputValue( selected[ 1 ], 1 );
1243 }, 0 );
1244 } else {
1245 selected[ 1 ].show();
1246 }
1247
1248 this._.currentTabId = id;
1249 this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
1250 },
1251
1252 /**
1253 * Dialog state-specific style updates.
1254 */
1255 updateStyle: function() {
1256 // If only a single page shown, a different style is used in the central pane.
1257 this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );
1258 },
1259
1260 /**
1261 * Hides a page's tab away from the dialog.
1262 *
1263 * dialog.hidePage( 'tab_3' );
1264 *
1265 * @param {String} id The page's Id.
1266 */
1267 hidePage: function( id ) {
1268 var tab = this._.tabs[ id ] && this._.tabs[ id ][ 0 ];
1269 if ( !tab || this._.pageCount == 1 || !tab.isVisible() )
1270 return;
1271 // Switch to other tab first when we're hiding the active tab.
1272 else if ( id == this._.currentTabId )
1273 this.selectPage( getPreviousVisibleTab.call( this ) );
1274
1275 tab.hide();
1276 this._.pageCount--;
1277 this.updateStyle();
1278 },
1279
1280 /**
1281 * Unhides a page's tab.
1282 *
1283 * dialog.showPage( 'tab_2' );
1284 *
1285 * @param {String} id The page's Id.
1286 */
1287 showPage: function( id ) {
1288 var tab = this._.tabs[ id ] && this._.tabs[ id ][ 0 ];
1289 if ( !tab )
1290 return;
1291 tab.show();
1292 this._.pageCount++;
1293 this.updateStyle();
1294 },
1295
1296 /**
1297 * Gets the root DOM element of the dialog.
1298 *
1299 * var dialogElement = dialogObj.getElement().getFirst();
1300 * dialogElement.setStyle( 'padding', '5px' );
1301 *
1302 * @returns {CKEDITOR.dom.element} The `<span>` element containing this dialog.
1303 */
1304 getElement: function() {
1305 return this._.element;
1306 },
1307
1308 /**
1309 * Gets the name of the dialog.
1310 *
1311 * var dialogName = dialogObj.getName();
1312 *
1313 * @returns {String} The name of this dialog.
1314 */
1315 getName: function() {
1316 return this._.name;
1317 },
1318
1319 /**
1320 * Gets a dialog UI element object from a dialog page.
1321 *
1322 * dialogObj.getContentElement( 'tabId', 'elementId' ).setValue( 'Example' );
1323 *
1324 * @param {String} pageId id of dialog page.
1325 * @param {String} elementId id of UI element.
1326 * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.
1327 */
1328 getContentElement: function( pageId, elementId ) {
1329 var page = this._.contents[ pageId ];
1330 return page && page[ elementId ];
1331 },
1332
1333 /**
1334 * Gets the value of a dialog UI element.
1335 *
1336 * alert( dialogObj.getValueOf( 'tabId', 'elementId' ) );
1337 *
1338 * @param {String} pageId id of dialog page.
1339 * @param {String} elementId id of UI element.
1340 * @returns {Object} The value of the UI element.
1341 */
1342 getValueOf: function( pageId, elementId ) {
1343 return this.getContentElement( pageId, elementId ).getValue();
1344 },
1345
1346 /**
1347 * Sets the value of a dialog UI element.
1348 *
1349 * dialogObj.setValueOf( 'tabId', 'elementId', 'Example' );
1350 *
1351 * @param {String} pageId id of the dialog page.
1352 * @param {String} elementId id of the UI element.
1353 * @param {Object} value The new value of the UI element.
1354 */
1355 setValueOf: function( pageId, elementId, value ) {
1356 return this.getContentElement( pageId, elementId ).setValue( value );
1357 },
1358
1359 /**
1360 * Gets the UI element of a button in the dialog's button row.
1361 *
1362 * @returns {CKEDITOR.ui.dialog.button} The button object.
1363 *
1364 * @param {String} id The id of the button.
1365 */
1366 getButton: function( id ) {
1367 return this._.buttons[ id ];
1368 },
1369
1370 /**
1371 * Simulates a click to a dialog button in the dialog's button row.
1372 *
1373 * @returns The return value of the dialog's `click` event.
1374 *
1375 * @param {String} id The id of the button.
1376 */
1377 click: function( id ) {
1378 return this._.buttons[ id ].click();
1379 },
1380
1381 /**
1382 * Disables a dialog button.
1383 *
1384 * @param {String} id The id of the button.
1385 */
1386 disableButton: function( id ) {
1387 return this._.buttons[ id ].disable();
1388 },
1389
1390 /**
1391 * Enables a dialog button.
1392 *
1393 * @param {String} id The id of the button.
1394 */
1395 enableButton: function( id ) {
1396 return this._.buttons[ id ].enable();
1397 },
1398
1399 /**
1400 * Gets the number of pages in the dialog.
1401 *
1402 * @returns {Number} Page count.
1403 */
1404 getPageCount: function() {
1405 return this._.pageCount;
1406 },
1407
1408 /**
1409 * Gets the editor instance which opened this dialog.
1410 *
1411 * @returns {CKEDITOR.editor} Parent editor instances.
1412 */
1413 getParentEditor: function() {
1414 return this._.editor;
1415 },
1416
1417 /**
1418 * Gets the element that was selected when opening the dialog, if any.
1419 *
1420 * @returns {CKEDITOR.dom.element} The element that was selected, or `null`.
1421 */
1422 getSelectedElement: function() {
1423 return this.getParentEditor().getSelection().getSelectedElement();
1424 },
1425
1426 /**
1427 * Adds element to dialog's focusable list.
1428 *
1429 * @param {CKEDITOR.dom.element} element
1430 * @param {Number} [index]
1431 */
1432 addFocusable: function( element, index ) {
1433 if ( typeof index == 'undefined' ) {
1434 index = this._.focusList.length;
1435 this._.focusList.push( new Focusable( this, element, index ) );
1436 } else {
1437 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );
1438 for ( var i = index + 1; i < this._.focusList.length; i++ )
1439 this._.focusList[ i ].focusIndex++;
1440 }
1441 },
1442
1443 /**
1444 * Sets the dialog {@link #property-state}.
1445 *
1446 * @since 4.5
1447 * @param {Number} state Either {@link CKEDITOR#DIALOG_STATE_IDLE} or {@link CKEDITOR#DIALOG_STATE_BUSY}.
1448 */
1449 setState: function( state ) {
1450 var oldState = this.state;
1451
1452 if ( oldState == state ) {
1453 return;
1454 }
1455
1456 this.state = state;
1457
1458 if ( state == CKEDITOR.DIALOG_STATE_BUSY ) {
1459 // Insert the spinner on demand.
1460 if ( !this.parts.spinner ) {
1461 var dir = this.getParentEditor().lang.dir,
1462 spinnerDef = {
1463 attributes: {
1464 'class': 'cke_dialog_spinner'
1465 },
1466 styles: {
1467 'float': dir == 'rtl' ? 'right' : 'left'
1468 }
1469 };
1470
1471 spinnerDef.styles[ 'margin-' + ( dir == 'rtl' ? 'left' : 'right' ) ] = '8px';
1472
1473 this.parts.spinner = CKEDITOR.document.createElement( 'div', spinnerDef );
1474
1475 this.parts.spinner.setHtml( '&#8987;' );
1476 this.parts.spinner.appendTo( this.parts.title, 1 );
1477 }
1478
1479 // Finally, show the spinner.
1480 this.parts.spinner.show();
1481
1482 this.getButton( 'ok' ).disable();
1483 } else if ( state == CKEDITOR.DIALOG_STATE_IDLE ) {
1484 // Hide the spinner. But don't do anything if there is no spinner yet.
1485 this.parts.spinner && this.parts.spinner.hide();
1486
1487 this.getButton( 'ok' ).enable();
1488 }
1489
1490 this.fire( 'state', state );
1491 }
1492 };
1493
1494 CKEDITOR.tools.extend( CKEDITOR.dialog, {
1495 /**
1496 * Registers a dialog.
1497 *
1498 * // Full sample plugin, which does not only register a dialog window but also adds an item to the context menu.
1499 * // To open the dialog window, choose "Open dialog" in the context menu.
1500 * CKEDITOR.plugins.add( 'myplugin', {
1501 * init: function( editor ) {
1502 * editor.addCommand( 'mydialog',new CKEDITOR.dialogCommand( 'mydialog' ) );
1503 *
1504 * if ( editor.contextMenu ) {
1505 * editor.addMenuGroup( 'mygroup', 10 );
1506 * editor.addMenuItem( 'My Dialog', {
1507 * label: 'Open dialog',
1508 * command: 'mydialog',
1509 * group: 'mygroup'
1510 * } );
1511 * editor.contextMenu.addListener( function( element ) {
1512 * return { 'My Dialog': CKEDITOR.TRISTATE_OFF };
1513 * } );
1514 * }
1515 *
1516 * CKEDITOR.dialog.add( 'mydialog', function( api ) {
1517 * // CKEDITOR.dialog.definition
1518 * var dialogDefinition = {
1519 * title: 'Sample dialog',
1520 * minWidth: 390,
1521 * minHeight: 130,
1522 * contents: [
1523 * {
1524 * id: 'tab1',
1525 * label: 'Label',
1526 * title: 'Title',
1527 * expand: true,
1528 * padding: 0,
1529 * elements: [
1530 * {
1531 * type: 'html',
1532 * html: '<p>This is some sample HTML content.</p>'
1533 * },
1534 * {
1535 * type: 'textarea',
1536 * id: 'textareaId',
1537 * rows: 4,
1538 * cols: 40
1539 * }
1540 * ]
1541 * }
1542 * ],
1543 * buttons: [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ],
1544 * onOk: function() {
1545 * // "this" is now a CKEDITOR.dialog object.
1546 * // Accessing dialog elements:
1547 * var textareaObj = this.getContentElement( 'tab1', 'textareaId' );
1548 * alert( "You have entered: " + textareaObj.getValue() );
1549 * }
1550 * };
1551 *
1552 * return dialogDefinition;
1553 * } );
1554 * }
1555 * } );
1556 *
1557 * CKEDITOR.replace( 'editor1', { extraPlugins: 'myplugin' } );
1558 *
1559 * @static
1560 * @param {String} name The dialog's name.
1561 * @param {Function/String} dialogDefinition
1562 * A function returning the dialog's definition, or the URL to the `.js` file holding the function.
1563 * The function should accept an argument `editor` which is the current editor instance, and
1564 * return an object conforming to {@link CKEDITOR.dialog.definition}.
1565 * @see CKEDITOR.dialog.definition
1566 */
1567 add: function( name, dialogDefinition ) {
1568 // Avoid path registration from multiple instances override definition.
1569 if ( !this._.dialogDefinitions[ name ] || typeof dialogDefinition == 'function' )
1570 this._.dialogDefinitions[ name ] = dialogDefinition;
1571 },
1572
1573 /**
1574 * @static
1575 * @todo
1576 */
1577 exists: function( name ) {
1578 return !!this._.dialogDefinitions[ name ];
1579 },
1580
1581 /**
1582 * @static
1583 * @todo
1584 */
1585 getCurrent: function() {
1586 return CKEDITOR.dialog._.currentTop;
1587 },
1588
1589 /**
1590 * Check whether tab wasn't removed by {@link CKEDITOR.config#removeDialogTabs}.
1591 *
1592 * @since 4.1
1593 * @static
1594 * @param {CKEDITOR.editor} editor
1595 * @param {String} dialogName
1596 * @param {String} tabName
1597 * @returns {Boolean}
1598 */
1599 isTabEnabled: function( editor, dialogName, tabName ) {
1600 var cfg = editor.config.removeDialogTabs;
1601
1602 return !( cfg && cfg.match( new RegExp( '(?:^|;)' + dialogName + ':' + tabName + '(?:$|;)', 'i' ) ) );
1603 },
1604
1605 /**
1606 * The default OK button for dialogs. Fires the `ok` event and closes the dialog if the event succeeds.
1607 *
1608 * @static
1609 * @method
1610 */
1611 okButton: ( function() {
1612 var retval = function( editor, override ) {
1613 override = override || {};
1614 return CKEDITOR.tools.extend( {
1615 id: 'ok',
1616 type: 'button',
1617 label: editor.lang.common.ok,
1618 'class': 'cke_dialog_ui_button_ok',
1619 onClick: function( evt ) {
1620 var dialog = evt.data.dialog;
1621 if ( dialog.fire( 'ok', { hide: true } ).hide !== false )
1622 dialog.hide();
1623 }
1624 }, override, true );
1625 };
1626 retval.type = 'button';
1627 retval.override = function( override ) {
1628 return CKEDITOR.tools.extend( function( editor ) {
1629 return retval( editor, override );
1630 }, { type: 'button' }, true );
1631 };
1632 return retval;
1633 } )(),
1634
1635 /**
1636 * The default cancel button for dialogs. Fires the `cancel` event and
1637 * closes the dialog if no UI element value changed.
1638 *
1639 * @static
1640 * @method
1641 */
1642 cancelButton: ( function() {
1643 var retval = function( editor, override ) {
1644 override = override || {};
1645 return CKEDITOR.tools.extend( {
1646 id: 'cancel',
1647 type: 'button',
1648 label: editor.lang.common.cancel,
1649 'class': 'cke_dialog_ui_button_cancel',
1650 onClick: function( evt ) {
1651 var dialog = evt.data.dialog;
1652 if ( dialog.fire( 'cancel', { hide: true } ).hide !== false )
1653 dialog.hide();
1654 }
1655 }, override, true );
1656 };
1657 retval.type = 'button';
1658 retval.override = function( override ) {
1659 return CKEDITOR.tools.extend( function( editor ) {
1660 return retval( editor, override );
1661 }, { type: 'button' }, true );
1662 };
1663 return retval;
1664 } )(),
1665
1666 /**
1667 * Registers a dialog UI element.
1668 *
1669 * @static
1670 * @param {String} typeName The name of the UI element.
1671 * @param {Function} builder The function to build the UI element.
1672 */
1673 addUIElement: function( typeName, builder ) {
1674 this._.uiElementBuilders[ typeName ] = builder;
1675 }
1676 } );
1677
1678 CKEDITOR.dialog._ = {
1679 uiElementBuilders: {},
1680
1681 dialogDefinitions: {},
1682
1683 currentTop: null,
1684
1685 currentZIndex: null
1686 };
1687
1688 // "Inherit" (copy actually) from CKEDITOR.event.
1689 CKEDITOR.event.implementOn( CKEDITOR.dialog );
1690 CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype );
1691
1692 var defaultDialogDefinition = {
1693 resizable: CKEDITOR.DIALOG_RESIZE_BOTH,
1694 minWidth: 600,
1695 minHeight: 400,
1696 buttons: [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
1697 };
1698
1699 // Tool function used to return an item from an array based on its id
1700 // property.
1701 var getById = function( array, id, recurse ) {
1702 for ( var i = 0, item;
1703 ( item = array[ i ] ); i++ ) {
1704 if ( item.id == id )
1705 return item;
1706 if ( recurse && item[ recurse ] ) {
1707 var retval = getById( item[ recurse ], id, recurse );
1708 if ( retval )
1709 return retval;
1710 }
1711 }
1712 return null;
1713 };
1714
1715 // Tool function used to add an item into an array.
1716 var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound ) {
1717 if ( nextSiblingId ) {
1718 for ( var i = 0, item;
1719 ( item = array[ i ] ); i++ ) {
1720 if ( item.id == nextSiblingId ) {
1721 array.splice( i, 0, newItem );
1722 return newItem;
1723 }
1724
1725 if ( recurse && item[ recurse ] ) {
1726 var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
1727 if ( retval )
1728 return retval;
1729 }
1730 }
1731
1732 if ( nullIfNotFound )
1733 return null;
1734 }
1735
1736 array.push( newItem );
1737 return newItem;
1738 };
1739
1740 // Tool function used to remove an item from an array based on its id.
1741 var removeById = function( array, id, recurse ) {
1742 for ( var i = 0, item;
1743 ( item = array[ i ] ); i++ ) {
1744 if ( item.id == id )
1745 return array.splice( i, 1 );
1746 if ( recurse && item[ recurse ] ) {
1747 var retval = removeById( item[ recurse ], id, recurse );
1748 if ( retval )
1749 return retval;
1750 }
1751 }
1752 return null;
1753 };
1754
1755 /**
1756 * This class is not really part of the API. It is the `definition` property value
1757 * passed to `dialogDefinition` event handlers.
1758 *
1759 * CKEDITOR.on( 'dialogDefinition', function( evt ) {
1760 * var definition = evt.data.definition;
1761 * var content = definition.getContents( 'page1' );
1762 * // ...
1763 * } );
1764 *
1765 * @private
1766 * @class CKEDITOR.dialog.definitionObject
1767 * @extends CKEDITOR.dialog.definition
1768 * @constructor Creates a definitionObject class instance.
1769 */
1770 var definitionObject = function( dialog, dialogDefinition ) {
1771 // TODO : Check if needed.
1772 this.dialog = dialog;
1773
1774 // Transform the contents entries in contentObjects.
1775 var contents = dialogDefinition.contents;
1776 for ( var i = 0, content;
1777 ( content = contents[ i ] ); i++ )
1778 contents[ i ] = content && new contentObject( dialog, content );
1779
1780 CKEDITOR.tools.extend( this, dialogDefinition );
1781 };
1782
1783 definitionObject.prototype = {
1784 /**
1785 * Gets a content definition.
1786 *
1787 * @param {String} id The id of the content definition.
1788 * @returns {CKEDITOR.dialog.definition.content} The content definition matching id.
1789 */
1790 getContents: function( id ) {
1791 return getById( this.contents, id );
1792 },
1793
1794 /**
1795 * Gets a button definition.
1796 *
1797 * @param {String} id The id of the button definition.
1798 * @returns {CKEDITOR.dialog.definition.button} The button definition matching id.
1799 */
1800 getButton: function( id ) {
1801 return getById( this.buttons, id );
1802 },
1803
1804 /**
1805 * Adds a content definition object under this dialog definition.
1806 *
1807 * @param {CKEDITOR.dialog.definition.content} contentDefinition The
1808 * content definition.
1809 * @param {String} [nextSiblingId] The id of an existing content
1810 * definition which the new content definition will be inserted
1811 * before. Omit if the new content definition is to be inserted as
1812 * the last item.
1813 * @returns {CKEDITOR.dialog.definition.content} The inserted content definition.
1814 */
1815 addContents: function( contentDefinition, nextSiblingId ) {
1816 return addById( this.contents, contentDefinition, nextSiblingId );
1817 },
1818
1819 /**
1820 * Adds a button definition object under this dialog definition.
1821 *
1822 * @param {CKEDITOR.dialog.definition.button} buttonDefinition The
1823 * button definition.
1824 * @param {String} [nextSiblingId] The id of an existing button
1825 * definition which the new button definition will be inserted
1826 * before. Omit if the new button definition is to be inserted as
1827 * the last item.
1828 * @returns {CKEDITOR.dialog.definition.button} The inserted button definition.
1829 */
1830 addButton: function( buttonDefinition, nextSiblingId ) {
1831 return addById( this.buttons, buttonDefinition, nextSiblingId );
1832 },
1833
1834 /**
1835 * Removes a content definition from this dialog definition.
1836 *
1837 * @param {String} id The id of the content definition to be removed.
1838 * @returns {CKEDITOR.dialog.definition.content} The removed content definition.
1839 */
1840 removeContents: function( id ) {
1841 removeById( this.contents, id );
1842 },
1843
1844 /**
1845 * Removes a button definition from the dialog definition.
1846 *
1847 * @param {String} id The id of the button definition to be removed.
1848 * @returns {CKEDITOR.dialog.definition.button} The removed button definition.
1849 */
1850 removeButton: function( id ) {
1851 removeById( this.buttons, id );
1852 }
1853 };
1854
1855 /**
1856 * This class is not really part of the API. It is the template of the
1857 * objects representing content pages inside the
1858 * CKEDITOR.dialog.definitionObject.
1859 *
1860 * CKEDITOR.on( 'dialogDefinition', function( evt ) {
1861 * var definition = evt.data.definition;
1862 * var content = definition.getContents( 'page1' );
1863 * content.remove( 'textInput1' );
1864 * // ...
1865 * } );
1866 *
1867 * @private
1868 * @class CKEDITOR.dialog.definition.contentObject
1869 * @constructor Creates a contentObject class instance.
1870 */
1871 function contentObject( dialog, contentDefinition ) {
1872 this._ = {
1873 dialog: dialog
1874 };
1875
1876 CKEDITOR.tools.extend( this, contentDefinition );
1877 }
1878
1879 contentObject.prototype = {
1880 /**
1881 * Gets a UI element definition under the content definition.
1882 *
1883 * @param {String} id The id of the UI element definition.
1884 * @returns {CKEDITOR.dialog.definition.uiElement}
1885 */
1886 get: function( id ) {
1887 return getById( this.elements, id, 'children' );
1888 },
1889
1890 /**
1891 * Adds a UI element definition to the content definition.
1892 *
1893 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition The
1894 * UI elemnet definition to be added.
1895 * @param {String} nextSiblingId The id of an existing UI element
1896 * definition which the new UI element definition will be inserted
1897 * before. Omit if the new button definition is to be inserted as
1898 * the last item.
1899 * @returns {CKEDITOR.dialog.definition.uiElement} The element definition inserted.
1900 */
1901 add: function( elementDefinition, nextSiblingId ) {
1902 return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
1903 },
1904
1905 /**
1906 * Removes a UI element definition from the content definition.
1907 *
1908 * @param {String} id The id of the UI element definition to be removed.
1909 * @returns {CKEDITOR.dialog.definition.uiElement} The element definition removed.
1910 */
1911 remove: function( id ) {
1912 removeById( this.elements, id, 'children' );
1913 }
1914 };
1915
1916 function initDragAndDrop( dialog ) {
1917 var lastCoords = null,
1918 abstractDialogCoords = null,
1919 editor = dialog.getParentEditor(),
1920 magnetDistance = editor.config.dialog_magnetDistance,
1921 margins = CKEDITOR.skin.margins || [ 0, 0, 0, 0 ];
1922
1923 if ( typeof magnetDistance == 'undefined' )
1924 magnetDistance = 20;
1925
1926 function mouseMoveHandler( evt ) {
1927 var dialogSize = dialog.getSize(),
1928 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
1929 x = evt.data.$.screenX,
1930 y = evt.data.$.screenY,
1931 dx = x - lastCoords.x,
1932 dy = y - lastCoords.y,
1933 realX, realY;
1934
1935 lastCoords = { x: x, y: y };
1936 abstractDialogCoords.x += dx;
1937 abstractDialogCoords.y += dy;
1938
1939 if ( abstractDialogCoords.x + margins[ 3 ] < magnetDistance )
1940 realX = -margins[ 3 ];
1941 else if ( abstractDialogCoords.x - margins[ 1 ] > viewPaneSize.width - dialogSize.width - magnetDistance )
1942 realX = viewPaneSize.width - dialogSize.width + ( editor.lang.dir == 'rtl' ? 0 : margins[ 1 ] );
1943 else
1944 realX = abstractDialogCoords.x;
1945
1946 if ( abstractDialogCoords.y + margins[ 0 ] < magnetDistance )
1947 realY = -margins[ 0 ];
1948 else if ( abstractDialogCoords.y - margins[ 2 ] > viewPaneSize.height - dialogSize.height - magnetDistance )
1949 realY = viewPaneSize.height - dialogSize.height + margins[ 2 ];
1950 else
1951 realY = abstractDialogCoords.y;
1952
1953 dialog.move( realX, realY, 1 );
1954
1955 evt.data.preventDefault();
1956 }
1957
1958 function mouseUpHandler() {
1959 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
1960 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
1961
1962 if ( CKEDITOR.env.ie6Compat ) {
1963 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
1964 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
1965 coverDoc.removeListener( 'mouseup', mouseUpHandler );
1966 }
1967 }
1968
1969 dialog.parts.title.on( 'mousedown', function( evt ) {
1970 lastCoords = { x: evt.data.$.screenX, y: evt.data.$.screenY };
1971
1972 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
1973 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
1974 abstractDialogCoords = dialog.getPosition();
1975
1976 if ( CKEDITOR.env.ie6Compat ) {
1977 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
1978 coverDoc.on( 'mousemove', mouseMoveHandler );
1979 coverDoc.on( 'mouseup', mouseUpHandler );
1980 }
1981
1982 evt.data.preventDefault();
1983 }, dialog );
1984 }
1985
1986 function initResizeHandles( dialog ) {
1987 var def = dialog.definition,
1988 resizable = def.resizable;
1989
1990 if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE )
1991 return;
1992
1993 var editor = dialog.getParentEditor();
1994 var wrapperWidth, wrapperHeight, viewSize, origin, startSize, dialogCover;
1995
1996 var mouseDownFn = CKEDITOR.tools.addFunction( function( $event ) {
1997 startSize = dialog.getSize();
1998
1999 var content = dialog.parts.contents,
2000 iframeDialog = content.$.getElementsByTagName( 'iframe' ).length;
2001
2002 // Shim to help capturing "mousemove" over iframe.
2003 if ( iframeDialog ) {
2004 dialogCover = CKEDITOR.dom.element.createFromHtml( '<div class="cke_dialog_resize_cover" style="height: 100%; position: absolute; width: 100%;"></div>' );
2005 content.append( dialogCover );
2006 }
2007
2008 // Calculate the offset between content and chrome size.
2009 wrapperHeight = startSize.height - dialog.parts.contents.getSize( 'height', !( CKEDITOR.env.gecko || CKEDITOR.env.ie && CKEDITOR.env.quirks ) );
2010 wrapperWidth = startSize.width - dialog.parts.contents.getSize( 'width', 1 );
2011
2012 origin = { x: $event.screenX, y: $event.screenY };
2013
2014 viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
2015
2016 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
2017 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
2018
2019 if ( CKEDITOR.env.ie6Compat ) {
2020 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
2021 coverDoc.on( 'mousemove', mouseMoveHandler );
2022 coverDoc.on( 'mouseup', mouseUpHandler );
2023 }
2024
2025 $event.preventDefault && $event.preventDefault();
2026 } );
2027
2028 // Prepend the grip to the dialog.
2029 dialog.on( 'load', function() {
2030 var direction = '';
2031 if ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH )
2032 direction = ' cke_resizer_horizontal';
2033 else if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT )
2034 direction = ' cke_resizer_vertical';
2035 var resizer = CKEDITOR.dom.element.createFromHtml(
2036 '<div' +
2037 ' class="cke_resizer' + direction + ' cke_resizer_' + editor.lang.dir + '"' +
2038 ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.common.resize ) + '"' +
2039 ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event )">' +
2040 // BLACK LOWER RIGHT TRIANGLE (ltr)
2041 // BLACK LOWER LEFT TRIANGLE (rtl)
2042 ( editor.lang.dir == 'ltr' ? '\u25E2' : '\u25E3' ) +
2043 '</div>' );
2044 dialog.parts.footer.append( resizer, 1 );
2045 } );
2046 editor.on( 'destroy', function() {
2047 CKEDITOR.tools.removeFunction( mouseDownFn );
2048 } );
2049
2050 function mouseMoveHandler( evt ) {
2051 var rtl = editor.lang.dir == 'rtl',
2052 dx = ( evt.data.$.screenX - origin.x ) * ( rtl ? -1 : 1 ),
2053 dy = evt.data.$.screenY - origin.y,
2054 width = startSize.width,
2055 height = startSize.height,
2056 internalWidth = width + dx * ( dialog._.moved ? 1 : 2 ),
2057 internalHeight = height + dy * ( dialog._.moved ? 1 : 2 ),
2058 element = dialog._.element.getFirst(),
2059 right = rtl && element.getComputedStyle( 'right' ),
2060 position = dialog.getPosition();
2061
2062 if ( position.y + internalHeight > viewSize.height )
2063 internalHeight = viewSize.height - position.y;
2064
2065 if ( ( rtl ? right : position.x ) + internalWidth > viewSize.width )
2066 internalWidth = viewSize.width - ( rtl ? right : position.x );
2067
2068 // Make sure the dialog will not be resized to the wrong side when it's in the leftmost position for RTL.
2069 if ( ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH || resizable == CKEDITOR.DIALOG_RESIZE_BOTH ) )
2070 width = Math.max( def.minWidth || 0, internalWidth - wrapperWidth );
2071
2072 if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT || resizable == CKEDITOR.DIALOG_RESIZE_BOTH )
2073 height = Math.max( def.minHeight || 0, internalHeight - wrapperHeight );
2074
2075 dialog.resize( width, height );
2076
2077 if ( !dialog._.moved )
2078 dialog.layout();
2079
2080 evt.data.preventDefault();
2081 }
2082
2083 function mouseUpHandler() {
2084 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
2085 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
2086
2087 if ( dialogCover ) {
2088 dialogCover.remove();
2089 dialogCover = null;
2090 }
2091
2092 if ( CKEDITOR.env.ie6Compat ) {
2093 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
2094 coverDoc.removeListener( 'mouseup', mouseUpHandler );
2095 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
2096 }
2097 }
2098 }
2099
2100 var resizeCover;
2101 // Caching resuable covers and allowing only one cover
2102 // on screen.
2103 var covers = {},
2104 currentCover;
2105
2106 function cancelEvent( ev ) {
2107 ev.data.preventDefault( 1 );
2108 }
2109
2110 function showCover( editor ) {
2111 var win = CKEDITOR.document.getWindow(),
2112 config = editor.config,
2113 skinName = ( CKEDITOR.skinName || editor.config.skin ),
2114 backgroundColorStyle = config.dialog_backgroundCoverColor || ( skinName == 'moono-lisa' ? 'black' : 'white' ),
2115 backgroundCoverOpacity = config.dialog_backgroundCoverOpacity,
2116 baseFloatZIndex = config.baseFloatZIndex,
2117 coverKey = CKEDITOR.tools.genKey( backgroundColorStyle, backgroundCoverOpacity, baseFloatZIndex ),
2118 coverElement = covers[ coverKey ];
2119
2120 if ( !coverElement ) {
2121 var html = [
2122 '<div tabIndex="-1" style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),
2123 '; z-index: ', baseFloatZIndex,
2124 '; top: 0px; left: 0px; ',
2125 ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),
2126 '" class="cke_dialog_background_cover">'
2127 ];
2128
2129 if ( CKEDITOR.env.ie6Compat ) {
2130 // Support for custom document.domain in IE.
2131 var iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
2132
2133 html.push( '<iframe' +
2134 ' hidefocus="true"' +
2135 ' frameborder="0"' +
2136 ' id="cke_dialog_background_iframe"' +
2137 ' src="javascript:' );
2138
2139 html.push( 'void((function(){' + encodeURIComponent(
2140 'document.open();' +
2141 // Support for custom document.domain in IE.
2142 '(' + CKEDITOR.tools.fixDomain + ')();' +
2143 'document.write( \'' + iframeHtml + '\' );' +
2144 'document.close();'
2145 ) + '})())' );
2146
2147 html.push( '"' +
2148 ' style="' +
2149 'position:absolute;' +
2150 'left:0;' +
2151 'top:0;' +
2152 'width:100%;' +
2153 'height: 100%;' +
2154 'filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
2155 '</iframe>' );
2156 }
2157
2158 html.push( '</div>' );
2159
2160 coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
2161 coverElement.setOpacity( backgroundCoverOpacity !== undefined ? backgroundCoverOpacity : 0.5 );
2162
2163 coverElement.on( 'keydown', cancelEvent );
2164 coverElement.on( 'keypress', cancelEvent );
2165 coverElement.on( 'keyup', cancelEvent );
2166
2167 coverElement.appendTo( CKEDITOR.document.getBody() );
2168 covers[ coverKey ] = coverElement;
2169 } else {
2170 coverElement.show();
2171 }
2172
2173 // Makes the dialog cover a focus holder as well.
2174 editor.focusManager.add( coverElement );
2175
2176 currentCover = coverElement;
2177 var resizeFunc = function() {
2178 var size = win.getViewPaneSize();
2179 coverElement.setStyles( {
2180 width: size.width + 'px',
2181 height: size.height + 'px'
2182 } );
2183 };
2184
2185 var scrollFunc = function() {
2186 var pos = win.getScrollPosition(),
2187 cursor = CKEDITOR.dialog._.currentTop;
2188 coverElement.setStyles( {
2189 left: pos.x + 'px',
2190 top: pos.y + 'px'
2191 } );
2192
2193 if ( cursor ) {
2194 do {
2195 var dialogPos = cursor.getPosition();
2196 cursor.move( dialogPos.x, dialogPos.y );
2197 } while ( ( cursor = cursor._.parentDialog ) );
2198 }
2199 };
2200
2201 resizeCover = resizeFunc;
2202 win.on( 'resize', resizeFunc );
2203 resizeFunc();
2204 // Using Safari/Mac, focus must be kept where it is (http://dev.ckeditor.com/ticket/7027)
2205 if ( !( CKEDITOR.env.mac && CKEDITOR.env.webkit ) )
2206 coverElement.focus();
2207
2208 if ( CKEDITOR.env.ie6Compat ) {
2209 // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
2210 // So we need to invent a really funny way to make it work.
2211 var myScrollHandler = function() {
2212 scrollFunc();
2213 arguments.callee.prevScrollHandler.apply( this, arguments );
2214 };
2215 win.$.setTimeout( function() {
2216 myScrollHandler.prevScrollHandler = window.onscroll ||
2217 function() {};
2218 window.onscroll = myScrollHandler;
2219 }, 0 );
2220 scrollFunc();
2221 }
2222 }
2223
2224 function hideCover( editor ) {
2225 if ( !currentCover )
2226 return;
2227
2228 editor.focusManager.remove( currentCover );
2229 var win = CKEDITOR.document.getWindow();
2230 currentCover.hide();
2231 win.removeListener( 'resize', resizeCover );
2232
2233 if ( CKEDITOR.env.ie6Compat ) {
2234 win.$.setTimeout( function() {
2235 var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
2236 window.onscroll = prevScrollHandler || null;
2237 }, 0 );
2238 }
2239 resizeCover = null;
2240 }
2241
2242 function removeCovers() {
2243 for ( var coverId in covers )
2244 covers[ coverId ].remove();
2245 covers = {};
2246 }
2247
2248 var accessKeyProcessors = {};
2249
2250 var accessKeyDownHandler = function( evt ) {
2251 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
2252 alt = evt.data.$.altKey,
2253 shift = evt.data.$.shiftKey,
2254 key = String.fromCharCode( evt.data.$.keyCode ),
2255 keyProcessor = accessKeyProcessors[ ( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '' ) + ( shift ? 'SHIFT+' : '' ) + key ];
2256
2257 if ( !keyProcessor || !keyProcessor.length )
2258 return;
2259
2260 keyProcessor = keyProcessor[ keyProcessor.length - 1 ];
2261 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
2262 evt.data.preventDefault();
2263 };
2264
2265 var accessKeyUpHandler = function( evt ) {
2266 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
2267 alt = evt.data.$.altKey,
2268 shift = evt.data.$.shiftKey,
2269 key = String.fromCharCode( evt.data.$.keyCode ),
2270 keyProcessor = accessKeyProcessors[ ( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '' ) + ( shift ? 'SHIFT+' : '' ) + key ];
2271
2272 if ( !keyProcessor || !keyProcessor.length )
2273 return;
2274
2275 keyProcessor = keyProcessor[ keyProcessor.length - 1 ];
2276 if ( keyProcessor.keyup ) {
2277 keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
2278 evt.data.preventDefault();
2279 }
2280 };
2281
2282 var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc ) {
2283 var procList = accessKeyProcessors[ key ] || ( accessKeyProcessors[ key ] = [] );
2284 procList.push( {
2285 uiElement: uiElement,
2286 dialog: dialog,
2287 key: key,
2288 keyup: upFunc || uiElement.accessKeyUp,
2289 keydown: downFunc || uiElement.accessKeyDown
2290 } );
2291 };
2292
2293 var unregisterAccessKey = function( obj ) {
2294 for ( var i in accessKeyProcessors ) {
2295 var list = accessKeyProcessors[ i ];
2296 for ( var j = list.length - 1; j >= 0; j-- ) {
2297 if ( list[ j ].dialog == obj || list[ j ].uiElement == obj )
2298 list.splice( j, 1 );
2299 }
2300 if ( list.length === 0 )
2301 delete accessKeyProcessors[ i ];
2302 }
2303 };
2304
2305 var tabAccessKeyUp = function( dialog, key ) {
2306 if ( dialog._.accessKeyMap[ key ] )
2307 dialog.selectPage( dialog._.accessKeyMap[ key ] );
2308 };
2309
2310 var tabAccessKeyDown = function() {};
2311
2312 ( function() {
2313 CKEDITOR.ui.dialog = {
2314 /**
2315 * The base class of all dialog UI elements.
2316 *
2317 * @class CKEDITOR.ui.dialog.uiElement
2318 * @constructor Creates a uiElement class instance.
2319 * @param {CKEDITOR.dialog} dialog Parent dialog object.
2320 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition Element
2321 * definition.
2322 *
2323 * Accepted fields:
2324 *
2325 * * `id` (Required) The id of the UI element. See {@link CKEDITOR.dialog#getContentElement}.
2326 * * `type` (Required) The type of the UI element. The
2327 * value to this field specifies which UI element class will be used to
2328 * generate the final widget.
2329 * * `title` (Optional) The popup tooltip for the UI
2330 * element.
2331 * * `hidden` (Optional) A flag that tells if the element
2332 * should be initially visible.
2333 * * `className` (Optional) Additional CSS class names
2334 * to add to the UI element. Separated by space.
2335 * * `style` (Optional) Additional CSS inline styles
2336 * to add to the UI element. A semicolon (;) is required after the last
2337 * style declaration.
2338 * * `accessKey` (Optional) The alphanumeric access key
2339 * for this element. Access keys are automatically prefixed by CTRL.
2340 * * `on*` (Optional) Any UI element definition field that
2341 * starts with `on` followed immediately by a capital letter and
2342 * probably more letters is an event handler. Event handlers may be further
2343 * divided into registered event handlers and DOM event handlers. Please
2344 * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and
2345 * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more information.
2346 *
2347 * @param {Array} htmlList
2348 * List of HTML code to be added to the dialog's content area.
2349 * @param {Function/String} [nodeNameArg='div']
2350 * A function returning a string, or a simple string for the node name for
2351 * the root DOM node.
2352 * @param {Function/Object} [stylesArg={}]
2353 * A function returning an object, or a simple object for CSS styles applied
2354 * to the DOM node.
2355 * @param {Function/Object} [attributesArg={}]
2356 * A fucntion returning an object, or a simple object for attributes applied
2357 * to the DOM node.
2358 * @param {Function/String} [contentsArg='']
2359 * A function returning a string, or a simple string for the HTML code inside
2360 * the root DOM node. Default is empty string.
2361 */
2362 uiElement: function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg ) {
2363 if ( arguments.length < 4 )
2364 return;
2365
2366 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',
2367 html = [ '<', nodeName, ' ' ],
2368 styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},
2369 attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},
2370 innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',
2371 domId = this.domId = attributes.id || CKEDITOR.tools.getNextId() + '_uiElement',
2372 i;
2373
2374 if ( elementDefinition.requiredContent && !dialog.getParentEditor().filter.check( elementDefinition.requiredContent ) ) {
2375 styles.display = 'none';
2376 this.notAllowed = true;
2377 }
2378
2379 // Set the id, a unique id is required for getElement() to work.
2380 attributes.id = domId;
2381
2382 // Set the type and definition CSS class names.
2383 var classes = {};
2384 if ( elementDefinition.type )
2385 classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;
2386 if ( elementDefinition.className )
2387 classes[ elementDefinition.className ] = 1;
2388 if ( elementDefinition.disabled )
2389 classes.cke_disabled = 1;
2390
2391 var attributeClasses = ( attributes[ 'class' ] && attributes[ 'class' ].split ) ? attributes[ 'class' ].split( ' ' ) : [];
2392 for ( i = 0; i < attributeClasses.length; i++ ) {
2393 if ( attributeClasses[ i ] )
2394 classes[ attributeClasses[ i ] ] = 1;
2395 }
2396 var finalClasses = [];
2397 for ( i in classes )
2398 finalClasses.push( i );
2399 attributes[ 'class' ] = finalClasses.join( ' ' );
2400
2401 // Set the popup tooltop.
2402 if ( elementDefinition.title )
2403 attributes.title = elementDefinition.title;
2404
2405 // Write the inline CSS styles.
2406 var styleStr = ( elementDefinition.style || '' ).split( ';' );
2407
2408 // Element alignment support.
2409 if ( elementDefinition.align ) {
2410 var align = elementDefinition.align;
2411 styles[ 'margin-left' ] = align == 'left' ? 0 : 'auto';
2412 styles[ 'margin-right' ] = align == 'right' ? 0 : 'auto';
2413 }
2414
2415 for ( i in styles )
2416 styleStr.push( i + ':' + styles[ i ] );
2417 if ( elementDefinition.hidden )
2418 styleStr.push( 'display:none' );
2419 for ( i = styleStr.length - 1; i >= 0; i-- ) {
2420 if ( styleStr[ i ] === '' )
2421 styleStr.splice( i, 1 );
2422 }
2423 if ( styleStr.length > 0 )
2424 attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
2425
2426 // Write the attributes.
2427 for ( i in attributes )
2428 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[ i ] ) + '" ' );
2429
2430 // Write the content HTML.
2431 html.push( '>', innerHTML, '</', nodeName, '>' );
2432
2433 // Add contents to the parent HTML array.
2434 htmlList.push( html.join( '' ) );
2435
2436 ( this._ || ( this._ = {} ) ).dialog = dialog;
2437
2438 // Override isChanged if it is defined in element definition.
2439 if ( typeof elementDefinition.isChanged == 'boolean' )
2440 this.isChanged = function() {
2441 return elementDefinition.isChanged;
2442 };
2443 if ( typeof elementDefinition.isChanged == 'function' )
2444 this.isChanged = elementDefinition.isChanged;
2445
2446 // Overload 'get(set)Value' on definition.
2447 if ( typeof elementDefinition.setValue == 'function' ) {
2448 this.setValue = CKEDITOR.tools.override( this.setValue, function( org ) {
2449 return function( val ) {
2450 org.call( this, elementDefinition.setValue.call( this, val ) );
2451 };
2452 } );
2453 }
2454
2455 if ( typeof elementDefinition.getValue == 'function' ) {
2456 this.getValue = CKEDITOR.tools.override( this.getValue, function( org ) {
2457 return function() {
2458 return elementDefinition.getValue.call( this, org.call( this ) );
2459 };
2460 } );
2461 }
2462
2463 // Add events.
2464 CKEDITOR.event.implementOn( this );
2465
2466 this.registerEvents( elementDefinition );
2467 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
2468 registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
2469
2470 var me = this;
2471 dialog.on( 'load', function() {
2472 var input = me.getInputElement();
2473 if ( input ) {
2474 var focusClass = me.type in { 'checkbox': 1, 'ratio': 1 } && CKEDITOR.env.ie && CKEDITOR.env.version < 8 ? 'cke_dialog_ui_focused' : '';
2475 input.on( 'focus', function() {
2476 dialog._.tabBarMode = false;
2477 dialog._.hasFocus = true;
2478 me.fire( 'focus' );
2479 focusClass && this.addClass( focusClass );
2480
2481 } );
2482
2483 input.on( 'blur', function() {
2484 me.fire( 'blur' );
2485 focusClass && this.removeClass( focusClass );
2486 } );
2487 }
2488 } );
2489
2490 // Completes this object with everything we have in the
2491 // definition.
2492 CKEDITOR.tools.extend( this, elementDefinition );
2493
2494 // Register the object as a tab focus if it can be included.
2495 if ( this.keyboardFocusable ) {
2496 this.tabIndex = elementDefinition.tabIndex || 0;
2497
2498 this.focusIndex = dialog._.focusList.push( this ) - 1;
2499 this.on( 'focus', function() {
2500 dialog._.currentFocusIndex = me.focusIndex;
2501 } );
2502 }
2503 },
2504
2505 /**
2506 * Horizontal layout box for dialog UI elements, auto-expends to available width of container.
2507 *
2508 * @class CKEDITOR.ui.dialog.hbox
2509 * @extends CKEDITOR.ui.dialog.uiElement
2510 * @constructor Creates a hbox class instance.
2511 * @param {CKEDITOR.dialog} dialog Parent dialog object.
2512 * @param {Array} childObjList
2513 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this container.
2514 * @param {Array} childHtmlList
2515 * Array of HTML code that correspond to the HTML output of all the
2516 * objects in childObjList.
2517 * @param {Array} htmlList
2518 * Array of HTML code that this element will output to.
2519 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
2520 * The element definition. Accepted fields:
2521 *
2522 * * `widths` (Optional) The widths of child cells.
2523 * * `height` (Optional) The height of the layout.
2524 * * `padding` (Optional) The padding width inside child cells.
2525 * * `align` (Optional) The alignment of the whole layout.
2526 */
2527 hbox: function( dialog, childObjList, childHtmlList, htmlList, elementDefinition ) {
2528 if ( arguments.length < 4 )
2529 return;
2530
2531 this._ || ( this._ = {} );
2532
2533 var children = this._.children = childObjList,
2534 widths = elementDefinition && elementDefinition.widths || null,
2535 height = elementDefinition && elementDefinition.height || null,
2536 styles = {},
2537 i;
2538 /** @ignore */
2539 var innerHTML = function() {
2540 var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];
2541 for ( i = 0; i < childHtmlList.length; i++ ) {
2542 var className = 'cke_dialog_ui_hbox_child',
2543 styles = [];
2544 if ( i === 0 ) {
2545 className = 'cke_dialog_ui_hbox_first';
2546 }
2547 if ( i == childHtmlList.length - 1 ) {
2548 className = 'cke_dialog_ui_hbox_last';
2549 }
2550
2551 html.push( '<td class="', className, '" role="presentation" ' );
2552 if ( widths ) {
2553 if ( widths[ i ] ) {
2554 styles.push( 'width:' + cssLength( widths[i] ) );
2555 }
2556 } else {
2557 styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
2558 }
2559 if ( height ) {
2560 styles.push( 'height:' + cssLength( height ) );
2561 }
2562 if ( elementDefinition && elementDefinition.padding !== undefined ) {
2563 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
2564 }
2565 // In IE Quirks alignment has to be done on table cells. (http://dev.ckeditor.com/ticket/7324)
2566 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && children[ i ].align ) {
2567 styles.push( 'text-align:' + children[ i ].align );
2568 }
2569 if ( styles.length > 0 ) {
2570 html.push( 'style="' + styles.join( '; ' ) + '" ' );
2571 }
2572 html.push( '>', childHtmlList[ i ], '</td>' );
2573 }
2574 html.push( '</tr></tbody>' );
2575 return html.join( '' );
2576 };
2577
2578 var attribs = { role: 'presentation' };
2579 elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );
2580
2581 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type: 'hbox' }, htmlList, 'table', styles, attribs, innerHTML );
2582 },
2583
2584 /**
2585 * Vertical layout box for dialog UI elements.
2586 *
2587 * @class CKEDITOR.ui.dialog.vbox
2588 * @extends CKEDITOR.ui.dialog.hbox
2589 * @constructor Creates a vbox class instance.
2590 * @param {CKEDITOR.dialog} dialog Parent dialog object.
2591 * @param {Array} childObjList
2592 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this container.
2593 * @param {Array} childHtmlList
2594 * Array of HTML code that correspond to the HTML output of all the
2595 * objects in childObjList.
2596 * @param {Array} htmlList Array of HTML code that this element will output to.
2597 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
2598 * The element definition. Accepted fields:
2599 *
2600 * * `width` (Optional) The width of the layout.
2601 * * `heights` (Optional) The heights of individual cells.
2602 * * `align` (Optional) The alignment of the layout.
2603 * * `padding` (Optional) The padding width inside child cells.
2604 * * `expand` (Optional) Whether the layout should expand
2605 * vertically to fill its container.
2606 */
2607 vbox: function( dialog, childObjList, childHtmlList, htmlList, elementDefinition ) {
2608 if ( arguments.length < 3 )
2609 return;
2610
2611 this._ || ( this._ = {} );
2612
2613 var children = this._.children = childObjList,
2614 width = elementDefinition && elementDefinition.width || null,
2615 heights = elementDefinition && elementDefinition.heights || null;
2616 /** @ignore */
2617 var innerHTML = function() {
2618 var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];
2619 html.push( 'style="' );
2620 if ( elementDefinition && elementDefinition.expand )
2621 html.push( 'height:100%;' );
2622 html.push( 'width:' + cssLength( width || '100%' ), ';' );
2623
2624 // (http://dev.ckeditor.com/ticket/10123) Temp fix for dialog broken layout in latest webkit.
2625 if ( CKEDITOR.env.webkit )
2626 html.push( 'float:none;' );
2627
2628 html.push( '"' );
2629 html.push( 'align="', CKEDITOR.tools.htmlEncode(
2630 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
2631
2632 html.push( '><tbody>' );
2633 for ( var i = 0; i < childHtmlList.length; i++ ) {
2634 var styles = [];
2635 html.push( '<tr><td role="presentation" ' );
2636 if ( width )
2637 styles.push( 'width:' + cssLength( width || '100%' ) );
2638 if ( heights )
2639 styles.push( 'height:' + cssLength( heights[ i ] ) );
2640 else if ( elementDefinition && elementDefinition.expand )
2641 styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
2642 if ( elementDefinition && elementDefinition.padding !== undefined )
2643 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
2644 // In IE Quirks alignment has to be done on table cells. (http://dev.ckeditor.com/ticket/7324)
2645 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && children[ i ].align )
2646 styles.push( 'text-align:' + children[ i ].align );
2647 if ( styles.length > 0 )
2648 html.push( 'style="', styles.join( '; ' ), '" ' );
2649 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[ i ], '</td></tr>' );
2650 }
2651 html.push( '</tbody></table>' );
2652 return html.join( '' );
2653 };
2654 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type: 'vbox' }, htmlList, 'div', null, { role: 'presentation' }, innerHTML );
2655 }
2656 };
2657 } )();
2658
2659 /** @class CKEDITOR.ui.dialog.uiElement */
2660 CKEDITOR.ui.dialog.uiElement.prototype = {
2661 /**
2662 * Gets the root DOM element of this dialog UI object.
2663 *
2664 * uiElement.getElement().hide();
2665 *
2666 * @returns {CKEDITOR.dom.element} Root DOM element of UI object.
2667 */
2668 getElement: function() {
2669 return CKEDITOR.document.getById( this.domId );
2670 },
2671
2672 /**
2673 * Gets the DOM element that the user inputs values.
2674 *
2675 * This function is used by {@link #setValue}, {@link #getValue} and {@link #focus}. It should
2676 * be overrided in child classes where the input element isn't the root
2677 * element.
2678 *
2679 * var rawValue = textInput.getInputElement().$.value;
2680 *
2681 * @returns {CKEDITOR.dom.element} The element where the user input values.
2682 */
2683 getInputElement: function() {
2684 return this.getElement();
2685 },
2686
2687 /**
2688 * Gets the parent dialog object containing this UI element.
2689 *
2690 * var dialog = uiElement.getDialog();
2691 *
2692 * @returns {CKEDITOR.dialog} Parent dialog object.
2693 */
2694 getDialog: function() {
2695 return this._.dialog;
2696 },
2697
2698 /**
2699 * Sets the value of this dialog UI object.
2700 *
2701 * uiElement.setValue( 'Dingo' );
2702 *
2703 * @chainable
2704 * @param {Object} value The new value.
2705 * @param {Boolean} noChangeEvent Internal commit, to supress `change` event on this element.
2706 */
2707 setValue: function( value, noChangeEvent ) {
2708 this.getInputElement().setValue( value );
2709 !noChangeEvent && this.fire( 'change', { value: value } );
2710 return this;
2711 },
2712
2713 /**
2714 * Gets the current value of this dialog UI object.
2715 *
2716 * var myValue = uiElement.getValue();
2717 *
2718 * @returns {Object} The current value.
2719 */
2720 getValue: function() {
2721 return this.getInputElement().getValue();
2722 },
2723
2724 /**
2725 * Tells whether the UI object's value has changed.
2726 *
2727 * if ( uiElement.isChanged() )
2728 * confirm( 'Value changed! Continue?' );
2729 *
2730 * @returns {Boolean} `true` if changed, `false` if not changed.
2731 */
2732 isChanged: function() {
2733 // Override in input classes.
2734 return false;
2735 },
2736
2737 /**
2738 * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
2739 *
2740 * focus : function() {
2741 * this.selectParentTab();
2742 * // do something else.
2743 * }
2744 *
2745 * @chainable
2746 */
2747 selectParentTab: function() {
2748 var element = this.getInputElement(),
2749 cursor = element,
2750 tabId;
2751 while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 ) {
2752
2753 }
2754
2755 // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
2756 if ( !cursor )
2757 return this;
2758
2759 tabId = cursor.getAttribute( 'name' );
2760 // Avoid duplicate select.
2761 if ( this._.dialog._.currentTabId != tabId )
2762 this._.dialog.selectPage( tabId );
2763 return this;
2764 },
2765
2766 /**
2767 * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
2768 *
2769 * uiElement.focus();
2770 *
2771 * @chainable
2772 */
2773 focus: function() {
2774 this.selectParentTab().getInputElement().focus();
2775 return this;
2776 },
2777
2778 /**
2779 * Registers the `on*` event handlers defined in the element definition.
2780 *
2781 * The default behavior of this function is:
2782 *
2783 * 1. If the on* event is defined in the class's eventProcesors list,
2784 * then the registration is delegated to the corresponding function
2785 * in the eventProcessors list.
2786 * 2. If the on* event is not defined in the eventProcessors list, then
2787 * register the event handler under the corresponding DOM event of
2788 * the UI element's input DOM element (as defined by the return value
2789 * of {@link #getInputElement}).
2790 *
2791 * This function is only called at UI element instantiation, but can
2792 * be overridded in child classes if they require more flexibility.
2793 *
2794 * @chainable
2795 * @param {CKEDITOR.dialog.definition.uiElement} definition The UI element
2796 * definition.
2797 */
2798 registerEvents: function( definition ) {
2799 var regex = /^on([A-Z]\w+)/,
2800 match;
2801
2802 var registerDomEvent = function( uiElement, dialog, eventName, func ) {
2803 dialog.on( 'load', function() {
2804 uiElement.getInputElement().on( eventName, func, uiElement );
2805 } );
2806 };
2807
2808 for ( var i in definition ) {
2809 if ( !( match = i.match( regex ) ) )
2810 continue;
2811 if ( this.eventProcessors[ i ] )
2812 this.eventProcessors[ i ].call( this, this._.dialog, definition[ i ] );
2813 else
2814 registerDomEvent( this, this._.dialog, match[ 1 ].toLowerCase(), definition[ i ] );
2815 }
2816
2817 return this;
2818 },
2819
2820 /**
2821 * The event processor list used by
2822 * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element
2823 * instantiation. The default list defines three `on*` events:
2824 *
2825 * 1. `onLoad` - Called when the element's parent dialog opens for the
2826 * first time.
2827 * 2. `onShow` - Called whenever the element's parent dialog opens.
2828 * 3. `onHide` - Called whenever the element's parent dialog closes.
2829 *
2830 * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick
2831 * // handlers in the UI element's definitions.
2832 * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},
2833 * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
2834 * { onClick : function( dialog, func ) { this.on( 'click', func ); } },
2835 * true
2836 * );
2837 *
2838 * @property {Object}
2839 */
2840 eventProcessors: {
2841 onLoad: function( dialog, func ) {
2842 dialog.on( 'load', func, this );
2843 },
2844
2845 onShow: function( dialog, func ) {
2846 dialog.on( 'show', func, this );
2847 },
2848
2849 onHide: function( dialog, func ) {
2850 dialog.on( 'hide', func, this );
2851 }
2852 },
2853
2854 /**
2855 * The default handler for a UI element's access key down event, which
2856 * tries to put focus to the UI element.
2857 *
2858 * Can be overridded in child classes for more sophisticaed behavior.
2859 *
2860 * @param {CKEDITOR.dialog} dialog The parent dialog object.
2861 * @param {String} key The key combination pressed. Since access keys
2862 * are defined to always include the `CTRL` key, its value should always
2863 * include a `'CTRL+'` prefix.
2864 */
2865 accessKeyDown: function() {
2866 this.focus();
2867 },
2868
2869 /**
2870 * The default handler for a UI element's access key up event, which
2871 * does nothing.
2872 *
2873 * Can be overridded in child classes for more sophisticated behavior.
2874 *
2875 * @param {CKEDITOR.dialog} dialog The parent dialog object.
2876 * @param {String} key The key combination pressed. Since access keys
2877 * are defined to always include the `CTRL` key, its value should always
2878 * include a `'CTRL+'` prefix.
2879 */
2880 accessKeyUp: function() {},
2881
2882 /**
2883 * Disables a UI element.
2884 */
2885 disable: function() {
2886 var element = this.getElement(),
2887 input = this.getInputElement();
2888 input.setAttribute( 'disabled', 'true' );
2889 element.addClass( 'cke_disabled' );
2890 },
2891
2892 /**
2893 * Enables a UI element.
2894 */
2895 enable: function() {
2896 var element = this.getElement(),
2897 input = this.getInputElement();
2898 input.removeAttribute( 'disabled' );
2899 element.removeClass( 'cke_disabled' );
2900 },
2901
2902 /**
2903 * Determines whether an UI element is enabled or not.
2904 *
2905 * @returns {Boolean} Whether the UI element is enabled.
2906 */
2907 isEnabled: function() {
2908 return !this.getElement().hasClass( 'cke_disabled' );
2909 },
2910
2911 /**
2912 * Determines whether an UI element is visible or not.
2913 *
2914 * @returns {Boolean} Whether the UI element is visible.
2915 */
2916 isVisible: function() {
2917 return this.getInputElement().isVisible();
2918 },
2919
2920 /**
2921 * Determines whether an UI element is focus-able or not.
2922 * Focus-able is defined as being both visible and enabled.
2923 *
2924 * @returns {Boolean} Whether the UI element can be focused.
2925 */
2926 isFocusable: function() {
2927 if ( !this.isEnabled() || !this.isVisible() )
2928 return false;
2929 return true;
2930 }
2931 };
2932
2933 /** @class CKEDITOR.ui.dialog.hbox */
2934 CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement(), {
2935 /**
2936 * Gets a child UI element inside this container.
2937 *
2938 * var checkbox = hbox.getChild( [0,1] );
2939 * checkbox.setValue( true );
2940 *
2941 * @param {Array/Number} indices An array or a single number to indicate the child's
2942 * position in the container's descendant tree. Omit to get all the children in an array.
2943 * @returns {Array/CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container
2944 * if no argument given, or the specified UI element if indices is given.
2945 */
2946 getChild: function( indices ) {
2947 // If no arguments, return a clone of the children array.
2948 if ( arguments.length < 1 )
2949 return this._.children.concat();
2950
2951 // If indices isn't array, make it one.
2952 if ( !indices.splice )
2953 indices = [ indices ];
2954
2955 // Retrieve the child element according to tree position.
2956 if ( indices.length < 2 )
2957 return this._.children[ indices[ 0 ] ];
2958 else
2959 return ( this._.children[ indices[ 0 ] ] && this._.children[ indices[ 0 ] ].getChild ) ? this._.children[ indices[ 0 ] ].getChild( indices.slice( 1, indices.length ) ) : null;
2960 }
2961 }, true );
2962
2963 CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
2964
2965 ( function() {
2966 var commonBuilder = {
2967 build: function( dialog, elementDefinition, output ) {
2968 var children = elementDefinition.children,
2969 child,
2970 childHtmlList = [],
2971 childObjList = [];
2972 for ( var i = 0;
2973 ( i < children.length && ( child = children[ i ] ) ); i++ ) {
2974 var childHtml = [];
2975 childHtmlList.push( childHtml );
2976 childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
2977 }
2978 return new CKEDITOR.ui.dialog[ elementDefinition.type ]( dialog, childObjList, childHtmlList, output, elementDefinition );
2979 }
2980 };
2981
2982 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
2983 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
2984 } )();
2985
2986 /**
2987 * Generic dialog command. It opens a specific dialog when executed.
2988 *
2989 * // Register the "link" command which opens the "link" dialog.
2990 * editor.addCommand( 'link', new CKEDITOR.dialogCommand( 'link' ) );
2991 *
2992 * @class
2993 * @constructor Creates a dialogCommand class instance.
2994 * @extends CKEDITOR.commandDefinition
2995 * @param {String} dialogName The name of the dialog to open when executing
2996 * this command.
2997 * @param {Object} [ext] Additional command definition's properties.
2998 * @param {String} [ext.tabId] You can provide additional property (`tabId`) if you wish to open the dialog on a specific tabId.
2999 *
3000 * // Open the dialog on the 'keystroke' tabId.
3001 * editor.addCommand( 'keystroke', new CKEDITOR.dialogCommand( 'a11yHelp', { tabId: 'keystroke' } ) );
3002 */
3003 CKEDITOR.dialogCommand = function( dialogName, ext ) {
3004 this.dialogName = dialogName;
3005 CKEDITOR.tools.extend( this, ext, true );
3006 };
3007
3008 CKEDITOR.dialogCommand.prototype = {
3009 exec: function( editor ) {
3010 var tabId = this.tabId;
3011 editor.openDialog( this.dialogName, function( dialog ) {
3012 // Select different tab if it's provided (#830).
3013 if ( tabId ) {
3014 dialog.selectPage( tabId );
3015 }
3016 } );
3017 },
3018
3019 // Dialog commands just open a dialog ui, thus require no undo logic,
3020 // undo support should dedicate to specific dialog implementation.
3021 canUndo: false,
3022
3023 editorFocus: 1
3024 };
3025
3026 ( function() {
3027 var notEmptyRegex = /^([a]|[^a])+$/,
3028 integerRegex = /^\d*$/,
3029 numberRegex = /^\d*(?:\.\d+)?$/,
3030 htmlLengthRegex = /^(((\d*(\.\d+))|(\d*))(px|\%)?)?$/,
3031 cssLengthRegex = /^(((\d*(\.\d+))|(\d*))(px|em|ex|in|cm|mm|pt|pc|\%)?)?$/i,
3032 inlineStyleRegex = /^(\s*[\w-]+\s*:\s*[^:;]+(?:;|$))*$/;
3033
3034 CKEDITOR.VALIDATE_OR = 1;
3035 CKEDITOR.VALIDATE_AND = 2;
3036
3037 CKEDITOR.dialog.validate = {
3038 functions: function() {
3039 var args = arguments;
3040 return function() {
3041 /**
3042 * It's important for validate functions to be able to accept the value
3043 * as argument in addition to this.getValue(), so that it is possible to
3044 * combine validate functions together to make more sophisticated
3045 * validators.
3046 */
3047 var value = this && this.getValue ? this.getValue() : args[ 0 ];
3048
3049 var msg,
3050 relation = CKEDITOR.VALIDATE_AND,
3051 functions = [],
3052 i;
3053
3054 for ( i = 0; i < args.length; i++ ) {
3055 if ( typeof args[ i ] == 'function' )
3056 functions.push( args[ i ] );
3057 else
3058 break;
3059 }
3060
3061 if ( i < args.length && typeof args[ i ] == 'string' ) {
3062 msg = args[ i ];
3063 i++;
3064 }
3065
3066 if ( i < args.length && typeof args[ i ] == 'number' )
3067 relation = args[ i ];
3068
3069 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );
3070 for ( i = 0; i < functions.length; i++ ) {
3071 if ( relation == CKEDITOR.VALIDATE_AND )
3072 passed = passed && functions[ i ]( value );
3073 else
3074 passed = passed || functions[ i ]( value );
3075 }
3076
3077 return !passed ? msg : true;
3078 };
3079 },
3080
3081 regex: function( regex, msg ) {
3082 /*
3083 * Can be greatly shortened by deriving from functions validator if code size
3084 * turns out to be more important than performance.
3085 */
3086 return function() {
3087 var value = this && this.getValue ? this.getValue() : arguments[ 0 ];
3088 return !regex.test( value ) ? msg : true;
3089 };
3090 },
3091
3092 notEmpty: function( msg ) {
3093 return this.regex( notEmptyRegex, msg );
3094 },
3095
3096 integer: function( msg ) {
3097 return this.regex( integerRegex, msg );
3098 },
3099
3100 'number': function( msg ) {
3101 return this.regex( numberRegex, msg );
3102 },
3103
3104 'cssLength': function( msg ) {
3105 return this.functions( function( val ) {
3106 return cssLengthRegex.test( CKEDITOR.tools.trim( val ) );
3107 }, msg );
3108 },
3109
3110 'htmlLength': function( msg ) {
3111 return this.functions( function( val ) {
3112 return htmlLengthRegex.test( CKEDITOR.tools.trim( val ) );
3113 }, msg );
3114 },
3115
3116 'inlineStyle': function( msg ) {
3117 return this.functions( function( val ) {
3118 return inlineStyleRegex.test( CKEDITOR.tools.trim( val ) );
3119 }, msg );
3120 },
3121
3122 equals: function( value, msg ) {
3123 return this.functions( function( val ) {
3124 return val == value;
3125 }, msg );
3126 },
3127
3128 notEqual: function( value, msg ) {
3129 return this.functions( function( val ) {
3130 return val != value;
3131 }, msg );
3132 }
3133 };
3134
3135 CKEDITOR.on( 'instanceDestroyed', function( evt ) {
3136 // Remove dialog cover on last instance destroy.
3137 if ( CKEDITOR.tools.isEmpty( CKEDITOR.instances ) ) {
3138 var currentTopDialog;
3139 while ( ( currentTopDialog = CKEDITOR.dialog._.currentTop ) )
3140 currentTopDialog.hide();
3141 removeCovers();
3142 }
3143
3144 var dialogs = evt.editor._.storedDialogs;
3145 for ( var name in dialogs )
3146 dialogs[ name ].destroy();
3147
3148 } );
3149
3150 } )();
3151
3152 // Extend the CKEDITOR.editor class with dialog specific functions.
3153 CKEDITOR.tools.extend( CKEDITOR.editor.prototype, {
3154 /**
3155 * Loads and opens a registered dialog.
3156 *
3157 * CKEDITOR.instances.editor1.openDialog( 'smiley' );
3158 *
3159 * @member CKEDITOR.editor
3160 * @param {String} dialogName The registered name of the dialog.
3161 * @param {Function} callback The function to be invoked after dialog instance created.
3162 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed.
3163 * `null` if the dialog name is not registered.
3164 * @see CKEDITOR.dialog#add
3165 */
3166 openDialog: function( dialogName, callback ) {
3167 var dialog = null, dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];
3168
3169 if ( CKEDITOR.dialog._.currentTop === null )
3170 showCover( this );
3171
3172 // If the dialogDefinition is already loaded, open it immediately.
3173 if ( typeof dialogDefinitions == 'function' ) {
3174 var storedDialogs = this._.storedDialogs || ( this._.storedDialogs = {} );
3175
3176 dialog = storedDialogs[ dialogName ] || ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
3177
3178 callback && callback.call( dialog, dialog );
3179 dialog.show();
3180
3181 } else if ( dialogDefinitions == 'failed' ) {
3182 hideCover( this );
3183 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
3184 } else if ( typeof dialogDefinitions == 'string' ) {
3185
3186 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ),
3187 function() {
3188 var dialogDefinition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];
3189 // In case of plugin error, mark it as loading failed.
3190 if ( typeof dialogDefinition != 'function' )
3191 CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';
3192
3193 this.openDialog( dialogName, callback );
3194 }, this, 0, 1 );
3195 }
3196
3197 CKEDITOR.skin.loadPart( 'dialog' );
3198
3199 return dialog;
3200 }
3201 } );
3202 } )();
3203
3204 CKEDITOR.plugins.add( 'dialog', {
3205 requires: 'dialogui',
3206 init: function( editor ) {
3207 editor.on( 'doubleclick', function( evt ) {
3208 if ( evt.data.dialog )
3209 editor.openDialog( evt.data.dialog );
3210 }, null, null, 999 );
3211 }
3212 } );
3213
3214 // Dialog related configurations.
3215
3216 /**
3217 * The color of the dialog background cover. It should be a valid CSS color string.
3218 *
3219 * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
3220 *
3221 * @cfg {String} [dialog_backgroundCoverColor='white']
3222 * @member CKEDITOR.config
3223 */
3224
3225 /**
3226 * The opacity of the dialog background cover. It should be a number within the
3227 * range `[0.0, 1.0]`.
3228 *
3229 * config.dialog_backgroundCoverOpacity = 0.7;
3230 *
3231 * @cfg {Number} [dialog_backgroundCoverOpacity=0.5]
3232 * @member CKEDITOR.config
3233 */
3234
3235 /**
3236 * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.
3237 *
3238 * config.dialog_startupFocusTab = true;
3239 *
3240 * @cfg {Boolean} [dialog_startupFocusTab=false]
3241 * @member CKEDITOR.config
3242 */
3243
3244 /**
3245 * The distance of magnetic borders used in moving and resizing dialogs,
3246 * measured in pixels.
3247 *
3248 * config.dialog_magnetDistance = 30;
3249 *
3250 * @cfg {Number} [dialog_magnetDistance=20]
3251 * @member CKEDITOR.config
3252 */
3253
3254 /**
3255 * The guideline to follow when generating the dialog buttons. There are 3 possible options:
3256 *
3257 * * `'OS'` - the buttons will be displayed in the default order of the user's OS;
3258 * * `'ltr'` - for Left-To-Right order;
3259 * * `'rtl'` - for Right-To-Left order.
3260 *
3261 * Example:
3262 *
3263 * config.dialog_buttonsOrder = 'rtl';
3264 *
3265 * @since 3.5
3266 * @cfg {String} [dialog_buttonsOrder='OS']
3267 * @member CKEDITOR.config
3268 */
3269
3270 /**
3271 * The dialog contents to removed. It's a string composed by dialog name and tab name with a colon between them.
3272 *
3273 * Separate each pair with semicolon (see example).
3274 *
3275 * **Note:** All names are case-sensitive.
3276 *
3277 * **Note:** Be cautious when specifying dialog tabs that are mandatory,
3278 * like `'info'`, dialog functionality might be broken because of this!
3279 *
3280 * config.removeDialogTabs = 'flash:advanced;image:Link';
3281 *
3282 * @since 3.5
3283 * @cfg {String} [removeDialogTabs='']
3284 * @member CKEDITOR.config
3285 */
3286
3287 /**
3288 * Tells if user should not be asked to confirm close, if any dialog field was modified.
3289 * By default it is set to `false` meaning that the confirmation dialog will be shown.
3290 *
3291 * config.dialog_noConfirmCancel = true;
3292 *
3293 * @since 4.3
3294 * @cfg {Boolean} [dialog_noConfirmCancel=false]
3295 * @member CKEDITOR.config
3296 */
3297
3298 /**
3299 * Event fired when a dialog definition is about to be used to create a dialog into
3300 * an editor instance. This event makes it possible to customize the definition
3301 * before creating it.
3302 *
3303 * Note that this event is called only the first time a specific dialog is
3304 * opened. Successive openings will use the cached dialog, and this event will
3305 * not get fired.
3306 *
3307 * @event dialogDefinition
3308 * @member CKEDITOR
3309 * @param {CKEDITOR.dialog.definition} data The dialog defination that
3310 * is being loaded.
3311 * @param {CKEDITOR.editor} editor The editor instance that will use the dialog.
3312 */
3313
3314 /**
3315 * Event fired when a tab is going to be selected in a dialog.
3316 *
3317 * @event selectPage
3318 * @member CKEDITOR.dialog
3319 * @param data
3320 * @param {String} data.page The id of the page that it's gonna be selected.
3321 * @param {String} data.currentPage The id of the current page.
3322 */
3323
3324 /**
3325 * Event fired when the user tries to dismiss a dialog.
3326 *
3327 * @event cancel
3328 * @member CKEDITOR.dialog
3329 * @param data
3330 * @param {Boolean} data.hide Whether the event should proceed or not.
3331 */
3332
3333 /**
3334 * Event fired when the user tries to confirm a dialog.
3335 *
3336 * @event ok
3337 * @member CKEDITOR.dialog
3338 * @param data
3339 * @param {Boolean} data.hide Whether the event should proceed or not.
3340 */
3341
3342 /**
3343 * Event fired when a dialog is shown.
3344 *
3345 * @event show
3346 * @member CKEDITOR.dialog
3347 */
3348
3349 /**
3350 * Event fired when a dialog is shown.
3351 *
3352 * @event dialogShow
3353 * @member CKEDITOR.editor
3354 * @param {CKEDITOR.editor} editor This editor instance.
3355 * @param {CKEDITOR.dialog} data The opened dialog instance.
3356 */
3357
3358 /**
3359 * Event fired when a dialog is hidden.
3360 *
3361 * @event hide
3362 * @member CKEDITOR.dialog
3363 */
3364
3365 /**
3366 * Event fired when a dialog is hidden.
3367 *
3368 * @event dialogHide
3369 * @member CKEDITOR.editor
3370 * @param {CKEDITOR.editor} editor This editor instance.
3371 * @param {CKEDITOR.dialog} data The hidden dialog instance.
3372 */
3373
3374 /**
3375 * Event fired when a dialog is being resized. The event is fired on
3376 * both the {@link CKEDITOR.dialog} object and the dialog instance
3377 * since 3.5.3, previously it was only available in the global object.
3378 *
3379 * @static
3380 * @event resize
3381 * @member CKEDITOR.dialog
3382 * @param data
3383 * @param {CKEDITOR.dialog} data.dialog The dialog being resized (if
3384 * it is fired on the dialog itself, this parameter is not sent).
3385 * @param {String} data.skin The skin name.
3386 * @param {Number} data.width The new width.
3387 * @param {Number} data.height The new height.
3388 */
3389
3390 /**
3391 * Event fired when a dialog is being resized. The event is fired on
3392 * both the {@link CKEDITOR.dialog} object and the dialog instance
3393 * since 3.5.3, previously it was only available in the global object.
3394 *
3395 * @since 3.5
3396 * @event resize
3397 * @member CKEDITOR.dialog
3398 * @param data
3399 * @param {Number} data.width The new width.
3400 * @param {Number} data.height The new height.
3401 */
3402
3403 /**
3404 * Event fired when the dialog state changes, usually by {@link CKEDITOR.dialog#setState}.
3405 *
3406 * @since 4.5
3407 * @event state
3408 * @member CKEDITOR.dialog
3409 * @param data
3410 * @param {Number} data The new state. Either {@link CKEDITOR#DIALOG_STATE_IDLE} or {@link CKEDITOR#DIALOG_STATE_BUSY}.
3411 */