]> git.immae.eu Git - perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git/blob - sources/plugins/dialog/plugin.js
Initial commit
[perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git] / sources / plugins / dialog / plugin.js
1 /**
2 * @license Copyright (c) 2003-2016, 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 (#13184).
181 editor.plugins.clipboard && CKEDITOR.plugins.clipboard.preventDefaultDropOnElement( body );
182
183 // IFrame shim for dialog that masks activeX in IE. (#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 (#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 (#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 (#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 (#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 (#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. (#4531,#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 (#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 // (#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 // Select the first tab by default.
866 this.selectPage( this.definition.contents[ 0 ].id );
867
868 // Set z-index.
869 if ( CKEDITOR.dialog._.currentZIndex === null )
870 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;
871 this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
872
873 // Maintain the dialog ordering and dialog cover.
874 if ( CKEDITOR.dialog._.currentTop === null ) {
875 CKEDITOR.dialog._.currentTop = this;
876 this._.parentDialog = null;
877 showCover( this._.editor );
878
879 } else {
880 this._.parentDialog = CKEDITOR.dialog._.currentTop;
881 var parentElement = this._.parentDialog.getElement().getFirst();
882 parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );
883 CKEDITOR.dialog._.currentTop = this;
884 }
885
886 element.on( 'keydown', accessKeyDownHandler );
887 element.on( 'keyup', accessKeyUpHandler );
888
889 // Reset the hasFocus state.
890 this._.hasFocus = false;
891
892 for ( var i in definition.contents ) {
893 if ( !definition.contents[ i ] )
894 continue;
895
896 var content = definition.contents[ i ],
897 tab = this._.tabs[ content.id ],
898 requiredContent = content.requiredContent,
899 enableElements = 0;
900
901 if ( !tab )
902 continue;
903
904 for ( var j in this._.contents[ content.id ] ) {
905 var elem = this._.contents[ content.id ][ j ];
906
907 if ( elem.type == 'hbox' || elem.type == 'vbox' || !elem.getInputElement() )
908 continue;
909
910 if ( elem.requiredContent && !this._.editor.activeFilter.check( elem.requiredContent ) )
911 elem.disable();
912 else {
913 elem.enable();
914 enableElements++;
915 }
916 }
917
918 if ( !enableElements || ( requiredContent && !this._.editor.activeFilter.check( requiredContent ) ) )
919 tab[ 0 ].addClass( 'cke_dialog_tab_disabled' );
920 else
921 tab[ 0 ].removeClass( 'cke_dialog_tab_disabled' );
922 }
923
924 CKEDITOR.tools.setTimeout( function() {
925 this.layout();
926 resizeWithWindow( this );
927
928 this.parts.dialog.setStyle( 'visibility', '' );
929
930 // Execute onLoad for the first show.
931 this.fireOnce( 'load', {} );
932 CKEDITOR.ui.fire( 'ready', this );
933
934 this.fire( 'show', {} );
935 this._.editor.fire( 'dialogShow', this );
936
937 if ( !this._.parentDialog )
938 this._.editor.focusManager.lock();
939
940 // Save the initial values of the dialog.
941 this.foreach( function( contentObj ) {
942 contentObj.setInitValue && contentObj.setInitValue();
943 } );
944
945 }, 100, this );
946 },
947
948 /**
949 * Rearrange the dialog to its previous position or the middle of the window.
950 *
951 * @since 3.5
952 */
953 layout: function() {
954 var el = this.parts.dialog;
955 var dialogSize = this.getSize();
956 var win = CKEDITOR.document.getWindow(),
957 viewSize = win.getViewPaneSize();
958
959 var posX = ( viewSize.width - dialogSize.width ) / 2,
960 posY = ( viewSize.height - dialogSize.height ) / 2;
961
962 // Switch to absolute position when viewport is smaller than dialog size.
963 if ( !CKEDITOR.env.ie6Compat ) {
964 if ( dialogSize.height + ( posY > 0 ? posY : 0 ) > viewSize.height || dialogSize.width + ( posX > 0 ? posX : 0 ) > viewSize.width ) {
965 el.setStyle( 'position', 'absolute' );
966 } else {
967 el.setStyle( 'position', 'fixed' );
968 }
969 }
970
971 this.move( this._.moved ? this._.position.x : posX, this._.moved ? this._.position.y : posY );
972 },
973
974 /**
975 * Executes a function for each UI element.
976 *
977 * @param {Function} fn Function to execute for each UI element.
978 * @returns {CKEDITOR.dialog} The current dialog object.
979 */
980 foreach: function( fn ) {
981 for ( var i in this._.contents ) {
982 for ( var j in this._.contents[ i ] ) {
983 fn.call( this, this._.contents[i][j] );
984 }
985 }
986
987 return this;
988 },
989
990 /**
991 * Resets all input values in the dialog.
992 *
993 * dialogObj.reset();
994 *
995 * @method
996 * @chainable
997 */
998 reset: ( function() {
999 var fn = function( widget ) {
1000 if ( widget.reset )
1001 widget.reset( 1 );
1002 };
1003 return function() {
1004 this.foreach( fn );
1005 return this;
1006 };
1007 } )(),
1008
1009
1010 /**
1011 * Calls the {@link CKEDITOR.dialog.definition.uiElement#setup} method of each
1012 * of the UI elements, with the arguments passed through it.
1013 * It is usually being called when the dialog is opened, to put the initial value inside the field.
1014 *
1015 * dialogObj.setupContent();
1016 *
1017 * var timestamp = ( new Date() ).valueOf();
1018 * dialogObj.setupContent( timestamp );
1019 */
1020 setupContent: function() {
1021 var args = arguments;
1022 this.foreach( function( widget ) {
1023 if ( widget.setup )
1024 widget.setup.apply( widget, args );
1025 } );
1026 },
1027
1028 /**
1029 * Calls the {@link CKEDITOR.dialog.definition.uiElement#commit} method of each
1030 * of the UI elements, with the arguments passed through it.
1031 * It is usually being called when the user confirms the dialog, to process the values.
1032 *
1033 * dialogObj.commitContent();
1034 *
1035 * var timestamp = ( new Date() ).valueOf();
1036 * dialogObj.commitContent( timestamp );
1037 */
1038 commitContent: function() {
1039 var args = arguments;
1040 this.foreach( function( widget ) {
1041 // Make sure IE triggers "change" event on last focused input before closing the dialog. (#7915)
1042 if ( CKEDITOR.env.ie && this._.currentFocusIndex == widget.focusIndex )
1043 widget.getInputElement().$.blur();
1044
1045 if ( widget.commit )
1046 widget.commit.apply( widget, args );
1047 } );
1048 },
1049
1050 /**
1051 * Hides the dialog box.
1052 *
1053 * dialogObj.hide();
1054 */
1055 hide: function() {
1056 if ( !this.parts.dialog.isVisible() )
1057 return;
1058
1059 this.fire( 'hide', {} );
1060 this._.editor.fire( 'dialogHide', this );
1061 // Reset the tab page.
1062 this.selectPage( this._.tabIdList[ 0 ] );
1063 var element = this._.element;
1064 element.setStyle( 'display', 'none' );
1065 this.parts.dialog.setStyle( 'visibility', 'hidden' );
1066 // Unregister all access keys associated with this dialog.
1067 unregisterAccessKey( this );
1068
1069 // Close any child(top) dialogs first.
1070 while ( CKEDITOR.dialog._.currentTop != this )
1071 CKEDITOR.dialog._.currentTop.hide();
1072
1073 // Maintain dialog ordering and remove cover if needed.
1074 if ( !this._.parentDialog )
1075 hideCover( this._.editor );
1076 else {
1077 var parentElement = this._.parentDialog.getElement().getFirst();
1078 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
1079 }
1080 CKEDITOR.dialog._.currentTop = this._.parentDialog;
1081
1082 // Deduct or clear the z-index.
1083 if ( !this._.parentDialog ) {
1084 CKEDITOR.dialog._.currentZIndex = null;
1085
1086 // Remove access key handlers.
1087 element.removeListener( 'keydown', accessKeyDownHandler );
1088 element.removeListener( 'keyup', accessKeyUpHandler );
1089
1090 var editor = this._.editor;
1091 editor.focus();
1092
1093 // Give a while before unlock, waiting for focus to return to the editable. (#172)
1094 setTimeout( function() {
1095 editor.focusManager.unlock();
1096
1097 // Fixed iOS focus issue (#12381).
1098 // Keep in mind that editor.focus() does not work in this case.
1099 if ( CKEDITOR.env.iOS ) {
1100 editor.window.focus();
1101 }
1102 }, 0 );
1103
1104 } else {
1105 CKEDITOR.dialog._.currentZIndex -= 10;
1106 }
1107
1108 delete this._.parentDialog;
1109 // Reset the initial values of the dialog.
1110 this.foreach( function( contentObj ) {
1111 contentObj.resetInitValue && contentObj.resetInitValue();
1112 } );
1113
1114 // Reset dialog state back to IDLE, if busy (#13213).
1115 this.setState( CKEDITOR.DIALOG_STATE_IDLE );
1116 },
1117
1118 /**
1119 * Adds a tabbed page into the dialog.
1120 *
1121 * @param {Object} contents Content definition.
1122 */
1123 addPage: function( contents ) {
1124 if ( contents.requiredContent && !this._.editor.filter.check( contents.requiredContent ) )
1125 return;
1126
1127 var pageHtml = [],
1128 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
1129 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this, {
1130 type: 'vbox',
1131 className: 'cke_dialog_page_contents',
1132 children: contents.elements,
1133 expand: !!contents.expand,
1134 padding: contents.padding,
1135 style: contents.style || 'width: 100%;'
1136 }, pageHtml );
1137
1138 var contentMap = this._.contents[ contents.id ] = {},
1139 cursor,
1140 children = vbox.getChild(),
1141 enabledFields = 0;
1142
1143 while ( ( cursor = children.shift() ) ) {
1144 // Count all allowed fields.
1145 if ( !cursor.notAllowed && cursor.type != 'hbox' && cursor.type != 'vbox' )
1146 enabledFields++;
1147
1148 contentMap[ cursor.id ] = cursor;
1149 if ( typeof cursor.getChild == 'function' )
1150 children.push.apply( children, cursor.getChild() );
1151 }
1152
1153 // If all fields are disabled (because they are not allowed) hide this tab.
1154 if ( !enabledFields )
1155 contents.hidden = true;
1156
1157 // Create the HTML for the tab and the content block.
1158 var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
1159 page.setAttribute( 'role', 'tabpanel' );
1160
1161 var env = CKEDITOR.env;
1162 var tabId = 'cke_' + contents.id + '_' + CKEDITOR.tools.getNextNumber(),
1163 tab = CKEDITOR.dom.element.createFromHtml( [
1164 '<a class="cke_dialog_tab"',
1165 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),
1166 titleHtml,
1167 ( !!contents.hidden ? ' style="display:none"' : '' ),
1168 ' id="', tabId, '"',
1169 env.gecko && !env.hc ? '' : ' href="javascript:void(0)"',
1170 ' tabIndex="-1"',
1171 ' hidefocus="true"',
1172 ' role="tab">',
1173 contents.label,
1174 '</a>'
1175 ].join( '' ) );
1176
1177 page.setAttribute( 'aria-labelledby', tabId );
1178
1179 // Take records for the tabs and elements created.
1180 this._.tabs[ contents.id ] = [ tab, page ];
1181 this._.tabIdList.push( contents.id );
1182 !contents.hidden && this._.pageCount++;
1183 this._.lastTab = tab;
1184 this.updateStyle();
1185
1186 // Attach the DOM nodes.
1187
1188 page.setAttribute( 'name', contents.id );
1189 page.appendTo( this.parts.contents );
1190
1191 tab.unselectable();
1192 this.parts.tabs.append( tab );
1193
1194 // Add access key handlers if access key is defined.
1195 if ( contents.accessKey ) {
1196 registerAccessKey( this, this, 'CTRL+' + contents.accessKey, tabAccessKeyDown, tabAccessKeyUp );
1197 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;
1198 }
1199 },
1200
1201 /**
1202 * Activates a tab page in the dialog by its id.
1203 *
1204 * dialogObj.selectPage( 'tab_1' );
1205 *
1206 * @param {String} id The id of the dialog tab to be activated.
1207 */
1208 selectPage: function( id ) {
1209 if ( this._.currentTabId == id )
1210 return;
1211
1212 if ( this._.tabs[ id ][ 0 ].hasClass( 'cke_dialog_tab_disabled' ) )
1213 return;
1214
1215 // If event was canceled - do nothing.
1216 if ( this.fire( 'selectPage', { page: id, currentPage: this._.currentTabId } ) === false )
1217 return;
1218
1219 // Hide the non-selected tabs and pages.
1220 for ( var i in this._.tabs ) {
1221 var tab = this._.tabs[ i ][ 0 ],
1222 page = this._.tabs[ i ][ 1 ];
1223 if ( i != id ) {
1224 tab.removeClass( 'cke_dialog_tab_selected' );
1225 page.hide();
1226 }
1227 page.setAttribute( 'aria-hidden', i != id );
1228 }
1229
1230 var selected = this._.tabs[ id ];
1231 selected[ 0 ].addClass( 'cke_dialog_tab_selected' );
1232
1233 // [IE] an invisible input[type='text'] will enlarge it's width
1234 // if it's value is long when it shows, so we clear it's value
1235 // before it shows and then recover it (#5649)
1236 if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat ) {
1237 clearOrRecoverTextInputValue( selected[ 1 ] );
1238 selected[ 1 ].show();
1239 setTimeout( function() {
1240 clearOrRecoverTextInputValue( selected[ 1 ], 1 );
1241 }, 0 );
1242 } else {
1243 selected[ 1 ].show();
1244 }
1245
1246 this._.currentTabId = id;
1247 this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
1248 },
1249
1250 /**
1251 * Dialog state-specific style updates.
1252 */
1253 updateStyle: function() {
1254 // If only a single page shown, a different style is used in the central pane.
1255 this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );
1256 },
1257
1258 /**
1259 * Hides a page's tab away from the dialog.
1260 *
1261 * dialog.hidePage( 'tab_3' );
1262 *
1263 * @param {String} id The page's Id.
1264 */
1265 hidePage: function( id ) {
1266 var tab = this._.tabs[ id ] && this._.tabs[ id ][ 0 ];
1267 if ( !tab || this._.pageCount == 1 || !tab.isVisible() )
1268 return;
1269 // Switch to other tab first when we're hiding the active tab.
1270 else if ( id == this._.currentTabId )
1271 this.selectPage( getPreviousVisibleTab.call( this ) );
1272
1273 tab.hide();
1274 this._.pageCount--;
1275 this.updateStyle();
1276 },
1277
1278 /**
1279 * Unhides a page's tab.
1280 *
1281 * dialog.showPage( 'tab_2' );
1282 *
1283 * @param {String} id The page's Id.
1284 */
1285 showPage: function( id ) {
1286 var tab = this._.tabs[ id ] && this._.tabs[ id ][ 0 ];
1287 if ( !tab )
1288 return;
1289 tab.show();
1290 this._.pageCount++;
1291 this.updateStyle();
1292 },
1293
1294 /**
1295 * Gets the root DOM element of the dialog.
1296 *
1297 * var dialogElement = dialogObj.getElement().getFirst();
1298 * dialogElement.setStyle( 'padding', '5px' );
1299 *
1300 * @returns {CKEDITOR.dom.element} The `<span>` element containing this dialog.
1301 */
1302 getElement: function() {
1303 return this._.element;
1304 },
1305
1306 /**
1307 * Gets the name of the dialog.
1308 *
1309 * var dialogName = dialogObj.getName();
1310 *
1311 * @returns {String} The name of this dialog.
1312 */
1313 getName: function() {
1314 return this._.name;
1315 },
1316
1317 /**
1318 * Gets a dialog UI element object from a dialog page.
1319 *
1320 * dialogObj.getContentElement( 'tabId', 'elementId' ).setValue( 'Example' );
1321 *
1322 * @param {String} pageId id of dialog page.
1323 * @param {String} elementId id of UI element.
1324 * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.
1325 */
1326 getContentElement: function( pageId, elementId ) {
1327 var page = this._.contents[ pageId ];
1328 return page && page[ elementId ];
1329 },
1330
1331 /**
1332 * Gets the value of a dialog UI element.
1333 *
1334 * alert( dialogObj.getValueOf( 'tabId', 'elementId' ) );
1335 *
1336 * @param {String} pageId id of dialog page.
1337 * @param {String} elementId id of UI element.
1338 * @returns {Object} The value of the UI element.
1339 */
1340 getValueOf: function( pageId, elementId ) {
1341 return this.getContentElement( pageId, elementId ).getValue();
1342 },
1343
1344 /**
1345 * Sets the value of a dialog UI element.
1346 *
1347 * dialogObj.setValueOf( 'tabId', 'elementId', 'Example' );
1348 *
1349 * @param {String} pageId id of the dialog page.
1350 * @param {String} elementId id of the UI element.
1351 * @param {Object} value The new value of the UI element.
1352 */
1353 setValueOf: function( pageId, elementId, value ) {
1354 return this.getContentElement( pageId, elementId ).setValue( value );
1355 },
1356
1357 /**
1358 * Gets the UI element of a button in the dialog's button row.
1359 *
1360 * @returns {CKEDITOR.ui.dialog.button} The button object.
1361 *
1362 * @param {String} id The id of the button.
1363 */
1364 getButton: function( id ) {
1365 return this._.buttons[ id ];
1366 },
1367
1368 /**
1369 * Simulates a click to a dialog button in the dialog's button row.
1370 *
1371 * @returns The return value of the dialog's `click` event.
1372 *
1373 * @param {String} id The id of the button.
1374 */
1375 click: function( id ) {
1376 return this._.buttons[ id ].click();
1377 },
1378
1379 /**
1380 * Disables a dialog button.
1381 *
1382 * @param {String} id The id of the button.
1383 */
1384 disableButton: function( id ) {
1385 return this._.buttons[ id ].disable();
1386 },
1387
1388 /**
1389 * Enables a dialog button.
1390 *
1391 * @param {String} id The id of the button.
1392 */
1393 enableButton: function( id ) {
1394 return this._.buttons[ id ].enable();
1395 },
1396
1397 /**
1398 * Gets the number of pages in the dialog.
1399 *
1400 * @returns {Number} Page count.
1401 */
1402 getPageCount: function() {
1403 return this._.pageCount;
1404 },
1405
1406 /**
1407 * Gets the editor instance which opened this dialog.
1408 *
1409 * @returns {CKEDITOR.editor} Parent editor instances.
1410 */
1411 getParentEditor: function() {
1412 return this._.editor;
1413 },
1414
1415 /**
1416 * Gets the element that was selected when opening the dialog, if any.
1417 *
1418 * @returns {CKEDITOR.dom.element} The element that was selected, or `null`.
1419 */
1420 getSelectedElement: function() {
1421 return this.getParentEditor().getSelection().getSelectedElement();
1422 },
1423
1424 /**
1425 * Adds element to dialog's focusable list.
1426 *
1427 * @param {CKEDITOR.dom.element} element
1428 * @param {Number} [index]
1429 */
1430 addFocusable: function( element, index ) {
1431 if ( typeof index == 'undefined' ) {
1432 index = this._.focusList.length;
1433 this._.focusList.push( new Focusable( this, element, index ) );
1434 } else {
1435 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );
1436 for ( var i = index + 1; i < this._.focusList.length; i++ )
1437 this._.focusList[ i ].focusIndex++;
1438 }
1439 },
1440
1441 /**
1442 * Sets the dialog {@link #property-state}.
1443 *
1444 * @since 4.5
1445 * @param {Number} state Either {@link CKEDITOR#DIALOG_STATE_IDLE} or {@link CKEDITOR#DIALOG_STATE_BUSY}.
1446 */
1447 setState: function( state ) {
1448 var oldState = this.state;
1449
1450 if ( oldState == state ) {
1451 return;
1452 }
1453
1454 this.state = state;
1455
1456 if ( state == CKEDITOR.DIALOG_STATE_BUSY ) {
1457 // Insert the spinner on demand.
1458 if ( !this.parts.spinner ) {
1459 var dir = this.getParentEditor().lang.dir,
1460 spinnerDef = {
1461 attributes: {
1462 'class': 'cke_dialog_spinner'
1463 },
1464 styles: {
1465 'float': dir == 'rtl' ? 'right' : 'left'
1466 }
1467 };
1468
1469 spinnerDef.styles[ 'margin-' + ( dir == 'rtl' ? 'left' : 'right' ) ] = '8px';
1470
1471 this.parts.spinner = CKEDITOR.document.createElement( 'div', spinnerDef );
1472
1473 this.parts.spinner.setHtml( '&#8987;' );
1474 this.parts.spinner.appendTo( this.parts.title, 1 );
1475 }
1476
1477 // Finally, show the spinner.
1478 this.parts.spinner.show();
1479
1480 this.getButton( 'ok' ).disable();
1481 } else if ( state == CKEDITOR.DIALOG_STATE_IDLE ) {
1482 // Hide the spinner. But don't do anything if there is no spinner yet.
1483 this.parts.spinner && this.parts.spinner.hide();
1484
1485 this.getButton( 'ok' ).enable();
1486 }
1487
1488 this.fire( 'state', state );
1489 }
1490 };
1491
1492 CKEDITOR.tools.extend( CKEDITOR.dialog, {
1493 /**
1494 * Registers a dialog.
1495 *
1496 * // Full sample plugin, which does not only register a dialog window but also adds an item to the context menu.
1497 * // To open the dialog window, choose "Open dialog" in the context menu.
1498 * CKEDITOR.plugins.add( 'myplugin', {
1499 * init: function( editor ) {
1500 * editor.addCommand( 'mydialog',new CKEDITOR.dialogCommand( 'mydialog' ) );
1501 *
1502 * if ( editor.contextMenu ) {
1503 * editor.addMenuGroup( 'mygroup', 10 );
1504 * editor.addMenuItem( 'My Dialog', {
1505 * label: 'Open dialog',
1506 * command: 'mydialog',
1507 * group: 'mygroup'
1508 * } );
1509 * editor.contextMenu.addListener( function( element ) {
1510 * return { 'My Dialog': CKEDITOR.TRISTATE_OFF };
1511 * } );
1512 * }
1513 *
1514 * CKEDITOR.dialog.add( 'mydialog', function( api ) {
1515 * // CKEDITOR.dialog.definition
1516 * var dialogDefinition = {
1517 * title: 'Sample dialog',
1518 * minWidth: 390,
1519 * minHeight: 130,
1520 * contents: [
1521 * {
1522 * id: 'tab1',
1523 * label: 'Label',
1524 * title: 'Title',
1525 * expand: true,
1526 * padding: 0,
1527 * elements: [
1528 * {
1529 * type: 'html',
1530 * html: '<p>This is some sample HTML content.</p>'
1531 * },
1532 * {
1533 * type: 'textarea',
1534 * id: 'textareaId',
1535 * rows: 4,
1536 * cols: 40
1537 * }
1538 * ]
1539 * }
1540 * ],
1541 * buttons: [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ],
1542 * onOk: function() {
1543 * // "this" is now a CKEDITOR.dialog object.
1544 * // Accessing dialog elements:
1545 * var textareaObj = this.getContentElement( 'tab1', 'textareaId' );
1546 * alert( "You have entered: " + textareaObj.getValue() );
1547 * }
1548 * };
1549 *
1550 * return dialogDefinition;
1551 * } );
1552 * }
1553 * } );
1554 *
1555 * CKEDITOR.replace( 'editor1', { extraPlugins: 'myplugin' } );
1556 *
1557 * @static
1558 * @param {String} name The dialog's name.
1559 * @param {Function/String} dialogDefinition
1560 * A function returning the dialog's definition, or the URL to the `.js` file holding the function.
1561 * The function should accept an argument `editor` which is the current editor instance, and
1562 * return an object conforming to {@link CKEDITOR.dialog.definition}.
1563 * @see CKEDITOR.dialog.definition
1564 */
1565 add: function( name, dialogDefinition ) {
1566 // Avoid path registration from multiple instances override definition.
1567 if ( !this._.dialogDefinitions[ name ] || typeof dialogDefinition == 'function' )
1568 this._.dialogDefinitions[ name ] = dialogDefinition;
1569 },
1570
1571 /**
1572 * @static
1573 * @todo
1574 */
1575 exists: function( name ) {
1576 return !!this._.dialogDefinitions[ name ];
1577 },
1578
1579 /**
1580 * @static
1581 * @todo
1582 */
1583 getCurrent: function() {
1584 return CKEDITOR.dialog._.currentTop;
1585 },
1586
1587 /**
1588 * Check whether tab wasn't removed by {@link CKEDITOR.config#removeDialogTabs}.
1589 *
1590 * @since 4.1
1591 * @static
1592 * @param {CKEDITOR.editor} editor
1593 * @param {String} dialogName
1594 * @param {String} tabName
1595 * @returns {Boolean}
1596 */
1597 isTabEnabled: function( editor, dialogName, tabName ) {
1598 var cfg = editor.config.removeDialogTabs;
1599
1600 return !( cfg && cfg.match( new RegExp( '(?:^|;)' + dialogName + ':' + tabName + '(?:$|;)', 'i' ) ) );
1601 },
1602
1603 /**
1604 * The default OK button for dialogs. Fires the `ok` event and closes the dialog if the event succeeds.
1605 *
1606 * @static
1607 * @method
1608 */
1609 okButton: ( function() {
1610 var retval = function( editor, override ) {
1611 override = override || {};
1612 return CKEDITOR.tools.extend( {
1613 id: 'ok',
1614 type: 'button',
1615 label: editor.lang.common.ok,
1616 'class': 'cke_dialog_ui_button_ok',
1617 onClick: function( evt ) {
1618 var dialog = evt.data.dialog;
1619 if ( dialog.fire( 'ok', { hide: true } ).hide !== false )
1620 dialog.hide();
1621 }
1622 }, override, true );
1623 };
1624 retval.type = 'button';
1625 retval.override = function( override ) {
1626 return CKEDITOR.tools.extend( function( editor ) {
1627 return retval( editor, override );
1628 }, { type: 'button' }, true );
1629 };
1630 return retval;
1631 } )(),
1632
1633 /**
1634 * The default cancel button for dialogs. Fires the `cancel` event and
1635 * closes the dialog if no UI element value changed.
1636 *
1637 * @static
1638 * @method
1639 */
1640 cancelButton: ( function() {
1641 var retval = function( editor, override ) {
1642 override = override || {};
1643 return CKEDITOR.tools.extend( {
1644 id: 'cancel',
1645 type: 'button',
1646 label: editor.lang.common.cancel,
1647 'class': 'cke_dialog_ui_button_cancel',
1648 onClick: function( evt ) {
1649 var dialog = evt.data.dialog;
1650 if ( dialog.fire( 'cancel', { hide: true } ).hide !== false )
1651 dialog.hide();
1652 }
1653 }, override, true );
1654 };
1655 retval.type = 'button';
1656 retval.override = function( override ) {
1657 return CKEDITOR.tools.extend( function( editor ) {
1658 return retval( editor, override );
1659 }, { type: 'button' }, true );
1660 };
1661 return retval;
1662 } )(),
1663
1664 /**
1665 * Registers a dialog UI element.
1666 *
1667 * @static
1668 * @param {String} typeName The name of the UI element.
1669 * @param {Function} builder The function to build the UI element.
1670 */
1671 addUIElement: function( typeName, builder ) {
1672 this._.uiElementBuilders[ typeName ] = builder;
1673 }
1674 } );
1675
1676 CKEDITOR.dialog._ = {
1677 uiElementBuilders: {},
1678
1679 dialogDefinitions: {},
1680
1681 currentTop: null,
1682
1683 currentZIndex: null
1684 };
1685
1686 // "Inherit" (copy actually) from CKEDITOR.event.
1687 CKEDITOR.event.implementOn( CKEDITOR.dialog );
1688 CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype );
1689
1690 var defaultDialogDefinition = {
1691 resizable: CKEDITOR.DIALOG_RESIZE_BOTH,
1692 minWidth: 600,
1693 minHeight: 400,
1694 buttons: [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
1695 };
1696
1697 // Tool function used to return an item from an array based on its id
1698 // property.
1699 var getById = function( array, id, recurse ) {
1700 for ( var i = 0, item;
1701 ( item = array[ i ] ); i++ ) {
1702 if ( item.id == id )
1703 return item;
1704 if ( recurse && item[ recurse ] ) {
1705 var retval = getById( item[ recurse ], id, recurse );
1706 if ( retval )
1707 return retval;
1708 }
1709 }
1710 return null;
1711 };
1712
1713 // Tool function used to add an item into an array.
1714 var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound ) {
1715 if ( nextSiblingId ) {
1716 for ( var i = 0, item;
1717 ( item = array[ i ] ); i++ ) {
1718 if ( item.id == nextSiblingId ) {
1719 array.splice( i, 0, newItem );
1720 return newItem;
1721 }
1722
1723 if ( recurse && item[ recurse ] ) {
1724 var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
1725 if ( retval )
1726 return retval;
1727 }
1728 }
1729
1730 if ( nullIfNotFound )
1731 return null;
1732 }
1733
1734 array.push( newItem );
1735 return newItem;
1736 };
1737
1738 // Tool function used to remove an item from an array based on its id.
1739 var removeById = function( array, id, recurse ) {
1740 for ( var i = 0, item;
1741 ( item = array[ i ] ); i++ ) {
1742 if ( item.id == id )
1743 return array.splice( i, 1 );
1744 if ( recurse && item[ recurse ] ) {
1745 var retval = removeById( item[ recurse ], id, recurse );
1746 if ( retval )
1747 return retval;
1748 }
1749 }
1750 return null;
1751 };
1752
1753 /**
1754 * This class is not really part of the API. It is the `definition` property value
1755 * passed to `dialogDefinition` event handlers.
1756 *
1757 * CKEDITOR.on( 'dialogDefinition', function( evt ) {
1758 * var definition = evt.data.definition;
1759 * var content = definition.getContents( 'page1' );
1760 * // ...
1761 * } );
1762 *
1763 * @private
1764 * @class CKEDITOR.dialog.definitionObject
1765 * @extends CKEDITOR.dialog.definition
1766 * @constructor Creates a definitionObject class instance.
1767 */
1768 var definitionObject = function( dialog, dialogDefinition ) {
1769 // TODO : Check if needed.
1770 this.dialog = dialog;
1771
1772 // Transform the contents entries in contentObjects.
1773 var contents = dialogDefinition.contents;
1774 for ( var i = 0, content;
1775 ( content = contents[ i ] ); i++ )
1776 contents[ i ] = content && new contentObject( dialog, content );
1777
1778 CKEDITOR.tools.extend( this, dialogDefinition );
1779 };
1780
1781 definitionObject.prototype = {
1782 /**
1783 * Gets a content definition.
1784 *
1785 * @param {String} id The id of the content definition.
1786 * @returns {CKEDITOR.dialog.definition.content} The content definition matching id.
1787 */
1788 getContents: function( id ) {
1789 return getById( this.contents, id );
1790 },
1791
1792 /**
1793 * Gets a button definition.
1794 *
1795 * @param {String} id The id of the button definition.
1796 * @returns {CKEDITOR.dialog.definition.button} The button definition matching id.
1797 */
1798 getButton: function( id ) {
1799 return getById( this.buttons, id );
1800 },
1801
1802 /**
1803 * Adds a content definition object under this dialog definition.
1804 *
1805 * @param {CKEDITOR.dialog.definition.content} contentDefinition The
1806 * content definition.
1807 * @param {String} [nextSiblingId] The id of an existing content
1808 * definition which the new content definition will be inserted
1809 * before. Omit if the new content definition is to be inserted as
1810 * the last item.
1811 * @returns {CKEDITOR.dialog.definition.content} The inserted content definition.
1812 */
1813 addContents: function( contentDefinition, nextSiblingId ) {
1814 return addById( this.contents, contentDefinition, nextSiblingId );
1815 },
1816
1817 /**
1818 * Adds a button definition object under this dialog definition.
1819 *
1820 * @param {CKEDITOR.dialog.definition.button} buttonDefinition The
1821 * button definition.
1822 * @param {String} [nextSiblingId] The id of an existing button
1823 * definition which the new button definition will be inserted
1824 * before. Omit if the new button definition is to be inserted as
1825 * the last item.
1826 * @returns {CKEDITOR.dialog.definition.button} The inserted button definition.
1827 */
1828 addButton: function( buttonDefinition, nextSiblingId ) {
1829 return addById( this.buttons, buttonDefinition, nextSiblingId );
1830 },
1831
1832 /**
1833 * Removes a content definition from this dialog definition.
1834 *
1835 * @param {String} id The id of the content definition to be removed.
1836 * @returns {CKEDITOR.dialog.definition.content} The removed content definition.
1837 */
1838 removeContents: function( id ) {
1839 removeById( this.contents, id );
1840 },
1841
1842 /**
1843 * Removes a button definition from the dialog definition.
1844 *
1845 * @param {String} id The id of the button definition to be removed.
1846 * @returns {CKEDITOR.dialog.definition.button} The removed button definition.
1847 */
1848 removeButton: function( id ) {
1849 removeById( this.buttons, id );
1850 }
1851 };
1852
1853 /**
1854 * This class is not really part of the API. It is the template of the
1855 * objects representing content pages inside the
1856 * CKEDITOR.dialog.definitionObject.
1857 *
1858 * CKEDITOR.on( 'dialogDefinition', function( evt ) {
1859 * var definition = evt.data.definition;
1860 * var content = definition.getContents( 'page1' );
1861 * content.remove( 'textInput1' );
1862 * // ...
1863 * } );
1864 *
1865 * @private
1866 * @class CKEDITOR.dialog.definition.contentObject
1867 * @constructor Creates a contentObject class instance.
1868 */
1869 function contentObject( dialog, contentDefinition ) {
1870 this._ = {
1871 dialog: dialog
1872 };
1873
1874 CKEDITOR.tools.extend( this, contentDefinition );
1875 }
1876
1877 contentObject.prototype = {
1878 /**
1879 * Gets a UI element definition under the content definition.
1880 *
1881 * @param {String} id The id of the UI element definition.
1882 * @returns {CKEDITOR.dialog.definition.uiElement}
1883 */
1884 get: function( id ) {
1885 return getById( this.elements, id, 'children' );
1886 },
1887
1888 /**
1889 * Adds a UI element definition to the content definition.
1890 *
1891 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition The
1892 * UI elemnet definition to be added.
1893 * @param {String} nextSiblingId The id of an existing UI element
1894 * definition which the new UI element definition will be inserted
1895 * before. Omit if the new button definition is to be inserted as
1896 * the last item.
1897 * @returns {CKEDITOR.dialog.definition.uiElement} The element definition inserted.
1898 */
1899 add: function( elementDefinition, nextSiblingId ) {
1900 return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
1901 },
1902
1903 /**
1904 * Removes a UI element definition from the content definition.
1905 *
1906 * @param {String} id The id of the UI element definition to be removed.
1907 * @returns {CKEDITOR.dialog.definition.uiElement} The element definition removed.
1908 */
1909 remove: function( id ) {
1910 removeById( this.elements, id, 'children' );
1911 }
1912 };
1913
1914 function initDragAndDrop( dialog ) {
1915 var lastCoords = null,
1916 abstractDialogCoords = null,
1917 editor = dialog.getParentEditor(),
1918 magnetDistance = editor.config.dialog_magnetDistance,
1919 margins = CKEDITOR.skin.margins || [ 0, 0, 0, 0 ];
1920
1921 if ( typeof magnetDistance == 'undefined' )
1922 magnetDistance = 20;
1923
1924 function mouseMoveHandler( evt ) {
1925 var dialogSize = dialog.getSize(),
1926 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
1927 x = evt.data.$.screenX,
1928 y = evt.data.$.screenY,
1929 dx = x - lastCoords.x,
1930 dy = y - lastCoords.y,
1931 realX, realY;
1932
1933 lastCoords = { x: x, y: y };
1934 abstractDialogCoords.x += dx;
1935 abstractDialogCoords.y += dy;
1936
1937 if ( abstractDialogCoords.x + margins[ 3 ] < magnetDistance )
1938 realX = -margins[ 3 ];
1939 else if ( abstractDialogCoords.x - margins[ 1 ] > viewPaneSize.width - dialogSize.width - magnetDistance )
1940 realX = viewPaneSize.width - dialogSize.width + ( editor.lang.dir == 'rtl' ? 0 : margins[ 1 ] );
1941 else
1942 realX = abstractDialogCoords.x;
1943
1944 if ( abstractDialogCoords.y + margins[ 0 ] < magnetDistance )
1945 realY = -margins[ 0 ];
1946 else if ( abstractDialogCoords.y - margins[ 2 ] > viewPaneSize.height - dialogSize.height - magnetDistance )
1947 realY = viewPaneSize.height - dialogSize.height + margins[ 2 ];
1948 else
1949 realY = abstractDialogCoords.y;
1950
1951 dialog.move( realX, realY, 1 );
1952
1953 evt.data.preventDefault();
1954 }
1955
1956 function mouseUpHandler() {
1957 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
1958 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
1959
1960 if ( CKEDITOR.env.ie6Compat ) {
1961 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
1962 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
1963 coverDoc.removeListener( 'mouseup', mouseUpHandler );
1964 }
1965 }
1966
1967 dialog.parts.title.on( 'mousedown', function( evt ) {
1968 lastCoords = { x: evt.data.$.screenX, y: evt.data.$.screenY };
1969
1970 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
1971 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
1972 abstractDialogCoords = dialog.getPosition();
1973
1974 if ( CKEDITOR.env.ie6Compat ) {
1975 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
1976 coverDoc.on( 'mousemove', mouseMoveHandler );
1977 coverDoc.on( 'mouseup', mouseUpHandler );
1978 }
1979
1980 evt.data.preventDefault();
1981 }, dialog );
1982 }
1983
1984 function initResizeHandles( dialog ) {
1985 var def = dialog.definition,
1986 resizable = def.resizable;
1987
1988 if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE )
1989 return;
1990
1991 var editor = dialog.getParentEditor();
1992 var wrapperWidth, wrapperHeight, viewSize, origin, startSize, dialogCover;
1993
1994 var mouseDownFn = CKEDITOR.tools.addFunction( function( $event ) {
1995 startSize = dialog.getSize();
1996
1997 var content = dialog.parts.contents,
1998 iframeDialog = content.$.getElementsByTagName( 'iframe' ).length;
1999
2000 // Shim to help capturing "mousemove" over iframe.
2001 if ( iframeDialog ) {
2002 dialogCover = CKEDITOR.dom.element.createFromHtml( '<div class="cke_dialog_resize_cover" style="height: 100%; position: absolute; width: 100%;"></div>' );
2003 content.append( dialogCover );
2004 }
2005
2006 // Calculate the offset between content and chrome size.
2007 wrapperHeight = startSize.height - dialog.parts.contents.getSize( 'height', !( CKEDITOR.env.gecko || CKEDITOR.env.ie && CKEDITOR.env.quirks ) );
2008 wrapperWidth = startSize.width - dialog.parts.contents.getSize( 'width', 1 );
2009
2010 origin = { x: $event.screenX, y: $event.screenY };
2011
2012 viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
2013
2014 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
2015 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
2016
2017 if ( CKEDITOR.env.ie6Compat ) {
2018 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
2019 coverDoc.on( 'mousemove', mouseMoveHandler );
2020 coverDoc.on( 'mouseup', mouseUpHandler );
2021 }
2022
2023 $event.preventDefault && $event.preventDefault();
2024 } );
2025
2026 // Prepend the grip to the dialog.
2027 dialog.on( 'load', function() {
2028 var direction = '';
2029 if ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH )
2030 direction = ' cke_resizer_horizontal';
2031 else if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT )
2032 direction = ' cke_resizer_vertical';
2033 var resizer = CKEDITOR.dom.element.createFromHtml(
2034 '<div' +
2035 ' class="cke_resizer' + direction + ' cke_resizer_' + editor.lang.dir + '"' +
2036 ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.common.resize ) + '"' +
2037 ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event )">' +
2038 // BLACK LOWER RIGHT TRIANGLE (ltr)
2039 // BLACK LOWER LEFT TRIANGLE (rtl)
2040 ( editor.lang.dir == 'ltr' ? '\u25E2' : '\u25E3' ) +
2041 '</div>' );
2042 dialog.parts.footer.append( resizer, 1 );
2043 } );
2044 editor.on( 'destroy', function() {
2045 CKEDITOR.tools.removeFunction( mouseDownFn );
2046 } );
2047
2048 function mouseMoveHandler( evt ) {
2049 var rtl = editor.lang.dir == 'rtl',
2050 dx = ( evt.data.$.screenX - origin.x ) * ( rtl ? -1 : 1 ),
2051 dy = evt.data.$.screenY - origin.y,
2052 width = startSize.width,
2053 height = startSize.height,
2054 internalWidth = width + dx * ( dialog._.moved ? 1 : 2 ),
2055 internalHeight = height + dy * ( dialog._.moved ? 1 : 2 ),
2056 element = dialog._.element.getFirst(),
2057 right = rtl && element.getComputedStyle( 'right' ),
2058 position = dialog.getPosition();
2059
2060 if ( position.y + internalHeight > viewSize.height )
2061 internalHeight = viewSize.height - position.y;
2062
2063 if ( ( rtl ? right : position.x ) + internalWidth > viewSize.width )
2064 internalWidth = viewSize.width - ( rtl ? right : position.x );
2065
2066 // Make sure the dialog will not be resized to the wrong side when it's in the leftmost position for RTL.
2067 if ( ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH || resizable == CKEDITOR.DIALOG_RESIZE_BOTH ) )
2068 width = Math.max( def.minWidth || 0, internalWidth - wrapperWidth );
2069
2070 if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT || resizable == CKEDITOR.DIALOG_RESIZE_BOTH )
2071 height = Math.max( def.minHeight || 0, internalHeight - wrapperHeight );
2072
2073 dialog.resize( width, height );
2074
2075 if ( !dialog._.moved )
2076 dialog.layout();
2077
2078 evt.data.preventDefault();
2079 }
2080
2081 function mouseUpHandler() {
2082 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
2083 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
2084
2085 if ( dialogCover ) {
2086 dialogCover.remove();
2087 dialogCover = null;
2088 }
2089
2090 if ( CKEDITOR.env.ie6Compat ) {
2091 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
2092 coverDoc.removeListener( 'mouseup', mouseUpHandler );
2093 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
2094 }
2095 }
2096 }
2097
2098 var resizeCover;
2099 // Caching resuable covers and allowing only one cover
2100 // on screen.
2101 var covers = {},
2102 currentCover;
2103
2104 function cancelEvent( ev ) {
2105 ev.data.preventDefault( 1 );
2106 }
2107
2108 function showCover( editor ) {
2109 var win = CKEDITOR.document.getWindow();
2110 var config = editor.config,
2111 backgroundColorStyle = config.dialog_backgroundCoverColor || 'white',
2112 backgroundCoverOpacity = config.dialog_backgroundCoverOpacity,
2113 baseFloatZIndex = config.baseFloatZIndex,
2114 coverKey = CKEDITOR.tools.genKey( backgroundColorStyle, backgroundCoverOpacity, baseFloatZIndex ),
2115 coverElement = covers[ coverKey ];
2116
2117 if ( !coverElement ) {
2118 var html = [
2119 '<div tabIndex="-1" style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),
2120 '; z-index: ', baseFloatZIndex,
2121 '; top: 0px; left: 0px; ',
2122 ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),
2123 '" class="cke_dialog_background_cover">'
2124 ];
2125
2126 if ( CKEDITOR.env.ie6Compat ) {
2127 // Support for custom document.domain in IE.
2128 var iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
2129
2130 html.push( '<iframe' +
2131 ' hidefocus="true"' +
2132 ' frameborder="0"' +
2133 ' id="cke_dialog_background_iframe"' +
2134 ' src="javascript:' );
2135
2136 html.push( 'void((function(){' + encodeURIComponent(
2137 'document.open();' +
2138 // Support for custom document.domain in IE.
2139 '(' + CKEDITOR.tools.fixDomain + ')();' +
2140 'document.write( \'' + iframeHtml + '\' );' +
2141 'document.close();'
2142 ) + '})())' );
2143
2144 html.push( '"' +
2145 ' style="' +
2146 'position:absolute;' +
2147 'left:0;' +
2148 'top:0;' +
2149 'width:100%;' +
2150 'height: 100%;' +
2151 'filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
2152 '</iframe>' );
2153 }
2154
2155 html.push( '</div>' );
2156
2157 coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
2158 coverElement.setOpacity( backgroundCoverOpacity !== undefined ? backgroundCoverOpacity : 0.5 );
2159
2160 coverElement.on( 'keydown', cancelEvent );
2161 coverElement.on( 'keypress', cancelEvent );
2162 coverElement.on( 'keyup', cancelEvent );
2163
2164 coverElement.appendTo( CKEDITOR.document.getBody() );
2165 covers[ coverKey ] = coverElement;
2166 } else {
2167 coverElement.show();
2168 }
2169
2170 // Makes the dialog cover a focus holder as well.
2171 editor.focusManager.add( coverElement );
2172
2173 currentCover = coverElement;
2174 var resizeFunc = function() {
2175 var size = win.getViewPaneSize();
2176 coverElement.setStyles( {
2177 width: size.width + 'px',
2178 height: size.height + 'px'
2179 } );
2180 };
2181
2182 var scrollFunc = function() {
2183 var pos = win.getScrollPosition(),
2184 cursor = CKEDITOR.dialog._.currentTop;
2185 coverElement.setStyles( {
2186 left: pos.x + 'px',
2187 top: pos.y + 'px'
2188 } );
2189
2190 if ( cursor ) {
2191 do {
2192 var dialogPos = cursor.getPosition();
2193 cursor.move( dialogPos.x, dialogPos.y );
2194 } while ( ( cursor = cursor._.parentDialog ) );
2195 }
2196 };
2197
2198 resizeCover = resizeFunc;
2199 win.on( 'resize', resizeFunc );
2200 resizeFunc();
2201 // Using Safari/Mac, focus must be kept where it is (#7027)
2202 if ( !( CKEDITOR.env.mac && CKEDITOR.env.webkit ) )
2203 coverElement.focus();
2204
2205 if ( CKEDITOR.env.ie6Compat ) {
2206 // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
2207 // So we need to invent a really funny way to make it work.
2208 var myScrollHandler = function() {
2209 scrollFunc();
2210 arguments.callee.prevScrollHandler.apply( this, arguments );
2211 };
2212 win.$.setTimeout( function() {
2213 myScrollHandler.prevScrollHandler = window.onscroll ||
2214 function() {};
2215 window.onscroll = myScrollHandler;
2216 }, 0 );
2217 scrollFunc();
2218 }
2219 }
2220
2221 function hideCover( editor ) {
2222 if ( !currentCover )
2223 return;
2224
2225 editor.focusManager.remove( currentCover );
2226 var win = CKEDITOR.document.getWindow();
2227 currentCover.hide();
2228 win.removeListener( 'resize', resizeCover );
2229
2230 if ( CKEDITOR.env.ie6Compat ) {
2231 win.$.setTimeout( function() {
2232 var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
2233 window.onscroll = prevScrollHandler || null;
2234 }, 0 );
2235 }
2236 resizeCover = null;
2237 }
2238
2239 function removeCovers() {
2240 for ( var coverId in covers )
2241 covers[ coverId ].remove();
2242 covers = {};
2243 }
2244
2245 var accessKeyProcessors = {};
2246
2247 var accessKeyDownHandler = function( evt ) {
2248 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
2249 alt = evt.data.$.altKey,
2250 shift = evt.data.$.shiftKey,
2251 key = String.fromCharCode( evt.data.$.keyCode ),
2252 keyProcessor = accessKeyProcessors[ ( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '' ) + ( shift ? 'SHIFT+' : '' ) + key ];
2253
2254 if ( !keyProcessor || !keyProcessor.length )
2255 return;
2256
2257 keyProcessor = keyProcessor[ keyProcessor.length - 1 ];
2258 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
2259 evt.data.preventDefault();
2260 };
2261
2262 var accessKeyUpHandler = function( evt ) {
2263 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
2264 alt = evt.data.$.altKey,
2265 shift = evt.data.$.shiftKey,
2266 key = String.fromCharCode( evt.data.$.keyCode ),
2267 keyProcessor = accessKeyProcessors[ ( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '' ) + ( shift ? 'SHIFT+' : '' ) + key ];
2268
2269 if ( !keyProcessor || !keyProcessor.length )
2270 return;
2271
2272 keyProcessor = keyProcessor[ keyProcessor.length - 1 ];
2273 if ( keyProcessor.keyup ) {
2274 keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
2275 evt.data.preventDefault();
2276 }
2277 };
2278
2279 var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc ) {
2280 var procList = accessKeyProcessors[ key ] || ( accessKeyProcessors[ key ] = [] );
2281 procList.push( {
2282 uiElement: uiElement,
2283 dialog: dialog,
2284 key: key,
2285 keyup: upFunc || uiElement.accessKeyUp,
2286 keydown: downFunc || uiElement.accessKeyDown
2287 } );
2288 };
2289
2290 var unregisterAccessKey = function( obj ) {
2291 for ( var i in accessKeyProcessors ) {
2292 var list = accessKeyProcessors[ i ];
2293 for ( var j = list.length - 1; j >= 0; j-- ) {
2294 if ( list[ j ].dialog == obj || list[ j ].uiElement == obj )
2295 list.splice( j, 1 );
2296 }
2297 if ( list.length === 0 )
2298 delete accessKeyProcessors[ i ];
2299 }
2300 };
2301
2302 var tabAccessKeyUp = function( dialog, key ) {
2303 if ( dialog._.accessKeyMap[ key ] )
2304 dialog.selectPage( dialog._.accessKeyMap[ key ] );
2305 };
2306
2307 var tabAccessKeyDown = function() {};
2308
2309 ( function() {
2310 CKEDITOR.ui.dialog = {
2311 /**
2312 * The base class of all dialog UI elements.
2313 *
2314 * @class CKEDITOR.ui.dialog.uiElement
2315 * @constructor Creates a uiElement class instance.
2316 * @param {CKEDITOR.dialog} dialog Parent dialog object.
2317 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition Element
2318 * definition.
2319 *
2320 * Accepted fields:
2321 *
2322 * * `id` (Required) The id of the UI element. See {@link CKEDITOR.dialog#getContentElement}.
2323 * * `type` (Required) The type of the UI element. The
2324 * value to this field specifies which UI element class will be used to
2325 * generate the final widget.
2326 * * `title` (Optional) The popup tooltip for the UI
2327 * element.
2328 * * `hidden` (Optional) A flag that tells if the element
2329 * should be initially visible.
2330 * * `className` (Optional) Additional CSS class names
2331 * to add to the UI element. Separated by space.
2332 * * `style` (Optional) Additional CSS inline styles
2333 * to add to the UI element. A semicolon (;) is required after the last
2334 * style declaration.
2335 * * `accessKey` (Optional) The alphanumeric access key
2336 * for this element. Access keys are automatically prefixed by CTRL.
2337 * * `on*` (Optional) Any UI element definition field that
2338 * starts with `on` followed immediately by a capital letter and
2339 * probably more letters is an event handler. Event handlers may be further
2340 * divided into registered event handlers and DOM event handlers. Please
2341 * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and
2342 * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more information.
2343 *
2344 * @param {Array} htmlList
2345 * List of HTML code to be added to the dialog's content area.
2346 * @param {Function/String} [nodeNameArg='div']
2347 * A function returning a string, or a simple string for the node name for
2348 * the root DOM node.
2349 * @param {Function/Object} [stylesArg={}]
2350 * A function returning an object, or a simple object for CSS styles applied
2351 * to the DOM node.
2352 * @param {Function/Object} [attributesArg={}]
2353 * A fucntion returning an object, or a simple object for attributes applied
2354 * to the DOM node.
2355 * @param {Function/String} [contentsArg='']
2356 * A function returning a string, or a simple string for the HTML code inside
2357 * the root DOM node. Default is empty string.
2358 */
2359 uiElement: function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg ) {
2360 if ( arguments.length < 4 )
2361 return;
2362
2363 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',
2364 html = [ '<', nodeName, ' ' ],
2365 styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},
2366 attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},
2367 innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',
2368 domId = this.domId = attributes.id || CKEDITOR.tools.getNextId() + '_uiElement',
2369 i;
2370
2371 if ( elementDefinition.requiredContent && !dialog.getParentEditor().filter.check( elementDefinition.requiredContent ) ) {
2372 styles.display = 'none';
2373 this.notAllowed = true;
2374 }
2375
2376 // Set the id, a unique id is required for getElement() to work.
2377 attributes.id = domId;
2378
2379 // Set the type and definition CSS class names.
2380 var classes = {};
2381 if ( elementDefinition.type )
2382 classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;
2383 if ( elementDefinition.className )
2384 classes[ elementDefinition.className ] = 1;
2385 if ( elementDefinition.disabled )
2386 classes.cke_disabled = 1;
2387
2388 var attributeClasses = ( attributes[ 'class' ] && attributes[ 'class' ].split ) ? attributes[ 'class' ].split( ' ' ) : [];
2389 for ( i = 0; i < attributeClasses.length; i++ ) {
2390 if ( attributeClasses[ i ] )
2391 classes[ attributeClasses[ i ] ] = 1;
2392 }
2393 var finalClasses = [];
2394 for ( i in classes )
2395 finalClasses.push( i );
2396 attributes[ 'class' ] = finalClasses.join( ' ' );
2397
2398 // Set the popup tooltop.
2399 if ( elementDefinition.title )
2400 attributes.title = elementDefinition.title;
2401
2402 // Write the inline CSS styles.
2403 var styleStr = ( elementDefinition.style || '' ).split( ';' );
2404
2405 // Element alignment support.
2406 if ( elementDefinition.align ) {
2407 var align = elementDefinition.align;
2408 styles[ 'margin-left' ] = align == 'left' ? 0 : 'auto';
2409 styles[ 'margin-right' ] = align == 'right' ? 0 : 'auto';
2410 }
2411
2412 for ( i in styles )
2413 styleStr.push( i + ':' + styles[ i ] );
2414 if ( elementDefinition.hidden )
2415 styleStr.push( 'display:none' );
2416 for ( i = styleStr.length - 1; i >= 0; i-- ) {
2417 if ( styleStr[ i ] === '' )
2418 styleStr.splice( i, 1 );
2419 }
2420 if ( styleStr.length > 0 )
2421 attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
2422
2423 // Write the attributes.
2424 for ( i in attributes )
2425 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[ i ] ) + '" ' );
2426
2427 // Write the content HTML.
2428 html.push( '>', innerHTML, '</', nodeName, '>' );
2429
2430 // Add contents to the parent HTML array.
2431 htmlList.push( html.join( '' ) );
2432
2433 ( this._ || ( this._ = {} ) ).dialog = dialog;
2434
2435 // Override isChanged if it is defined in element definition.
2436 if ( typeof elementDefinition.isChanged == 'boolean' )
2437 this.isChanged = function() {
2438 return elementDefinition.isChanged;
2439 };
2440 if ( typeof elementDefinition.isChanged == 'function' )
2441 this.isChanged = elementDefinition.isChanged;
2442
2443 // Overload 'get(set)Value' on definition.
2444 if ( typeof elementDefinition.setValue == 'function' ) {
2445 this.setValue = CKEDITOR.tools.override( this.setValue, function( org ) {
2446 return function( val ) {
2447 org.call( this, elementDefinition.setValue.call( this, val ) );
2448 };
2449 } );
2450 }
2451
2452 if ( typeof elementDefinition.getValue == 'function' ) {
2453 this.getValue = CKEDITOR.tools.override( this.getValue, function( org ) {
2454 return function() {
2455 return elementDefinition.getValue.call( this, org.call( this ) );
2456 };
2457 } );
2458 }
2459
2460 // Add events.
2461 CKEDITOR.event.implementOn( this );
2462
2463 this.registerEvents( elementDefinition );
2464 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
2465 registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
2466
2467 var me = this;
2468 dialog.on( 'load', function() {
2469 var input = me.getInputElement();
2470 if ( input ) {
2471 var focusClass = me.type in { 'checkbox': 1, 'ratio': 1 } && CKEDITOR.env.ie && CKEDITOR.env.version < 8 ? 'cke_dialog_ui_focused' : '';
2472 input.on( 'focus', function() {
2473 dialog._.tabBarMode = false;
2474 dialog._.hasFocus = true;
2475 me.fire( 'focus' );
2476 focusClass && this.addClass( focusClass );
2477
2478 } );
2479
2480 input.on( 'blur', function() {
2481 me.fire( 'blur' );
2482 focusClass && this.removeClass( focusClass );
2483 } );
2484 }
2485 } );
2486
2487 // Completes this object with everything we have in the
2488 // definition.
2489 CKEDITOR.tools.extend( this, elementDefinition );
2490
2491 // Register the object as a tab focus if it can be included.
2492 if ( this.keyboardFocusable ) {
2493 this.tabIndex = elementDefinition.tabIndex || 0;
2494
2495 this.focusIndex = dialog._.focusList.push( this ) - 1;
2496 this.on( 'focus', function() {
2497 dialog._.currentFocusIndex = me.focusIndex;
2498 } );
2499 }
2500 },
2501
2502 /**
2503 * Horizontal layout box for dialog UI elements, auto-expends to available width of container.
2504 *
2505 * @class CKEDITOR.ui.dialog.hbox
2506 * @extends CKEDITOR.ui.dialog.uiElement
2507 * @constructor Creates a hbox class instance.
2508 * @param {CKEDITOR.dialog} dialog Parent dialog object.
2509 * @param {Array} childObjList
2510 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this container.
2511 * @param {Array} childHtmlList
2512 * Array of HTML code that correspond to the HTML output of all the
2513 * objects in childObjList.
2514 * @param {Array} htmlList
2515 * Array of HTML code that this element will output to.
2516 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
2517 * The element definition. Accepted fields:
2518 *
2519 * * `widths` (Optional) The widths of child cells.
2520 * * `height` (Optional) The height of the layout.
2521 * * `padding` (Optional) The padding width inside child cells.
2522 * * `align` (Optional) The alignment of the whole layout.
2523 */
2524 hbox: function( dialog, childObjList, childHtmlList, htmlList, elementDefinition ) {
2525 if ( arguments.length < 4 )
2526 return;
2527
2528 this._ || ( this._ = {} );
2529
2530 var children = this._.children = childObjList,
2531 widths = elementDefinition && elementDefinition.widths || null,
2532 height = elementDefinition && elementDefinition.height || null,
2533 styles = {},
2534 i;
2535 /** @ignore */
2536 var innerHTML = function() {
2537 var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];
2538 for ( i = 0; i < childHtmlList.length; i++ ) {
2539 var className = 'cke_dialog_ui_hbox_child',
2540 styles = [];
2541 if ( i === 0 ) {
2542 className = 'cke_dialog_ui_hbox_first';
2543 }
2544 if ( i == childHtmlList.length - 1 ) {
2545 className = 'cke_dialog_ui_hbox_last';
2546 }
2547
2548 html.push( '<td class="', className, '" role="presentation" ' );
2549 if ( widths ) {
2550 if ( widths[ i ] ) {
2551 styles.push( 'width:' + cssLength( widths[i] ) );
2552 }
2553 } else {
2554 styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
2555 }
2556 if ( height ) {
2557 styles.push( 'height:' + cssLength( height ) );
2558 }
2559 if ( elementDefinition && elementDefinition.padding !== undefined ) {
2560 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
2561 }
2562 // In IE Quirks alignment has to be done on table cells. (#7324)
2563 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && children[ i ].align ) {
2564 styles.push( 'text-align:' + children[ i ].align );
2565 }
2566 if ( styles.length > 0 ) {
2567 html.push( 'style="' + styles.join( '; ' ) + '" ' );
2568 }
2569 html.push( '>', childHtmlList[ i ], '</td>' );
2570 }
2571 html.push( '</tr></tbody>' );
2572 return html.join( '' );
2573 };
2574
2575 var attribs = { role: 'presentation' };
2576 elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );
2577
2578 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type: 'hbox' }, htmlList, 'table', styles, attribs, innerHTML );
2579 },
2580
2581 /**
2582 * Vertical layout box for dialog UI elements.
2583 *
2584 * @class CKEDITOR.ui.dialog.vbox
2585 * @extends CKEDITOR.ui.dialog.hbox
2586 * @constructor Creates a vbox class instance.
2587 * @param {CKEDITOR.dialog} dialog Parent dialog object.
2588 * @param {Array} childObjList
2589 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this container.
2590 * @param {Array} childHtmlList
2591 * Array of HTML code that correspond to the HTML output of all the
2592 * objects in childObjList.
2593 * @param {Array} htmlList Array of HTML code that this element will output to.
2594 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
2595 * The element definition. Accepted fields:
2596 *
2597 * * `width` (Optional) The width of the layout.
2598 * * `heights` (Optional) The heights of individual cells.
2599 * * `align` (Optional) The alignment of the layout.
2600 * * `padding` (Optional) The padding width inside child cells.
2601 * * `expand` (Optional) Whether the layout should expand
2602 * vertically to fill its container.
2603 */
2604 vbox: function( dialog, childObjList, childHtmlList, htmlList, elementDefinition ) {
2605 if ( arguments.length < 3 )
2606 return;
2607
2608 this._ || ( this._ = {} );
2609
2610 var children = this._.children = childObjList,
2611 width = elementDefinition && elementDefinition.width || null,
2612 heights = elementDefinition && elementDefinition.heights || null;
2613 /** @ignore */
2614 var innerHTML = function() {
2615 var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];
2616 html.push( 'style="' );
2617 if ( elementDefinition && elementDefinition.expand )
2618 html.push( 'height:100%;' );
2619 html.push( 'width:' + cssLength( width || '100%' ), ';' );
2620
2621 // (#10123) Temp fix for dialog broken layout in latest webkit.
2622 if ( CKEDITOR.env.webkit )
2623 html.push( 'float:none;' );
2624
2625 html.push( '"' );
2626 html.push( 'align="', CKEDITOR.tools.htmlEncode(
2627 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
2628
2629 html.push( '><tbody>' );
2630 for ( var i = 0; i < childHtmlList.length; i++ ) {
2631 var styles = [];
2632 html.push( '<tr><td role="presentation" ' );
2633 if ( width )
2634 styles.push( 'width:' + cssLength( width || '100%' ) );
2635 if ( heights )
2636 styles.push( 'height:' + cssLength( heights[ i ] ) );
2637 else if ( elementDefinition && elementDefinition.expand )
2638 styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
2639 if ( elementDefinition && elementDefinition.padding !== undefined )
2640 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
2641 // In IE Quirks alignment has to be done on table cells. (#7324)
2642 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && children[ i ].align )
2643 styles.push( 'text-align:' + children[ i ].align );
2644 if ( styles.length > 0 )
2645 html.push( 'style="', styles.join( '; ' ), '" ' );
2646 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[ i ], '</td></tr>' );
2647 }
2648 html.push( '</tbody></table>' );
2649 return html.join( '' );
2650 };
2651 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type: 'vbox' }, htmlList, 'div', null, { role: 'presentation' }, innerHTML );
2652 }
2653 };
2654 } )();
2655
2656 /** @class CKEDITOR.ui.dialog.uiElement */
2657 CKEDITOR.ui.dialog.uiElement.prototype = {
2658 /**
2659 * Gets the root DOM element of this dialog UI object.
2660 *
2661 * uiElement.getElement().hide();
2662 *
2663 * @returns {CKEDITOR.dom.element} Root DOM element of UI object.
2664 */
2665 getElement: function() {
2666 return CKEDITOR.document.getById( this.domId );
2667 },
2668
2669 /**
2670 * Gets the DOM element that the user inputs values.
2671 *
2672 * This function is used by {@link #setValue}, {@link #getValue} and {@link #focus}. It should
2673 * be overrided in child classes where the input element isn't the root
2674 * element.
2675 *
2676 * var rawValue = textInput.getInputElement().$.value;
2677 *
2678 * @returns {CKEDITOR.dom.element} The element where the user input values.
2679 */
2680 getInputElement: function() {
2681 return this.getElement();
2682 },
2683
2684 /**
2685 * Gets the parent dialog object containing this UI element.
2686 *
2687 * var dialog = uiElement.getDialog();
2688 *
2689 * @returns {CKEDITOR.dialog} Parent dialog object.
2690 */
2691 getDialog: function() {
2692 return this._.dialog;
2693 },
2694
2695 /**
2696 * Sets the value of this dialog UI object.
2697 *
2698 * uiElement.setValue( 'Dingo' );
2699 *
2700 * @chainable
2701 * @param {Object} value The new value.
2702 * @param {Boolean} noChangeEvent Internal commit, to supress `change` event on this element.
2703 */
2704 setValue: function( value, noChangeEvent ) {
2705 this.getInputElement().setValue( value );
2706 !noChangeEvent && this.fire( 'change', { value: value } );
2707 return this;
2708 },
2709
2710 /**
2711 * Gets the current value of this dialog UI object.
2712 *
2713 * var myValue = uiElement.getValue();
2714 *
2715 * @returns {Object} The current value.
2716 */
2717 getValue: function() {
2718 return this.getInputElement().getValue();
2719 },
2720
2721 /**
2722 * Tells whether the UI object's value has changed.
2723 *
2724 * if ( uiElement.isChanged() )
2725 * confirm( 'Value changed! Continue?' );
2726 *
2727 * @returns {Boolean} `true` if changed, `false` if not changed.
2728 */
2729 isChanged: function() {
2730 // Override in input classes.
2731 return false;
2732 },
2733
2734 /**
2735 * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
2736 *
2737 * focus : function() {
2738 * this.selectParentTab();
2739 * // do something else.
2740 * }
2741 *
2742 * @chainable
2743 */
2744 selectParentTab: function() {
2745 var element = this.getInputElement(),
2746 cursor = element,
2747 tabId;
2748 while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 ) {
2749
2750 }
2751
2752 // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
2753 if ( !cursor )
2754 return this;
2755
2756 tabId = cursor.getAttribute( 'name' );
2757 // Avoid duplicate select.
2758 if ( this._.dialog._.currentTabId != tabId )
2759 this._.dialog.selectPage( tabId );
2760 return this;
2761 },
2762
2763 /**
2764 * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
2765 *
2766 * uiElement.focus();
2767 *
2768 * @chainable
2769 */
2770 focus: function() {
2771 this.selectParentTab().getInputElement().focus();
2772 return this;
2773 },
2774
2775 /**
2776 * Registers the `on*` event handlers defined in the element definition.
2777 *
2778 * The default behavior of this function is:
2779 *
2780 * 1. If the on* event is defined in the class's eventProcesors list,
2781 * then the registration is delegated to the corresponding function
2782 * in the eventProcessors list.
2783 * 2. If the on* event is not defined in the eventProcessors list, then
2784 * register the event handler under the corresponding DOM event of
2785 * the UI element's input DOM element (as defined by the return value
2786 * of {@link #getInputElement}).
2787 *
2788 * This function is only called at UI element instantiation, but can
2789 * be overridded in child classes if they require more flexibility.
2790 *
2791 * @chainable
2792 * @param {CKEDITOR.dialog.definition.uiElement} definition The UI element
2793 * definition.
2794 */
2795 registerEvents: function( definition ) {
2796 var regex = /^on([A-Z]\w+)/,
2797 match;
2798
2799 var registerDomEvent = function( uiElement, dialog, eventName, func ) {
2800 dialog.on( 'load', function() {
2801 uiElement.getInputElement().on( eventName, func, uiElement );
2802 } );
2803 };
2804
2805 for ( var i in definition ) {
2806 if ( !( match = i.match( regex ) ) )
2807 continue;
2808 if ( this.eventProcessors[ i ] )
2809 this.eventProcessors[ i ].call( this, this._.dialog, definition[ i ] );
2810 else
2811 registerDomEvent( this, this._.dialog, match[ 1 ].toLowerCase(), definition[ i ] );
2812 }
2813
2814 return this;
2815 },
2816
2817 /**
2818 * The event processor list used by
2819 * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element
2820 * instantiation. The default list defines three `on*` events:
2821 *
2822 * 1. `onLoad` - Called when the element's parent dialog opens for the
2823 * first time.
2824 * 2. `onShow` - Called whenever the element's parent dialog opens.
2825 * 3. `onHide` - Called whenever the element's parent dialog closes.
2826 *
2827 * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick
2828 * // handlers in the UI element's definitions.
2829 * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},
2830 * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
2831 * { onClick : function( dialog, func ) { this.on( 'click', func ); } },
2832 * true
2833 * );
2834 *
2835 * @property {Object}
2836 */
2837 eventProcessors: {
2838 onLoad: function( dialog, func ) {
2839 dialog.on( 'load', func, this );
2840 },
2841
2842 onShow: function( dialog, func ) {
2843 dialog.on( 'show', func, this );
2844 },
2845
2846 onHide: function( dialog, func ) {
2847 dialog.on( 'hide', func, this );
2848 }
2849 },
2850
2851 /**
2852 * The default handler for a UI element's access key down event, which
2853 * tries to put focus to the UI element.
2854 *
2855 * Can be overridded in child classes for more sophisticaed behavior.
2856 *
2857 * @param {CKEDITOR.dialog} dialog The parent dialog object.
2858 * @param {String} key The key combination pressed. Since access keys
2859 * are defined to always include the `CTRL` key, its value should always
2860 * include a `'CTRL+'` prefix.
2861 */
2862 accessKeyDown: function() {
2863 this.focus();
2864 },
2865
2866 /**
2867 * The default handler for a UI element's access key up event, which
2868 * does nothing.
2869 *
2870 * Can be overridded in child classes for more sophisticated behavior.
2871 *
2872 * @param {CKEDITOR.dialog} dialog The parent dialog object.
2873 * @param {String} key The key combination pressed. Since access keys
2874 * are defined to always include the `CTRL` key, its value should always
2875 * include a `'CTRL+'` prefix.
2876 */
2877 accessKeyUp: function() {},
2878
2879 /**
2880 * Disables a UI element.
2881 */
2882 disable: function() {
2883 var element = this.getElement(),
2884 input = this.getInputElement();
2885 input.setAttribute( 'disabled', 'true' );
2886 element.addClass( 'cke_disabled' );
2887 },
2888
2889 /**
2890 * Enables a UI element.
2891 */
2892 enable: function() {
2893 var element = this.getElement(),
2894 input = this.getInputElement();
2895 input.removeAttribute( 'disabled' );
2896 element.removeClass( 'cke_disabled' );
2897 },
2898
2899 /**
2900 * Determines whether an UI element is enabled or not.
2901 *
2902 * @returns {Boolean} Whether the UI element is enabled.
2903 */
2904 isEnabled: function() {
2905 return !this.getElement().hasClass( 'cke_disabled' );
2906 },
2907
2908 /**
2909 * Determines whether an UI element is visible or not.
2910 *
2911 * @returns {Boolean} Whether the UI element is visible.
2912 */
2913 isVisible: function() {
2914 return this.getInputElement().isVisible();
2915 },
2916
2917 /**
2918 * Determines whether an UI element is focus-able or not.
2919 * Focus-able is defined as being both visible and enabled.
2920 *
2921 * @returns {Boolean} Whether the UI element can be focused.
2922 */
2923 isFocusable: function() {
2924 if ( !this.isEnabled() || !this.isVisible() )
2925 return false;
2926 return true;
2927 }
2928 };
2929
2930 /** @class CKEDITOR.ui.dialog.hbox */
2931 CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement(), {
2932 /**
2933 * Gets a child UI element inside this container.
2934 *
2935 * var checkbox = hbox.getChild( [0,1] );
2936 * checkbox.setValue( true );
2937 *
2938 * @param {Array/Number} indices An array or a single number to indicate the child's
2939 * position in the container's descendant tree. Omit to get all the children in an array.
2940 * @returns {Array/CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container
2941 * if no argument given, or the specified UI element if indices is given.
2942 */
2943 getChild: function( indices ) {
2944 // If no arguments, return a clone of the children array.
2945 if ( arguments.length < 1 )
2946 return this._.children.concat();
2947
2948 // If indices isn't array, make it one.
2949 if ( !indices.splice )
2950 indices = [ indices ];
2951
2952 // Retrieve the child element according to tree position.
2953 if ( indices.length < 2 )
2954 return this._.children[ indices[ 0 ] ];
2955 else
2956 return ( this._.children[ indices[ 0 ] ] && this._.children[ indices[ 0 ] ].getChild ) ? this._.children[ indices[ 0 ] ].getChild( indices.slice( 1, indices.length ) ) : null;
2957 }
2958 }, true );
2959
2960 CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
2961
2962 ( function() {
2963 var commonBuilder = {
2964 build: function( dialog, elementDefinition, output ) {
2965 var children = elementDefinition.children,
2966 child,
2967 childHtmlList = [],
2968 childObjList = [];
2969 for ( var i = 0;
2970 ( i < children.length && ( child = children[ i ] ) ); i++ ) {
2971 var childHtml = [];
2972 childHtmlList.push( childHtml );
2973 childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
2974 }
2975 return new CKEDITOR.ui.dialog[ elementDefinition.type ]( dialog, childObjList, childHtmlList, output, elementDefinition );
2976 }
2977 };
2978
2979 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
2980 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
2981 } )();
2982
2983 /**
2984 * Generic dialog command. It opens a specific dialog when executed.
2985 *
2986 * // Register the "link" command, which opens the "link" dialog.
2987 * editor.addCommand( 'link', new CKEDITOR.dialogCommand( 'link' ) );
2988 *
2989 * @class
2990 * @constructor Creates a dialogCommand class instance.
2991 * @extends CKEDITOR.commandDefinition
2992 * @param {String} dialogName The name of the dialog to open when executing
2993 * this command.
2994 * @param {Object} [ext] Additional command definition's properties.
2995 */
2996 CKEDITOR.dialogCommand = function( dialogName, ext ) {
2997 this.dialogName = dialogName;
2998 CKEDITOR.tools.extend( this, ext, true );
2999 };
3000
3001 CKEDITOR.dialogCommand.prototype = {
3002 exec: function( editor ) {
3003 editor.openDialog( this.dialogName );
3004 },
3005
3006 // Dialog commands just open a dialog ui, thus require no undo logic,
3007 // undo support should dedicate to specific dialog implementation.
3008 canUndo: false,
3009
3010 editorFocus: 1
3011 };
3012
3013 ( function() {
3014 var notEmptyRegex = /^([a]|[^a])+$/,
3015 integerRegex = /^\d*$/,
3016 numberRegex = /^\d*(?:\.\d+)?$/,
3017 htmlLengthRegex = /^(((\d*(\.\d+))|(\d*))(px|\%)?)?$/,
3018 cssLengthRegex = /^(((\d*(\.\d+))|(\d*))(px|em|ex|in|cm|mm|pt|pc|\%)?)?$/i,
3019 inlineStyleRegex = /^(\s*[\w-]+\s*:\s*[^:;]+(?:;|$))*$/;
3020
3021 CKEDITOR.VALIDATE_OR = 1;
3022 CKEDITOR.VALIDATE_AND = 2;
3023
3024 CKEDITOR.dialog.validate = {
3025 functions: function() {
3026 var args = arguments;
3027 return function() {
3028 /**
3029 * It's important for validate functions to be able to accept the value
3030 * as argument in addition to this.getValue(), so that it is possible to
3031 * combine validate functions together to make more sophisticated
3032 * validators.
3033 */
3034 var value = this && this.getValue ? this.getValue() : args[ 0 ];
3035
3036 var msg,
3037 relation = CKEDITOR.VALIDATE_AND,
3038 functions = [],
3039 i;
3040
3041 for ( i = 0; i < args.length; i++ ) {
3042 if ( typeof args[ i ] == 'function' )
3043 functions.push( args[ i ] );
3044 else
3045 break;
3046 }
3047
3048 if ( i < args.length && typeof args[ i ] == 'string' ) {
3049 msg = args[ i ];
3050 i++;
3051 }
3052
3053 if ( i < args.length && typeof args[ i ] == 'number' )
3054 relation = args[ i ];
3055
3056 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );
3057 for ( i = 0; i < functions.length; i++ ) {
3058 if ( relation == CKEDITOR.VALIDATE_AND )
3059 passed = passed && functions[ i ]( value );
3060 else
3061 passed = passed || functions[ i ]( value );
3062 }
3063
3064 return !passed ? msg : true;
3065 };
3066 },
3067
3068 regex: function( regex, msg ) {
3069 /*
3070 * Can be greatly shortened by deriving from functions validator if code size
3071 * turns out to be more important than performance.
3072 */
3073 return function() {
3074 var value = this && this.getValue ? this.getValue() : arguments[ 0 ];
3075 return !regex.test( value ) ? msg : true;
3076 };
3077 },
3078
3079 notEmpty: function( msg ) {
3080 return this.regex( notEmptyRegex, msg );
3081 },
3082
3083 integer: function( msg ) {
3084 return this.regex( integerRegex, msg );
3085 },
3086
3087 'number': function( msg ) {
3088 return this.regex( numberRegex, msg );
3089 },
3090
3091 'cssLength': function( msg ) {
3092 return this.functions( function( val ) {
3093 return cssLengthRegex.test( CKEDITOR.tools.trim( val ) );
3094 }, msg );
3095 },
3096
3097 'htmlLength': function( msg ) {
3098 return this.functions( function( val ) {
3099 return htmlLengthRegex.test( CKEDITOR.tools.trim( val ) );
3100 }, msg );
3101 },
3102
3103 'inlineStyle': function( msg ) {
3104 return this.functions( function( val ) {
3105 return inlineStyleRegex.test( CKEDITOR.tools.trim( val ) );
3106 }, msg );
3107 },
3108
3109 equals: function( value, msg ) {
3110 return this.functions( function( val ) {
3111 return val == value;
3112 }, msg );
3113 },
3114
3115 notEqual: function( value, msg ) {
3116 return this.functions( function( val ) {
3117 return val != value;
3118 }, msg );
3119 }
3120 };
3121
3122 CKEDITOR.on( 'instanceDestroyed', function( evt ) {
3123 // Remove dialog cover on last instance destroy.
3124 if ( CKEDITOR.tools.isEmpty( CKEDITOR.instances ) ) {
3125 var currentTopDialog;
3126 while ( ( currentTopDialog = CKEDITOR.dialog._.currentTop ) )
3127 currentTopDialog.hide();
3128 removeCovers();
3129 }
3130
3131 var dialogs = evt.editor._.storedDialogs;
3132 for ( var name in dialogs )
3133 dialogs[ name ].destroy();
3134
3135 } );
3136
3137 } )();
3138
3139 // Extend the CKEDITOR.editor class with dialog specific functions.
3140 CKEDITOR.tools.extend( CKEDITOR.editor.prototype, {
3141 /**
3142 * Loads and opens a registered dialog.
3143 *
3144 * CKEDITOR.instances.editor1.openDialog( 'smiley' );
3145 *
3146 * @member CKEDITOR.editor
3147 * @param {String} dialogName The registered name of the dialog.
3148 * @param {Function} callback The function to be invoked after dialog instance created.
3149 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed.
3150 * `null` if the dialog name is not registered.
3151 * @see CKEDITOR.dialog#add
3152 */
3153 openDialog: function( dialogName, callback ) {
3154 var dialog = null, dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];
3155
3156 if ( CKEDITOR.dialog._.currentTop === null )
3157 showCover( this );
3158
3159 // If the dialogDefinition is already loaded, open it immediately.
3160 if ( typeof dialogDefinitions == 'function' ) {
3161 var storedDialogs = this._.storedDialogs || ( this._.storedDialogs = {} );
3162
3163 dialog = storedDialogs[ dialogName ] || ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
3164
3165 callback && callback.call( dialog, dialog );
3166 dialog.show();
3167
3168 } else if ( dialogDefinitions == 'failed' ) {
3169 hideCover( this );
3170 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
3171 } else if ( typeof dialogDefinitions == 'string' ) {
3172
3173 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ),
3174 function() {
3175 var dialogDefinition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];
3176 // In case of plugin error, mark it as loading failed.
3177 if ( typeof dialogDefinition != 'function' )
3178 CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';
3179
3180 this.openDialog( dialogName, callback );
3181 }, this, 0, 1 );
3182 }
3183
3184 CKEDITOR.skin.loadPart( 'dialog' );
3185
3186 return dialog;
3187 }
3188 } );
3189 } )();
3190
3191 CKEDITOR.plugins.add( 'dialog', {
3192 requires: 'dialogui',
3193 init: function( editor ) {
3194 editor.on( 'doubleclick', function( evt ) {
3195 if ( evt.data.dialog )
3196 editor.openDialog( evt.data.dialog );
3197 }, null, null, 999 );
3198 }
3199 } );
3200
3201 // Dialog related configurations.
3202
3203 /**
3204 * The color of the dialog background cover. It should be a valid CSS color string.
3205 *
3206 * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
3207 *
3208 * @cfg {String} [dialog_backgroundCoverColor='white']
3209 * @member CKEDITOR.config
3210 */
3211
3212 /**
3213 * The opacity of the dialog background cover. It should be a number within the
3214 * range `[0.0, 1.0]`.
3215 *
3216 * config.dialog_backgroundCoverOpacity = 0.7;
3217 *
3218 * @cfg {Number} [dialog_backgroundCoverOpacity=0.5]
3219 * @member CKEDITOR.config
3220 */
3221
3222 /**
3223 * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.
3224 *
3225 * config.dialog_startupFocusTab = true;
3226 *
3227 * @cfg {Boolean} [dialog_startupFocusTab=false]
3228 * @member CKEDITOR.config
3229 */
3230
3231 /**
3232 * The distance of magnetic borders used in moving and resizing dialogs,
3233 * measured in pixels.
3234 *
3235 * config.dialog_magnetDistance = 30;
3236 *
3237 * @cfg {Number} [dialog_magnetDistance=20]
3238 * @member CKEDITOR.config
3239 */
3240
3241 /**
3242 * The guideline to follow when generating the dialog buttons. There are 3 possible options:
3243 *
3244 * * `'OS'` - the buttons will be displayed in the default order of the user's OS;
3245 * * `'ltr'` - for Left-To-Right order;
3246 * * `'rtl'` - for Right-To-Left order.
3247 *
3248 * Example:
3249 *
3250 * config.dialog_buttonsOrder = 'rtl';
3251 *
3252 * @since 3.5
3253 * @cfg {String} [dialog_buttonsOrder='OS']
3254 * @member CKEDITOR.config
3255 */
3256
3257 /**
3258 * The dialog contents to removed. It's a string composed by dialog name and tab name with a colon between them.
3259 *
3260 * Separate each pair with semicolon (see example).
3261 *
3262 * **Note:** All names are case-sensitive.
3263 *
3264 * **Note:** Be cautious when specifying dialog tabs that are mandatory,
3265 * like `'info'`, dialog functionality might be broken because of this!
3266 *
3267 * config.removeDialogTabs = 'flash:advanced;image:Link';
3268 *
3269 * @since 3.5
3270 * @cfg {String} [removeDialogTabs='']
3271 * @member CKEDITOR.config
3272 */
3273
3274 /**
3275 * Tells if user should not be asked to confirm close, if any dialog field was modified.
3276 * By default it is set to `false` meaning that the confirmation dialog will be shown.
3277 *
3278 * config.dialog_noConfirmCancel = true;
3279 *
3280 * @since 4.3
3281 * @cfg {Boolean} [dialog_noConfirmCancel=false]
3282 * @member CKEDITOR.config
3283 */
3284
3285 /**
3286 * Event fired when a dialog definition is about to be used to create a dialog into
3287 * an editor instance. This event makes it possible to customize the definition
3288 * before creating it.
3289 *
3290 * Note that this event is called only the first time a specific dialog is
3291 * opened. Successive openings will use the cached dialog, and this event will
3292 * not get fired.
3293 *
3294 * @event dialogDefinition
3295 * @member CKEDITOR
3296 * @param {CKEDITOR.dialog.definition} data The dialog defination that
3297 * is being loaded.
3298 * @param {CKEDITOR.editor} editor The editor instance that will use the dialog.
3299 */
3300
3301 /**
3302 * Event fired when a tab is going to be selected in a dialog.
3303 *
3304 * @event selectPage
3305 * @member CKEDITOR.dialog
3306 * @param data
3307 * @param {String} data.page The id of the page that it's gonna be selected.
3308 * @param {String} data.currentPage The id of the current page.
3309 */
3310
3311 /**
3312 * Event fired when the user tries to dismiss a dialog.
3313 *
3314 * @event cancel
3315 * @member CKEDITOR.dialog
3316 * @param data
3317 * @param {Boolean} data.hide Whether the event should proceed or not.
3318 */
3319
3320 /**
3321 * Event fired when the user tries to confirm a dialog.
3322 *
3323 * @event ok
3324 * @member CKEDITOR.dialog
3325 * @param data
3326 * @param {Boolean} data.hide Whether the event should proceed or not.
3327 */
3328
3329 /**
3330 * Event fired when a dialog is shown.
3331 *
3332 * @event show
3333 * @member CKEDITOR.dialog
3334 */
3335
3336 /**
3337 * Event fired when a dialog is shown.
3338 *
3339 * @event dialogShow
3340 * @member CKEDITOR.editor
3341 * @param {CKEDITOR.editor} editor This editor instance.
3342 * @param {CKEDITOR.dialog} data The opened dialog instance.
3343 */
3344
3345 /**
3346 * Event fired when a dialog is hidden.
3347 *
3348 * @event hide
3349 * @member CKEDITOR.dialog
3350 */
3351
3352 /**
3353 * Event fired when a dialog is hidden.
3354 *
3355 * @event dialogHide
3356 * @member CKEDITOR.editor
3357 * @param {CKEDITOR.editor} editor This editor instance.
3358 * @param {CKEDITOR.dialog} data The hidden dialog instance.
3359 */
3360
3361 /**
3362 * Event fired when a dialog is being resized. The event is fired on
3363 * both the {@link CKEDITOR.dialog} object and the dialog instance
3364 * since 3.5.3, previously it was only available in the global object.
3365 *
3366 * @static
3367 * @event resize
3368 * @member CKEDITOR.dialog
3369 * @param data
3370 * @param {CKEDITOR.dialog} data.dialog The dialog being resized (if
3371 * it is fired on the dialog itself, this parameter is not sent).
3372 * @param {String} data.skin The skin name.
3373 * @param {Number} data.width The new width.
3374 * @param {Number} data.height The new height.
3375 */
3376
3377 /**
3378 * Event fired when a dialog is being resized. The event is fired on
3379 * both the {@link CKEDITOR.dialog} object and the dialog instance
3380 * since 3.5.3, previously it was only available in the global object.
3381 *
3382 * @since 3.5
3383 * @event resize
3384 * @member CKEDITOR.dialog
3385 * @param data
3386 * @param {Number} data.width The new width.
3387 * @param {Number} data.height The new height.
3388 */
3389
3390 /**
3391 * Event fired when the dialog state changes, usually by {@link CKEDITOR.dialog#setState}.
3392 *
3393 * @since 4.5
3394 * @event state
3395 * @member CKEDITOR.dialog
3396 * @param data
3397 * @param {Number} data The new state. Either {@link CKEDITOR#DIALOG_STATE_IDLE} or {@link CKEDITOR#DIALOG_STATE_BUSY}.
3398 */