2
* Modified version of the resize plugin to support touch events.
4
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
5
* For licensing, see LICENSE.md or http://ckeditor.com/license
9
* @fileOverview The floating dialog plugin.
13
* No resize for this dialog.
16
* @property {Number} [=0]
19
CKEDITOR.DIALOG_RESIZE_NONE = 0;
22
* Only allow horizontal resizing for this dialog, disable vertical resizing.
25
* @property {Number} [=1]
28
CKEDITOR.DIALOG_RESIZE_WIDTH = 1;
31
* Only allow vertical resizing for this dialog, disable horizontal resizing.
34
* @property {Number} [=2]
37
CKEDITOR.DIALOG_RESIZE_HEIGHT = 2;
40
* Allow the dialog to be resized in both directions.
43
* @property {Number} [=3]
46
CKEDITOR.DIALOG_RESIZE_BOTH = 3;
49
* Dialog state when idle.
52
* @property {Number} [=1]
55
CKEDITOR.DIALOG_STATE_IDLE = 1;
58
* Dialog state when busy.
61
* @property {Number} [=2]
64
CKEDITOR.DIALOG_STATE_BUSY = 2;
67
var cssLength = CKEDITOR.tools.cssLength;
69
function isTabVisible( tabId ) {
70
return !!this._.tabs[ tabId ][ 0 ].$.offsetHeight;
73
function getPreviousVisibleTab() {
74
var tabId = this._.currentTabId,
75
length = this._.tabIdList.length,
76
tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId ) + length;
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 ];
86
function getNextVisibleTab() {
87
var tabId = this._.currentTabId,
88
length = this._.tabIdList.length,
89
tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId );
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 ];
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 ] );
105
if ( item.getAttribute( 'type' ).toLowerCase() == 'text' ) {
107
item.setAttribute( 'value', item.getCustomData( 'fake_value' ) || '' );
108
item.removeCustomData( 'fake_value' );
110
item.setCustomData( 'fake_value', item.getAttribute( 'value' ) );
111
item.setAttribute( 'value', '' );
117
// Handle dialog element validation state UI changes.
118
function handleFieldValidated( isValid, msg ) {
119
var input = this.getInputElement();
121
isValid ? input.removeAttribute( 'aria-invalid' ) : input.setAttribute( 'aria-invalid', true );
130
msg && alert( msg ); // jshint ignore:line
132
this.fire( 'validated', { valid: isValid, msg: msg } );
135
function resetField() {
136
var input = this.getInputElement();
137
input && input.removeAttribute( 'aria-invalid' );
140
var templateSource = '<div class="cke_reset_all {editorId} {editorDialogClass} {hidpi}' +
141
'" dir="{langDir}"' +
142
' lang="{langCode}"' +
144
' aria-labelledby="cke_dialog_title_{id}"' +
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">' +
155
'<td id="cke_dialog_contents_{id}" class="cke_dialog_contents_body" role="presentation"></td>' +
158
'<td id="cke_dialog_footer_{id}" class="cke_dialog_footer" role="presentation"></td>' +
166
function buildDialog( editor ) {
167
var element = CKEDITOR.dom.element.createFromHtml( CKEDITOR.addTemplate( 'dialog', templateSource ).output( {
168
id: CKEDITOR.tools.getNextNumber(),
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' : ''
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 );
182
// Don't allow dragging on dialog (#13184).
183
// editor.plugins.clipboard && CKEDITOR.plugins.clipboard.preventDefaultDropOnElement( body );
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' +
190
' class="cke_iframe_shim"' +
191
' src="' + src + '"' +
194
iframe.appendTo( body.getParent() );
197
// Make the Title and Close Button unselectable.
198
title.unselectable();
199
close.unselectable();
204
dialog: element.getChild( 0 ),
207
tabs: body.getChild( 2 ),
208
contents: body.getChild( [ 3, 0, 0, 0 ] ),
209
footer: body.getChild( [ 3, 0, 1, 0 ] )
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.
218
* var dialogObj = new CKEDITOR.dialog( editor, 'smiley' );
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.
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,
232
i, processed, stopPropagation;
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();
239
// Completes the definition with the default values.
240
definition = CKEDITOR.tools.extend( definition( editor ), defaultDefinition );
242
// Clone a functionally independent copy for this dialog.
243
definition = CKEDITOR.tools.clone( definition );
245
// Create a complex definition object, extending it with the API
247
definition = new definitionObject( this, definition );
249
var themeBuilt = buildDialog( editor );
251
// Initialize some basic parameters.
254
element: themeBuilt.element,
256
contentSize: { width: 0, height: 0 },
257
size: { width: 0, height: 0 },
262
// Initialize the tab and page map.
266
currentTabIndex: null,
271
// Initialize the tab order array for input widgets.
273
currentFocusIndex: 0,
277
this.parts = themeBuilt.parts;
279
CKEDITOR.tools.setTimeout( function() {
280
editor.fire( 'ariaWidget', this.parts.contents );
283
// Set the startup styles for the dialog, avoiding it enlarging the
284
// page size on the dialog creation.
286
position: CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed',
291
startStyles[ dir == 'rtl' ? 'right' : 'left' ] = 0;
292
this.parts.dialog.setStyles( startStyles );
295
// Call the CKEDITOR.event constructor to initialize this instance.
296
CKEDITOR.event.call( this );
298
// Fire the "dialogDefinition" event, making it possible to customize
299
// the dialog definition.
300
this.definition = definition = CKEDITOR.fire( 'dialogDefinition', {
302
definition: definition
303
}, editor ).definition;
305
// Cache tabs that should be removed.
306
if ( !( 'removeDialogTabs' in editor._ ) && editor.config.removeDialogTabs ) {
307
var removeContents = editor.config.removeDialogTabs.split( ';' );
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 ] );
318
editor._.removeDialogTabs = tabsToRemove;
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 ] );
327
// Initialize load, show, hide, ok and cancel events.
328
if ( definition.onLoad )
329
this.on( 'load', definition.onLoad );
331
if ( definition.onShow )
332
this.on( 'show', definition.onShow );
334
if ( definition.onHide )
335
this.on( 'hide', definition.onHide );
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' );
344
if ( definition.onOk.call( this, evt ) === false )
345
evt.data.hide = false;
349
// Set default dialog state.
350
this.state = CKEDITOR.DIALOG_STATE_IDLE;
352
if ( definition.onCancel ) {
353
this.on( 'cancel', function( evt ) {
354
if ( definition.onCancel.call( this, evt ) === false )
355
evt.data.hide = false;
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,
367
for ( var i in contents ) {
368
for ( var j in contents[ i ] ) {
369
stop = func.call( this, contents[ i ][ j ] );
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;
383
evt.data.hide = false;
387
handleFieldValidated.call( item, !invalid, typeof retval == 'string' ? retval : undefined );
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;
403
this.parts.close.on( 'click', function( evt ) {
404
if ( this.fire( 'cancel', { hide: true } ).hide !== false )
406
evt.data.preventDefault();
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';
419
return a.focusIndex - b.focusIndex;
422
var size = focusList.length;
423
for ( var i = 0; i < size; i++ )
424
focusList[ i ].focusIndex = i;
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;
432
if ( focusList.length < 1 )
435
var startIndex = me._.currentFocusIndex;
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).
443
// Trigger the 'blur' event of any input element before anything,
444
// since certain UI updates may depend on it.
446
focusList[ startIndex ].getInputElement().$.blur();
449
var currentIndex = startIndex,
450
hasTabs = me._.pageCount > 1;
453
currentIndex = currentIndex + offset;
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;
461
// Early return, in order to avoid accessing focusList[ -1 ].
465
currentIndex = ( currentIndex + focusList.length ) % focusList.length;
467
if ( currentIndex == startIndex ) {
470
} while ( offset && !focusList[ currentIndex ].isFocusable() );
472
focusList[ currentIndex ].focus();
474
// Select whole field content.
475
if ( focusList[ currentIndex ].type == 'text' )
476
focusList[ currentIndex ].select();
479
this.changeFocus = changeFocus;
482
function keydownHandler( evt ) {
483
// If I'm not the top dialog, ignore.
484
if ( me != CKEDITOR.dialog._.currentTop )
487
var keystroke = evt.data.getKeystroke(),
488
rtl = editor.lang.dir == 'rtl',
489
arrowKeys = [ 37, 38, 39, 40 ],
492
processed = stopPropagation = 0;
494
if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 ) {
495
var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
496
changeFocus( shiftPressed ? -1 : 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;
504
} else if ( CKEDITOR.tools.indexOf( arrowKeys, keystroke ) != -1 && me._.tabBarMode ) {
505
// Array with key codes that activate previous tab.
507
// Depending on the lang dir: right or left key
509
// Top/bot arrow: actually for both cases it's the same.
512
nextId = CKEDITOR.tools.indexOf( prevKeyCodes, keystroke ) != -1 ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );
514
me.selectPage( nextId );
515
me._.tabs[ nextId ][ 0 ].focus();
517
} else if ( ( keystroke == 13 || keystroke == 32 ) && me._.tabBarMode ) {
518
this.selectPage( this._.currentTabId );
519
this._.tabBarMode = false;
520
this._.currentFocusIndex = -1;
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 );
533
stopPropagation = 1; // Always block the propagation (#4269)
534
} else if ( keystroke == 27 /*ESC*/ ) {
535
button = this.getButton( 'cancel' );
537
// If there's a Cancel button, click it, else just fire the cancel event and hide the dialog.
539
CKEDITOR.tools.setTimeout( button.click, 0, button );
541
if ( this.fire( 'cancel', { hide: true } ).hide !== false )
544
stopPropagation = 1; // Always block the propagation (#4269)
549
keypressHandler( evt );
552
function keypressHandler( evt ) {
554
evt.data.preventDefault( 1 );
555
else if ( stopPropagation )
556
evt.data.stopPropagation();
559
var dialogElement = this._.element;
561
editor.focusManager.add( dialogElement, 1 );
563
// Add the dialog keyboard handlers.
564
this.on( 'show', function() {
565
dialogElement.on( 'keydown', keydownHandler, this );
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 );
573
this.on( 'hide', function() {
574
dialogElement.removeListener( 'keydown', keydownHandler );
575
if ( CKEDITOR.env.gecko )
576
dialogElement.removeListener( 'keypress', keypressHandler );
578
// Reset fields state when closing dialog.
579
iterContents( function( item ) {
580
resetField.apply( item );
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 );
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.
594
var hasTabs = me._.pageCount > 1;
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;
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();
610
// Focus the first field in layout order.
615
}, this, null, 0xffffffff );
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();
624
inner.appendTo( outer );
628
initDragAndDrop( this );
629
initResizeHandles( this );
632
( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );
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 );
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( '_' ) ) );
648
if ( this._.tabBarMode ) {
649
this._.tabBarMode = false;
650
this._.currentFocusIndex = -1;
653
evt.data.preventDefault();
658
var buttonsHtml = [],
659
buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this, {
661
className: 'cke_dialog_footer_buttons',
663
children: definition.buttons
664
}, buttonsHtml ).getChild();
665
this.parts.footer.setHtml( buttonsHtml.join( '' ) );
667
for ( i = 0; i < buttons.length; i++ )
668
this._.buttons[ buttons[ i ].id ] = buttons[ i ];
671
* Current state of the dialog. Use the {@link #setState} method to update it.
672
* See the {@link #event-state} event to know more.
675
* @property {Number} [state=CKEDITOR.DIALOG_STATE_IDLE]
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.
685
this.isFocusable = function() {
686
return !element.getAttribute( 'disabled' ) && element.isVisible();
688
this.focus = function() {
689
dialog._.currentFocusIndex = this.focusIndex;
690
this.element.focus();
693
element.on( 'keydown', function( e ) {
694
if ( e.data.getKeystroke() in { 32: 1, 13: 1 } )
695
this.fire( 'click' );
697
element.on( 'focus', function() {
698
this.fire( 'mouseover' );
700
element.on( 'blur', function() {
701
this.fire( 'mouseout' );
705
// Re-layout the dialog on window resize.
706
function resizeWithWindow( dialog ) {
707
var win = CKEDITOR.document.getWindow();
708
function resizeHandler() {
711
win.on( 'resize', resizeHandler );
712
dialog.on( 'hide', function() {
713
win.removeListener( 'resize', resizeHandler );
717
CKEDITOR.dialog.prototype = {
718
destroy: function() {
720
this._.element.remove();
724
* Resizes the dialog.
726
* dialogObj.resize( 800, 640 );
729
* @param {Number} width The width of the dialog in pixels.
730
* @param {Number} height The height of the dialog in pixels.
732
resize: ( function() {
733
return function( width, height ) {
734
if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )
737
CKEDITOR.dialog.fire( 'resize', {
743
this.fire( 'resize', {
748
var contents = this.parts.contents;
749
contents.setStyles( {
751
height: height + 'px'
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 );
758
this._.contentSize = { width: width, height: height };
763
* Gets the current size of the dialog in pixels.
765
* var width = dialogObj.getSize().width;
768
* @returns {Number} return.width
769
* @returns {Number} return.height
771
getSize: function() {
772
var element = this._.element.getFirst();
773
return { width: element.$.offsetWidth || 0, height: element.$.offsetHeight || 0 };
777
* Moves the dialog to an `(x, y)` coordinate relative to the window.
779
* dialogObj.move( 10, 40 );
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.
786
move: function( x, y, save ) {
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';
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
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%' );
804
if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
807
// Save the current position.
808
this._.position = { x: x, y: y };
810
// If not fixed positioned, add scroll position to the coordinates.
812
var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
813
x += scrollPosition.x;
814
y += scrollPosition.y;
817
// Translate coordinate for RTL.
819
var dialogSize = this.getSize(), viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize();
820
x = viewPaneSize.width - dialogSize.width - x;
823
var styles = { 'top': ( y > 0 ? y : 0 ) + 'px' };
824
styles[ rtl ? 'right' : 'left' ] = ( x > 0 ? x : 0 ) + 'px';
826
element.setStyles( styles );
828
save && ( this._.moved = 1 );
832
* Gets the dialog's position in the window.
834
* var dialogX = dialogObj.getPosition().x;
837
* @returns {Number} return.x
838
* @returns {Number} return.y
840
getPosition: function() {
841
return CKEDITOR.tools.extend( {}, this._.position );
845
* Shows the dialog box.
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() );
856
element.setStyle( 'display', 'block' );
858
// First, set the dialog to an appropriate size.
860
this._.contentSize && this._.contentSize.width || definition.width || definition.minWidth,
861
this._.contentSize && this._.contentSize.height || definition.height || definition.minHeight
864
// Reset all inputs back to their default value.
867
// Select the first tab by default.
868
this.selectPage( this.definition.contents[ 0 ].id );
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 );
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 );
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;
888
element.on( 'keydown', accessKeyDownHandler );
889
element.on( 'keyup', accessKeyUpHandler );
891
// Reset the hasFocus state.
892
this._.hasFocus = false;
894
for ( var i in definition.contents ) {
895
if ( !definition.contents[ i ] )
898
var content = definition.contents[ i ],
899
tab = this._.tabs[ content.id ],
900
requiredContent = content.requiredContent,
906
for ( var j in this._.contents[ content.id ] ) {
907
var elem = this._.contents[ content.id ][ j ];
909
if ( elem.type == 'hbox' || elem.type == 'vbox' || !elem.getInputElement() )
912
if ( elem.requiredContent && !this._.editor.activeFilter.check( elem.requiredContent ) )
920
if ( !enableElements || ( requiredContent && !this._.editor.activeFilter.check( requiredContent ) ) )
921
tab[ 0 ].addClass( 'cke_dialog_tab_disabled' );
923
tab[ 0 ].removeClass( 'cke_dialog_tab_disabled' );
926
CKEDITOR.tools.setTimeout( function() {
928
resizeWithWindow( this );
930
this.parts.dialog.setStyle( 'visibility', '' );
932
// Execute onLoad for the first show.
933
this.fireOnce( 'load', {} );
934
CKEDITOR.ui.fire( 'ready', this );
936
this.fire( 'show', {} );
937
this._.editor.fire( 'dialogShow', this );
939
if ( !this._.parentDialog )
940
this._.editor.focusManager.lock();
942
// Save the initial values of the dialog.
943
this.foreach( function( contentObj ) {
944
contentObj.setInitValue && contentObj.setInitValue();
951
* Rearrange the dialog to its previous position or the middle of the window.
956
var el = this.parts.dialog;
957
var dialogSize = this.getSize();
958
var win = CKEDITOR.document.getWindow(),
959
viewSize = win.getViewPaneSize();
961
var posX = ( viewSize.width - dialogSize.width ) / 2,
962
posY = ( viewSize.height - dialogSize.height ) / 2;
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' );
969
el.setStyle( 'position', 'fixed' );
973
this.move( this._.moved ? this._.position.x : posX, this._.moved ? this._.position.y : posY );
977
* Executes a function for each UI element.
979
* @param {Function} fn Function to execute for each UI element.
980
* @returns {CKEDITOR.dialog} The current dialog object.
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] );
993
* Resets all input values in the dialog.
1000
reset: ( function() {
1001
var fn = function( widget ) {
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.
1017
* dialogObj.setupContent();
1019
* var timestamp = ( new Date() ).valueOf();
1020
* dialogObj.setupContent( timestamp );
1022
setupContent: function() {
1023
var args = arguments;
1024
this.foreach( function( widget ) {
1026
widget.setup.apply( widget, args );
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.
1035
* dialogObj.commitContent();
1037
* var timestamp = ( new Date() ).valueOf();
1038
* dialogObj.commitContent( timestamp );
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();
1047
if ( widget.commit )
1048
widget.commit.apply( widget, args );
1053
* Hides the dialog box.
1058
if ( !this.parts.dialog.isVisible() )
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 );
1071
// Close any child(top) dialogs first.
1072
while ( CKEDITOR.dialog._.currentTop != this )
1073
CKEDITOR.dialog._.currentTop.hide();
1075
// Maintain dialog ordering and remove cover if needed.
1076
if ( !this._.parentDialog )
1077
hideCover( this._.editor );
1079
var parentElement = this._.parentDialog.getElement().getFirst();
1080
parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
1082
CKEDITOR.dialog._.currentTop = this._.parentDialog;
1084
// Deduct or clear the z-index.
1085
if ( !this._.parentDialog ) {
1086
CKEDITOR.dialog._.currentZIndex = null;
1088
// Remove access key handlers.
1089
element.removeListener( 'keydown', accessKeyDownHandler );
1090
element.removeListener( 'keyup', accessKeyUpHandler );
1092
var editor = this._.editor;
1095
// Give a while before unlock, waiting for focus to return to the editable. (#172)
1096
setTimeout( function() {
1097
editor.focusManager.unlock();
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();
1107
CKEDITOR.dialog._.currentZIndex -= 10;
1110
delete this._.parentDialog;
1111
// Reset the initial values of the dialog.
1112
this.foreach( function( contentObj ) {
1113
contentObj.resetInitValue && contentObj.resetInitValue();
1116
// Reset dialog state back to IDLE, if busy (#13213).
1117
this.setState( CKEDITOR.DIALOG_STATE_IDLE );
1121
* Adds a tabbed page into the dialog.
1123
* @param {Object} contents Content definition.
1125
addPage: function( contents ) {
1126
if ( contents.requiredContent && !this._.editor.filter.check( contents.requiredContent ) )
1130
titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
1131
vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this, {
1133
className: 'cke_dialog_page_contents',
1134
children: contents.elements,
1135
expand: !!contents.expand,
1136
padding: contents.padding,
1137
style: contents.style || 'width: 100%;'
1140
var contentMap = this._.contents[ contents.id ] = {},
1142
children = vbox.getChild(),
1145
while ( ( cursor = children.shift() ) ) {
1146
// Count all allowed fields.
1147
if ( !cursor.notAllowed && cursor.type != 'hbox' && cursor.type != 'vbox' )
1150
contentMap[ cursor.id ] = cursor;
1151
if ( typeof cursor.getChild == 'function' )
1152
children.push.apply( children, cursor.getChild() );
1155
// If all fields are disabled (because they are not allowed) hide this tab.
1156
if ( !enabledFields )
1157
contents.hidden = true;
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' );
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' ),
1169
( !!contents.hidden ? ' style="display:none"' : '' ),
1170
' id="', tabId, '"',
1171
env.gecko && !env.hc ? '' : ' href="javascript:void(0)"',
1173
' hidefocus="true"',
1179
page.setAttribute( 'aria-labelledby', tabId );
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;
1188
// Attach the DOM nodes.
1190
page.setAttribute( 'name', contents.id );
1191
page.appendTo( this.parts.contents );
1194
this.parts.tabs.append( tab );
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;
1204
* Activates a tab page in the dialog by its id.
1206
* dialogObj.selectPage( 'tab_1' );
1208
* @param {String} id The id of the dialog tab to be activated.
1210
selectPage: function( id ) {
1211
if ( this._.currentTabId == id )
1214
if ( this._.tabs[ id ][ 0 ].hasClass( 'cke_dialog_tab_disabled' ) )
1217
// If event was canceled - do nothing.
1218
if ( this.fire( 'selectPage', { page: id, currentPage: this._.currentTabId } ) === false )
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 ];
1226
tab.removeClass( 'cke_dialog_tab_selected' );
1229
page.setAttribute( 'aria-hidden', i != id );
1232
var selected = this._.tabs[ id ];
1233
selected[ 0 ].addClass( 'cke_dialog_tab_selected' );
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 );
1245
selected[ 1 ].show();
1248
this._.currentTabId = id;
1249
this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
1253
* Dialog state-specific style updates.
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' );
1261
* Hides a page's tab away from the dialog.
1263
* dialog.hidePage( 'tab_3' );
1265
* @param {String} id The page's Id.
1267
hidePage: function( id ) {
1268
var tab = this._.tabs[ id ] && this._.tabs[ id ][ 0 ];
1269
if ( !tab || this._.pageCount == 1 || !tab.isVisible() )
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 ) );
1281
* Unhides a page's tab.
1283
* dialog.showPage( 'tab_2' );
1285
* @param {String} id The page's Id.
1287
showPage: function( id ) {
1288
var tab = this._.tabs[ id ] && this._.tabs[ id ][ 0 ];
1297
* Gets the root DOM element of the dialog.
1299
* var dialogElement = dialogObj.getElement().getFirst();
1300
* dialogElement.setStyle( 'padding', '5px' );
1302
* @returns {CKEDITOR.dom.element} The `<span>` element containing this dialog.
1304
getElement: function() {
1305
return this._.element;
1309
* Gets the name of the dialog.
1311
* var dialogName = dialogObj.getName();
1313
* @returns {String} The name of this dialog.
1315
getName: function() {
1320
* Gets a dialog UI element object from a dialog page.
1322
* dialogObj.getContentElement( 'tabId', 'elementId' ).setValue( 'Example' );
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.
1328
getContentElement: function( pageId, elementId ) {
1329
var page = this._.contents[ pageId ];
1330
return page && page[ elementId ];
1334
* Gets the value of a dialog UI element.
1336
* alert( dialogObj.getValueOf( 'tabId', 'elementId' ) );
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.
1342
getValueOf: function( pageId, elementId ) {
1343
return this.getContentElement( pageId, elementId ).getValue();
1347
* Sets the value of a dialog UI element.
1349
* dialogObj.setValueOf( 'tabId', 'elementId', 'Example' );
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.
1355
setValueOf: function( pageId, elementId, value ) {
1356
return this.getContentElement( pageId, elementId ).setValue( value );
1360
* Gets the UI element of a button in the dialog's button row.
1362
* @returns {CKEDITOR.ui.dialog.button} The button object.
1364
* @param {String} id The id of the button.
1366
getButton: function( id ) {
1367
return this._.buttons[ id ];
1371
* Simulates a click to a dialog button in the dialog's button row.
1373
* @returns The return value of the dialog's `click` event.
1375
* @param {String} id The id of the button.
1377
click: function( id ) {
1378
return this._.buttons[ id ].click();
1382
* Disables a dialog button.
1384
* @param {String} id The id of the button.
1386
disableButton: function( id ) {
1387
return this._.buttons[ id ].disable();
1391
* Enables a dialog button.
1393
* @param {String} id The id of the button.
1395
enableButton: function( id ) {
1396
return this._.buttons[ id ].enable();
1400
* Gets the number of pages in the dialog.
1402
* @returns {Number} Page count.
1404
getPageCount: function() {
1405
return this._.pageCount;
1409
* Gets the editor instance which opened this dialog.
1411
* @returns {CKEDITOR.editor} Parent editor instances.
1413
getParentEditor: function() {
1414
return this._.editor;
1418
* Gets the element that was selected when opening the dialog, if any.
1420
* @returns {CKEDITOR.dom.element} The element that was selected, or `null`.
1422
getSelectedElement: function() {
1423
return this.getParentEditor().getSelection().getSelectedElement();
1427
* Adds element to dialog's focusable list.
1429
* @param {CKEDITOR.dom.element} element
1430
* @param {Number} [index]
1432
addFocusable: function( element, index ) {
1433
if ( typeof index == 'undefined' ) {
1434
index = this._.focusList.length;
1435
this._.focusList.push( new Focusable( this, element, index ) );
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++;
1444
* Sets the dialog {@link #property-state}.
1447
* @param {Number} state Either {@link CKEDITOR#DIALOG_STATE_IDLE} or {@link CKEDITOR#DIALOG_STATE_BUSY}.
1449
setState: function( state ) {
1450
var oldState = this.state;
1452
if ( oldState == state ) {
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,
1464
'class': 'cke_dialog_spinner'
1467
'float': dir == 'rtl' ? 'right' : 'left'
1471
spinnerDef.styles[ 'margin-' + ( dir == 'rtl' ? 'left' : 'right' ) ] = '8px';
1473
this.parts.spinner = CKEDITOR.document.createElement( 'div', spinnerDef );
1475
this.parts.spinner.setHtml( '⌛' );
1476
this.parts.spinner.appendTo( this.parts.title, 1 );
1479
// Finally, show the spinner.
1480
this.parts.spinner.show();
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();
1487
this.getButton( 'ok' ).enable();
1490
this.fire( 'state', state );
1494
CKEDITOR.tools.extend( CKEDITOR.dialog, {
1496
* Registers a dialog.
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' ) );
1504
* if ( editor.contextMenu ) {
1505
* editor.addMenuGroup( 'mygroup', 10 );
1506
* editor.addMenuItem( 'My Dialog', {
1507
* label: 'Open dialog',
1508
* command: 'mydialog',
1511
* editor.contextMenu.addListener( function( element ) {
1512
* return { 'My Dialog': CKEDITOR.TRISTATE_OFF };
1516
* CKEDITOR.dialog.add( 'mydialog', function( api ) {
1517
* // CKEDITOR.dialog.definition
1518
* var dialogDefinition = {
1519
* title: 'Sample dialog',
1532
* html: '<p>This is some sample HTML content.</p>'
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() );
1552
* return dialogDefinition;
1557
* CKEDITOR.replace( 'editor1', { extraPlugins: 'myplugin' } );
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
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;
1577
exists: function( name ) {
1578
return !!this._.dialogDefinitions[ name ];
1585
getCurrent: function() {
1586
return CKEDITOR.dialog._.currentTop;
1590
* Check whether tab wasn't removed by {@link CKEDITOR.config#removeDialogTabs}.
1594
* @param {CKEDITOR.editor} editor
1595
* @param {String} dialogName
1596
* @param {String} tabName
1597
* @returns {Boolean}
1599
isTabEnabled: function( editor, dialogName, tabName ) {
1600
var cfg = editor.config.removeDialogTabs;
1602
return !( cfg && cfg.match( new RegExp( '(?:^|;)' + dialogName + ':' + tabName + '(?:$|;)', 'i' ) ) );
1606
* The default OK button for dialogs. Fires the `ok` event and closes the dialog if the event succeeds.
1611
okButton: ( function() {
1612
var retval = function( editor, override ) {
1613
override = override || {};
1614
return CKEDITOR.tools.extend( {
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 )
1624
}, override, true );
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 );
1636
* The default cancel button for dialogs. Fires the `cancel` event and
1637
* closes the dialog if no UI element value changed.
1642
cancelButton: ( function() {
1643
var retval = function( editor, override ) {
1644
override = override || {};
1645
return CKEDITOR.tools.extend( {
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 )
1655
}, override, true );
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 );
1667
* Registers a dialog UI element.
1670
* @param {String} typeName The name of the UI element.
1671
* @param {Function} builder The function to build the UI element.
1673
addUIElement: function( typeName, builder ) {
1674
this._.uiElementBuilders[ typeName ] = builder;
1678
CKEDITOR.dialog._ = {
1679
uiElementBuilders: {},
1681
dialogDefinitions: {},
1688
// "Inherit" (copy actually) from CKEDITOR.event.
1689
CKEDITOR.event.implementOn( CKEDITOR.dialog );
1690
CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype );
1692
var defaultDialogDefinition = {
1693
resizable: CKEDITOR.DIALOG_RESIZE_BOTH,
1696
buttons: [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
1699
// Tool function used to return an item from an array based on its id
1701
var getById = function( array, id, recurse ) {
1702
for ( var i = 0, item;
1703
( item = array[ i ] ); i++ ) {
1704
if ( item.id == id )
1706
if ( recurse && item[ recurse ] ) {
1707
var retval = getById( item[ recurse ], id, recurse );
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 );
1725
if ( recurse && item[ recurse ] ) {
1726
var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
1732
if ( nullIfNotFound )
1736
array.push( newItem );
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 );
1756
* This class is not really part of the API. It is the `definition` property value
1757
* passed to `dialogDefinition` event handlers.
1759
* CKEDITOR.on( 'dialogDefinition', function( evt ) {
1760
* var definition = evt.data.definition;
1761
* var content = definition.getContents( 'page1' );
1766
* @class CKEDITOR.dialog.definitionObject
1767
* @extends CKEDITOR.dialog.definition
1768
* @constructor Creates a definitionObject class instance.
1770
var definitionObject = function( dialog, dialogDefinition ) {
1771
// TODO : Check if needed.
1772
this.dialog = dialog;
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 );
1780
CKEDITOR.tools.extend( this, dialogDefinition );
1783
definitionObject.prototype = {
1785
* Gets a content definition.
1787
* @param {String} id The id of the content definition.
1788
* @returns {CKEDITOR.dialog.definition.content} The content definition matching id.
1790
getContents: function( id ) {
1791
return getById( this.contents, id );
1795
* Gets a button definition.
1797
* @param {String} id The id of the button definition.
1798
* @returns {CKEDITOR.dialog.definition.button} The button definition matching id.
1800
getButton: function( id ) {
1801
return getById( this.buttons, id );
1805
* Adds a content definition object under this dialog definition.
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
1813
* @returns {CKEDITOR.dialog.definition.content} The inserted content definition.
1815
addContents: function( contentDefinition, nextSiblingId ) {
1816
return addById( this.contents, contentDefinition, nextSiblingId );
1820
* Adds a button definition object under this dialog definition.
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
1828
* @returns {CKEDITOR.dialog.definition.button} The inserted button definition.
1830
addButton: function( buttonDefinition, nextSiblingId ) {
1831
return addById( this.buttons, buttonDefinition, nextSiblingId );
1835
* Removes a content definition from this dialog definition.
1837
* @param {String} id The id of the content definition to be removed.
1838
* @returns {CKEDITOR.dialog.definition.content} The removed content definition.
1840
removeContents: function( id ) {
1841
removeById( this.contents, id );
1845
* Removes a button definition from the dialog definition.
1847
* @param {String} id The id of the button definition to be removed.
1848
* @returns {CKEDITOR.dialog.definition.button} The removed button definition.
1850
removeButton: function( id ) {
1851
removeById( this.buttons, id );
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.
1860
* CKEDITOR.on( 'dialogDefinition', function( evt ) {
1861
* var definition = evt.data.definition;
1862
* var content = definition.getContents( 'page1' );
1863
* content.remove( 'textInput1' );
1868
* @class CKEDITOR.dialog.definition.contentObject
1869
* @constructor Creates a contentObject class instance.
1871
function contentObject( dialog, contentDefinition ) {
1876
CKEDITOR.tools.extend( this, contentDefinition );
1879
contentObject.prototype = {
1881
* Gets a UI element definition under the content definition.
1883
* @param {String} id The id of the UI element definition.
1884
* @returns {CKEDITOR.dialog.definition.uiElement}
1886
get: function( id ) {
1887
return getById( this.elements, id, 'children' );
1891
* Adds a UI element definition to the content definition.
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
1899
* @returns {CKEDITOR.dialog.definition.uiElement} The element definition inserted.
1901
add: function( elementDefinition, nextSiblingId ) {
1902
return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
1906
* Removes a UI element definition from the content definition.
1908
* @param {String} id The id of the UI element definition to be removed.
1909
* @returns {CKEDITOR.dialog.definition.uiElement} The element definition removed.
1911
remove: function( id ) {
1912
removeById( this.elements, id, 'children' );
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 ];
1923
if ( typeof magnetDistance == 'undefined' )
1924
magnetDistance = 20;
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,
1935
lastCoords = { x: x, y: y };
1936
abstractDialogCoords.x += dx;
1937
abstractDialogCoords.y += dy;
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 ] );
1944
realX = abstractDialogCoords.x;
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 ];
1951
realY = abstractDialogCoords.y;
1953
dialog.move( realX, realY, 1 );
1955
evt.preventDefault();
1958
function mouseUpHandler() {
1959
CMS.$(CKEDITOR.document.$).off( 'pointermove', mouseMoveHandler );
1960
CMS.$(CKEDITOR.document.$).off( 'pointerup', mouseUpHandler );
1962
if ( CKEDITOR.env.ie6Compat ) {
1963
var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
1964
coverDoc.removeListener( 'mousemove', mouseMoveHandler );
1965
coverDoc.removeListener( 'mouseup', mouseUpHandler );
1969
CMS.$(dialog.parts.title.$).on( 'pointerdown', function( evt ) {
1970
lastCoords = { x: evt.originalEvent.screenX, y: evt.originalEvent.screenY };
1972
CMS.$(CKEDITOR.document.$).on( 'pointermove', mouseMoveHandler );
1973
CMS.$(CKEDITOR.document.$).on( 'pointerup', mouseUpHandler );
1974
abstractDialogCoords = dialog.getPosition();
1976
if ( CKEDITOR.env.ie6Compat ) {
1977
var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
1978
coverDoc.on( 'mousemove', mouseMoveHandler );
1979
coverDoc.on( 'mouseup', mouseUpHandler );
1982
evt.preventDefault();
1986
function initResizeHandles( dialog ) {
1987
var def = dialog.definition,
1988
resizable = def.resizable;
1990
if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE )
1993
var editor = dialog.getParentEditor();
1994
var wrapperWidth, wrapperHeight, viewSize, origin, startSize, dialogCover;
1996
var mouseDownFn = CKEDITOR.tools.addFunction( function( $event ) {
1997
startSize = dialog.getSize();
1999
var content = dialog.parts.contents,
2000
iframeDialog = content.$.getElementsByTagName( 'iframe' ).length;
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 );
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 );
2013
origin = { x: $event.screenX, y: $event.screenY };
2015
viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
2017
CMS.$(CKEDITOR.document.$).on( 'pointermove', mouseMoveHandler );
2018
CMS.$(CKEDITOR.document.$).on( 'pointerup', mouseUpHandler );
2020
if ( CKEDITOR.env.ie6Compat ) {
2021
var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
2022
coverDoc.on( 'mousemove', mouseMoveHandler );
2023
coverDoc.on( 'mouseup', mouseUpHandler );
2026
$event.preventDefault && $event.preventDefault();
2029
// Prepend the grip to the dialog.
2030
dialog.on( 'load', function() {
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(
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' ) +
2045
dialog.parts.footer.append( resizer, 1 );
2047
editor.on( 'destroy', function() {
2048
CKEDITOR.tools.removeFunction( mouseDownFn );
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();
2063
if ( position.y + internalHeight > viewSize.height )
2064
internalHeight = viewSize.height - position.y;
2066
if ( ( rtl ? right : position.x ) + internalWidth > viewSize.width )
2067
internalWidth = viewSize.width - ( rtl ? right : position.x );
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 );
2073
if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT || resizable == CKEDITOR.DIALOG_RESIZE_BOTH )
2074
height = Math.max( def.minHeight || 0, internalHeight - wrapperHeight );
2076
dialog.resize( width, height );
2078
if ( !dialog._.moved )
2081
evt.preventDefault();
2084
function mouseUpHandler() {
2085
CMS.$(CKEDITOR.document.$).off( 'pointermove', mouseMoveHandler );
2086
CMS.$(CKEDITOR.document.$).off( 'pointerup', mouseUpHandler );
2088
if ( dialogCover ) {
2089
dialogCover.remove();
2093
if ( CKEDITOR.env.ie6Compat ) {
2094
var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
2095
coverDoc.removeListener( 'mouseup', mouseUpHandler );
2096
coverDoc.removeListener( 'mousemove', mouseMoveHandler );
2102
// Caching resuable covers and allowing only one cover
2107
function cancelEvent( ev ) {
2108
ev.data.preventDefault( 1 );
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 ];
2120
if ( !coverElement ) {
2121
CMS.$('.cke_dialog_background_cover:not(".cms-ckeditor-dialog-background-cover")').remove();
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">'
2130
if ( CKEDITOR.env.ie6Compat ) {
2131
// Support for custom document.domain in IE.
2132
var iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
2134
html.push( '<iframe' +
2135
' hidefocus="true"' +
2136
' frameborder="0"' +
2137
' id="cke_dialog_background_iframe"' +
2138
' src="javascript:' );
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 + '\' );' +
2150
'position:absolute;' +
2155
'filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
2159
html.push( '</div>' );
2161
coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
2162
coverElement.setOpacity( backgroundCoverOpacity !== undefined ? backgroundCoverOpacity : 0.5 );
2164
coverElement.on( 'keydown', cancelEvent );
2165
coverElement.on( 'keypress', cancelEvent );
2166
coverElement.on( 'keyup', cancelEvent );
2168
coverElement.appendTo( CKEDITOR.document.getBody() );
2169
covers[ coverKey ] = coverElement;
2171
coverElement.show();
2174
// Makes the dialog cover a focus holder as well.
2175
editor.focusManager.add( coverElement );
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'
2186
var scrollFunc = function() {
2187
var pos = win.getScrollPosition(),
2188
cursor = CKEDITOR.dialog._.currentTop;
2189
coverElement.setStyles( {
2196
var dialogPos = cursor.getPosition();
2197
cursor.move( dialogPos.x, dialogPos.y );
2198
} while ( ( cursor = cursor._.parentDialog ) );
2202
resizeCover = resizeFunc;
2203
win.on( 'resize', resizeFunc );
2205
// Using Safari/Mac, focus must be kept where it is (#7027)
2206
if ( !( CKEDITOR.env.mac && CKEDITOR.env.webkit ) )
2207
coverElement.focus();
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() {
2214
arguments.callee.prevScrollHandler.apply( this, arguments );
2216
win.$.setTimeout( function() {
2217
myScrollHandler.prevScrollHandler = window.onscroll ||
2219
window.onscroll = myScrollHandler;
2225
function hideCover( editor ) {
2226
if ( !currentCover )
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 );
2235
if ( CKEDITOR.env.ie6Compat ) {
2236
win.$.setTimeout( function() {
2237
var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
2238
window.onscroll = prevScrollHandler || null;
2244
function removeCovers() {
2245
for ( var coverId in covers )
2246
covers[ coverId ].remove();
2250
var accessKeyProcessors = {};
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 ];
2259
if ( !keyProcessor || !keyProcessor.length )
2262
keyProcessor = keyProcessor[ keyProcessor.length - 1 ];
2263
keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
2264
evt.data.preventDefault();
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 ];
2274
if ( !keyProcessor || !keyProcessor.length )
2277
keyProcessor = keyProcessor[ keyProcessor.length - 1 ];
2278
if ( keyProcessor.keyup ) {
2279
keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
2280
evt.data.preventDefault();
2284
var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc ) {
2285
var procList = accessKeyProcessors[ key ] || ( accessKeyProcessors[ key ] = [] );
2287
uiElement: uiElement,
2290
keyup: upFunc || uiElement.accessKeyUp,
2291
keydown: downFunc || uiElement.accessKeyDown
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 );
2302
if ( list.length === 0 )
2303
delete accessKeyProcessors[ i ];
2307
var tabAccessKeyUp = function( dialog, key ) {
2308
if ( dialog._.accessKeyMap[ key ] )
2309
dialog.selectPage( dialog._.accessKeyMap[ key ] );
2312
var tabAccessKeyDown = function() {};
2315
CKEDITOR.ui.dialog = {
2317
* The base class of all dialog UI elements.
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
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
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.
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
2357
* @param {Function/Object} [attributesArg={}]
2358
* A fucntion returning an object, or a simple object for attributes applied
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.
2364
uiElement: function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg ) {
2365
if ( arguments.length < 4 )
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',
2376
if ( elementDefinition.requiredContent && !dialog.getParentEditor().filter.check( elementDefinition.requiredContent ) ) {
2377
styles.display = 'none';
2378
this.notAllowed = true;
2381
// Set the id, a unique id is required for getElement() to work.
2382
attributes.id = domId;
2384
// Set the type and definition CSS class names.
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;
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;
2398
var finalClasses = [];
2399
for ( i in classes )
2400
finalClasses.push( i );
2401
attributes[ 'class' ] = finalClasses.join( ' ' );
2403
// Set the popup tooltop.
2404
if ( elementDefinition.title )
2405
attributes.title = elementDefinition.title;
2407
// Write the inline CSS styles.
2408
var styleStr = ( elementDefinition.style || '' ).split( ';' );
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';
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 );
2425
if ( styleStr.length > 0 )
2426
attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
2428
// Write the attributes.
2429
for ( i in attributes )
2430
html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[ i ] ) + '" ' );
2432
// Write the content HTML.
2433
html.push( '>', innerHTML, '</', nodeName, '>' );
2435
// Add contents to the parent HTML array.
2436
htmlList.push( html.join( '' ) );
2438
( this._ || ( this._ = {} ) ).dialog = dialog;
2440
// Override isChanged if it is defined in element definition.
2441
if ( typeof elementDefinition.isChanged == 'boolean' )
2442
this.isChanged = function() {
2443
return elementDefinition.isChanged;
2445
if ( typeof elementDefinition.isChanged == 'function' )
2446
this.isChanged = elementDefinition.isChanged;
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 ) );
2457
if ( typeof elementDefinition.getValue == 'function' ) {
2458
this.getValue = CKEDITOR.tools.override( this.getValue, function( org ) {
2460
return elementDefinition.getValue.call( this, org.call( this ) );
2466
CKEDITOR.event.implementOn( this );
2468
this.registerEvents( elementDefinition );
2469
if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
2470
registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
2473
dialog.on( 'load', function() {
2474
var input = me.getInputElement();
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;
2481
focusClass && this.addClass( focusClass );
2485
input.on( 'blur', function() {
2487
focusClass && this.removeClass( focusClass );
2492
// Completes this object with everything we have in the
2494
CKEDITOR.tools.extend( this, elementDefinition );
2496
// Register the object as a tab focus if it can be included.
2497
if ( this.keyboardFocusable ) {
2498
this.tabIndex = elementDefinition.tabIndex || 0;
2500
this.focusIndex = dialog._.focusList.push( this ) - 1;
2501
this.on( 'focus', function() {
2502
dialog._.currentFocusIndex = me.focusIndex;
2508
* Horizontal layout box for dialog UI elements, auto-expends to available width of container.
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:
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.
2529
hbox: function( dialog, childObjList, childHtmlList, htmlList, elementDefinition ) {
2530
if ( arguments.length < 4 )
2533
this._ || ( this._ = {} );
2535
var children = this._.children = childObjList,
2536
widths = elementDefinition && elementDefinition.widths || null,
2537
height = elementDefinition && elementDefinition.height || null,
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',
2547
className = 'cke_dialog_ui_hbox_first';
2549
if ( i == childHtmlList.length - 1 ) {
2550
className = 'cke_dialog_ui_hbox_last';
2553
html.push( '<td class="', className, '" role="presentation" ' );
2555
if ( widths[ i ] ) {
2556
styles.push( 'width:' + cssLength( widths[i] ) );
2559
styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
2562
styles.push( 'height:' + cssLength( height ) );
2564
if ( elementDefinition && elementDefinition.padding !== undefined ) {
2565
styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
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 );
2571
if ( styles.length > 0 ) {
2572
html.push( 'style="' + styles.join( '; ' ) + '" ' );
2574
html.push( '>', childHtmlList[ i ], '</td>' );
2576
html.push( '</tr></tbody>' );
2577
return html.join( '' );
2580
var attribs = { role: 'presentation' };
2581
elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );
2583
CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type: 'hbox' }, htmlList, 'table', styles, attribs, innerHTML );
2587
* Vertical layout box for dialog UI elements.
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:
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.
2609
vbox: function( dialog, childObjList, childHtmlList, htmlList, elementDefinition ) {
2610
if ( arguments.length < 3 )
2613
this._ || ( this._ = {} );
2615
var children = this._.children = childObjList,
2616
width = elementDefinition && elementDefinition.width || null,
2617
heights = elementDefinition && elementDefinition.heights || null;
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%' ), ';' );
2626
// (#10123) Temp fix for dialog broken layout in latest webkit.
2627
if ( CKEDITOR.env.webkit )
2628
html.push( 'float:none;' );
2631
html.push( 'align="', CKEDITOR.tools.htmlEncode(
2632
( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
2634
html.push( '><tbody>' );
2635
for ( var i = 0; i < childHtmlList.length; i++ ) {
2637
html.push( '<tr><td role="presentation" ' );
2639
styles.push( 'width:' + cssLength( width || '100%' ) );
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>' );
2653
html.push( '</tbody></table>' );
2654
return html.join( '' );
2656
CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type: 'vbox' }, htmlList, 'div', null, { role: 'presentation' }, innerHTML );
2661
/** @class CKEDITOR.ui.dialog.uiElement */
2662
CKEDITOR.ui.dialog.uiElement.prototype = {
2664
* Gets the root DOM element of this dialog UI object.
2666
* uiElement.getElement().hide();
2668
* @returns {CKEDITOR.dom.element} Root DOM element of UI object.
2670
getElement: function() {
2671
return CKEDITOR.document.getById( this.domId );
2675
* Gets the DOM element that the user inputs values.
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
2681
* var rawValue = textInput.getInputElement().$.value;
2683
* @returns {CKEDITOR.dom.element} The element where the user input values.
2685
getInputElement: function() {
2686
return this.getElement();
2690
* Gets the parent dialog object containing this UI element.
2692
* var dialog = uiElement.getDialog();
2694
* @returns {CKEDITOR.dialog} Parent dialog object.
2696
getDialog: function() {
2697
return this._.dialog;
2701
* Sets the value of this dialog UI object.
2703
* uiElement.setValue( 'Dingo' );
2706
* @param {Object} value The new value.
2707
* @param {Boolean} noChangeEvent Internal commit, to supress `change` event on this element.
2709
setValue: function( value, noChangeEvent ) {
2710
this.getInputElement().setValue( value );
2711
!noChangeEvent && this.fire( 'change', { value: value } );
2716
* Gets the current value of this dialog UI object.
2718
* var myValue = uiElement.getValue();
2720
* @returns {Object} The current value.
2722
getValue: function() {
2723
return this.getInputElement().getValue();
2727
* Tells whether the UI object's value has changed.
2729
* if ( uiElement.isChanged() )
2730
* confirm( 'Value changed! Continue?' );
2732
* @returns {Boolean} `true` if changed, `false` if not changed.
2734
isChanged: function() {
2735
// Override in input classes.
2740
* Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
2742
* focus : function() {
2743
* this.selectParentTab();
2744
* // do something else.
2749
selectParentTab: function() {
2750
var element = this.getInputElement(),
2753
while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 ) {
2757
// Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
2761
tabId = cursor.getAttribute( 'name' );
2762
// Avoid duplicate select.
2763
if ( this._.dialog._.currentTabId != tabId )
2764
this._.dialog.selectPage( tabId );
2769
* Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
2771
* uiElement.focus();
2776
this.selectParentTab().getInputElement().focus();
2781
* Registers the `on*` event handlers defined in the element definition.
2783
* The default behavior of this function is:
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}).
2793
* This function is only called at UI element instantiation, but can
2794
* be overridded in child classes if they require more flexibility.
2797
* @param {CKEDITOR.dialog.definition.uiElement} definition The UI element
2800
registerEvents: function( definition ) {
2801
var regex = /^on([A-Z]\w+)/,
2804
var registerDomEvent = function( uiElement, dialog, eventName, func ) {
2805
dialog.on( 'load', function() {
2806
uiElement.getInputElement().on( eventName, func, uiElement );
2810
for ( var i in definition ) {
2811
if ( !( match = i.match( regex ) ) )
2813
if ( this.eventProcessors[ i ] )
2814
this.eventProcessors[ i ].call( this, this._.dialog, definition[ i ] );
2816
registerDomEvent( this, this._.dialog, match[ 1 ].toLowerCase(), definition[ i ] );
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:
2827
* 1. `onLoad` - Called when the element's parent dialog opens for the
2829
* 2. `onShow` - Called whenever the element's parent dialog opens.
2830
* 3. `onHide` - Called whenever the element's parent dialog closes.
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 ); } },
2840
* @property {Object}
2843
onLoad: function( dialog, func ) {
2844
dialog.on( 'load', func, this );
2847
onShow: function( dialog, func ) {
2848
dialog.on( 'show', func, this );
2851
onHide: function( dialog, func ) {
2852
dialog.on( 'hide', func, this );
2857
* The default handler for a UI element's access key down event, which
2858
* tries to put focus to the UI element.
2860
* Can be overridded in child classes for more sophisticaed behavior.
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.
2867
accessKeyDown: function() {
2872
* The default handler for a UI element's access key up event, which
2875
* Can be overridded in child classes for more sophisticated behavior.
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.
2882
accessKeyUp: function() {},
2885
* Disables a UI element.
2887
disable: function() {
2888
var element = this.getElement(),
2889
input = this.getInputElement();
2890
input.setAttribute( 'disabled', 'true' );
2891
element.addClass( 'cke_disabled' );
2895
* Enables a UI element.
2897
enable: function() {
2898
var element = this.getElement(),
2899
input = this.getInputElement();
2900
input.removeAttribute( 'disabled' );
2901
element.removeClass( 'cke_disabled' );
2905
* Determines whether an UI element is enabled or not.
2907
* @returns {Boolean} Whether the UI element is enabled.
2909
isEnabled: function() {
2910
return !this.getElement().hasClass( 'cke_disabled' );
2914
* Determines whether an UI element is visible or not.
2916
* @returns {Boolean} Whether the UI element is visible.
2918
isVisible: function() {
2919
return this.getInputElement().isVisible();
2923
* Determines whether an UI element is focus-able or not.
2924
* Focus-able is defined as being both visible and enabled.
2926
* @returns {Boolean} Whether the UI element can be focused.
2928
isFocusable: function() {
2929
if ( !this.isEnabled() || !this.isVisible() )
2935
/** @class CKEDITOR.ui.dialog.hbox */
2936
CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement(), {
2938
* Gets a child UI element inside this container.
2940
* var checkbox = hbox.getChild( [0,1] );
2941
* checkbox.setValue( true );
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.
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();
2953
// If indices isn't array, make it one.
2954
if ( !indices.splice )
2955
indices = [ indices ];
2957
// Retrieve the child element according to tree position.
2958
if ( indices.length < 2 )
2959
return this._.children[ indices[ 0 ] ];
2961
return ( this._.children[ indices[ 0 ] ] && this._.children[ indices[ 0 ] ].getChild ) ? this._.children[ indices[ 0 ] ].getChild( indices.slice( 1, indices.length ) ) : null;
2965
CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
2968
var commonBuilder = {
2969
build: function( dialog, elementDefinition, output ) {
2970
var children = elementDefinition.children,
2975
( i < children.length && ( child = children[ i ] ) ); i++ ) {
2977
childHtmlList.push( childHtml );
2978
childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
2980
return new CKEDITOR.ui.dialog[ elementDefinition.type ]( dialog, childObjList, childHtmlList, output, elementDefinition );
2984
CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
2985
CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
2989
* Generic dialog command. It opens a specific dialog when executed.
2991
* // Register the "link" command, which opens the "link" dialog.
2992
* editor.addCommand( 'link', new CKEDITOR.dialogCommand( 'link' ) );
2995
* @constructor Creates a dialogCommand class instance.
2996
* @extends CKEDITOR.commandDefinition
2997
* @param {String} dialogName The name of the dialog to open when executing
2999
* @param {Object} [ext] Additional command definition's properties.
3001
CKEDITOR.dialogCommand = function( dialogName, ext ) {
3002
this.dialogName = dialogName;
3003
CKEDITOR.tools.extend( this, ext, true );
3006
CKEDITOR.dialogCommand.prototype = {
3007
exec: function( editor ) {
3008
editor.openDialog( this.dialogName );
3011
// Dialog commands just open a dialog ui, thus require no undo logic,
3012
// undo support should dedicate to specific dialog implementation.
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*[^:;]+(?:;|$))*$/;
3026
CKEDITOR.VALIDATE_OR = 1;
3027
CKEDITOR.VALIDATE_AND = 2;
3029
CKEDITOR.dialog.validate = {
3030
functions: function() {
3031
var args = arguments;
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
3039
var value = this && this.getValue ? this.getValue() : args[ 0 ];
3042
relation = CKEDITOR.VALIDATE_AND,
3046
for ( i = 0; i < args.length; i++ ) {
3047
if ( typeof args[ i ] == 'function' )
3048
functions.push( args[ i ] );
3053
if ( i < args.length && typeof args[ i ] == 'string' ) {
3058
if ( i < args.length && typeof args[ i ] == 'number' )
3059
relation = args[ i ];
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 );
3066
passed = passed || functions[ i ]( value );
3069
return !passed ? msg : true;
3073
regex: function( regex, msg ) {
3075
* Can be greatly shortened by deriving from functions validator if code size
3076
* turns out to be more important than performance.
3079
var value = this && this.getValue ? this.getValue() : arguments[ 0 ];
3080
return !regex.test( value ) ? msg : true;
3084
notEmpty: function( msg ) {
3085
return this.regex( notEmptyRegex, msg );
3088
integer: function( msg ) {
3089
return this.regex( integerRegex, msg );
3092
'number': function( msg ) {
3093
return this.regex( numberRegex, msg );
3096
'cssLength': function( msg ) {
3097
return this.functions( function( val ) {
3098
return cssLengthRegex.test( CKEDITOR.tools.trim( val ) );
3102
'htmlLength': function( msg ) {
3103
return this.functions( function( val ) {
3104
return htmlLengthRegex.test( CKEDITOR.tools.trim( val ) );
3108
'inlineStyle': function( msg ) {
3109
return this.functions( function( val ) {
3110
return inlineStyleRegex.test( CKEDITOR.tools.trim( val ) );
3114
equals: function( value, msg ) {
3115
return this.functions( function( val ) {
3116
return val == value;
3120
notEqual: function( value, msg ) {
3121
return this.functions( function( val ) {
3122
return val != value;
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();
3136
var dialogs = evt.editor._.storedDialogs;
3137
for ( var name in dialogs )
3138
dialogs[ name ].destroy();
3144
// Extend the CKEDITOR.editor class with dialog specific functions.
3145
CKEDITOR.tools.extend( CKEDITOR.editor.prototype, {
3147
* Loads and opens a registered dialog.
3149
* CKEDITOR.instances.editor1.openDialog( 'smiley' );
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
3158
openDialog: function( dialogName, callback ) {
3159
var dialog = null, dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];
3161
if ( CKEDITOR.dialog._.currentTop === null )
3164
// If the dialogDefinition is already loaded, open it immediately.
3165
if ( typeof dialogDefinitions == 'function' ) {
3166
var storedDialogs = this._.storedDialogs || ( this._.storedDialogs = {} );
3168
dialog = storedDialogs[ dialogName ] || ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
3170
callback && callback.call( dialog, dialog );
3173
} else if ( dialogDefinitions == 'failed' ) {
3175
throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
3176
} else if ( typeof dialogDefinitions == 'string' ) {
3178
CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ),
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';
3185
this.openDialog( dialogName, callback );
3189
CKEDITOR.skin.loadPart( 'dialog' );
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 );
3206
// Dialog related configurations.
3209
* The color of the dialog background cover. It should be a valid CSS color string.
3211
* config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
3213
* @cfg {String} [dialog_backgroundCoverColor='white']
3214
* @member CKEDITOR.config
3218
* The opacity of the dialog background cover. It should be a number within the
3219
* range `[0.0, 1.0]`.
3221
* config.dialog_backgroundCoverOpacity = 0.7;
3223
* @cfg {Number} [dialog_backgroundCoverOpacity=0.5]
3224
* @member CKEDITOR.config
3228
* If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.
3230
* config.dialog_startupFocusTab = true;
3232
* @cfg {Boolean} [dialog_startupFocusTab=false]
3233
* @member CKEDITOR.config
3237
* The distance of magnetic borders used in moving and resizing dialogs,
3238
* measured in pixels.
3240
* config.dialog_magnetDistance = 30;
3242
* @cfg {Number} [dialog_magnetDistance=20]
3243
* @member CKEDITOR.config
3247
* The guideline to follow when generating the dialog buttons. There are 3 possible options:
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.
3255
* config.dialog_buttonsOrder = 'rtl';
3258
* @cfg {String} [dialog_buttonsOrder='OS']
3259
* @member CKEDITOR.config
3263
* The dialog contents to removed. It's a string composed by dialog name and tab name with a colon between them.
3265
* Separate each pair with semicolon (see example).
3267
* **Note:** All names are case-sensitive.
3269
* **Note:** Be cautious when specifying dialog tabs that are mandatory,
3270
* like `'info'`, dialog functionality might be broken because of this!
3272
* config.removeDialogTabs = 'flash:advanced;image:Link';
3275
* @cfg {String} [removeDialogTabs='']
3276
* @member CKEDITOR.config
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.
3283
* config.dialog_noConfirmCancel = true;
3286
* @cfg {Boolean} [dialog_noConfirmCancel=false]
3287
* @member CKEDITOR.config
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.
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
3299
* @event dialogDefinition
3301
* @param {CKEDITOR.dialog.definition} data The dialog defination that
3303
* @param {CKEDITOR.editor} editor The editor instance that will use the dialog.
3307
* Event fired when a tab is going to be selected in a dialog.
3310
* @member CKEDITOR.dialog
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.
3317
* Event fired when the user tries to dismiss a dialog.
3320
* @member CKEDITOR.dialog
3322
* @param {Boolean} data.hide Whether the event should proceed or not.
3326
* Event fired when the user tries to confirm a dialog.
3329
* @member CKEDITOR.dialog
3331
* @param {Boolean} data.hide Whether the event should proceed or not.
3335
* Event fired when a dialog is shown.
3338
* @member CKEDITOR.dialog
3342
* Event fired when a dialog is shown.
3345
* @member CKEDITOR.editor
3346
* @param {CKEDITOR.editor} editor This editor instance.
3347
* @param {CKEDITOR.dialog} data The opened dialog instance.
3351
* Event fired when a dialog is hidden.
3354
* @member CKEDITOR.dialog
3358
* Event fired when a dialog is hidden.
3361
* @member CKEDITOR.editor
3362
* @param {CKEDITOR.editor} editor This editor instance.
3363
* @param {CKEDITOR.dialog} data The hidden dialog instance.
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.
3373
* @member CKEDITOR.dialog
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.
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.
3389
* @member CKEDITOR.dialog
3391
* @param {Number} data.width The new width.
3392
* @param {Number} data.height The new height.
3396
* Event fired when the dialog state changes, usually by {@link CKEDITOR.dialog#setState}.
3400
* @member CKEDITOR.dialog
3402
* @param {Number} data The new state. Either {@link CKEDITOR#DIALOG_STATE_IDLE} or {@link CKEDITOR#DIALOG_STATE_BUSY}.