2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @fileOverview The floating dialog plugin.
11 * No resize for this dialog.
14 CKEDITOR.DIALOG_RESIZE_NONE = 0;
17 * Only allow horizontal resizing for this dialog, disable vertical resizing.
20 CKEDITOR.DIALOG_RESIZE_WIDTH = 1;
23 * Only allow vertical resizing for this dialog, disable horizontal resizing.
26 CKEDITOR.DIALOG_RESIZE_HEIGHT = 2;
29 * Allow the dialog to be resized in both directions.
32 CKEDITOR.DIALOG_RESIZE_BOTH = 3;
36 var cssLength = CKEDITOR.tools.cssLength;
37 function isTabVisible( tabId )
39 return !!this._.tabs[ tabId ][ 0 ].$.offsetHeight;
42 function getPreviousVisibleTab()
44 var tabId = this._.currentTabId,
45 length = this._.tabIdList.length,
46 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId ) + length;
48 for ( var i = tabIndex - 1 ; i > tabIndex - length ; i-- )
50 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
51 return this._.tabIdList[ i % length ];
57 function getNextVisibleTab()
59 var tabId = this._.currentTabId,
60 length = this._.tabIdList.length,
61 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId );
63 for ( var i = tabIndex + 1 ; i < tabIndex + length ; i++ )
65 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
66 return this._.tabIdList[ i % length ];
73 function clearOrRecoverTextInputValue( container, isRecover )
75 var inputs = container.$.getElementsByTagName( 'input' );
76 for ( var i = 0, length = inputs.length; i < length ; i++ )
78 var item = new CKEDITOR.dom.element( inputs[ i ] );
80 if ( item.getAttribute( 'type' ).toLowerCase() == 'text' )
84 item.setAttribute( 'value', item.getCustomData( 'fake_value' ) || '' );
85 item.removeCustomData( 'fake_value' );
89 item.setCustomData( 'fake_value', item.getAttribute( 'value' ) );
90 item.setAttribute( 'value', '' );
97 * This is the base class for runtime dialog objects. An instance of this
98 * class represents a single named dialog for a single editor instance.
99 * @param {Object} editor The editor which created the dialog.
100 * @param {String} dialogName The dialog's registered name.
103 * var dialogObj = new CKEDITOR.dialog( editor, 'smiley' );
105 CKEDITOR.dialog = function( editor, dialogName )
107 // Load the dialog definition.
108 var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
109 defaultDefinition = CKEDITOR.tools.clone( defaultDialogDefinition ),
110 buttonsOrder = editor.config.dialog_buttonsOrder || 'OS',
111 dir = editor.lang.dir;
113 if ( ( buttonsOrder == 'OS' && CKEDITOR.env.mac ) || // The buttons in MacOS Apps are in reverse order (#4750)
114 ( buttonsOrder == 'rtl' && dir == 'ltr' ) ||
115 ( buttonsOrder == 'ltr' && dir == 'rtl' ) )
116 defaultDefinition.buttons.reverse();
119 // Completes the definition with the default values.
120 definition = CKEDITOR.tools.extend( definition( editor ), defaultDefinition );
122 // Clone a functionally independent copy for this dialog.
123 definition = CKEDITOR.tools.clone( definition );
125 // Create a complex definition object, extending it with the API
127 definition = new definitionObject( this, definition );
129 var doc = CKEDITOR.document;
131 var themeBuilt = editor.theme.buildDialog( editor );
133 // Initialize some basic parameters.
137 element : themeBuilt.element,
139 contentSize : { width : 0, height : 0 },
140 size : { width : 0, height : 0 },
145 // Initialize the tab and page map.
149 currentTabIndex : null,
154 // Initialize the tab order array for input widgets.
156 currentFocusIndex : 0,
160 this.parts = themeBuilt.parts;
162 CKEDITOR.tools.setTimeout( function()
164 editor.fire( 'ariaWidget', this.parts.contents );
168 // Set the startup styles for the dialog, avoiding it enlarging the
169 // page size on the dialog creation.
170 this.parts.dialog.setStyles(
172 position : CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed',
175 visibility : 'hidden'
178 // Call the CKEDITOR.event constructor to initialize this instance.
179 CKEDITOR.event.call( this );
181 // Fire the "dialogDefinition" event, making it possible to customize
182 // the dialog definition.
183 this.definition = definition = CKEDITOR.fire( 'dialogDefinition',
186 definition : definition
188 , editor ).definition;
190 var tabsToRemove = {};
191 // Cache tabs that should be removed.
192 if ( !( 'removeDialogTabs' in editor._ ) && editor.config.removeDialogTabs )
194 var removeContents = editor.config.removeDialogTabs.split( ';' );
196 for ( i = 0; i < removeContents.length; i++ )
198 var parts = removeContents[ i ].split( ':' );
199 if ( parts.length == 2 )
201 var removeDialogName = parts[ 0 ];
202 if ( !tabsToRemove[ removeDialogName ] )
203 tabsToRemove[ removeDialogName ] = [];
204 tabsToRemove[ removeDialogName ].push( parts[ 1 ] );
207 editor._.removeDialogTabs = tabsToRemove;
210 // Remove tabs of this dialog.
211 if ( editor._.removeDialogTabs && ( tabsToRemove = editor._.removeDialogTabs[ dialogName ] ) )
213 for ( i = 0; i < tabsToRemove.length; i++ )
214 definition.removeContents( tabsToRemove[ i ] );
217 // Initialize load, show, hide, ok and cancel events.
218 if ( definition.onLoad )
219 this.on( 'load', definition.onLoad );
221 if ( definition.onShow )
222 this.on( 'show', definition.onShow );
224 if ( definition.onHide )
225 this.on( 'hide', definition.onHide );
227 if ( definition.onOk )
229 this.on( 'ok', function( evt )
231 // Dialog confirm might probably introduce content changes (#5415).
232 editor.fire( 'saveSnapshot' );
233 setTimeout( function () { editor.fire( 'saveSnapshot' ); }, 0 );
234 if ( definition.onOk.call( this, evt ) === false )
235 evt.data.hide = false;
239 if ( definition.onCancel )
241 this.on( 'cancel', function( evt )
243 if ( definition.onCancel.call( this, evt ) === false )
244 evt.data.hide = false;
250 // Iterates over all items inside all content in the dialog, calling a
251 // function for each of them.
252 var iterContents = function( func )
254 var contents = me._.contents,
257 for ( var i in contents )
259 for ( var j in contents[i] )
261 stop = func.call( this, contents[i][j] );
268 this.on( 'ok', function( evt )
270 iterContents( function( item )
274 var isValid = item.validate( this );
276 if ( typeof isValid == 'string' )
282 if ( isValid === false )
289 evt.data.hide = false;
297 this.on( 'cancel', function( evt )
299 iterContents( function( item )
301 if ( item.isChanged() )
303 if ( !confirm( editor.lang.common.confirmCancel ) )
304 evt.data.hide = false;
310 this.parts.close.on( 'click', function( evt )
312 if ( this.fire( 'cancel', { hide : true } ).hide !== false )
314 evt.data.preventDefault();
317 // Sort focus list according to tab order definitions.
318 function setupFocus()
320 var focusList = me._.focusList;
321 focusList.sort( function( a, b )
323 // Mimics browser tab order logics;
324 if ( a.tabIndex != b.tabIndex )
325 return b.tabIndex - a.tabIndex;
326 // Sort is not stable in some browsers,
327 // fall-back the comparator to 'focusIndex';
329 return a.focusIndex - b.focusIndex;
332 var size = focusList.length;
333 for ( var i = 0; i < size; i++ )
334 focusList[ i ].focusIndex = i;
337 function changeFocus( forward )
339 var focusList = me._.focusList,
340 offset = forward ? 1 : -1;
341 if ( focusList.length < 1 )
344 var current = me._.currentFocusIndex;
346 // Trigger the 'blur' event of any input element before anything,
347 // since certain UI updates may depend on it.
350 focusList[ current ].getInputElement().$.blur();
354 var startIndex = ( current + offset + focusList.length ) % focusList.length,
355 currentIndex = startIndex;
356 while ( !focusList[ currentIndex ].isFocusable() )
358 currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length;
359 if ( currentIndex == startIndex )
362 focusList[ currentIndex ].focus();
364 // Select whole field content.
365 if ( focusList[ currentIndex ].type == 'text' )
366 focusList[ currentIndex ].select();
369 this.changeFocus = changeFocus;
373 function focusKeydownHandler( evt )
375 // If I'm not the top dialog, ignore.
376 if ( me != CKEDITOR.dialog._.currentTop )
379 var keystroke = evt.data.getKeystroke(),
380 rtl = editor.lang.dir == 'rtl';
383 if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )
385 var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
387 // Handling Tab and Shift-Tab.
388 if ( me._.tabBarMode )
391 var nextId = shiftPressed ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );
392 me.selectPage( nextId );
393 me._.tabs[ nextId ][ 0 ].focus();
397 // Change the focus of inputs.
398 changeFocus( !shiftPressed );
403 else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode && me.getPageCount() > 1 )
405 // Alt-F10 puts focus into the current tab item in the tab bar.
406 me._.tabBarMode = true;
407 me._.tabs[ me._.currentTabId ][ 0 ].focus();
410 else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode )
412 // Arrow keys - used for changing tabs.
413 nextId = ( keystroke == ( rtl ? 39 : 37 ) ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) );
414 me.selectPage( nextId );
415 me._.tabs[ nextId ][ 0 ].focus();
418 else if ( ( keystroke == 13 || keystroke == 32 ) && me._.tabBarMode )
420 this.selectPage( this._.currentTabId );
421 this._.tabBarMode = false;
422 this._.currentFocusIndex = -1;
430 evt.data.preventDefault();
434 function focusKeyPressHandler( evt )
436 processed && evt.data.preventDefault();
439 var dialogElement = this._.element;
440 // Add the dialog keyboard handlers.
441 this.on( 'show', function()
443 dialogElement.on( 'keydown', focusKeydownHandler, this, null, 0 );
444 // Some browsers instead, don't cancel key events in the keydown, but in the
445 // keypress. So we must do a longer trip in those cases. (#4531)
446 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
447 dialogElement.on( 'keypress', focusKeyPressHandler, this );
450 this.on( 'hide', function()
452 dialogElement.removeListener( 'keydown', focusKeydownHandler );
453 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
454 dialogElement.removeListener( 'keypress', focusKeyPressHandler );
456 this.on( 'iframeAdded', function( evt )
458 var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );
459 doc.on( 'keydown', focusKeydownHandler, this, null, 0 );
462 // Auto-focus logic in dialog.
463 this.on( 'show', function()
465 // Setup tabIndex on showing the dialog instead of on loading
466 // to allow dynamic tab order happen in dialog definition.
469 if ( editor.config.dialog_startupFocusTab
470 && me._.pageCount > 1 )
472 me._.tabBarMode = true;
473 me._.tabs[ me._.currentTabId ][ 0 ].focus();
475 else if ( !this._.hasFocus )
477 this._.currentFocusIndex = -1;
479 // Decide where to put the initial focus.
480 if ( definition.onFocus )
482 var initialFocus = definition.onFocus.call( this );
483 // Focus the field that the user specified.
484 initialFocus && initialFocus.focus();
486 // Focus the first field in layout order.
491 * IE BUG: If the initial focus went into a non-text element (e.g. button),
492 * then IE would still leave the caret inside the editing area.
494 if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
496 var $selection = editor.document.$.selection,
497 $range = $selection.createRange();
501 if ( $range.parentElement && $range.parentElement().ownerDocument == editor.document.$
502 || $range.item && $range.item( 0 ).ownerDocument == editor.document.$ )
504 var $myRange = document.body.createTextRange();
505 $myRange.moveToElementText( this.getElement().getFirst().$ );
506 $myRange.collapse( true );
512 }, this, null, 0xffffffff );
514 // IE6 BUG: Text fields and text areas are only half-rendered the first time the dialog appears in IE6 (#2661).
515 // This is still needed after [2708] and [2709] because text fields in hidden TR tags are still broken.
516 if ( CKEDITOR.env.ie6Compat )
518 this.on( 'load', function( evt )
520 var outer = this.getElement(),
521 inner = outer.getFirst();
523 inner.appendTo( outer );
527 initDragAndDrop( this );
528 initResizeHandles( this );
531 ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );
533 // Insert the tabs and contents.
534 for ( var i = 0 ; i < definition.contents.length ; i++ )
536 var page = definition.contents[i];
537 page && this.addPage( page );
540 this.parts[ 'tabs' ].on( 'click', function( evt )
542 var target = evt.data.getTarget();
543 // If we aren't inside a tab, bail out.
544 if ( target.hasClass( 'cke_dialog_tab' ) )
546 // Get the ID of the tab, without the 'cke_' prefix and the unique number suffix.
547 var id = target.$.id;
548 this.selectPage( id.substring( 4, id.lastIndexOf( '_' ) ) );
550 if ( this._.tabBarMode )
552 this._.tabBarMode = false;
553 this._.currentFocusIndex = -1;
556 evt.data.preventDefault();
561 var buttonsHtml = [],
562 buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this,
565 className : 'cke_dialog_footer_buttons',
567 children : definition.buttons
568 }, buttonsHtml ).getChild();
569 this.parts.footer.setHtml( buttonsHtml.join( '' ) );
571 for ( i = 0 ; i < buttons.length ; i++ )
572 this._.buttons[ buttons[i].id ] = buttons[i];
575 // Focusable interface. Use it via dialog.addFocusable.
576 function Focusable( dialog, element, index )
578 this.element = element;
579 this.focusIndex = index;
580 // TODO: support tabIndex for focusables.
582 this.isFocusable = function()
584 return !element.getAttribute( 'disabled' ) && element.isVisible();
586 this.focus = function()
588 dialog._.currentFocusIndex = this.focusIndex;
589 this.element.focus();
592 element.on( 'keydown', function( e )
594 if ( e.data.getKeystroke() in { 32:1, 13:1 } )
595 this.fire( 'click' );
597 element.on( 'focus', function()
599 this.fire( 'mouseover' );
601 element.on( 'blur', function()
603 this.fire( 'mouseout' );
607 CKEDITOR.dialog.prototype =
612 this._.element.remove();
616 * Resizes the dialog.
617 * @param {Number} width The width of the dialog in pixels.
618 * @param {Number} height The height of the dialog in pixels.
621 * dialogObj.resize( 800, 640 );
625 return function( width, height )
627 if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )
630 CKEDITOR.dialog.fire( 'resize',
633 skin : this._.editor.skinName,
638 this._.contentSize = { width : width, height : height };
643 * Gets the current size of the dialog in pixels.
644 * @returns {Object} An object with "width" and "height" properties.
646 * var width = dialogObj.getSize().width;
650 var element = this._.element.getFirst();
651 return { width : element.$.offsetWidth || 0, height : element.$.offsetHeight || 0};
655 * Moves the dialog to an (x, y) coordinate relative to the window.
657 * @param {Number} x The target x-coordinate.
658 * @param {Number} y The target y-coordinate.
659 * @param {Boolean} save Flag indicate whether the dialog position should be remembered on next open up.
661 * dialogObj.move( 10, 40 );
666 return function( x, y, save )
668 // The dialog may be fixed positioned or absolute positioned. Ask the
669 // browser what is the current situation first.
670 var element = this._.element.getFirst();
671 if ( isFixed === undefined )
672 isFixed = element.getComputedStyle( 'position' ) == 'fixed';
674 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
677 // Save the current position.
678 this._.position = { x : x, y : y };
680 // If not fixed positioned, add scroll position to the coordinates.
683 var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
684 x += scrollPosition.x;
685 y += scrollPosition.y;
690 'left' : ( x > 0 ? x : 0 ) + 'px',
691 'top' : ( y > 0 ? y : 0 ) + 'px'
694 save && ( this._.moved = 1 );
699 * Gets the dialog's position in the window.
700 * @returns {Object} An object with "x" and "y" properties.
702 * var dialogX = dialogObj.getPosition().x;
704 getPosition : function(){ return CKEDITOR.tools.extend( {}, this._.position ); },
707 * Shows the dialog box.
713 // Insert the dialog's element to the root document.
714 var element = this._.element;
715 var definition = this.definition;
716 if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )
717 element.appendTo( CKEDITOR.document.getBody() );
719 element.setStyle( 'display', 'block' );
721 // FIREFOX BUG: Fix vanishing caret for Firefox 2 or Gecko 1.8.
722 if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
724 var dialogElement = this.parts.dialog;
725 dialogElement.setStyle( 'position', 'absolute' );
726 setTimeout( function()
728 dialogElement.setStyle( 'position', 'fixed' );
733 // First, set the dialog to an appropriate size.
734 this.resize( this._.contentSize && this._.contentSize.width || definition.minWidth,
735 this._.contentSize && this._.contentSize.height || definition.minHeight );
737 // Reset all inputs back to their default value.
740 // Select the first tab by default.
741 this.selectPage( this.definition.contents[0].id );
744 if ( CKEDITOR.dialog._.currentZIndex === null )
745 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;
746 this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
748 // Maintain the dialog ordering and dialog cover.
749 // Also register key handlers if first dialog.
750 if ( CKEDITOR.dialog._.currentTop === null )
752 CKEDITOR.dialog._.currentTop = this;
753 this._.parentDialog = null;
754 showCover( this._.editor );
756 element.on( 'keydown', accessKeyDownHandler );
757 element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
759 // Prevent some keys from bubbling up. (#4269)
760 for ( var event in { keyup :1, keydown :1, keypress :1 } )
761 element.on( event, preventKeyBubbling );
765 this._.parentDialog = CKEDITOR.dialog._.currentTop;
766 var parentElement = this._.parentDialog.getElement().getFirst();
767 parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );
768 CKEDITOR.dialog._.currentTop = this;
771 // Register the Esc hotkeys.
772 registerAccessKey( this, this, '\x1b', null, function()
774 this.getButton( 'cancel' ) && this.getButton( 'cancel' ).click();
777 // Reset the hasFocus state.
778 this._.hasFocus = false;
780 CKEDITOR.tools.setTimeout( function()
783 this.parts.dialog.setStyle( 'visibility', '' );
785 // Execute onLoad for the first show.
786 this.fireOnce( 'load', {} );
787 CKEDITOR.ui.fire( 'ready', this );
789 this.fire( 'show', {} );
790 this._.editor.fire( 'dialogShow', this );
792 // Save the initial values of the dialog.
793 this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } );
800 * Rearrange the dialog to its previous position or the middle of the window.
805 var viewSize = CKEDITOR.document.getWindow().getViewPaneSize(),
806 dialogSize = this.getSize();
808 this.move( this._.moved ? this._.position.x : ( viewSize.width - dialogSize.width ) / 2,
809 this._.moved ? this._.position.y : ( viewSize.height - dialogSize.height ) / 2 );
813 * Executes a function for each UI element.
814 * @param {Function} fn Function to execute for each UI element.
815 * @returns {CKEDITOR.dialog} The current dialog object.
817 foreach : function( fn )
819 for ( var i in this._.contents )
821 for ( var j in this._.contents[i] )
822 fn( this._.contents[i][j] );
828 * Resets all input values in the dialog.
831 * @returns {CKEDITOR.dialog} The current dialog object.
835 var fn = function( widget ){ if ( widget.reset ) widget.reset( 1 ); };
836 return function(){ this.foreach( fn ); return this; };
839 setupContent : function()
841 var args = arguments;
842 this.foreach( function( widget )
845 widget.setup.apply( widget, args );
849 commitContent : function()
851 var args = arguments;
852 this.foreach( function( widget )
855 widget.commit.apply( widget, args );
860 * Hides the dialog box.
866 if ( !this.parts.dialog.isVisible() )
869 this.fire( 'hide', {} );
870 this._.editor.fire( 'dialogHide', this );
871 var element = this._.element;
872 element.setStyle( 'display', 'none' );
873 this.parts.dialog.setStyle( 'visibility', 'hidden' );
874 // Unregister all access keys associated with this dialog.
875 unregisterAccessKey( this );
877 // Close any child(top) dialogs first.
878 while( CKEDITOR.dialog._.currentTop != this )
879 CKEDITOR.dialog._.currentTop.hide();
881 // Maintain dialog ordering and remove cover if needed.
882 if ( !this._.parentDialog )
886 var parentElement = this._.parentDialog.getElement().getFirst();
887 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
889 CKEDITOR.dialog._.currentTop = this._.parentDialog;
891 // Deduct or clear the z-index.
892 if ( !this._.parentDialog )
894 CKEDITOR.dialog._.currentZIndex = null;
896 // Remove access key handlers.
897 element.removeListener( 'keydown', accessKeyDownHandler );
898 element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
900 // Remove bubbling-prevention handler. (#4269)
901 for ( var event in { keyup :1, keydown :1, keypress :1 } )
902 element.removeListener( event, preventKeyBubbling );
904 var editor = this._.editor;
907 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
909 var selection = editor.getSelection();
910 selection && selection.unlock( true );
914 CKEDITOR.dialog._.currentZIndex -= 10;
916 delete this._.parentDialog;
917 // Reset the initial values of the dialog.
918 this.foreach( function( contentObj ) { contentObj.resetInitValue && contentObj.resetInitValue(); } );
922 * Adds a tabbed page into the dialog.
923 * @param {Object} contents Content definition.
926 addPage : function( contents )
929 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
930 elements = contents.elements,
931 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this,
934 className : 'cke_dialog_page_contents',
935 children : contents.elements,
936 expand : !!contents.expand,
937 padding : contents.padding,
938 style : contents.style || 'width: 100%;'
941 // Create the HTML for the tab and the content block.
942 var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
943 page.setAttribute( 'role', 'tabpanel' );
945 var env = CKEDITOR.env;
946 var tabId = 'cke_' + contents.id + '_' + CKEDITOR.tools.getNextNumber(),
947 tab = CKEDITOR.dom.element.createFromHtml( [
948 '<a class="cke_dialog_tab"',
949 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),
951 ( !!contents.hidden ? ' style="display:none"' : '' ),
953 env.gecko && env.version >= 10900 && !env.hc ? '' : ' href="javascript:void(0)"',
961 page.setAttribute( 'aria-labelledby', tabId );
963 // Take records for the tabs and elements created.
964 this._.tabs[ contents.id ] = [ tab, page ];
965 this._.tabIdList.push( contents.id );
966 !contents.hidden && this._.pageCount++;
967 this._.lastTab = tab;
970 var contentMap = this._.contents[ contents.id ] = {},
972 children = vbox.getChild();
974 while ( ( cursor = children.shift() ) )
976 contentMap[ cursor.id ] = cursor;
977 if ( typeof( cursor.getChild ) == 'function' )
978 children.push.apply( children, cursor.getChild() );
981 // Attach the DOM nodes.
983 page.setAttribute( 'name', contents.id );
984 page.appendTo( this.parts.contents );
987 this.parts.tabs.append( tab );
989 // Add access key handlers if access key is defined.
990 if ( contents.accessKey )
992 registerAccessKey( this, this, 'CTRL+' + contents.accessKey,
993 tabAccessKeyDown, tabAccessKeyUp );
994 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;
999 * Activates a tab page in the dialog by its id.
1000 * @param {String} id The id of the dialog tab to be activated.
1002 * dialogObj.selectPage( 'tab_1' );
1004 selectPage : function( id )
1006 if ( this._.currentTabId == id )
1009 // Returning true means that the event has been canceled
1010 if ( this.fire( 'selectPage', { page : id, currentPage : this._.currentTabId } ) === true )
1013 // Hide the non-selected tabs and pages.
1014 for ( var i in this._.tabs )
1016 var tab = this._.tabs[i][0],
1017 page = this._.tabs[i][1];
1020 tab.removeClass( 'cke_dialog_tab_selected' );
1023 page.setAttribute( 'aria-hidden', i != id );
1026 var selected = this._.tabs[ id ];
1027 selected[ 0 ].addClass( 'cke_dialog_tab_selected' );
1029 // [IE] an invisible input[type='text'] will enlarge it's width
1030 // if it's value is long when it shows, so we clear it's value
1031 // before it shows and then recover it (#5649)
1032 if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat )
1034 clearOrRecoverTextInputValue( selected[ 1 ] );
1035 selected[ 1 ].show();
1036 setTimeout( function()
1038 clearOrRecoverTextInputValue( selected[ 1 ], 1 );
1042 selected[ 1 ].show();
1044 this._.currentTabId = id;
1045 this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
1048 // Dialog state-specific style updates.
1049 updateStyle : function()
1051 // If only a single page shown, a different style is used in the central pane.
1052 this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );
1056 * Hides a page's tab away from the dialog.
1057 * @param {String} id The page's Id.
1059 * dialog.hidePage( 'tab_3' );
1061 hidePage : function( id )
1063 var tab = this._.tabs[id] && this._.tabs[id][0];
1064 if ( !tab || this._.pageCount == 1 || !tab.isVisible() )
1066 // Switch to other tab first when we're hiding the active tab.
1067 else if ( id == this._.currentTabId )
1068 this.selectPage( getPreviousVisibleTab.call( this ) );
1076 * Unhides a page's tab.
1077 * @param {String} id The page's Id.
1079 * dialog.showPage( 'tab_2' );
1081 showPage : function( id )
1083 var tab = this._.tabs[id] && this._.tabs[id][0];
1092 * Gets the root DOM element of the dialog.
1093 * @returns {CKEDITOR.dom.element} The <span> element containing this dialog.
1095 * var dialogElement = dialogObj.getElement().getFirst();
1096 * dialogElement.setStyle( 'padding', '5px' );
1098 getElement : function()
1100 return this._.element;
1104 * Gets the name of the dialog.
1105 * @returns {String} The name of this dialog.
1107 * var dialogName = dialogObj.getName();
1109 getName : function()
1115 * Gets a dialog UI element object from a dialog page.
1116 * @param {String} pageId id of dialog page.
1117 * @param {String} elementId id of UI element.
1119 * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.
1121 getContentElement : function( pageId, elementId )
1123 var page = this._.contents[ pageId ];
1124 return page && page[ elementId ];
1128 * Gets the value of a dialog UI element.
1129 * @param {String} pageId id of dialog page.
1130 * @param {String} elementId id of UI element.
1132 * @returns {Object} The value of the UI element.
1134 getValueOf : function( pageId, elementId )
1136 return this.getContentElement( pageId, elementId ).getValue();
1140 * Sets the value of a dialog UI element.
1141 * @param {String} pageId id of the dialog page.
1142 * @param {String} elementId id of the UI element.
1143 * @param {Object} value The new value of the UI element.
1146 setValueOf : function( pageId, elementId, value )
1148 return this.getContentElement( pageId, elementId ).setValue( value );
1152 * Gets the UI element of a button in the dialog's button row.
1153 * @param {String} id The id of the button.
1155 * @returns {CKEDITOR.ui.dialog.button} The button object.
1157 getButton : function( id )
1159 return this._.buttons[ id ];
1163 * Simulates a click to a dialog button in the dialog's button row.
1164 * @param {String} id The id of the button.
1166 * @returns The return value of the dialog's "click" event.
1168 click : function( id )
1170 return this._.buttons[ id ].click();
1174 * Disables a dialog button.
1175 * @param {String} id The id of the button.
1178 disableButton : function( id )
1180 return this._.buttons[ id ].disable();
1184 * Enables a dialog button.
1185 * @param {String} id The id of the button.
1188 enableButton : function( id )
1190 return this._.buttons[ id ].enable();
1194 * Gets the number of pages in the dialog.
1195 * @returns {Number} Page count.
1197 getPageCount : function()
1199 return this._.pageCount;
1203 * Gets the editor instance which opened this dialog.
1204 * @returns {CKEDITOR.editor} Parent editor instances.
1206 getParentEditor : function()
1208 return this._.editor;
1212 * Gets the element that was selected when opening the dialog, if any.
1213 * @returns {CKEDITOR.dom.element} The element that was selected, or null.
1215 getSelectedElement : function()
1217 return this.getParentEditor().getSelection().getSelectedElement();
1221 * Adds element to dialog's focusable list.
1223 * @param {CKEDITOR.dom.element} element
1224 * @param {Number} [index]
1226 addFocusable: function( element, index ) {
1227 if ( typeof index == 'undefined' )
1229 index = this._.focusList.length;
1230 this._.focusList.push( new Focusable( this, element, index ) );
1234 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );
1235 for ( var i = index + 1 ; i < this._.focusList.length ; i++ )
1236 this._.focusList[ i ].focusIndex++;
1241 CKEDITOR.tools.extend( CKEDITOR.dialog,
1243 * @lends CKEDITOR.dialog
1247 * Registers a dialog.
1248 * @param {String} name The dialog's name.
1249 * @param {Function|String} dialogDefinition
1250 * A function returning the dialog's definition, or the URL to the .js file holding the function.
1251 * The function should accept an argument "editor" which is the current editor instance, and
1252 * return an object conforming to {@link CKEDITOR.dialog.dialogDefinition}.
1254 * @see CKEDITOR.dialog.dialogDefinition
1256 add : function( name, dialogDefinition )
1258 // Avoid path registration from multiple instances override definition.
1259 if ( !this._.dialogDefinitions[name]
1260 || typeof dialogDefinition == 'function' )
1261 this._.dialogDefinitions[name] = dialogDefinition;
1264 exists : function( name )
1266 return !!this._.dialogDefinitions[ name ];
1269 getCurrent : function()
1271 return CKEDITOR.dialog._.currentTop;
1275 * The default OK button for dialogs. Fires the "ok" event and closes the dialog if the event succeeds.
1281 okButton : (function()
1283 var retval = function( editor, override )
1285 override = override || {};
1286 return CKEDITOR.tools.extend( {
1289 label : editor.lang.common.ok,
1290 'class' : 'cke_dialog_ui_button_ok',
1291 onClick : function( evt )
1293 var dialog = evt.data.dialog;
1294 if ( dialog.fire( 'ok', { hide : true } ).hide !== false )
1297 }, override, true );
1299 retval.type = 'button';
1300 retval.override = function( override )
1302 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
1303 { type : 'button' }, true );
1309 * The default cancel button for dialogs. Fires the "cancel" event and closes the dialog if no UI element value changed.
1315 cancelButton : (function()
1317 var retval = function( editor, override )
1319 override = override || {};
1320 return CKEDITOR.tools.extend( {
1323 label : editor.lang.common.cancel,
1324 'class' : 'cke_dialog_ui_button_cancel',
1325 onClick : function( evt )
1327 var dialog = evt.data.dialog;
1328 if ( dialog.fire( 'cancel', { hide : true } ).hide !== false )
1331 }, override, true );
1333 retval.type = 'button';
1334 retval.override = function( override )
1336 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
1337 { type : 'button' }, true );
1343 * Registers a dialog UI element.
1344 * @param {String} typeName The name of the UI element.
1345 * @param {Function} builder The function to build the UI element.
1348 addUIElement : function( typeName, builder )
1350 this._.uiElementBuilders[ typeName ] = builder;
1356 uiElementBuilders : {},
1358 dialogDefinitions : {},
1362 currentZIndex : null
1365 // "Inherit" (copy actually) from CKEDITOR.event.
1366 CKEDITOR.event.implementOn( CKEDITOR.dialog );
1367 CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype, true );
1369 var defaultDialogDefinition =
1371 resizable : CKEDITOR.DIALOG_RESIZE_BOTH,
1374 buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
1377 // Tool function used to return an item from an array based on its id
1379 var getById = function( array, id, recurse )
1381 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
1383 if ( item.id == id )
1385 if ( recurse && item[ recurse ] )
1387 var retval = getById( item[ recurse ], id, recurse ) ;
1395 // Tool function used to add an item into an array.
1396 var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound )
1398 if ( nextSiblingId )
1400 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
1402 if ( item.id == nextSiblingId )
1404 array.splice( i, 0, newItem );
1408 if ( recurse && item[ recurse ] )
1410 var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
1416 if ( nullIfNotFound )
1420 array.push( newItem );
1424 // Tool function used to remove an item from an array based on its id.
1425 var removeById = function( array, id, recurse )
1427 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
1429 if ( item.id == id )
1430 return array.splice( i, 1 );
1431 if ( recurse && item[ recurse ] )
1433 var retval = removeById( item[ recurse ], id, recurse );
1442 * This class is not really part of the API. It is the "definition" property value
1443 * passed to "dialogDefinition" event handlers.
1445 * @name CKEDITOR.dialog.dialogDefinitionObject
1446 * @extends CKEDITOR.dialog.dialogDefinition
1448 * CKEDITOR.on( 'dialogDefinition', function( evt )
1450 * var definition = evt.data.definition;
1451 * var content = definition.getContents( 'page1' );
1455 var definitionObject = function( dialog, dialogDefinition )
1457 // TODO : Check if needed.
1458 this.dialog = dialog;
1460 // Transform the contents entries in contentObjects.
1461 var contents = dialogDefinition.contents;
1462 for ( var i = 0, content ; ( content = contents[i] ) ; i++ )
1463 contents[ i ] = content && new contentObject( dialog, content );
1465 CKEDITOR.tools.extend( this, dialogDefinition );
1468 definitionObject.prototype =
1469 /** @lends CKEDITOR.dialog.dialogDefinitionObject.prototype */
1472 * Gets a content definition.
1473 * @param {String} id The id of the content definition.
1474 * @returns {CKEDITOR.dialog.contentDefinition} The content definition
1477 getContents : function( id )
1479 return getById( this.contents, id );
1483 * Gets a button definition.
1484 * @param {String} id The id of the button definition.
1485 * @returns {CKEDITOR.dialog.buttonDefinition} The button definition
1488 getButton : function( id )
1490 return getById( this.buttons, id );
1494 * Adds a content definition object under this dialog definition.
1495 * @param {CKEDITOR.dialog.contentDefinition} contentDefinition The
1496 * content definition.
1497 * @param {String} [nextSiblingId] The id of an existing content
1498 * definition which the new content definition will be inserted
1499 * before. Omit if the new content definition is to be inserted as
1501 * @returns {CKEDITOR.dialog.contentDefinition} The inserted content
1504 addContents : function( contentDefinition, nextSiblingId )
1506 return addById( this.contents, contentDefinition, nextSiblingId );
1510 * Adds a button definition object under this dialog definition.
1511 * @param {CKEDITOR.dialog.buttonDefinition} buttonDefinition The
1512 * button definition.
1513 * @param {String} [nextSiblingId] The id of an existing button
1514 * definition which the new button definition will be inserted
1515 * before. Omit if the new button definition is to be inserted as
1517 * @returns {CKEDITOR.dialog.buttonDefinition} The inserted button
1520 addButton : function( buttonDefinition, nextSiblingId )
1522 return addById( this.buttons, buttonDefinition, nextSiblingId );
1526 * Removes a content definition from this dialog definition.
1527 * @param {String} id The id of the content definition to be removed.
1528 * @returns {CKEDITOR.dialog.contentDefinition} The removed content
1531 removeContents : function( id )
1533 removeById( this.contents, id );
1537 * Removes a button definition from the dialog definition.
1538 * @param {String} id The id of the button definition to be removed.
1539 * @returns {CKEDITOR.dialog.buttonDefinition} The removed button
1542 removeButton : function( id )
1544 removeById( this.buttons, id );
1549 * This class is not really part of the API. It is the template of the
1550 * objects representing content pages inside the
1551 * CKEDITOR.dialog.dialogDefinitionObject.
1553 * @name CKEDITOR.dialog.contentDefinitionObject
1555 * CKEDITOR.on( 'dialogDefinition', function( evt )
1557 * var definition = evt.data.definition;
1558 * var content = definition.getContents( 'page1' );
1559 * content.remove( 'textInput1' );
1563 function contentObject( dialog, contentDefinition )
1570 CKEDITOR.tools.extend( this, contentDefinition );
1573 contentObject.prototype =
1574 /** @lends CKEDITOR.dialog.contentDefinitionObject.prototype */
1577 * Gets a UI element definition under the content definition.
1578 * @param {String} id The id of the UI element definition.
1579 * @returns {CKEDITOR.dialog.uiElementDefinition}
1581 get : function( id )
1583 return getById( this.elements, id, 'children' );
1587 * Adds a UI element definition to the content definition.
1588 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition The
1589 * UI elemnet definition to be added.
1590 * @param {String} nextSiblingId The id of an existing UI element
1591 * definition which the new UI element definition will be inserted
1592 * before. Omit if the new button definition is to be inserted as
1594 * @returns {CKEDITOR.dialog.uiElementDefinition} The element
1595 * definition inserted.
1597 add : function( elementDefinition, nextSiblingId )
1599 return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
1603 * Removes a UI element definition from the content definition.
1604 * @param {String} id The id of the UI element definition to be
1606 * @returns {CKEDITOR.dialog.uiElementDefinition} The element
1607 * definition removed.
1610 remove : function( id )
1612 removeById( this.elements, id, 'children' );
1616 function initDragAndDrop( dialog )
1618 var lastCoords = null,
1619 abstractDialogCoords = null,
1620 element = dialog.getElement().getFirst(),
1621 editor = dialog.getParentEditor(),
1622 magnetDistance = editor.config.dialog_magnetDistance,
1623 margins = editor.skin.margins || [ 0, 0, 0, 0 ];
1625 if ( typeof magnetDistance == 'undefined' )
1626 magnetDistance = 20;
1628 function mouseMoveHandler( evt )
1630 var dialogSize = dialog.getSize(),
1631 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
1632 x = evt.data.$.screenX,
1633 y = evt.data.$.screenY,
1634 dx = x - lastCoords.x,
1635 dy = y - lastCoords.y,
1638 lastCoords = { x : x, y : y };
1639 abstractDialogCoords.x += dx;
1640 abstractDialogCoords.y += dy;
1642 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
1643 realX = - margins[3];
1644 else if ( abstractDialogCoords.x - margins[1] > viewPaneSize.width - dialogSize.width - magnetDistance )
1645 realX = viewPaneSize.width - dialogSize.width + ( editor.lang.dir == 'rtl' ? 0 : margins[1] );
1647 realX = abstractDialogCoords.x;
1649 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
1650 realY = - margins[0];
1651 else if ( abstractDialogCoords.y - margins[2] > viewPaneSize.height - dialogSize.height - magnetDistance )
1652 realY = viewPaneSize.height - dialogSize.height + margins[2];
1654 realY = abstractDialogCoords.y;
1656 dialog.move( realX, realY, 1 );
1658 evt.data.preventDefault();
1661 function mouseUpHandler( evt )
1663 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
1664 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
1666 if ( CKEDITOR.env.ie6Compat )
1668 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
1669 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
1670 coverDoc.removeListener( 'mouseup', mouseUpHandler );
1674 dialog.parts.title.on( 'mousedown', function( evt )
1676 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
1678 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
1679 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
1680 abstractDialogCoords = dialog.getPosition();
1682 if ( CKEDITOR.env.ie6Compat )
1684 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
1685 coverDoc.on( 'mousemove', mouseMoveHandler );
1686 coverDoc.on( 'mouseup', mouseUpHandler );
1689 evt.data.preventDefault();
1693 function initResizeHandles( dialog )
1695 var def = dialog.definition,
1696 resizable = def.resizable;
1698 if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE )
1701 var editor = dialog.getParentEditor();
1702 var wrapperWidth, wrapperHeight,
1703 viewSize, origin, startSize,
1706 function positionDialog( right )
1708 // Maintain righthand sizing in RTL.
1709 if ( dialog._.moved && editor.lang.dir == 'rtl' )
1711 var element = dialog._.element.getFirst();
1712 element.setStyle( 'right', right + "px" );
1713 element.removeStyle( 'left' );
1715 else if ( !dialog._.moved )
1719 var mouseDownFn = CKEDITOR.tools.addFunction( function( $event )
1721 startSize = dialog.getSize();
1723 var content = dialog.parts.contents,
1724 iframeDialog = content.$.getElementsByTagName( 'iframe' ).length;
1726 // Shim to help capturing "mousemove" over iframe.
1729 dialogCover = CKEDITOR.dom.element.createFromHtml( '<div class="cke_dialog_resize_cover" style="height: 100%; position: absolute; width: 100%;"></div>' );
1730 content.append( dialogCover );
1733 // Calculate the offset between content and chrome size.
1734 wrapperHeight = startSize.height - dialog.parts.contents.getSize( 'height', ! ( CKEDITOR.env.gecko || CKEDITOR.env.opera || CKEDITOR.env.ie && CKEDITOR.env.quirks ) );
1735 wrapperWidth = startSize.width - dialog.parts.contents.getSize( 'width', 1 );
1737 origin = { x : $event.screenX, y : $event.screenY };
1739 viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
1741 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
1742 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
1744 if ( CKEDITOR.env.ie6Compat )
1746 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
1747 coverDoc.on( 'mousemove', mouseMoveHandler );
1748 coverDoc.on( 'mouseup', mouseUpHandler );
1751 $event.preventDefault && $event.preventDefault();
1754 // Prepend the grip to the dialog.
1755 dialog.on( 'load', function()
1758 if ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH )
1759 direction = ' cke_resizer_horizontal';
1760 else if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT )
1761 direction = ' cke_resizer_vertical';
1762 var resizer = CKEDITOR.dom.element.createFromHtml( '<div class="cke_resizer' + direction + '"' +
1763 ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.resize ) + '"' +
1764 ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event )"></div>' );
1765 dialog.parts.footer.append( resizer, 1 );
1767 editor.on( 'destroy', function() { CKEDITOR.tools.removeFunction( mouseDownFn ); } );
1769 function mouseMoveHandler( evt )
1771 var rtl = editor.lang.dir == 'rtl',
1772 dx = ( evt.data.$.screenX - origin.x ) * ( rtl ? -1 : 1 ),
1773 dy = evt.data.$.screenY - origin.y,
1774 width = startSize.width,
1775 height = startSize.height,
1776 internalWidth = width + dx * ( dialog._.moved ? 1 : 2 ),
1777 internalHeight = height + dy * ( dialog._.moved ? 1 : 2 ),
1778 element = dialog._.element.getFirst(),
1779 right = rtl && element.getComputedStyle( 'right' ),
1780 position = dialog.getPosition();
1782 // IE might return "auto", we need exact position.
1784 right = right == 'auto' ? viewSize.width - ( position.x || 0 ) - element.getSize( 'width' ) : parseInt( right, 10 );
1786 if ( position.y + internalHeight > viewSize.height )
1787 internalHeight = viewSize.height - position.y;
1789 if ( ( rtl ? right : position.x ) + internalWidth > viewSize.width )
1790 internalWidth = viewSize.width - ( rtl ? right : position.x );
1792 // Make sure the dialog will not be resized to the wrong side when it's in the leftmost position for RTL.
1793 if ( ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH || resizable == CKEDITOR.DIALOG_RESIZE_BOTH ) && !( rtl && dx > 0 && !position.x ) )
1794 width = Math.max( def.minWidth || 0, internalWidth - wrapperWidth );
1796 if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT || resizable == CKEDITOR.DIALOG_RESIZE_BOTH )
1797 height = Math.max( def.minHeight || 0, internalHeight - wrapperHeight );
1799 dialog.resize( width, height );
1800 // The right property might get broken during resizing, so computing it before the resizing.
1801 positionDialog( right );
1803 evt.data.preventDefault();
1806 function mouseUpHandler()
1808 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
1809 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
1813 dialogCover.remove();
1817 if ( CKEDITOR.env.ie6Compat )
1819 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
1820 coverDoc.removeListener( 'mouseup', mouseUpHandler );
1821 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
1824 // Switch back to use the left property, if RTL is used.
1825 if ( editor.lang.dir == 'rtl' )
1827 var element = dialog._.element.getFirst(),
1828 left = element.getComputedStyle( 'left' );
1830 // IE might return "auto", we need exact position.
1831 if ( left == 'auto' )
1832 left = viewSize.width - parseInt( element.getStyle( 'right' ), 10 ) - dialog.getSize().width;
1834 left = parseInt( left, 10 );
1836 element.removeStyle( 'right' );
1837 // Make sure the left property gets applied, even if it is the same as previously.
1838 dialog._.position.x += 1;
1839 dialog.move( left, dialog._.position.y );
1845 // Caching resuable covers and allowing only one cover
1850 function showCover( editor )
1852 var win = CKEDITOR.document.getWindow();
1853 var config = editor.config,
1854 backgroundColorStyle = config.dialog_backgroundCoverColor || 'white',
1855 backgroundCoverOpacity = config.dialog_backgroundCoverOpacity,
1856 baseFloatZIndex = config.baseFloatZIndex,
1857 coverKey = CKEDITOR.tools.genKey(
1858 backgroundColorStyle,
1859 backgroundCoverOpacity,
1861 coverElement = covers[ coverKey ];
1863 if ( !coverElement )
1866 '<div tabIndex="-1" style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),
1867 '; z-index: ', baseFloatZIndex,
1868 '; top: 0px; left: 0px; ',
1869 ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),
1870 '" class="cke_dialog_background_cover">'
1873 if ( CKEDITOR.env.ie6Compat )
1875 // Support for custom document.domain in IE.
1876 var isCustomDomain = CKEDITOR.env.isCustomDomain(),
1877 iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
1881 ' hidefocus="true"' +
1882 ' frameborder="0"' +
1883 ' id="cke_dialog_background_iframe"' +
1884 ' src="javascript:' );
1886 html.push( 'void((function(){' +
1887 'document.open();' +
1888 ( isCustomDomain ? 'document.domain=\'' + document.domain + '\';' : '' ) +
1889 'document.write( \'' + iframeHtml + '\' );' +
1890 'document.close();' +
1896 'position:absolute;' +
1901 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
1905 html.push( '</div>' );
1907 coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
1908 coverElement.setOpacity( backgroundCoverOpacity != undefined ? backgroundCoverOpacity : 0.5 );
1910 coverElement.appendTo( CKEDITOR.document.getBody() );
1911 covers[ coverKey ] = coverElement;
1914 coverElement. show();
1916 currentCover = coverElement;
1917 var resizeFunc = function()
1919 var size = win.getViewPaneSize();
1920 coverElement.setStyles(
1922 width : size.width + 'px',
1923 height : size.height + 'px'
1927 var scrollFunc = function()
1929 var pos = win.getScrollPosition(),
1930 cursor = CKEDITOR.dialog._.currentTop;
1931 coverElement.setStyles(
1933 left : pos.x + 'px',
1941 var dialogPos = cursor.getPosition();
1942 cursor.move( dialogPos.x, dialogPos.y );
1943 } while ( ( cursor = cursor._.parentDialog ) );
1947 resizeCover = resizeFunc;
1948 win.on( 'resize', resizeFunc );
1950 // Using Safari/Mac, focus must be kept where it is (#7027)
1951 if ( !( CKEDITOR.env.mac && CKEDITOR.env.webkit ) )
1952 coverElement.focus();
1954 if ( CKEDITOR.env.ie6Compat )
1956 // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
1957 // So we need to invent a really funny way to make it work.
1958 var myScrollHandler = function()
1961 arguments.callee.prevScrollHandler.apply( this, arguments );
1963 win.$.setTimeout( function()
1965 myScrollHandler.prevScrollHandler = window.onscroll || function(){};
1966 window.onscroll = myScrollHandler;
1972 function hideCover()
1974 if ( !currentCover )
1977 var win = CKEDITOR.document.getWindow();
1978 currentCover.hide();
1979 win.removeListener( 'resize', resizeCover );
1981 if ( CKEDITOR.env.ie6Compat )
1983 win.$.setTimeout( function()
1985 var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
1986 window.onscroll = prevScrollHandler || null;
1992 function removeCovers()
1994 for ( var coverId in covers )
1995 covers[ coverId ].remove();
1999 var accessKeyProcessors = {};
2001 var accessKeyDownHandler = function( evt )
2003 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
2004 alt = evt.data.$.altKey,
2005 shift = evt.data.$.shiftKey,
2006 key = String.fromCharCode( evt.data.$.keyCode ),
2007 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
2009 if ( !keyProcessor || !keyProcessor.length )
2012 keyProcessor = keyProcessor[keyProcessor.length - 1];
2013 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
2014 evt.data.preventDefault();
2017 var accessKeyUpHandler = function( evt )
2019 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
2020 alt = evt.data.$.altKey,
2021 shift = evt.data.$.shiftKey,
2022 key = String.fromCharCode( evt.data.$.keyCode ),
2023 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
2025 if ( !keyProcessor || !keyProcessor.length )
2028 keyProcessor = keyProcessor[keyProcessor.length - 1];
2029 if ( keyProcessor.keyup )
2031 keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
2032 evt.data.preventDefault();
2036 var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc )
2038 var procList = accessKeyProcessors[key] || ( accessKeyProcessors[key] = [] );
2040 uiElement : uiElement,
2043 keyup : upFunc || uiElement.accessKeyUp,
2044 keydown : downFunc || uiElement.accessKeyDown
2048 var unregisterAccessKey = function( obj )
2050 for ( var i in accessKeyProcessors )
2052 var list = accessKeyProcessors[i];
2053 for ( var j = list.length - 1 ; j >= 0 ; j-- )
2055 if ( list[j].dialog == obj || list[j].uiElement == obj )
2056 list.splice( j, 1 );
2058 if ( list.length === 0 )
2059 delete accessKeyProcessors[i];
2063 var tabAccessKeyUp = function( dialog, key )
2065 if ( dialog._.accessKeyMap[key] )
2066 dialog.selectPage( dialog._.accessKeyMap[key] );
2069 var tabAccessKeyDown = function( dialog, key )
2074 var preventKeyBubblingKeys = { 27 :1, 13 :1 };
2075 var preventKeyBubbling = function( e )
2077 if ( e.data.getKeystroke() in preventKeyBubblingKeys )
2078 e.data.stopPropagation();
2083 CKEDITOR.ui.dialog =
2086 * The base class of all dialog UI elements.
2088 * @param {CKEDITOR.dialog} dialog Parent dialog object.
2089 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition Element
2090 * definition. Accepted fields:
2092 * <li><strong>id</strong> (Required) The id of the UI element. See {@link
2093 * CKEDITOR.dialog#getContentElement}</li>
2094 * <li><strong>type</strong> (Required) The type of the UI element. The
2095 * value to this field specifies which UI element class will be used to
2096 * generate the final widget.</li>
2097 * <li><strong>title</strong> (Optional) The popup tooltip for the UI
2099 * <li><strong>hidden</strong> (Optional) A flag that tells if the element
2100 * should be initially visible.</li>
2101 * <li><strong>className</strong> (Optional) Additional CSS class names
2102 * to add to the UI element. Separated by space.</li>
2103 * <li><strong>style</strong> (Optional) Additional CSS inline styles
2104 * to add to the UI element. A semicolon (;) is required after the last
2105 * style declaration.</li>
2106 * <li><strong>accessKey</strong> (Optional) The alphanumeric access key
2107 * for this element. Access keys are automatically prefixed by CTRL.</li>
2108 * <li><strong>on*</strong> (Optional) Any UI element definition field that
2109 * starts with <em>on</em> followed immediately by a capital letter and
2110 * probably more letters is an event handler. Event handlers may be further
2111 * divided into registered event handlers and DOM event handlers. Please
2112 * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and
2113 * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more
2116 * @param {Array} htmlList
2117 * List of HTML code to be added to the dialog's content area.
2118 * @param {Function|String} nodeNameArg
2119 * A function returning a string, or a simple string for the node name for
2120 * the root DOM node. Default is 'div'.
2121 * @param {Function|Object} stylesArg
2122 * A function returning an object, or a simple object for CSS styles applied
2123 * to the DOM node. Default is empty object.
2124 * @param {Function|Object} attributesArg
2125 * A fucntion returning an object, or a simple object for attributes applied
2126 * to the DOM node. Default is empty object.
2127 * @param {Function|String} contentsArg
2128 * A function returning a string, or a simple string for the HTML code inside
2129 * the root DOM node. Default is empty string.
2132 uiElement : function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg )
2134 if ( arguments.length < 4 )
2137 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',
2138 html = [ '<', nodeName, ' ' ],
2139 styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},
2140 attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},
2141 innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',
2142 domId = this.domId = attributes.id || CKEDITOR.tools.getNextId() + '_uiElement',
2143 id = this.id = elementDefinition.id,
2146 // Set the id, a unique id is required for getElement() to work.
2147 attributes.id = domId;
2149 // Set the type and definition CSS class names.
2151 if ( elementDefinition.type )
2152 classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;
2153 if ( elementDefinition.className )
2154 classes[ elementDefinition.className ] = 1;
2155 var attributeClasses = ( attributes['class'] && attributes['class'].split ) ? attributes['class'].split( ' ' ) : [];
2156 for ( i = 0 ; i < attributeClasses.length ; i++ )
2158 if ( attributeClasses[i] )
2159 classes[ attributeClasses[i] ] = 1;
2161 var finalClasses = [];
2162 for ( i in classes )
2163 finalClasses.push( i );
2164 attributes['class'] = finalClasses.join( ' ' );
2166 // Set the popup tooltop.
2167 if ( elementDefinition.title )
2168 attributes.title = elementDefinition.title;
2170 // Write the inline CSS styles.
2171 var styleStr = ( elementDefinition.style || '' ).split( ';' );
2173 styleStr.push( i + ':' + styles[i] );
2174 if ( elementDefinition.hidden )
2175 styleStr.push( 'display:none' );
2176 for ( i = styleStr.length - 1 ; i >= 0 ; i-- )
2178 if ( styleStr[i] === '' )
2179 styleStr.splice( i, 1 );
2181 if ( styleStr.length > 0 )
2182 attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
2184 // Write the attributes.
2185 for ( i in attributes )
2186 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '" ');
2188 // Write the content HTML.
2189 html.push( '>', innerHTML, '</', nodeName, '>' );
2191 // Add contents to the parent HTML array.
2192 htmlList.push( html.join( '' ) );
2194 ( this._ || ( this._ = {} ) ).dialog = dialog;
2196 // Override isChanged if it is defined in element definition.
2197 if ( typeof( elementDefinition.isChanged ) == 'boolean' )
2198 this.isChanged = function(){ return elementDefinition.isChanged; };
2199 if ( typeof( elementDefinition.isChanged ) == 'function' )
2200 this.isChanged = elementDefinition.isChanged;
2203 CKEDITOR.event.implementOn( this );
2205 this.registerEvents( elementDefinition );
2206 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
2207 registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
2210 dialog.on( 'load', function()
2212 if ( me.getInputElement() )
2214 me.getInputElement().on( 'focus', function()
2216 dialog._.tabBarMode = false;
2217 dialog._.hasFocus = true;
2223 // Register the object as a tab focus if it can be included.
2224 if ( this.keyboardFocusable )
2226 this.tabIndex = elementDefinition.tabIndex || 0;
2228 this.focusIndex = dialog._.focusList.push( this ) - 1;
2229 this.on( 'focus', function()
2231 dialog._.currentFocusIndex = me.focusIndex;
2235 // Completes this object with everything we have in the
2237 CKEDITOR.tools.extend( this, elementDefinition );
2241 * Horizontal layout box for dialog UI elements, auto-expends to available width of container.
2243 * @extends CKEDITOR.ui.dialog.uiElement
2244 * @param {CKEDITOR.dialog} dialog
2245 * Parent dialog object.
2246 * @param {Array} childObjList
2247 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
2249 * @param {Array} childHtmlList
2250 * Array of HTML code that correspond to the HTML output of all the
2251 * objects in childObjList.
2252 * @param {Array} htmlList
2253 * Array of HTML code that this element will output to.
2254 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
2255 * The element definition. Accepted fields:
2257 * <li><strong>widths</strong> (Optional) The widths of child cells.</li>
2258 * <li><strong>height</strong> (Optional) The height of the layout.</li>
2259 * <li><strong>padding</strong> (Optional) The padding width inside child
2261 * <li><strong>align</strong> (Optional) The alignment of the whole layout
2266 hbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
2268 if ( arguments.length < 4 )
2271 this._ || ( this._ = {} );
2273 var children = this._.children = childObjList,
2274 widths = elementDefinition && elementDefinition.widths || null,
2275 height = elementDefinition && elementDefinition.height || null,
2279 var innerHTML = function()
2281 var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];
2282 for ( i = 0 ; i < childHtmlList.length ; i++ )
2284 var className = 'cke_dialog_ui_hbox_child',
2287 className = 'cke_dialog_ui_hbox_first';
2288 if ( i == childHtmlList.length - 1 )
2289 className = 'cke_dialog_ui_hbox_last';
2290 html.push( '<td class="', className, '" role="presentation" ' );
2294 styles.push( 'width:' + cssLength( widths[i] ) );
2297 styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
2299 styles.push( 'height:' + cssLength( height ) );
2300 if ( elementDefinition && elementDefinition.padding != undefined )
2301 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
2302 if ( styles.length > 0 )
2303 html.push( 'style="' + styles.join('; ') + '" ' );
2304 html.push( '>', childHtmlList[i], '</td>' );
2306 html.push( '</tr></tbody>' );
2307 return html.join( '' );
2310 var attribs = { role : 'presentation' };
2311 elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );
2313 CKEDITOR.ui.dialog.uiElement.call(
2316 elementDefinition || { type : 'hbox' },
2325 * Vertical layout box for dialog UI elements.
2327 * @extends CKEDITOR.ui.dialog.hbox
2328 * @param {CKEDITOR.dialog} dialog
2329 * Parent dialog object.
2330 * @param {Array} childObjList
2331 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
2333 * @param {Array} childHtmlList
2334 * Array of HTML code that correspond to the HTML output of all the
2335 * objects in childObjList.
2336 * @param {Array} htmlList
2337 * Array of HTML code that this element will output to.
2338 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
2339 * The element definition. Accepted fields:
2341 * <li><strong>width</strong> (Optional) The width of the layout.</li>
2342 * <li><strong>heights</strong> (Optional) The heights of individual cells.
2344 * <li><strong>align</strong> (Optional) The alignment of the layout.</li>
2345 * <li><strong>padding</strong> (Optional) The padding width inside child
2347 * <li><strong>expand</strong> (Optional) Whether the layout should expand
2348 * vertically to fill its container.</li>
2352 vbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
2354 if ( arguments.length < 3 )
2357 this._ || ( this._ = {} );
2359 var children = this._.children = childObjList,
2360 width = elementDefinition && elementDefinition.width || null,
2361 heights = elementDefinition && elementDefinition.heights || null;
2363 var innerHTML = function()
2365 var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];
2366 html.push( 'style="' );
2367 if ( elementDefinition && elementDefinition.expand )
2368 html.push( 'height:100%;' );
2369 html.push( 'width:' + cssLength( width || '100%' ), ';' );
2371 html.push( 'align="', CKEDITOR.tools.htmlEncode(
2372 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
2374 html.push( '><tbody>' );
2375 for ( var i = 0 ; i < childHtmlList.length ; i++ )
2378 html.push( '<tr><td role="presentation" ' );
2380 styles.push( 'width:' + cssLength( width || '100%' ) );
2382 styles.push( 'height:' + cssLength( heights[i] ) );
2383 else if ( elementDefinition && elementDefinition.expand )
2384 styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
2385 if ( elementDefinition && elementDefinition.padding != undefined )
2386 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
2387 if ( styles.length > 0 )
2388 html.push( 'style="', styles.join( '; ' ), '" ' );
2389 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[i], '</td></tr>' );
2391 html.push( '</tbody></table>' );
2392 return html.join( '' );
2394 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type : 'vbox' }, htmlList, 'div', null, { role : 'presentation' }, innerHTML );
2399 CKEDITOR.ui.dialog.uiElement.prototype =
2402 * Gets the root DOM element of this dialog UI object.
2403 * @returns {CKEDITOR.dom.element} Root DOM element of UI object.
2405 * uiElement.getElement().hide();
2407 getElement : function()
2409 return CKEDITOR.document.getById( this.domId );
2413 * Gets the DOM element that the user inputs values.
2414 * This function is used by setValue(), getValue() and focus(). It should
2415 * be overrided in child classes where the input element isn't the root
2417 * @returns {CKEDITOR.dom.element} The element where the user input values.
2419 * var rawValue = textInput.getInputElement().$.value;
2421 getInputElement : function()
2423 return this.getElement();
2427 * Gets the parent dialog object containing this UI element.
2428 * @returns {CKEDITOR.dialog} Parent dialog object.
2430 * var dialog = uiElement.getDialog();
2432 getDialog : function()
2434 return this._.dialog;
2438 * Sets the value of this dialog UI object.
2439 * @param {Object} value The new value.
2440 * @param {Boolean} noChangeEvent Internal commit, to supress 'change' event on this element.
2441 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
2443 * uiElement.setValue( 'Dingo' );
2445 setValue : function( value, noChangeEvent )
2447 this.getInputElement().setValue( value );
2448 !noChangeEvent && this.fire( 'change', { value : value } );
2453 * Gets the current value of this dialog UI object.
2454 * @returns {Object} The current value.
2456 * var myValue = uiElement.getValue();
2458 getValue : function()
2460 return this.getInputElement().getValue();
2464 * Tells whether the UI object's value has changed.
2465 * @returns {Boolean} true if changed, false if not changed.
2467 * if ( uiElement.isChanged() )
2468 * confirm( 'Value changed! Continue?' );
2470 isChanged : function()
2472 // Override in input classes.
2477 * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
2478 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
2480 * focus : function()
2482 * this.selectParentTab();
2483 * // do something else.
2486 selectParentTab : function()
2488 var element = this.getInputElement(),
2491 while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 )
2494 // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
2498 tabId = cursor.getAttribute( 'name' );
2499 // Avoid duplicate select.
2500 if ( this._.dialog._.currentTabId != tabId )
2501 this._.dialog.selectPage( tabId );
2506 * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
2507 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
2509 * uiElement.focus();
2513 this.selectParentTab().getInputElement().focus();
2518 * Registers the on* event handlers defined in the element definition.
2519 * The default behavior of this function is:
2522 * If the on* event is defined in the class's eventProcesors list,
2523 * then the registration is delegated to the corresponding function
2524 * in the eventProcessors list.
2527 * If the on* event is not defined in the eventProcessors list, then
2528 * register the event handler under the corresponding DOM event of
2529 * the UI element's input DOM element (as defined by the return value
2530 * of {@link CKEDITOR.ui.dialog.uiElement#getInputElement}).
2533 * This function is only called at UI element instantiation, but can
2534 * be overridded in child classes if they require more flexibility.
2535 * @param {CKEDITOR.dialog.uiElementDefinition} definition The UI element
2537 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
2540 registerEvents : function( definition )
2542 var regex = /^on([A-Z]\w+)/,
2545 var registerDomEvent = function( uiElement, dialog, eventName, func )
2547 dialog.on( 'load', function()
2549 uiElement.getInputElement().on( eventName, func, uiElement );
2553 for ( var i in definition )
2555 if ( !( match = i.match( regex ) ) )
2557 if ( this.eventProcessors[i] )
2558 this.eventProcessors[i].call( this, this._.dialog, definition[i] );
2560 registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
2567 * The event processor list used by
2568 * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element
2569 * instantiation. The default list defines three on* events:
2571 * <li>onLoad - Called when the element's parent dialog opens for the
2573 * <li>onShow - Called whenever the element's parent dialog opens.</li>
2574 * <li>onHide - Called whenever the element's parent dialog closes.</li>
2579 * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick
2580 * // handlers in the UI element's definitions.
2581 * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},
2582 * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
2583 * { onClick : function( dialog, func ) { this.on( 'click', func ); } },
2584 * true );
2588 onLoad : function( dialog, func )
2590 dialog.on( 'load', func, this );
2593 onShow : function( dialog, func )
2595 dialog.on( 'show', func, this );
2598 onHide : function( dialog, func )
2600 dialog.on( 'hide', func, this );
2605 * The default handler for a UI element's access key down event, which
2606 * tries to put focus to the UI element.<br />
2607 * Can be overridded in child classes for more sophisticaed behavior.
2608 * @param {CKEDITOR.dialog} dialog The parent dialog object.
2609 * @param {String} key The key combination pressed. Since access keys
2610 * are defined to always include the CTRL key, its value should always
2611 * include a 'CTRL+' prefix.
2614 accessKeyDown : function( dialog, key )
2620 * The default handler for a UI element's access key up event, which
2621 * does nothing.<br />
2622 * Can be overridded in child classes for more sophisticated behavior.
2623 * @param {CKEDITOR.dialog} dialog The parent dialog object.
2624 * @param {String} key The key combination pressed. Since access keys
2625 * are defined to always include the CTRL key, its value should always
2626 * include a 'CTRL+' prefix.
2629 accessKeyUp : function( dialog, key )
2634 * Disables a UI element.
2637 disable : function()
2639 var element = this.getInputElement();
2640 element.setAttribute( 'disabled', 'true' );
2641 element.addClass( 'cke_disabled' );
2645 * Enables a UI element.
2650 var element = this.getInputElement();
2651 element.removeAttribute( 'disabled' );
2652 element.removeClass( 'cke_disabled' );
2656 * Determines whether an UI element is enabled or not.
2657 * @returns {Boolean} Whether the UI element is enabled.
2660 isEnabled : function()
2662 return !this.getInputElement().getAttribute( 'disabled' );
2666 * Determines whether an UI element is visible or not.
2667 * @returns {Boolean} Whether the UI element is visible.
2670 isVisible : function()
2672 return this.getInputElement().isVisible();
2676 * Determines whether an UI element is focus-able or not.
2677 * Focus-able is defined as being both visible and enabled.
2678 * @returns {Boolean} Whether the UI element can be focused.
2681 isFocusable : function()
2683 if ( !this.isEnabled() || !this.isVisible() )
2689 CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
2691 * @lends CKEDITOR.ui.dialog.hbox.prototype
2695 * Gets a child UI element inside this container.
2696 * @param {Array|Number} indices An array or a single number to indicate the child's
2697 * position in the container's descendant tree. Omit to get all the children in an array.
2698 * @returns {Array|CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container
2699 * if no argument given, or the specified UI element if indices is given.
2701 * var checkbox = hbox.getChild( [0,1] );
2702 * checkbox.setValue( true );
2704 getChild : function( indices )
2706 // If no arguments, return a clone of the children array.
2707 if ( arguments.length < 1 )
2708 return this._.children.concat();
2710 // If indices isn't array, make it one.
2711 if ( !indices.splice )
2712 indices = [ indices ];
2714 // Retrieve the child element according to tree position.
2715 if ( indices.length < 2 )
2716 return this._.children[ indices[0] ];
2718 return ( this._.children[ indices[0] ] && this._.children[ indices[0] ].getChild ) ?
2719 this._.children[ indices[0] ].getChild( indices.slice( 1, indices.length ) ) :
2724 CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
2730 var commonBuilder = {
2731 build : function( dialog, elementDefinition, output )
2733 var children = elementDefinition.children,
2737 for ( var i = 0 ; ( i < children.length && ( child = children[i] ) ) ; i++ )
2740 childHtmlList.push( childHtml );
2741 childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
2743 return new CKEDITOR.ui.dialog[elementDefinition.type]( dialog, childObjList, childHtmlList, output, elementDefinition );
2747 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
2748 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
2752 * Generic dialog command. It opens a specific dialog when executed.
2754 * @augments CKEDITOR.commandDefinition
2755 * @param {string} dialogName The name of the dialog to open when executing
2758 * // Register the "link" command, which opens the "link" dialog.
2759 * editor.addCommand( 'link', <b>new CKEDITOR.dialogCommand( 'link' )</b> );
2761 CKEDITOR.dialogCommand = function( dialogName )
2763 this.dialogName = dialogName;
2766 CKEDITOR.dialogCommand.prototype =
2769 exec : function( editor )
2771 editor.openDialog( this.dialogName );
2774 // Dialog commands just open a dialog ui, thus require no undo logic,
2775 // undo support should dedicate to specific dialog implementation.
2778 editorFocus : CKEDITOR.env.ie || CKEDITOR.env.webkit
2783 var notEmptyRegex = /^([a]|[^a])+$/,
2784 integerRegex = /^\d*$/,
2785 numberRegex = /^\d*(?:\.\d+)?$/;
2787 CKEDITOR.VALIDATE_OR = 1;
2788 CKEDITOR.VALIDATE_AND = 2;
2790 CKEDITOR.dialog.validate =
2792 functions : function()
2797 * It's important for validate functions to be able to accept the value
2798 * as argument in addition to this.getValue(), so that it is possible to
2799 * combine validate functions together to make more sophisticated
2802 var value = this && this.getValue ? this.getValue() : arguments[0];
2804 var msg = undefined,
2805 relation = CKEDITOR.VALIDATE_AND,
2808 for ( i = 0 ; i < arguments.length ; i++ )
2810 if ( typeof( arguments[i] ) == 'function' )
2811 functions.push( arguments[i] );
2816 if ( i < arguments.length && typeof( arguments[i] ) == 'string' )
2822 if ( i < arguments.length && typeof( arguments[i]) == 'number' )
2823 relation = arguments[i];
2825 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );
2826 for ( i = 0 ; i < functions.length ; i++ )
2828 if ( relation == CKEDITOR.VALIDATE_AND )
2829 passed = passed && functions[i]( value );
2831 passed = passed || functions[i]( value );
2836 if ( msg !== undefined )
2838 if ( this && ( this.select || this.focus ) )
2839 ( this.select || this.focus )();
2847 regex : function( regex, msg )
2850 * Can be greatly shortened by deriving from functions validator if code size
2851 * turns out to be more important than performance.
2855 var value = this && this.getValue ? this.getValue() : arguments[0];
2856 if ( !regex.test( value ) )
2858 if ( msg !== undefined )
2860 if ( this && ( this.select || this.focus ) )
2873 notEmpty : function( msg )
2875 return this.regex( notEmptyRegex, msg );
2878 integer : function( msg )
2880 return this.regex( integerRegex, msg );
2883 'number' : function( msg )
2885 return this.regex( numberRegex, msg );
2888 equals : function( value, msg )
2890 return this.functions( function( val ){ return val == value; }, msg );
2893 notEqual : function( value, msg )
2895 return this.functions( function( val ){ return val != value; }, msg );
2899 CKEDITOR.on( 'instanceDestroyed', function( evt )
2901 // Remove dialog cover on last instance destroy.
2902 if ( CKEDITOR.tools.isEmpty( CKEDITOR.instances ) )
2904 var currentTopDialog;
2905 while ( ( currentTopDialog = CKEDITOR.dialog._.currentTop ) )
2906 currentTopDialog.hide();
2910 var dialogs = evt.editor._.storedDialogs;
2911 for ( var name in dialogs )
2912 dialogs[ name ].destroy();
2918 // Extend the CKEDITOR.editor class with dialog specific functions.
2919 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
2920 /** @lends CKEDITOR.editor.prototype */
2923 * Loads and opens a registered dialog.
2924 * @param {String} dialogName The registered name of the dialog.
2925 * @param {Function} callback The function to be invoked after dialog instance created.
2926 * @see CKEDITOR.dialog.add
2928 * CKEDITOR.instances.editor1.openDialog( 'smiley' );
2929 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed. null if the dialog name is not registered.
2931 openDialog : function( dialogName, callback )
2933 if ( this.mode == 'wysiwyg' && CKEDITOR.env.ie )
2935 var selection = this.getSelection();
2936 selection && selection.lock();
2939 var dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
2940 dialogSkin = this.skin.dialog;
2942 if ( CKEDITOR.dialog._.currentTop === null )
2945 // If the dialogDefinition is already loaded, open it immediately.
2946 if ( typeof dialogDefinitions == 'function' && dialogSkin._isLoaded )
2948 var storedDialogs = this._.storedDialogs ||
2949 ( this._.storedDialogs = {} );
2951 var dialog = storedDialogs[ dialogName ] ||
2952 ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
2954 callback && callback.call( dialog, dialog );
2959 else if ( dialogDefinitions == 'failed' )
2960 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
2964 function onDialogFileLoaded( success )
2966 var dialogDefinition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
2967 skin = me.skin.dialog;
2969 // Check if both skin part and definition is loaded.
2970 if ( !skin._isLoaded || loadDefinition && typeof success == 'undefined' )
2973 // In case of plugin error, mark it as loading failed.
2974 if ( typeof dialogDefinition != 'function' )
2975 CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';
2977 me.openDialog( dialogName, callback );
2980 if ( typeof dialogDefinitions == 'string' )
2982 var loadDefinition = 1;
2983 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ), onDialogFileLoaded, null, 0, 1 );
2986 CKEDITOR.skins.load( this, 'dialog', onDialogFileLoaded );
2993 CKEDITOR.plugins.add( 'dialog',
2995 requires : [ 'dialogui' ]
2998 // Dialog related configurations.
3001 * The color of the dialog background cover. It should be a valid CSS color
3003 * @name CKEDITOR.config.dialog_backgroundCoverColor
3007 * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
3011 * The opacity of the dialog background cover. It should be a number within the
3013 * @name CKEDITOR.config.dialog_backgroundCoverOpacity
3017 * config.dialog_backgroundCoverOpacity = 0.7;
3021 * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.
3022 * @name CKEDITOR.config.dialog_startupFocusTab
3026 * config.dialog_startupFocusTab = true;
3030 * The distance of magnetic borders used in moving and resizing dialogs,
3031 * measured in pixels.
3032 * @name CKEDITOR.config.dialog_magnetDistance
3036 * config.dialog_magnetDistance = 30;
3040 * The guideline to follow when generating the dialog buttons. There are 3 possible options:
3042 * <li>'OS' - the buttons will be displayed in the default order of the user's OS;</li>
3043 * <li>'ltr' - for Left-To-Right order;</li>
3044 * <li>'rtl' - for Right-To-Left order.</li>
3046 * @name CKEDITOR.config.dialog_buttonsOrder
3051 * config.dialog_buttonsOrder = 'rtl';
3055 * The dialog contents to removed. It's a string composed by dialog name and tab name with a colon between them.
3056 * Separate each pair with semicolon (see example).
3057 * <b>Note: All names are case-sensitive.</b>
3058 * <b>Note: Be cautious when specifying dialog tabs that are mandatory, like "info", dialog functionality might be broken because of this!</b>
3059 * @name CKEDITOR.config.removeDialogTabs
3064 * config.removeDialogTabs = 'flash:advanced;image:Link';
3068 * Fired when a dialog definition is about to be used to create a dialog into
3069 * an editor instance. This event makes it possible to customize the definition
3070 * before creating it.
3071 * <p>Note that this event is called only the first time a specific dialog is
3072 * opened. Successive openings will use the cached dialog, and this event will
3073 * not get fired.</p>
3074 * @name CKEDITOR#dialogDefinition
3076 * @param {CKEDITOR.dialog.dialogDefinition} data The dialog defination that
3078 * @param {CKEDITOR.editor} editor The editor instance that will use the
3083 * Fired when a tab is going to be selected in a dialog
3084 * @name CKEDITOR.dialog#selectPage
3086 * @param {String} page The id of the page that it's gonna be selected.
3087 * @param {String} currentPage The id of the current page.
3091 * Fired when the user tries to dismiss a dialog
3092 * @name CKEDITOR.dialog#cancel
3094 * @param {Boolean} hide Whether the event should proceed or not.
3098 * Fired when the user tries to confirm a dialog
3099 * @name CKEDITOR.dialog#ok
3101 * @param {Boolean} hide Whether the event should proceed or not.
3105 * Fired when a dialog is shown
3106 * @name CKEDITOR.dialog#show
3111 * Fired when a dialog is shown
3112 * @name CKEDITOR.editor#dialogShow
3117 * Fired when a dialog is hidden
3118 * @name CKEDITOR.dialog#hide
3123 * Fired when a dialog is hidden
3124 * @name CKEDITOR.editor#dialogHide
3129 * Fired when a dialog is being resized. The event is fired on
3130 * the 'CKEDITOR.dialog' object, not a dialog instance.
3131 * @name CKEDITOR.dialog#resize
3134 * @param {CKEDITOR.dialog} dialog The dialog being resized.
3135 * @param {String} skin The skin name.
3136 * @param {Number} width The new width.
3137 * @param {Number} height The new height.