~hanspayer/+junk/kobersdorf

« back to all changes in this revision

Viewing changes to static/djangocms_text_ckeditor/ckeditor_plugins/cmsdialog/plugin.js

  • Committer: Payer Hans-Christian
  • Date: 2016-03-29 20:18:05 UTC
  • Revision ID: hans@net-so.org-20160329201805-cs2re2zwb7svwje4
base template working

Show diffs side-by-side

added added

removed removed

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