2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview The floating dialog plugin.
\r
11 * No resize for this dialog.
\r
14 CKEDITOR.DIALOG_RESIZE_NONE = 0;
\r
17 * Only allow horizontal resizing for this dialog, disable vertical resizing.
\r
20 CKEDITOR.DIALOG_RESIZE_WIDTH = 1;
\r
23 * Only allow vertical resizing for this dialog, disable horizontal resizing.
\r
26 CKEDITOR.DIALOG_RESIZE_HEIGHT = 2;
\r
29 * Allow the dialog to be resized in both directions.
\r
32 CKEDITOR.DIALOG_RESIZE_BOTH = 3;
\r
36 var cssLength = CKEDITOR.tools.cssLength;
\r
37 function isTabVisible( tabId )
\r
39 return !!this._.tabs[ tabId ][ 0 ].$.offsetHeight;
\r
42 function getPreviousVisibleTab()
\r
44 var tabId = this._.currentTabId,
\r
45 length = this._.tabIdList.length,
\r
46 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId ) + length;
\r
48 for ( var i = tabIndex - 1 ; i > tabIndex - length ; i-- )
\r
50 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
\r
51 return this._.tabIdList[ i % length ];
\r
57 function getNextVisibleTab()
\r
59 var tabId = this._.currentTabId,
\r
60 length = this._.tabIdList.length,
\r
61 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId );
\r
63 for ( var i = tabIndex + 1 ; i < tabIndex + length ; i++ )
\r
65 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
\r
66 return this._.tabIdList[ i % length ];
\r
73 function clearOrRecoverTextInputValue( container, isRecover )
\r
75 var inputs = container.$.getElementsByTagName( 'input' );
\r
76 for ( var i = 0, length = inputs.length; i < length ; i++ )
\r
78 var item = new CKEDITOR.dom.element( inputs[ i ] );
\r
80 if ( item.getAttribute( 'type' ).toLowerCase() == 'text' )
\r
84 item.setAttribute( 'value', item.getCustomData( 'fake_value' ) || '' );
\r
85 item.removeCustomData( 'fake_value' );
\r
89 item.setCustomData( 'fake_value', item.getAttribute( 'value' ) );
\r
90 item.setAttribute( 'value', '' );
\r
97 * This is the base class for runtime dialog objects. An instance of this
\r
98 * class represents a single named dialog for a single editor instance.
\r
99 * @param {Object} editor The editor which created the dialog.
\r
100 * @param {String} dialogName The dialog's registered name.
\r
103 * var dialogObj = new CKEDITOR.dialog( editor, 'smiley' );
\r
105 CKEDITOR.dialog = function( editor, dialogName )
\r
107 // Load the dialog definition.
\r
108 var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
109 defaultDefinition = CKEDITOR.tools.clone( defaultDialogDefinition ),
\r
110 buttonsOrder = editor.config.dialog_buttonsOrder || 'OS',
\r
111 dir = editor.lang.dir;
\r
113 if ( ( buttonsOrder == 'OS' && CKEDITOR.env.mac ) || // The buttons in MacOS Apps are in reverse order (#4750)
\r
114 ( buttonsOrder == 'rtl' && dir == 'ltr' ) ||
\r
115 ( buttonsOrder == 'ltr' && dir == 'rtl' ) )
\r
116 defaultDefinition.buttons.reverse();
\r
119 // Completes the definition with the default values.
\r
120 definition = CKEDITOR.tools.extend( definition( editor ), defaultDefinition );
\r
122 // Clone a functionally independent copy for this dialog.
\r
123 definition = CKEDITOR.tools.clone( definition );
\r
125 // Create a complex definition object, extending it with the API
\r
127 definition = new definitionObject( this, definition );
\r
129 var doc = CKEDITOR.document;
\r
131 var themeBuilt = editor.theme.buildDialog( editor );
\r
133 // Initialize some basic parameters.
\r
137 element : themeBuilt.element,
\r
139 contentSize : { width : 0, height : 0 },
\r
140 size : { width : 0, height : 0 },
\r
145 // Initialize the tab and page map.
\r
148 currentTabId : null,
\r
149 currentTabIndex : null,
\r
152 tabBarMode : false,
\r
154 // Initialize the tab order array for input widgets.
\r
156 currentFocusIndex : 0,
\r
160 this.parts = themeBuilt.parts;
\r
162 CKEDITOR.tools.setTimeout( function()
\r
164 editor.fire( 'ariaWidget', this.parts.contents );
\r
168 // Set the startup styles for the dialog, avoiding it enlarging the
\r
169 // page size on the dialog creation.
\r
170 var startStyles = {
\r
171 position : CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed',
\r
173 visibility : 'hidden'
\r
176 startStyles[ dir == 'rtl' ? 'right' : 'left' ] = 0;
\r
177 this.parts.dialog.setStyles( startStyles );
\r
180 // Call the CKEDITOR.event constructor to initialize this instance.
\r
181 CKEDITOR.event.call( this );
\r
183 // Fire the "dialogDefinition" event, making it possible to customize
\r
184 // the dialog definition.
\r
185 this.definition = definition = CKEDITOR.fire( 'dialogDefinition',
\r
188 definition : definition
\r
190 , editor ).definition;
\r
192 var tabsToRemove = {};
\r
193 // Cache tabs that should be removed.
\r
194 if ( !( 'removeDialogTabs' in editor._ ) && editor.config.removeDialogTabs )
\r
196 var removeContents = editor.config.removeDialogTabs.split( ';' );
\r
198 for ( i = 0; i < removeContents.length; i++ )
\r
200 var parts = removeContents[ i ].split( ':' );
\r
201 if ( parts.length == 2 )
\r
203 var removeDialogName = parts[ 0 ];
\r
204 if ( !tabsToRemove[ removeDialogName ] )
\r
205 tabsToRemove[ removeDialogName ] = [];
\r
206 tabsToRemove[ removeDialogName ].push( parts[ 1 ] );
\r
209 editor._.removeDialogTabs = tabsToRemove;
\r
212 // Remove tabs of this dialog.
\r
213 if ( editor._.removeDialogTabs && ( tabsToRemove = editor._.removeDialogTabs[ dialogName ] ) )
\r
215 for ( i = 0; i < tabsToRemove.length; i++ )
\r
216 definition.removeContents( tabsToRemove[ i ] );
\r
219 // Initialize load, show, hide, ok and cancel events.
\r
220 if ( definition.onLoad )
\r
221 this.on( 'load', definition.onLoad );
\r
223 if ( definition.onShow )
\r
224 this.on( 'show', definition.onShow );
\r
226 if ( definition.onHide )
\r
227 this.on( 'hide', definition.onHide );
\r
229 if ( definition.onOk )
\r
231 this.on( 'ok', function( evt )
\r
233 // Dialog confirm might probably introduce content changes (#5415).
\r
234 editor.fire( 'saveSnapshot' );
\r
235 setTimeout( function () { editor.fire( 'saveSnapshot' ); }, 0 );
\r
236 if ( definition.onOk.call( this, evt ) === false )
\r
237 evt.data.hide = false;
\r
241 if ( definition.onCancel )
\r
243 this.on( 'cancel', function( evt )
\r
245 if ( definition.onCancel.call( this, evt ) === false )
\r
246 evt.data.hide = false;
\r
252 // Iterates over all items inside all content in the dialog, calling a
\r
253 // function for each of them.
\r
254 var iterContents = function( func )
\r
256 var contents = me._.contents,
\r
259 for ( var i in contents )
\r
261 for ( var j in contents[i] )
\r
263 stop = func.call( this, contents[i][j] );
\r
270 this.on( 'ok', function( evt )
\r
272 iterContents( function( item )
\r
274 if ( item.validate )
\r
276 var isValid = item.validate( this );
\r
278 if ( typeof isValid == 'string' )
\r
284 if ( isValid === false )
\r
291 evt.data.hide = false;
\r
297 }, this, null, 0 );
\r
299 this.on( 'cancel', function( evt )
\r
301 iterContents( function( item )
\r
303 if ( item.isChanged() )
\r
305 if ( !confirm( editor.lang.common.confirmCancel ) )
\r
306 evt.data.hide = false;
\r
310 }, this, null, 0 );
\r
312 this.parts.close.on( 'click', function( evt )
\r
314 if ( this.fire( 'cancel', { hide : true } ).hide !== false )
\r
316 evt.data.preventDefault();
\r
319 // Sort focus list according to tab order definitions.
\r
320 function setupFocus()
\r
322 var focusList = me._.focusList;
\r
323 focusList.sort( function( a, b )
\r
325 // Mimics browser tab order logics;
\r
326 if ( a.tabIndex != b.tabIndex )
\r
327 return b.tabIndex - a.tabIndex;
\r
328 // Sort is not stable in some browsers,
\r
329 // fall-back the comparator to 'focusIndex';
\r
331 return a.focusIndex - b.focusIndex;
\r
334 var size = focusList.length;
\r
335 for ( var i = 0; i < size; i++ )
\r
336 focusList[ i ].focusIndex = i;
\r
339 function changeFocus( forward )
\r
341 var focusList = me._.focusList,
\r
342 offset = forward ? 1 : -1;
\r
343 if ( focusList.length < 1 )
\r
346 var current = me._.currentFocusIndex;
\r
348 // Trigger the 'blur' event of any input element before anything,
\r
349 // since certain UI updates may depend on it.
\r
352 focusList[ current ].getInputElement().$.blur();
\r
356 var startIndex = ( current + offset + focusList.length ) % focusList.length,
\r
357 currentIndex = startIndex;
\r
358 while ( !focusList[ currentIndex ].isFocusable() )
\r
360 currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length;
\r
361 if ( currentIndex == startIndex )
\r
364 focusList[ currentIndex ].focus();
\r
366 // Select whole field content.
\r
367 if ( focusList[ currentIndex ].type == 'text' )
\r
368 focusList[ currentIndex ].select();
\r
371 this.changeFocus = changeFocus;
\r
375 function focusKeydownHandler( evt )
\r
377 // If I'm not the top dialog, ignore.
\r
378 if ( me != CKEDITOR.dialog._.currentTop )
\r
381 var keystroke = evt.data.getKeystroke(),
\r
382 rtl = editor.lang.dir == 'rtl';
\r
385 if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )
\r
387 var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
\r
389 // Handling Tab and Shift-Tab.
\r
390 if ( me._.tabBarMode )
\r
393 var nextId = shiftPressed ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );
\r
394 me.selectPage( nextId );
\r
395 me._.tabs[ nextId ][ 0 ].focus();
\r
399 // Change the focus of inputs.
\r
400 changeFocus( !shiftPressed );
\r
405 else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode && me.getPageCount() > 1 )
\r
407 // Alt-F10 puts focus into the current tab item in the tab bar.
\r
408 me._.tabBarMode = true;
\r
409 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
412 else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode )
\r
414 // Arrow keys - used for changing tabs.
\r
415 nextId = ( keystroke == ( rtl ? 39 : 37 ) ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) );
\r
416 me.selectPage( nextId );
\r
417 me._.tabs[ nextId ][ 0 ].focus();
\r
420 else if ( ( keystroke == 13 || keystroke == 32 ) && me._.tabBarMode )
\r
422 this.selectPage( this._.currentTabId );
\r
423 this._.tabBarMode = false;
\r
424 this._.currentFocusIndex = -1;
\r
425 changeFocus( true );
\r
432 evt.data.preventDefault();
\r
436 function focusKeyPressHandler( evt )
\r
438 processed && evt.data.preventDefault();
\r
441 var dialogElement = this._.element;
\r
442 // Add the dialog keyboard handlers.
\r
443 this.on( 'show', function()
\r
445 dialogElement.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
446 // Some browsers instead, don't cancel key events in the keydown, but in the
\r
447 // keypress. So we must do a longer trip in those cases. (#4531)
\r
448 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
449 dialogElement.on( 'keypress', focusKeyPressHandler, this );
\r
452 this.on( 'hide', function()
\r
454 dialogElement.removeListener( 'keydown', focusKeydownHandler );
\r
455 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
456 dialogElement.removeListener( 'keypress', focusKeyPressHandler );
\r
458 this.on( 'iframeAdded', function( evt )
\r
460 var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );
\r
461 doc.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
464 // Auto-focus logic in dialog.
\r
465 this.on( 'show', function()
\r
467 // Setup tabIndex on showing the dialog instead of on loading
\r
468 // to allow dynamic tab order happen in dialog definition.
\r
471 if ( editor.config.dialog_startupFocusTab
\r
472 && me._.pageCount > 1 )
\r
474 me._.tabBarMode = true;
\r
475 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
477 else if ( !this._.hasFocus )
\r
479 this._.currentFocusIndex = -1;
\r
481 // Decide where to put the initial focus.
\r
482 if ( definition.onFocus )
\r
484 var initialFocus = definition.onFocus.call( this );
\r
485 // Focus the field that the user specified.
\r
486 initialFocus && initialFocus.focus();
\r
488 // Focus the first field in layout order.
\r
490 changeFocus( true );
\r
493 * IE BUG: If the initial focus went into a non-text element (e.g. button),
\r
494 * then IE would still leave the caret inside the editing area.
\r
496 if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
498 var $selection = editor.document.$.selection,
\r
499 $range = $selection.createRange();
\r
503 if ( $range.parentElement && $range.parentElement().ownerDocument == editor.document.$
\r
504 || $range.item && $range.item( 0 ).ownerDocument == editor.document.$ )
\r
506 var $myRange = document.body.createTextRange();
\r
507 $myRange.moveToElementText( this.getElement().getFirst().$ );
\r
508 $myRange.collapse( true );
\r
514 }, this, null, 0xffffffff );
\r
516 // IE6 BUG: Text fields and text areas are only half-rendered the first time the dialog appears in IE6 (#2661).
\r
517 // This is still needed after [2708] and [2709] because text fields in hidden TR tags are still broken.
\r
518 if ( CKEDITOR.env.ie6Compat )
\r
520 this.on( 'load', function( evt )
\r
522 var outer = this.getElement(),
\r
523 inner = outer.getFirst();
\r
525 inner.appendTo( outer );
\r
529 initDragAndDrop( this );
\r
530 initResizeHandles( this );
\r
532 // Insert the title.
\r
533 ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );
\r
535 // Insert the tabs and contents.
\r
536 for ( var i = 0 ; i < definition.contents.length ; i++ )
\r
538 var page = definition.contents[i];
\r
539 page && this.addPage( page );
\r
542 this.parts[ 'tabs' ].on( 'click', function( evt )
\r
544 var target = evt.data.getTarget();
\r
545 // If we aren't inside a tab, bail out.
\r
546 if ( target.hasClass( 'cke_dialog_tab' ) )
\r
548 // Get the ID of the tab, without the 'cke_' prefix and the unique number suffix.
\r
549 var id = target.$.id;
\r
550 this.selectPage( id.substring( 4, id.lastIndexOf( '_' ) ) );
\r
552 if ( this._.tabBarMode )
\r
554 this._.tabBarMode = false;
\r
555 this._.currentFocusIndex = -1;
\r
556 changeFocus( true );
\r
558 evt.data.preventDefault();
\r
563 var buttonsHtml = [],
\r
564 buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this,
\r
567 className : 'cke_dialog_footer_buttons',
\r
569 children : definition.buttons
\r
570 }, buttonsHtml ).getChild();
\r
571 this.parts.footer.setHtml( buttonsHtml.join( '' ) );
\r
573 for ( i = 0 ; i < buttons.length ; i++ )
\r
574 this._.buttons[ buttons[i].id ] = buttons[i];
\r
577 // Focusable interface. Use it via dialog.addFocusable.
\r
578 function Focusable( dialog, element, index )
\r
580 this.element = element;
\r
581 this.focusIndex = index;
\r
582 // TODO: support tabIndex for focusables.
\r
584 this.isFocusable = function()
\r
586 return !element.getAttribute( 'disabled' ) && element.isVisible();
\r
588 this.focus = function()
\r
590 dialog._.currentFocusIndex = this.focusIndex;
\r
591 this.element.focus();
\r
594 element.on( 'keydown', function( e )
\r
596 if ( e.data.getKeystroke() in { 32:1, 13:1 } )
\r
597 this.fire( 'click' );
\r
599 element.on( 'focus', function()
\r
601 this.fire( 'mouseover' );
\r
603 element.on( 'blur', function()
\r
605 this.fire( 'mouseout' );
\r
609 CKEDITOR.dialog.prototype =
\r
611 destroy : function()
\r
614 this._.element.remove();
\r
618 * Resizes the dialog.
\r
619 * @param {Number} width The width of the dialog in pixels.
\r
620 * @param {Number} height The height of the dialog in pixels.
\r
623 * dialogObj.resize( 800, 640 );
\r
625 resize : (function()
\r
627 return function( width, height )
\r
629 if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )
\r
632 CKEDITOR.dialog.fire( 'resize',
\r
635 skin : this._.editor.skinName,
\r
638 }, this._.editor );
\r
640 this.fire( 'resize',
\r
642 skin : this._.editor.skinName,
\r
645 }, this._.editor );
\r
647 // Update dialog position when dimension get changed in RTL.
\r
648 if ( this._.editor.lang.dir == 'rtl' && this._.position )
\r
649 this._.position.x = CKEDITOR.document.getWindow().getViewPaneSize().width -
\r
650 this._.contentSize.width - parseInt( this._.element.getFirst().getStyle( 'right' ), 10 );
\r
652 this._.contentSize = { width : width, height : height };
\r
657 * Gets the current size of the dialog in pixels.
\r
658 * @returns {Object} An object with "width" and "height" properties.
\r
660 * var width = dialogObj.getSize().width;
\r
662 getSize : function()
\r
664 var element = this._.element.getFirst();
\r
665 return { width : element.$.offsetWidth || 0, height : element.$.offsetHeight || 0};
\r
669 * Moves the dialog to an (x, y) coordinate relative to the window.
\r
671 * @param {Number} x The target x-coordinate.
\r
672 * @param {Number} y The target y-coordinate.
\r
673 * @param {Boolean} save Flag indicate whether the dialog position should be remembered on next open up.
\r
675 * dialogObj.move( 10, 40 );
\r
680 return function( x, y, save )
\r
682 // The dialog may be fixed positioned or absolute positioned. Ask the
\r
683 // browser what is the current situation first.
\r
684 var element = this._.element.getFirst(),
\r
685 rtl = this._.editor.lang.dir == 'rtl';
\r
687 if ( isFixed === undefined )
\r
688 isFixed = element.getComputedStyle( 'position' ) == 'fixed';
\r
690 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
\r
693 // Save the current position.
\r
694 this._.position = { x : x, y : y };
\r
696 // If not fixed positioned, add scroll position to the coordinates.
\r
699 var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
\r
700 x += scrollPosition.x;
\r
701 y += scrollPosition.y;
\r
704 // Translate coordinate for RTL.
\r
707 var dialogSize = this.getSize(),
\r
708 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize();
\r
709 x = viewPaneSize.width - dialogSize.width - x;
\r
712 var styles = { 'top' : ( y > 0 ? y : 0 ) + 'px' };
\r
713 styles[ rtl ? 'right' : 'left' ] = ( x > 0 ? x : 0 ) + 'px';
\r
715 element.setStyles( styles );
\r
717 save && ( this._.moved = 1 );
\r
722 * Gets the dialog's position in the window.
\r
723 * @returns {Object} An object with "x" and "y" properties.
\r
725 * var dialogX = dialogObj.getPosition().x;
\r
727 getPosition : function(){ return CKEDITOR.tools.extend( {}, this._.position ); },
\r
730 * Shows the dialog box.
\r
732 * dialogObj.show();
\r
736 // Insert the dialog's element to the root document.
\r
737 var element = this._.element;
\r
738 var definition = this.definition;
\r
739 if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )
\r
740 element.appendTo( CKEDITOR.document.getBody() );
\r
742 element.setStyle( 'display', 'block' );
\r
744 // FIREFOX BUG: Fix vanishing caret for Firefox 2 or Gecko 1.8.
\r
745 if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
\r
747 var dialogElement = this.parts.dialog;
\r
748 dialogElement.setStyle( 'position', 'absolute' );
\r
749 setTimeout( function()
\r
751 dialogElement.setStyle( 'position', 'fixed' );
\r
756 // First, set the dialog to an appropriate size.
\r
757 this.resize( this._.contentSize && this._.contentSize.width || definition.width || definition.minWidth,
\r
758 this._.contentSize && this._.contentSize.height || definition.height || definition.minHeight );
\r
760 // Reset all inputs back to their default value.
\r
763 // Select the first tab by default.
\r
764 this.selectPage( this.definition.contents[0].id );
\r
767 if ( CKEDITOR.dialog._.currentZIndex === null )
\r
768 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;
\r
769 this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
\r
771 // Maintain the dialog ordering and dialog cover.
\r
772 // Also register key handlers if first dialog.
\r
773 if ( CKEDITOR.dialog._.currentTop === null )
\r
775 CKEDITOR.dialog._.currentTop = this;
\r
776 this._.parentDialog = null;
\r
777 showCover( this._.editor );
\r
779 element.on( 'keydown', accessKeyDownHandler );
\r
780 element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
782 // Prevent some keys from bubbling up. (#4269)
\r
783 for ( var event in { keyup :1, keydown :1, keypress :1 } )
\r
784 element.on( event, preventKeyBubbling );
\r
788 this._.parentDialog = CKEDITOR.dialog._.currentTop;
\r
789 var parentElement = this._.parentDialog.getElement().getFirst();
\r
790 parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );
\r
791 CKEDITOR.dialog._.currentTop = this;
\r
794 // Register the Esc hotkeys.
\r
795 registerAccessKey( this, this, '\x1b', null, function()
\r
797 this.getButton( 'cancel' ) && this.getButton( 'cancel' ).click();
\r
800 // Reset the hasFocus state.
\r
801 this._.hasFocus = false;
\r
803 CKEDITOR.tools.setTimeout( function()
\r
806 this.parts.dialog.setStyle( 'visibility', '' );
\r
808 // Execute onLoad for the first show.
\r
809 this.fireOnce( 'load', {} );
\r
810 CKEDITOR.ui.fire( 'ready', this );
\r
812 this.fire( 'show', {} );
\r
813 this._.editor.fire( 'dialogShow', this );
\r
815 // Save the initial values of the dialog.
\r
816 this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } );
\r
823 * Rearrange the dialog to its previous position or the middle of the window.
\r
826 layout : function()
\r
828 var viewSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
829 dialogSize = this.getSize();
\r
831 this.move( this._.moved ? this._.position.x : ( viewSize.width - dialogSize.width ) / 2,
\r
832 this._.moved ? this._.position.y : ( viewSize.height - dialogSize.height ) / 2 );
\r
836 * Executes a function for each UI element.
\r
837 * @param {Function} fn Function to execute for each UI element.
\r
838 * @returns {CKEDITOR.dialog} The current dialog object.
\r
840 foreach : function( fn )
\r
842 for ( var i in this._.contents )
\r
844 for ( var j in this._.contents[i] )
\r
845 fn( this._.contents[i][j] );
\r
851 * Resets all input values in the dialog.
\r
853 * dialogObj.reset();
\r
854 * @returns {CKEDITOR.dialog} The current dialog object.
\r
856 reset : (function()
\r
858 var fn = function( widget ){ if ( widget.reset ) widget.reset( 1 ); };
\r
859 return function(){ this.foreach( fn ); return this; };
\r
864 * Calls the {@link CKEDITOR.dialog.definition.uiElement#setup} method of each of the UI elements, with the arguments passed through it.
\r
865 * It is usually being called when the dialog is opened, to put the initial value inside the field.
\r
867 * dialogObj.setupContent();
\r
869 * var timestamp = ( new Date() ).valueOf();
\r
870 * dialogObj.setupContent( timestamp );
\r
872 setupContent : function()
\r
874 var args = arguments;
\r
875 this.foreach( function( widget )
\r
877 if ( widget.setup )
\r
878 widget.setup.apply( widget, args );
\r
883 * Calls the {@link CKEDITOR.dialog.definition.uiElement#commit} method of each of the UI elements, with the arguments passed through it.
\r
884 * It is usually being called when the user confirms the dialog, to process the values.
\r
886 * dialogObj.commitContent();
\r
888 * var timestamp = ( new Date() ).valueOf();
\r
889 * dialogObj.commitContent( timestamp );
\r
891 commitContent : function()
\r
893 var args = arguments;
\r
894 this.foreach( function( widget )
\r
896 if ( widget.commit )
\r
897 widget.commit.apply( widget, args );
\r
902 * Hides the dialog box.
\r
904 * dialogObj.hide();
\r
908 if ( !this.parts.dialog.isVisible() )
\r
911 this.fire( 'hide', {} );
\r
912 this._.editor.fire( 'dialogHide', this );
\r
913 var element = this._.element;
\r
914 element.setStyle( 'display', 'none' );
\r
915 this.parts.dialog.setStyle( 'visibility', 'hidden' );
\r
916 // Unregister all access keys associated with this dialog.
\r
917 unregisterAccessKey( this );
\r
919 // Close any child(top) dialogs first.
\r
920 while( CKEDITOR.dialog._.currentTop != this )
\r
921 CKEDITOR.dialog._.currentTop.hide();
\r
923 // Maintain dialog ordering and remove cover if needed.
\r
924 if ( !this._.parentDialog )
\r
928 var parentElement = this._.parentDialog.getElement().getFirst();
\r
929 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
\r
931 CKEDITOR.dialog._.currentTop = this._.parentDialog;
\r
933 // Deduct or clear the z-index.
\r
934 if ( !this._.parentDialog )
\r
936 CKEDITOR.dialog._.currentZIndex = null;
\r
938 // Remove access key handlers.
\r
939 element.removeListener( 'keydown', accessKeyDownHandler );
\r
940 element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
942 // Remove bubbling-prevention handler. (#4269)
\r
943 for ( var event in { keyup :1, keydown :1, keypress :1 } )
\r
944 element.removeListener( event, preventKeyBubbling );
\r
946 var editor = this._.editor;
\r
949 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
951 var selection = editor.getSelection();
\r
952 selection && selection.unlock( true );
\r
956 CKEDITOR.dialog._.currentZIndex -= 10;
\r
958 delete this._.parentDialog;
\r
959 // Reset the initial values of the dialog.
\r
960 this.foreach( function( contentObj ) { contentObj.resetInitValue && contentObj.resetInitValue(); } );
\r
964 * Adds a tabbed page into the dialog.
\r
965 * @param {Object} contents Content definition.
\r
968 addPage : function( contents )
\r
971 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
\r
972 elements = contents.elements,
\r
973 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this,
\r
976 className : 'cke_dialog_page_contents',
\r
977 children : contents.elements,
\r
978 expand : !!contents.expand,
\r
979 padding : contents.padding,
\r
980 style : contents.style || 'width: 100%;height:100%'
\r
983 // Create the HTML for the tab and the content block.
\r
984 var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
\r
985 page.setAttribute( 'role', 'tabpanel' );
\r
987 var env = CKEDITOR.env;
\r
988 var tabId = 'cke_' + contents.id + '_' + CKEDITOR.tools.getNextNumber(),
\r
989 tab = CKEDITOR.dom.element.createFromHtml( [
\r
990 '<a class="cke_dialog_tab"',
\r
991 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),
\r
993 ( !!contents.hidden ? ' style="display:none"' : '' ),
\r
994 ' id="', tabId, '"',
\r
995 env.gecko && env.version >= 10900 && !env.hc ? '' : ' href="javascript:void(0)"',
\r
997 ' hidefocus="true"',
\r
1003 page.setAttribute( 'aria-labelledby', tabId );
\r
1005 // Take records for the tabs and elements created.
\r
1006 this._.tabs[ contents.id ] = [ tab, page ];
\r
1007 this._.tabIdList.push( contents.id );
\r
1008 !contents.hidden && this._.pageCount++;
\r
1009 this._.lastTab = tab;
\r
1010 this.updateStyle();
\r
1012 var contentMap = this._.contents[ contents.id ] = {},
\r
1014 children = vbox.getChild();
\r
1016 while ( ( cursor = children.shift() ) )
\r
1018 contentMap[ cursor.id ] = cursor;
\r
1019 if ( typeof( cursor.getChild ) == 'function' )
\r
1020 children.push.apply( children, cursor.getChild() );
\r
1023 // Attach the DOM nodes.
\r
1025 page.setAttribute( 'name', contents.id );
\r
1026 page.appendTo( this.parts.contents );
\r
1028 tab.unselectable();
\r
1029 this.parts.tabs.append( tab );
\r
1031 // Add access key handlers if access key is defined.
\r
1032 if ( contents.accessKey )
\r
1034 registerAccessKey( this, this, 'CTRL+' + contents.accessKey,
\r
1035 tabAccessKeyDown, tabAccessKeyUp );
\r
1036 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;
\r
1041 * Activates a tab page in the dialog by its id.
\r
1042 * @param {String} id The id of the dialog tab to be activated.
\r
1044 * dialogObj.selectPage( 'tab_1' );
\r
1046 selectPage : function( id )
\r
1048 if ( this._.currentTabId == id )
\r
1051 // Returning true means that the event has been canceled
\r
1052 if ( this.fire( 'selectPage', { page : id, currentPage : this._.currentTabId } ) === true )
\r
1055 // Hide the non-selected tabs and pages.
\r
1056 for ( var i in this._.tabs )
\r
1058 var tab = this._.tabs[i][0],
\r
1059 page = this._.tabs[i][1];
\r
1062 tab.removeClass( 'cke_dialog_tab_selected' );
\r
1065 page.setAttribute( 'aria-hidden', i != id );
\r
1068 var selected = this._.tabs[ id ];
\r
1069 selected[ 0 ].addClass( 'cke_dialog_tab_selected' );
\r
1071 // [IE] an invisible input[type='text'] will enlarge it's width
\r
1072 // if it's value is long when it shows, so we clear it's value
\r
1073 // before it shows and then recover it (#5649)
\r
1074 if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat )
\r
1076 clearOrRecoverTextInputValue( selected[ 1 ] );
\r
1077 selected[ 1 ].show();
\r
1078 setTimeout( function()
\r
1080 clearOrRecoverTextInputValue( selected[ 1 ], 1 );
\r
1084 selected[ 1 ].show();
\r
1086 this._.currentTabId = id;
\r
1087 this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
\r
1090 // Dialog state-specific style updates.
\r
1091 updateStyle : function()
\r
1093 // If only a single page shown, a different style is used in the central pane.
\r
1094 this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );
\r
1098 * Hides a page's tab away from the dialog.
\r
1099 * @param {String} id The page's Id.
\r
1101 * dialog.hidePage( 'tab_3' );
\r
1103 hidePage : function( id )
\r
1105 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
1106 if ( !tab || this._.pageCount == 1 || !tab.isVisible() )
\r
1108 // Switch to other tab first when we're hiding the active tab.
\r
1109 else if ( id == this._.currentTabId )
\r
1110 this.selectPage( getPreviousVisibleTab.call( this ) );
\r
1113 this._.pageCount--;
\r
1114 this.updateStyle();
\r
1118 * Unhides a page's tab.
\r
1119 * @param {String} id The page's Id.
\r
1121 * dialog.showPage( 'tab_2' );
\r
1123 showPage : function( id )
\r
1125 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
1129 this._.pageCount++;
\r
1130 this.updateStyle();
\r
1134 * Gets the root DOM element of the dialog.
\r
1135 * @returns {CKEDITOR.dom.element} The <span> element containing this dialog.
\r
1137 * var dialogElement = dialogObj.getElement().getFirst();
\r
1138 * dialogElement.setStyle( 'padding', '5px' );
\r
1140 getElement : function()
\r
1142 return this._.element;
\r
1146 * Gets the name of the dialog.
\r
1147 * @returns {String} The name of this dialog.
\r
1149 * var dialogName = dialogObj.getName();
\r
1151 getName : function()
\r
1153 return this._.name;
\r
1157 * Gets a dialog UI element object from a dialog page.
\r
1158 * @param {String} pageId id of dialog page.
\r
1159 * @param {String} elementId id of UI element.
\r
1161 * dialogObj.getContentElement( 'tabId', 'elementId' ).setValue( 'Example' );
\r
1162 * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.
\r
1164 getContentElement : function( pageId, elementId )
\r
1166 var page = this._.contents[ pageId ];
\r
1167 return page && page[ elementId ];
\r
1171 * Gets the value of a dialog UI element.
\r
1172 * @param {String} pageId id of dialog page.
\r
1173 * @param {String} elementId id of UI element.
\r
1175 * alert( dialogObj.getValueOf( 'tabId', 'elementId' ) );
\r
1176 * @returns {Object} The value of the UI element.
\r
1178 getValueOf : function( pageId, elementId )
\r
1180 return this.getContentElement( pageId, elementId ).getValue();
\r
1184 * Sets the value of a dialog UI element.
\r
1185 * @param {String} pageId id of the dialog page.
\r
1186 * @param {String} elementId id of the UI element.
\r
1187 * @param {Object} value The new value of the UI element.
\r
1189 * dialogObj.setValueOf( 'tabId', 'elementId', 'Example' );
\r
1191 setValueOf : function( pageId, elementId, value )
\r
1193 return this.getContentElement( pageId, elementId ).setValue( value );
\r
1197 * Gets the UI element of a button in the dialog's button row.
\r
1198 * @param {String} id The id of the button.
\r
1200 * @returns {CKEDITOR.ui.dialog.button} The button object.
\r
1202 getButton : function( id )
\r
1204 return this._.buttons[ id ];
\r
1208 * Simulates a click to a dialog button in the dialog's button row.
\r
1209 * @param {String} id The id of the button.
\r
1211 * @returns The return value of the dialog's "click" event.
\r
1213 click : function( id )
\r
1215 return this._.buttons[ id ].click();
\r
1219 * Disables a dialog button.
\r
1220 * @param {String} id The id of the button.
\r
1223 disableButton : function( id )
\r
1225 return this._.buttons[ id ].disable();
\r
1229 * Enables a dialog button.
\r
1230 * @param {String} id The id of the button.
\r
1233 enableButton : function( id )
\r
1235 return this._.buttons[ id ].enable();
\r
1239 * Gets the number of pages in the dialog.
\r
1240 * @returns {Number} Page count.
\r
1242 getPageCount : function()
\r
1244 return this._.pageCount;
\r
1248 * Gets the editor instance which opened this dialog.
\r
1249 * @returns {CKEDITOR.editor} Parent editor instances.
\r
1251 getParentEditor : function()
\r
1253 return this._.editor;
\r
1257 * Gets the element that was selected when opening the dialog, if any.
\r
1258 * @returns {CKEDITOR.dom.element} The element that was selected, or null.
\r
1260 getSelectedElement : function()
\r
1262 return this.getParentEditor().getSelection().getSelectedElement();
\r
1266 * Adds element to dialog's focusable list.
\r
1268 * @param {CKEDITOR.dom.element} element
\r
1269 * @param {Number} [index]
\r
1271 addFocusable: function( element, index ) {
\r
1272 if ( typeof index == 'undefined' )
\r
1274 index = this._.focusList.length;
\r
1275 this._.focusList.push( new Focusable( this, element, index ) );
\r
1279 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );
\r
1280 for ( var i = index + 1 ; i < this._.focusList.length ; i++ )
\r
1281 this._.focusList[ i ].focusIndex++;
\r
1286 CKEDITOR.tools.extend( CKEDITOR.dialog,
\r
1288 * @lends CKEDITOR.dialog
\r
1292 * Registers a dialog.
\r
1293 * @param {String} name The dialog's name.
\r
1294 * @param {Function|String} dialogDefinition
\r
1295 * A function returning the dialog's definition, or the URL to the .js file holding the function.
\r
1296 * The function should accept an argument "editor" which is the current editor instance, and
\r
1297 * return an object conforming to {@link CKEDITOR.dialog.definition}.
\r
1298 * @see CKEDITOR.dialog.definition
\r
1300 * // Full sample plugin, which does not only register a dialog window but also adds an item to the context menu.
\r
1301 * // To open the dialog window, choose "Open dialog" in the context menu.
\r
1302 * CKEDITOR.plugins.add( 'myplugin',
\r
1304 * init: function( editor )
\r
1306 * editor.addCommand( 'mydialog',new CKEDITOR.dialogCommand( 'mydialog' ) );
\r
1308 * if ( editor.contextMenu )
\r
1310 * editor.addMenuGroup( 'mygroup', 10 );
\r
1311 * editor.addMenuItem( 'My Dialog',
\r
1313 * label : 'Open dialog',
\r
1314 * command : 'mydialog',
\r
1315 * group : 'mygroup'
\r
1317 * editor.contextMenu.addListener( function( element )
\r
1319 * return { 'My Dialog' : CKEDITOR.TRISTATE_OFF };
\r
1323 * <strong>CKEDITOR.dialog.add</strong>( 'mydialog', function( api )
\r
1325 * // CKEDITOR.dialog.definition
\r
1326 * var <strong>dialogDefinition</strong> =
\r
1328 * title : 'Sample dialog',
\r
1330 * minHeight : 130,
\r
1334 * label : 'Label',
\r
1335 * title : 'Title',
\r
1342 * html : '<p>This is some sample HTML content.</p>'
\r
1345 * type : 'textarea',
\r
1346 * id : 'textareaId',
\r
1353 * buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ],
\r
1354 * onOk : function() {
\r
1355 * // "this" is now a CKEDITOR.dialog object.
\r
1356 * // Accessing dialog elements:
\r
1357 * var textareaObj = this.<strong>getContentElement</strong>( 'tab1', 'textareaId' );
\r
1358 * alert( "You have entered: " + textareaObj.getValue() );
\r
1362 * return dialogDefinition;
\r
1367 * CKEDITOR.replace( 'editor1', { extraPlugins : 'myplugin' } );
\r
1369 add : function( name, dialogDefinition )
\r
1371 // Avoid path registration from multiple instances override definition.
\r
1372 if ( !this._.dialogDefinitions[name]
\r
1373 || typeof dialogDefinition == 'function' )
\r
1374 this._.dialogDefinitions[name] = dialogDefinition;
\r
1377 exists : function( name )
\r
1379 return !!this._.dialogDefinitions[ name ];
\r
1382 getCurrent : function()
\r
1384 return CKEDITOR.dialog._.currentTop;
\r
1388 * The default OK button for dialogs. Fires the "ok" event and closes the dialog if the event succeeds.
\r
1394 okButton : (function()
\r
1396 var retval = function( editor, override )
\r
1398 override = override || {};
\r
1399 return CKEDITOR.tools.extend( {
\r
1402 label : editor.lang.common.ok,
\r
1403 'class' : 'cke_dialog_ui_button_ok',
\r
1404 onClick : function( evt )
\r
1406 var dialog = evt.data.dialog;
\r
1407 if ( dialog.fire( 'ok', { hide : true } ).hide !== false )
\r
1410 }, override, true );
\r
1412 retval.type = 'button';
\r
1413 retval.override = function( override )
\r
1415 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1416 { type : 'button' }, true );
\r
1422 * The default cancel button for dialogs. Fires the "cancel" event and closes the dialog if no UI element value changed.
\r
1428 cancelButton : (function()
\r
1430 var retval = function( editor, override )
\r
1432 override = override || {};
\r
1433 return CKEDITOR.tools.extend( {
\r
1436 label : editor.lang.common.cancel,
\r
1437 'class' : 'cke_dialog_ui_button_cancel',
\r
1438 onClick : function( evt )
\r
1440 var dialog = evt.data.dialog;
\r
1441 if ( dialog.fire( 'cancel', { hide : true } ).hide !== false )
\r
1444 }, override, true );
\r
1446 retval.type = 'button';
\r
1447 retval.override = function( override )
\r
1449 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1450 { type : 'button' }, true );
\r
1456 * Registers a dialog UI element.
\r
1457 * @param {String} typeName The name of the UI element.
\r
1458 * @param {Function} builder The function to build the UI element.
\r
1461 addUIElement : function( typeName, builder )
\r
1463 this._.uiElementBuilders[ typeName ] = builder;
\r
1467 CKEDITOR.dialog._ =
\r
1469 uiElementBuilders : {},
\r
1471 dialogDefinitions : {},
\r
1473 currentTop : null,
\r
1475 currentZIndex : null
\r
1478 // "Inherit" (copy actually) from CKEDITOR.event.
\r
1479 CKEDITOR.event.implementOn( CKEDITOR.dialog );
\r
1480 CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype, true );
\r
1482 var defaultDialogDefinition =
\r
1484 resizable : CKEDITOR.DIALOG_RESIZE_BOTH,
\r
1487 buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
\r
1490 // Tool function used to return an item from an array based on its id
\r
1492 var getById = function( array, id, recurse )
\r
1494 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1496 if ( item.id == id )
\r
1498 if ( recurse && item[ recurse ] )
\r
1500 var retval = getById( item[ recurse ], id, recurse ) ;
\r
1508 // Tool function used to add an item into an array.
\r
1509 var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound )
\r
1511 if ( nextSiblingId )
\r
1513 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1515 if ( item.id == nextSiblingId )
\r
1517 array.splice( i, 0, newItem );
\r
1521 if ( recurse && item[ recurse ] )
\r
1523 var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
\r
1529 if ( nullIfNotFound )
\r
1533 array.push( newItem );
\r
1537 // Tool function used to remove an item from an array based on its id.
\r
1538 var removeById = function( array, id, recurse )
\r
1540 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1542 if ( item.id == id )
\r
1543 return array.splice( i, 1 );
\r
1544 if ( recurse && item[ recurse ] )
\r
1546 var retval = removeById( item[ recurse ], id, recurse );
\r
1555 * This class is not really part of the API. It is the "definition" property value
\r
1556 * passed to "dialogDefinition" event handlers.
\r
1558 * @name CKEDITOR.dialog.definitionObject
\r
1559 * @extends CKEDITOR.dialog.definition
\r
1561 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1563 * var definition = evt.data.definition;
\r
1564 * var content = definition.getContents( 'page1' );
\r
1568 var definitionObject = function( dialog, dialogDefinition )
\r
1570 // TODO : Check if needed.
\r
1571 this.dialog = dialog;
\r
1573 // Transform the contents entries in contentObjects.
\r
1574 var contents = dialogDefinition.contents;
\r
1575 for ( var i = 0, content ; ( content = contents[i] ) ; i++ )
\r
1576 contents[ i ] = content && new contentObject( dialog, content );
\r
1578 CKEDITOR.tools.extend( this, dialogDefinition );
\r
1581 definitionObject.prototype =
\r
1582 /** @lends CKEDITOR.dialog.definitionObject.prototype */
\r
1585 * Gets a content definition.
\r
1586 * @param {String} id The id of the content definition.
\r
1587 * @returns {CKEDITOR.dialog.definition.content} The content definition
\r
1590 getContents : function( id )
\r
1592 return getById( this.contents, id );
\r
1596 * Gets a button definition.
\r
1597 * @param {String} id The id of the button definition.
\r
1598 * @returns {CKEDITOR.dialog.definition.button} The button definition
\r
1601 getButton : function( id )
\r
1603 return getById( this.buttons, id );
\r
1607 * Adds a content definition object under this dialog definition.
\r
1608 * @param {CKEDITOR.dialog.definition.content} contentDefinition The
\r
1609 * content definition.
\r
1610 * @param {String} [nextSiblingId] The id of an existing content
\r
1611 * definition which the new content definition will be inserted
\r
1612 * before. Omit if the new content definition is to be inserted as
\r
1614 * @returns {CKEDITOR.dialog.definition.content} The inserted content
\r
1617 addContents : function( contentDefinition, nextSiblingId )
\r
1619 return addById( this.contents, contentDefinition, nextSiblingId );
\r
1623 * Adds a button definition object under this dialog definition.
\r
1624 * @param {CKEDITOR.dialog.definition.button} buttonDefinition The
\r
1625 * button definition.
\r
1626 * @param {String} [nextSiblingId] The id of an existing button
\r
1627 * definition which the new button definition will be inserted
\r
1628 * before. Omit if the new button definition is to be inserted as
\r
1630 * @returns {CKEDITOR.dialog.definition.button} The inserted button
\r
1633 addButton : function( buttonDefinition, nextSiblingId )
\r
1635 return addById( this.buttons, buttonDefinition, nextSiblingId );
\r
1639 * Removes a content definition from this dialog definition.
\r
1640 * @param {String} id The id of the content definition to be removed.
\r
1641 * @returns {CKEDITOR.dialog.definition.content} The removed content
\r
1644 removeContents : function( id )
\r
1646 removeById( this.contents, id );
\r
1650 * Removes a button definition from the dialog definition.
\r
1651 * @param {String} id The id of the button definition to be removed.
\r
1652 * @returns {CKEDITOR.dialog.definition.button} The removed button
\r
1655 removeButton : function( id )
\r
1657 removeById( this.buttons, id );
\r
1662 * This class is not really part of the API. It is the template of the
\r
1663 * objects representing content pages inside the
\r
1664 * CKEDITOR.dialog.definitionObject.
\r
1666 * @name CKEDITOR.dialog.definition.contentObject
\r
1668 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1670 * var definition = evt.data.definition;
\r
1671 * var content = definition.getContents( 'page1' );
\r
1672 * content.remove( 'textInput1' );
\r
1676 function contentObject( dialog, contentDefinition )
\r
1683 CKEDITOR.tools.extend( this, contentDefinition );
\r
1686 contentObject.prototype =
\r
1687 /** @lends CKEDITOR.dialog.definition.contentObject.prototype */
\r
1690 * Gets a UI element definition under the content definition.
\r
1691 * @param {String} id The id of the UI element definition.
\r
1692 * @returns {CKEDITOR.dialog.definition.uiElement}
\r
1694 get : function( id )
\r
1696 return getById( this.elements, id, 'children' );
\r
1700 * Adds a UI element definition to the content definition.
\r
1701 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition The
\r
1702 * UI elemnet definition to be added.
\r
1703 * @param {String} nextSiblingId The id of an existing UI element
\r
1704 * definition which the new UI element definition will be inserted
\r
1705 * before. Omit if the new button definition is to be inserted as
\r
1707 * @returns {CKEDITOR.dialog.definition.uiElement} The element
\r
1708 * definition inserted.
\r
1710 add : function( elementDefinition, nextSiblingId )
\r
1712 return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
\r
1716 * Removes a UI element definition from the content definition.
\r
1717 * @param {String} id The id of the UI element definition to be
\r
1719 * @returns {CKEDITOR.dialog.definition.uiElement} The element
\r
1720 * definition removed.
\r
1723 remove : function( id )
\r
1725 removeById( this.elements, id, 'children' );
\r
1729 function initDragAndDrop( dialog )
\r
1731 var lastCoords = null,
\r
1732 abstractDialogCoords = null,
\r
1733 element = dialog.getElement().getFirst(),
\r
1734 editor = dialog.getParentEditor(),
\r
1735 magnetDistance = editor.config.dialog_magnetDistance,
\r
1736 margins = editor.skin.margins || [ 0, 0, 0, 0 ];
\r
1738 if ( typeof magnetDistance == 'undefined' )
\r
1739 magnetDistance = 20;
\r
1741 function mouseMoveHandler( evt )
\r
1743 var dialogSize = dialog.getSize(),
\r
1744 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
1745 x = evt.data.$.screenX,
\r
1746 y = evt.data.$.screenY,
\r
1747 dx = x - lastCoords.x,
\r
1748 dy = y - lastCoords.y,
\r
1751 lastCoords = { x : x, y : y };
\r
1752 abstractDialogCoords.x += dx;
\r
1753 abstractDialogCoords.y += dy;
\r
1755 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
\r
1756 realX = - margins[3];
\r
1757 else if ( abstractDialogCoords.x - margins[1] > viewPaneSize.width - dialogSize.width - magnetDistance )
\r
1758 realX = viewPaneSize.width - dialogSize.width + ( editor.lang.dir == 'rtl' ? 0 : margins[1] );
\r
1760 realX = abstractDialogCoords.x;
\r
1762 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
\r
1763 realY = - margins[0];
\r
1764 else if ( abstractDialogCoords.y - margins[2] > viewPaneSize.height - dialogSize.height - magnetDistance )
\r
1765 realY = viewPaneSize.height - dialogSize.height + margins[2];
\r
1767 realY = abstractDialogCoords.y;
\r
1769 dialog.move( realX, realY, 1 );
\r
1771 evt.data.preventDefault();
\r
1774 function mouseUpHandler( evt )
\r
1776 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1777 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1779 if ( CKEDITOR.env.ie6Compat )
\r
1781 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1782 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1783 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1787 dialog.parts.title.on( 'mousedown', function( evt )
\r
1789 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
\r
1791 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
\r
1792 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
\r
1793 abstractDialogCoords = dialog.getPosition();
\r
1795 if ( CKEDITOR.env.ie6Compat )
\r
1797 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1798 coverDoc.on( 'mousemove', mouseMoveHandler );
\r
1799 coverDoc.on( 'mouseup', mouseUpHandler );
\r
1802 evt.data.preventDefault();
\r
1806 function initResizeHandles( dialog )
\r
1808 var def = dialog.definition,
\r
1809 resizable = def.resizable;
\r
1811 if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE )
\r
1814 var editor = dialog.getParentEditor();
\r
1815 var wrapperWidth, wrapperHeight,
\r
1816 viewSize, origin, startSize,
\r
1819 var mouseDownFn = CKEDITOR.tools.addFunction( function( $event )
\r
1821 startSize = dialog.getSize();
\r
1823 var content = dialog.parts.contents,
\r
1824 iframeDialog = content.$.getElementsByTagName( 'iframe' ).length;
\r
1826 // Shim to help capturing "mousemove" over iframe.
\r
1827 if ( iframeDialog )
\r
1829 dialogCover = CKEDITOR.dom.element.createFromHtml( '<div class="cke_dialog_resize_cover" style="height: 100%; position: absolute; width: 100%;"></div>' );
\r
1830 content.append( dialogCover );
\r
1833 // Calculate the offset between content and chrome size.
\r
1834 wrapperHeight = startSize.height - dialog.parts.contents.getSize( 'height', ! ( CKEDITOR.env.gecko || CKEDITOR.env.opera || CKEDITOR.env.ie && CKEDITOR.env.quirks ) );
\r
1835 wrapperWidth = startSize.width - dialog.parts.contents.getSize( 'width', 1 );
\r
1837 origin = { x : $event.screenX, y : $event.screenY };
\r
1839 viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
\r
1841 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
\r
1842 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
\r
1844 if ( CKEDITOR.env.ie6Compat )
\r
1846 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1847 coverDoc.on( 'mousemove', mouseMoveHandler );
\r
1848 coverDoc.on( 'mouseup', mouseUpHandler );
\r
1851 $event.preventDefault && $event.preventDefault();
\r
1854 // Prepend the grip to the dialog.
\r
1855 dialog.on( 'load', function()
\r
1857 var direction = '';
\r
1858 if ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH )
\r
1859 direction = ' cke_resizer_horizontal';
\r
1860 else if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT )
\r
1861 direction = ' cke_resizer_vertical';
\r
1862 var resizer = CKEDITOR.dom.element.createFromHtml( '<div' +
\r
1863 ' class="cke_resizer' + direction + ' cke_resizer_' + editor.lang.dir + '"' +
\r
1864 ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.resize ) + '"' +
\r
1865 ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event )"></div>' );
\r
1866 dialog.parts.footer.append( resizer, 1 );
\r
1868 editor.on( 'destroy', function() { CKEDITOR.tools.removeFunction( mouseDownFn ); } );
\r
1870 function mouseMoveHandler( evt )
\r
1872 var rtl = editor.lang.dir == 'rtl',
\r
1873 dx = ( evt.data.$.screenX - origin.x ) * ( rtl ? -1 : 1 ),
\r
1874 dy = evt.data.$.screenY - origin.y,
\r
1875 width = startSize.width,
\r
1876 height = startSize.height,
\r
1877 internalWidth = width + dx * ( dialog._.moved ? 1 : 2 ),
\r
1878 internalHeight = height + dy * ( dialog._.moved ? 1 : 2 ),
\r
1879 element = dialog._.element.getFirst(),
\r
1880 right = rtl && element.getComputedStyle( 'right' ),
\r
1881 position = dialog.getPosition();
\r
1883 if ( position.y + internalHeight > viewSize.height )
\r
1884 internalHeight = viewSize.height - position.y;
\r
1886 if ( ( rtl ? right : position.x ) + internalWidth > viewSize.width )
\r
1887 internalWidth = viewSize.width - ( rtl ? right : position.x );
\r
1889 // Make sure the dialog will not be resized to the wrong side when it's in the leftmost position for RTL.
\r
1890 if ( ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH || resizable == CKEDITOR.DIALOG_RESIZE_BOTH ) )
\r
1891 width = Math.max( def.minWidth || 0, internalWidth - wrapperWidth );
\r
1893 if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT || resizable == CKEDITOR.DIALOG_RESIZE_BOTH )
\r
1894 height = Math.max( def.minHeight || 0, internalHeight - wrapperHeight );
\r
1896 dialog.resize( width, height );
\r
1898 if ( !dialog._.moved )
\r
1901 evt.data.preventDefault();
\r
1904 function mouseUpHandler()
\r
1906 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1907 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1909 if ( dialogCover )
\r
1911 dialogCover.remove();
\r
1912 dialogCover = null;
\r
1915 if ( CKEDITOR.env.ie6Compat )
\r
1917 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1918 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1919 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1925 // Caching resuable covers and allowing only one cover
\r
1930 function cancelEvent( ev )
\r
1932 ev.data.preventDefault(1);
\r
1935 function showCover( editor )
\r
1937 var win = CKEDITOR.document.getWindow();
\r
1938 var config = editor.config,
\r
1939 backgroundColorStyle = config.dialog_backgroundCoverColor || 'white',
\r
1940 backgroundCoverOpacity = config.dialog_backgroundCoverOpacity,
\r
1941 baseFloatZIndex = config.baseFloatZIndex,
\r
1942 coverKey = CKEDITOR.tools.genKey(
\r
1943 backgroundColorStyle,
\r
1944 backgroundCoverOpacity,
\r
1945 baseFloatZIndex ),
\r
1946 coverElement = covers[ coverKey ];
\r
1948 if ( !coverElement )
\r
1951 '<div tabIndex="-1" style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),
\r
1952 '; z-index: ', baseFloatZIndex,
\r
1953 '; top: 0px; left: 0px; ',
\r
1954 ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),
\r
1955 '" class="cke_dialog_background_cover">'
\r
1958 if ( CKEDITOR.env.ie6Compat )
\r
1960 // Support for custom document.domain in IE.
\r
1961 var isCustomDomain = CKEDITOR.env.isCustomDomain(),
\r
1962 iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
\r
1966 ' hidefocus="true"' +
\r
1967 ' frameborder="0"' +
\r
1968 ' id="cke_dialog_background_iframe"' +
\r
1969 ' src="javascript:' );
\r
1971 html.push( 'void((function(){' +
\r
1972 'document.open();' +
\r
1973 ( isCustomDomain ? 'document.domain=\'' + document.domain + '\';' : '' ) +
\r
1974 'document.write( \'' + iframeHtml + '\' );' +
\r
1975 'document.close();' +
\r
1981 'position:absolute;' +
\r
1986 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
\r
1990 html.push( '</div>' );
\r
1992 coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
\r
1993 coverElement.setOpacity( backgroundCoverOpacity != undefined ? backgroundCoverOpacity : 0.5 );
\r
1995 coverElement.on( 'keydown', cancelEvent );
\r
1996 coverElement.on( 'keypress', cancelEvent );
\r
1997 coverElement.on( 'keyup', cancelEvent );
\r
1999 coverElement.appendTo( CKEDITOR.document.getBody() );
\r
2000 covers[ coverKey ] = coverElement;
\r
2003 coverElement. show();
\r
2005 currentCover = coverElement;
\r
2006 var resizeFunc = function()
\r
2008 var size = win.getViewPaneSize();
\r
2009 coverElement.setStyles(
\r
2011 width : size.width + 'px',
\r
2012 height : size.height + 'px'
\r
2016 var scrollFunc = function()
\r
2018 var pos = win.getScrollPosition(),
\r
2019 cursor = CKEDITOR.dialog._.currentTop;
\r
2020 coverElement.setStyles(
\r
2022 left : pos.x + 'px',
\r
2023 top : pos.y + 'px'
\r
2030 var dialogPos = cursor.getPosition();
\r
2031 cursor.move( dialogPos.x, dialogPos.y );
\r
2032 } while ( ( cursor = cursor._.parentDialog ) );
\r
2036 resizeCover = resizeFunc;
\r
2037 win.on( 'resize', resizeFunc );
\r
2039 // Using Safari/Mac, focus must be kept where it is (#7027)
\r
2040 if ( !( CKEDITOR.env.mac && CKEDITOR.env.webkit ) )
\r
2041 coverElement.focus();
\r
2043 if ( CKEDITOR.env.ie6Compat )
\r
2045 // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
\r
2046 // So we need to invent a really funny way to make it work.
\r
2047 var myScrollHandler = function()
\r
2050 arguments.callee.prevScrollHandler.apply( this, arguments );
\r
2052 win.$.setTimeout( function()
\r
2054 myScrollHandler.prevScrollHandler = window.onscroll || function(){};
\r
2055 window.onscroll = myScrollHandler;
\r
2061 function hideCover()
\r
2063 if ( !currentCover )
\r
2066 var win = CKEDITOR.document.getWindow();
\r
2067 currentCover.hide();
\r
2068 win.removeListener( 'resize', resizeCover );
\r
2070 if ( CKEDITOR.env.ie6Compat )
\r
2072 win.$.setTimeout( function()
\r
2074 var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
\r
2075 window.onscroll = prevScrollHandler || null;
\r
2078 resizeCover = null;
\r
2081 function removeCovers()
\r
2083 for ( var coverId in covers )
\r
2084 covers[ coverId ].remove();
\r
2088 var accessKeyProcessors = {};
\r
2090 var accessKeyDownHandler = function( evt )
\r
2092 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
2093 alt = evt.data.$.altKey,
\r
2094 shift = evt.data.$.shiftKey,
\r
2095 key = String.fromCharCode( evt.data.$.keyCode ),
\r
2096 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
2098 if ( !keyProcessor || !keyProcessor.length )
\r
2101 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
2102 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
2103 evt.data.preventDefault();
\r
2106 var accessKeyUpHandler = function( evt )
\r
2108 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
2109 alt = evt.data.$.altKey,
\r
2110 shift = evt.data.$.shiftKey,
\r
2111 key = String.fromCharCode( evt.data.$.keyCode ),
\r
2112 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
2114 if ( !keyProcessor || !keyProcessor.length )
\r
2117 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
2118 if ( keyProcessor.keyup )
\r
2120 keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
2121 evt.data.preventDefault();
\r
2125 var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc )
\r
2127 var procList = accessKeyProcessors[key] || ( accessKeyProcessors[key] = [] );
\r
2129 uiElement : uiElement,
\r
2132 keyup : upFunc || uiElement.accessKeyUp,
\r
2133 keydown : downFunc || uiElement.accessKeyDown
\r
2137 var unregisterAccessKey = function( obj )
\r
2139 for ( var i in accessKeyProcessors )
\r
2141 var list = accessKeyProcessors[i];
\r
2142 for ( var j = list.length - 1 ; j >= 0 ; j-- )
\r
2144 if ( list[j].dialog == obj || list[j].uiElement == obj )
\r
2145 list.splice( j, 1 );
\r
2147 if ( list.length === 0 )
\r
2148 delete accessKeyProcessors[i];
\r
2152 var tabAccessKeyUp = function( dialog, key )
\r
2154 if ( dialog._.accessKeyMap[key] )
\r
2155 dialog.selectPage( dialog._.accessKeyMap[key] );
\r
2158 var tabAccessKeyDown = function( dialog, key )
\r
2163 var preventKeyBubblingKeys = { 27 :1, 13 :1 };
\r
2164 var preventKeyBubbling = function( e )
\r
2166 if ( e.data.getKeystroke() in preventKeyBubblingKeys )
\r
2167 e.data.stopPropagation();
\r
2172 CKEDITOR.ui.dialog =
\r
2175 * The base class of all dialog UI elements.
\r
2177 * @param {CKEDITOR.dialog} dialog Parent dialog object.
\r
2178 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition Element
\r
2179 * definition. Accepted fields:
\r
2181 * <li><strong>id</strong> (Required) The id of the UI element. See {@link
\r
2182 * CKEDITOR.dialog#getContentElement}</li>
\r
2183 * <li><strong>type</strong> (Required) The type of the UI element. The
\r
2184 * value to this field specifies which UI element class will be used to
\r
2185 * generate the final widget.</li>
\r
2186 * <li><strong>title</strong> (Optional) The popup tooltip for the UI
\r
2188 * <li><strong>hidden</strong> (Optional) A flag that tells if the element
\r
2189 * should be initially visible.</li>
\r
2190 * <li><strong>className</strong> (Optional) Additional CSS class names
\r
2191 * to add to the UI element. Separated by space.</li>
\r
2192 * <li><strong>style</strong> (Optional) Additional CSS inline styles
\r
2193 * to add to the UI element. A semicolon (;) is required after the last
\r
2194 * style declaration.</li>
\r
2195 * <li><strong>accessKey</strong> (Optional) The alphanumeric access key
\r
2196 * for this element. Access keys are automatically prefixed by CTRL.</li>
\r
2197 * <li><strong>on*</strong> (Optional) Any UI element definition field that
\r
2198 * starts with <em>on</em> followed immediately by a capital letter and
\r
2199 * probably more letters is an event handler. Event handlers may be further
\r
2200 * divided into registered event handlers and DOM event handlers. Please
\r
2201 * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and
\r
2202 * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more
\r
2203 * information.</li>
\r
2205 * @param {Array} htmlList
\r
2206 * List of HTML code to be added to the dialog's content area.
\r
2207 * @param {Function|String} nodeNameArg
\r
2208 * A function returning a string, or a simple string for the node name for
\r
2209 * the root DOM node. Default is 'div'.
\r
2210 * @param {Function|Object} stylesArg
\r
2211 * A function returning an object, or a simple object for CSS styles applied
\r
2212 * to the DOM node. Default is empty object.
\r
2213 * @param {Function|Object} attributesArg
\r
2214 * A fucntion returning an object, or a simple object for attributes applied
\r
2215 * to the DOM node. Default is empty object.
\r
2216 * @param {Function|String} contentsArg
\r
2217 * A function returning a string, or a simple string for the HTML code inside
\r
2218 * the root DOM node. Default is empty string.
\r
2221 uiElement : function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg )
\r
2223 if ( arguments.length < 4 )
\r
2226 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',
\r
2227 html = [ '<', nodeName, ' ' ],
\r
2228 styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},
\r
2229 attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},
\r
2230 innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',
\r
2231 domId = this.domId = attributes.id || CKEDITOR.tools.getNextId() + '_uiElement',
\r
2232 id = this.id = elementDefinition.id,
\r
2235 // Set the id, a unique id is required for getElement() to work.
\r
2236 attributes.id = domId;
\r
2238 // Set the type and definition CSS class names.
\r
2240 if ( elementDefinition.type )
\r
2241 classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;
\r
2242 if ( elementDefinition.className )
\r
2243 classes[ elementDefinition.className ] = 1;
\r
2244 var attributeClasses = ( attributes['class'] && attributes['class'].split ) ? attributes['class'].split( ' ' ) : [];
\r
2245 for ( i = 0 ; i < attributeClasses.length ; i++ )
\r
2247 if ( attributeClasses[i] )
\r
2248 classes[ attributeClasses[i] ] = 1;
\r
2250 var finalClasses = [];
\r
2251 for ( i in classes )
\r
2252 finalClasses.push( i );
\r
2253 attributes['class'] = finalClasses.join( ' ' );
\r
2255 // Set the popup tooltop.
\r
2256 if ( elementDefinition.title )
\r
2257 attributes.title = elementDefinition.title;
\r
2259 // Write the inline CSS styles.
\r
2260 var styleStr = ( elementDefinition.style || '' ).split( ';' );
\r
2261 for ( i in styles )
\r
2262 styleStr.push( i + ':' + styles[i] );
\r
2263 if ( elementDefinition.hidden )
\r
2264 styleStr.push( 'display:none' );
\r
2265 for ( i = styleStr.length - 1 ; i >= 0 ; i-- )
\r
2267 if ( styleStr[i] === '' )
\r
2268 styleStr.splice( i, 1 );
\r
2270 if ( styleStr.length > 0 )
\r
2271 attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
\r
2273 // Write the attributes.
\r
2274 for ( i in attributes )
\r
2275 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '" ');
\r
2277 // Write the content HTML.
\r
2278 html.push( '>', innerHTML, '</', nodeName, '>' );
\r
2280 // Add contents to the parent HTML array.
\r
2281 htmlList.push( html.join( '' ) );
\r
2283 ( this._ || ( this._ = {} ) ).dialog = dialog;
\r
2285 // Override isChanged if it is defined in element definition.
\r
2286 if ( typeof( elementDefinition.isChanged ) == 'boolean' )
\r
2287 this.isChanged = function(){ return elementDefinition.isChanged; };
\r
2288 if ( typeof( elementDefinition.isChanged ) == 'function' )
\r
2289 this.isChanged = elementDefinition.isChanged;
\r
2292 CKEDITOR.event.implementOn( this );
\r
2294 this.registerEvents( elementDefinition );
\r
2295 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
\r
2296 registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
\r
2299 dialog.on( 'load', function()
\r
2301 if ( me.getInputElement() )
\r
2303 me.getInputElement().on( 'focus', function()
\r
2305 dialog._.tabBarMode = false;
\r
2306 dialog._.hasFocus = true;
\r
2307 me.fire( 'focus' );
\r
2312 // Register the object as a tab focus if it can be included.
\r
2313 if ( this.keyboardFocusable )
\r
2315 this.tabIndex = elementDefinition.tabIndex || 0;
\r
2317 this.focusIndex = dialog._.focusList.push( this ) - 1;
\r
2318 this.on( 'focus', function()
\r
2320 dialog._.currentFocusIndex = me.focusIndex;
\r
2324 // Completes this object with everything we have in the
\r
2326 CKEDITOR.tools.extend( this, elementDefinition );
\r
2330 * Horizontal layout box for dialog UI elements, auto-expends to available width of container.
\r
2332 * @extends CKEDITOR.ui.dialog.uiElement
\r
2333 * @param {CKEDITOR.dialog} dialog
\r
2334 * Parent dialog object.
\r
2335 * @param {Array} childObjList
\r
2336 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2338 * @param {Array} childHtmlList
\r
2339 * Array of HTML code that correspond to the HTML output of all the
\r
2340 * objects in childObjList.
\r
2341 * @param {Array} htmlList
\r
2342 * Array of HTML code that this element will output to.
\r
2343 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
\r
2344 * The element definition. Accepted fields:
\r
2346 * <li><strong>widths</strong> (Optional) The widths of child cells.</li>
\r
2347 * <li><strong>height</strong> (Optional) The height of the layout.</li>
\r
2348 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2350 * <li><strong>align</strong> (Optional) The alignment of the whole layout
\r
2355 hbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2357 if ( arguments.length < 4 )
\r
2360 this._ || ( this._ = {} );
\r
2362 var children = this._.children = childObjList,
\r
2363 widths = elementDefinition && elementDefinition.widths || null,
\r
2364 height = elementDefinition && elementDefinition.height || null,
\r
2368 var innerHTML = function()
\r
2370 var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];
\r
2371 for ( i = 0 ; i < childHtmlList.length ; i++ )
\r
2373 var className = 'cke_dialog_ui_hbox_child',
\r
2376 className = 'cke_dialog_ui_hbox_first';
\r
2377 if ( i == childHtmlList.length - 1 )
\r
2378 className = 'cke_dialog_ui_hbox_last';
\r
2379 html.push( '<td class="', className, '" role="presentation" ' );
\r
2383 styles.push( 'width:' + cssLength( widths[i] ) );
\r
2386 styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2388 styles.push( 'height:' + cssLength( height ) );
\r
2389 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2390 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
\r
2391 if ( styles.length > 0 )
\r
2392 html.push( 'style="' + styles.join('; ') + '" ' );
\r
2393 html.push( '>', childHtmlList[i], '</td>' );
\r
2395 html.push( '</tr></tbody>' );
\r
2396 return html.join( '' );
\r
2399 var attribs = { role : 'presentation' };
\r
2400 elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );
\r
2402 CKEDITOR.ui.dialog.uiElement.call(
\r
2405 elementDefinition || { type : 'hbox' },
\r
2414 * Vertical layout box for dialog UI elements.
\r
2416 * @extends CKEDITOR.ui.dialog.hbox
\r
2417 * @param {CKEDITOR.dialog} dialog
\r
2418 * Parent dialog object.
\r
2419 * @param {Array} childObjList
\r
2420 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2422 * @param {Array} childHtmlList
\r
2423 * Array of HTML code that correspond to the HTML output of all the
\r
2424 * objects in childObjList.
\r
2425 * @param {Array} htmlList
\r
2426 * Array of HTML code that this element will output to.
\r
2427 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
\r
2428 * The element definition. Accepted fields:
\r
2430 * <li><strong>width</strong> (Optional) The width of the layout.</li>
\r
2431 * <li><strong>heights</strong> (Optional) The heights of individual cells.
\r
2433 * <li><strong>align</strong> (Optional) The alignment of the layout.</li>
\r
2434 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2436 * <li><strong>expand</strong> (Optional) Whether the layout should expand
\r
2437 * vertically to fill its container.</li>
\r
2441 vbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2443 if ( arguments.length < 3 )
\r
2446 this._ || ( this._ = {} );
\r
2448 var children = this._.children = childObjList,
\r
2449 width = elementDefinition && elementDefinition.width || null,
\r
2450 heights = elementDefinition && elementDefinition.heights || null;
\r
2452 var innerHTML = function()
\r
2454 var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];
\r
2455 html.push( 'style="' );
\r
2456 if ( elementDefinition && elementDefinition.expand )
\r
2457 html.push( 'height:100%;' );
\r
2458 html.push( 'width:' + cssLength( width || '100%' ), ';' );
\r
2460 html.push( 'align="', CKEDITOR.tools.htmlEncode(
\r
2461 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
\r
2463 html.push( '><tbody>' );
\r
2464 for ( var i = 0 ; i < childHtmlList.length ; i++ )
\r
2467 html.push( '<tr><td role="presentation" ' );
\r
2469 styles.push( 'width:' + cssLength( width || '100%' ) );
\r
2471 styles.push( 'height:' + cssLength( heights[i] ) );
\r
2472 else if ( elementDefinition && elementDefinition.expand )
\r
2473 styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2474 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2475 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
\r
2476 if ( styles.length > 0 )
\r
2477 html.push( 'style="', styles.join( '; ' ), '" ' );
\r
2478 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[i], '</td></tr>' );
\r
2480 html.push( '</tbody></table>' );
\r
2481 return html.join( '' );
\r
2483 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type : 'vbox' }, htmlList, 'div', null, { role : 'presentation' }, innerHTML );
\r
2488 CKEDITOR.ui.dialog.uiElement.prototype =
\r
2491 * Gets the root DOM element of this dialog UI object.
\r
2492 * @returns {CKEDITOR.dom.element} Root DOM element of UI object.
\r
2494 * uiElement.getElement().hide();
\r
2496 getElement : function()
\r
2498 return CKEDITOR.document.getById( this.domId );
\r
2502 * Gets the DOM element that the user inputs values.
\r
2503 * This function is used by setValue(), getValue() and focus(). It should
\r
2504 * be overrided in child classes where the input element isn't the root
\r
2506 * @returns {CKEDITOR.dom.element} The element where the user input values.
\r
2508 * var rawValue = textInput.getInputElement().$.value;
\r
2510 getInputElement : function()
\r
2512 return this.getElement();
\r
2516 * Gets the parent dialog object containing this UI element.
\r
2517 * @returns {CKEDITOR.dialog} Parent dialog object.
\r
2519 * var dialog = uiElement.getDialog();
\r
2521 getDialog : function()
\r
2523 return this._.dialog;
\r
2527 * Sets the value of this dialog UI object.
\r
2528 * @param {Object} value The new value.
\r
2529 * @param {Boolean} noChangeEvent Internal commit, to supress 'change' event on this element.
\r
2530 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2532 * uiElement.setValue( 'Dingo' );
\r
2534 setValue : function( value, noChangeEvent )
\r
2536 this.getInputElement().setValue( value );
\r
2537 !noChangeEvent && this.fire( 'change', { value : value } );
\r
2542 * Gets the current value of this dialog UI object.
\r
2543 * @returns {Object} The current value.
\r
2545 * var myValue = uiElement.getValue();
\r
2547 getValue : function()
\r
2549 return this.getInputElement().getValue();
\r
2553 * Tells whether the UI object's value has changed.
\r
2554 * @returns {Boolean} true if changed, false if not changed.
\r
2556 * if ( uiElement.isChanged() )
\r
2557 * confirm( 'Value changed! Continue?' );
\r
2559 isChanged : function()
\r
2561 // Override in input classes.
\r
2566 * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
\r
2567 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2569 * focus : function()
\r
2571 * this.selectParentTab();
\r
2572 * // do something else.
\r
2575 selectParentTab : function()
\r
2577 var element = this.getInputElement(),
\r
2580 while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 )
\r
2583 // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
\r
2587 tabId = cursor.getAttribute( 'name' );
\r
2588 // Avoid duplicate select.
\r
2589 if ( this._.dialog._.currentTabId != tabId )
\r
2590 this._.dialog.selectPage( tabId );
\r
2595 * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
\r
2596 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2598 * uiElement.focus();
\r
2600 focus : function()
\r
2602 this.selectParentTab().getInputElement().focus();
\r
2607 * Registers the on* event handlers defined in the element definition.
\r
2608 * The default behavior of this function is:
\r
2611 * If the on* event is defined in the class's eventProcesors list,
\r
2612 * then the registration is delegated to the corresponding function
\r
2613 * in the eventProcessors list.
\r
2616 * If the on* event is not defined in the eventProcessors list, then
\r
2617 * register the event handler under the corresponding DOM event of
\r
2618 * the UI element's input DOM element (as defined by the return value
\r
2619 * of {@link CKEDITOR.ui.dialog.uiElement#getInputElement}).
\r
2622 * This function is only called at UI element instantiation, but can
\r
2623 * be overridded in child classes if they require more flexibility.
\r
2624 * @param {CKEDITOR.dialog.definition.uiElement} definition The UI element
\r
2626 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2629 registerEvents : function( definition )
\r
2631 var regex = /^on([A-Z]\w+)/,
\r
2634 var registerDomEvent = function( uiElement, dialog, eventName, func )
\r
2636 dialog.on( 'load', function()
\r
2638 uiElement.getInputElement().on( eventName, func, uiElement );
\r
2642 for ( var i in definition )
\r
2644 if ( !( match = i.match( regex ) ) )
\r
2646 if ( this.eventProcessors[i] )
\r
2647 this.eventProcessors[i].call( this, this._.dialog, definition[i] );
\r
2649 registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
\r
2656 * The event processor list used by
\r
2657 * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element
\r
2658 * instantiation. The default list defines three on* events:
\r
2660 * <li>onLoad - Called when the element's parent dialog opens for the
\r
2662 * <li>onShow - Called whenever the element's parent dialog opens.</li>
\r
2663 * <li>onHide - Called whenever the element's parent dialog closes.</li>
\r
2668 * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick
\r
2669 * // handlers in the UI element's definitions.
\r
2670 * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},
\r
2671 * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
\r
2672 * { onClick : function( dialog, func ) { this.on( 'click', func ); } },
\r
2673 * true );
\r
2677 onLoad : function( dialog, func )
\r
2679 dialog.on( 'load', func, this );
\r
2682 onShow : function( dialog, func )
\r
2684 dialog.on( 'show', func, this );
\r
2687 onHide : function( dialog, func )
\r
2689 dialog.on( 'hide', func, this );
\r
2694 * The default handler for a UI element's access key down event, which
\r
2695 * tries to put focus to the UI element.<br />
\r
2696 * Can be overridded in child classes for more sophisticaed behavior.
\r
2697 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2698 * @param {String} key The key combination pressed. Since access keys
\r
2699 * are defined to always include the CTRL key, its value should always
\r
2700 * include a 'CTRL+' prefix.
\r
2703 accessKeyDown : function( dialog, key )
\r
2709 * The default handler for a UI element's access key up event, which
\r
2710 * does nothing.<br />
\r
2711 * Can be overridded in child classes for more sophisticated behavior.
\r
2712 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2713 * @param {String} key The key combination pressed. Since access keys
\r
2714 * are defined to always include the CTRL key, its value should always
\r
2715 * include a 'CTRL+' prefix.
\r
2718 accessKeyUp : function( dialog, key )
\r
2723 * Disables a UI element.
\r
2726 disable : function()
\r
2728 var element = this.getInputElement();
\r
2729 element.setAttribute( 'disabled', 'true' );
\r
2730 element.addClass( 'cke_disabled' );
\r
2734 * Enables a UI element.
\r
2737 enable : function()
\r
2739 var element = this.getInputElement();
\r
2740 element.removeAttribute( 'disabled' );
\r
2741 element.removeClass( 'cke_disabled' );
\r
2745 * Determines whether an UI element is enabled or not.
\r
2746 * @returns {Boolean} Whether the UI element is enabled.
\r
2749 isEnabled : function()
\r
2751 return !this.getInputElement().getAttribute( 'disabled' );
\r
2755 * Determines whether an UI element is visible or not.
\r
2756 * @returns {Boolean} Whether the UI element is visible.
\r
2759 isVisible : function()
\r
2761 return this.getInputElement().isVisible();
\r
2765 * Determines whether an UI element is focus-able or not.
\r
2766 * Focus-able is defined as being both visible and enabled.
\r
2767 * @returns {Boolean} Whether the UI element can be focused.
\r
2770 isFocusable : function()
\r
2772 if ( !this.isEnabled() || !this.isVisible() )
\r
2778 CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
\r
2780 * @lends CKEDITOR.ui.dialog.hbox.prototype
\r
2784 * Gets a child UI element inside this container.
\r
2785 * @param {Array|Number} indices An array or a single number to indicate the child's
\r
2786 * position in the container's descendant tree. Omit to get all the children in an array.
\r
2787 * @returns {Array|CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container
\r
2788 * if no argument given, or the specified UI element if indices is given.
\r
2790 * var checkbox = hbox.getChild( [0,1] );
\r
2791 * checkbox.setValue( true );
\r
2793 getChild : function( indices )
\r
2795 // If no arguments, return a clone of the children array.
\r
2796 if ( arguments.length < 1 )
\r
2797 return this._.children.concat();
\r
2799 // If indices isn't array, make it one.
\r
2800 if ( !indices.splice )
\r
2801 indices = [ indices ];
\r
2803 // Retrieve the child element according to tree position.
\r
2804 if ( indices.length < 2 )
\r
2805 return this._.children[ indices[0] ];
\r
2807 return ( this._.children[ indices[0] ] && this._.children[ indices[0] ].getChild ) ?
\r
2808 this._.children[ indices[0] ].getChild( indices.slice( 1, indices.length ) ) :
\r
2813 CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
\r
2819 var commonBuilder = {
\r
2820 build : function( dialog, elementDefinition, output )
\r
2822 var children = elementDefinition.children,
\r
2824 childHtmlList = [],
\r
2825 childObjList = [];
\r
2826 for ( var i = 0 ; ( i < children.length && ( child = children[i] ) ) ; i++ )
\r
2828 var childHtml = [];
\r
2829 childHtmlList.push( childHtml );
\r
2830 childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
\r
2832 return new CKEDITOR.ui.dialog[elementDefinition.type]( dialog, childObjList, childHtmlList, output, elementDefinition );
\r
2836 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
\r
2837 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
\r
2841 * Generic dialog command. It opens a specific dialog when executed.
\r
2843 * @augments CKEDITOR.commandDefinition
\r
2844 * @param {string} dialogName The name of the dialog to open when executing
\r
2847 * // Register the "link" command, which opens the "link" dialog.
\r
2848 * editor.addCommand( 'link', <b>new CKEDITOR.dialogCommand( 'link' )</b> );
\r
2850 CKEDITOR.dialogCommand = function( dialogName )
\r
2852 this.dialogName = dialogName;
\r
2855 CKEDITOR.dialogCommand.prototype =
\r
2858 exec : function( editor )
\r
2860 editor.openDialog( this.dialogName );
\r
2863 // Dialog commands just open a dialog ui, thus require no undo logic,
\r
2864 // undo support should dedicate to specific dialog implementation.
\r
2867 editorFocus : CKEDITOR.env.ie || CKEDITOR.env.webkit
\r
2872 var notEmptyRegex = /^([a]|[^a])+$/,
\r
2873 integerRegex = /^\d*$/,
\r
2874 numberRegex = /^\d*(?:\.\d+)?$/;
\r
2876 CKEDITOR.VALIDATE_OR = 1;
\r
2877 CKEDITOR.VALIDATE_AND = 2;
\r
2879 CKEDITOR.dialog.validate =
\r
2881 functions : function()
\r
2886 * It's important for validate functions to be able to accept the value
\r
2887 * as argument in addition to this.getValue(), so that it is possible to
\r
2888 * combine validate functions together to make more sophisticated
\r
2891 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
2893 var msg = undefined,
\r
2894 relation = CKEDITOR.VALIDATE_AND,
\r
2895 functions = [], i;
\r
2897 for ( i = 0 ; i < arguments.length ; i++ )
\r
2899 if ( typeof( arguments[i] ) == 'function' )
\r
2900 functions.push( arguments[i] );
\r
2905 if ( i < arguments.length && typeof( arguments[i] ) == 'string' )
\r
2907 msg = arguments[i];
\r
2911 if ( i < arguments.length && typeof( arguments[i]) == 'number' )
\r
2912 relation = arguments[i];
\r
2914 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );
\r
2915 for ( i = 0 ; i < functions.length ; i++ )
\r
2917 if ( relation == CKEDITOR.VALIDATE_AND )
\r
2918 passed = passed && functions[i]( value );
\r
2920 passed = passed || functions[i]( value );
\r
2925 if ( msg !== undefined )
\r
2927 if ( this && ( this.select || this.focus ) )
\r
2928 ( this.select || this.focus )();
\r
2936 regex : function( regex, msg )
\r
2939 * Can be greatly shortened by deriving from functions validator if code size
\r
2940 * turns out to be more important than performance.
\r
2944 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
2945 if ( !regex.test( value ) )
\r
2947 if ( msg !== undefined )
\r
2949 if ( this && ( this.select || this.focus ) )
\r
2951 if ( this.select )
\r
2962 notEmpty : function( msg )
\r
2964 return this.regex( notEmptyRegex, msg );
\r
2967 integer : function( msg )
\r
2969 return this.regex( integerRegex, msg );
\r
2972 'number' : function( msg )
\r
2974 return this.regex( numberRegex, msg );
\r
2977 equals : function( value, msg )
\r
2979 return this.functions( function( val ){ return val == value; }, msg );
\r
2982 notEqual : function( value, msg )
\r
2984 return this.functions( function( val ){ return val != value; }, msg );
\r
2988 CKEDITOR.on( 'instanceDestroyed', function( evt )
\r
2990 // Remove dialog cover on last instance destroy.
\r
2991 if ( CKEDITOR.tools.isEmpty( CKEDITOR.instances ) )
\r
2993 var currentTopDialog;
\r
2994 while ( ( currentTopDialog = CKEDITOR.dialog._.currentTop ) )
\r
2995 currentTopDialog.hide();
\r
2999 var dialogs = evt.editor._.storedDialogs;
\r
3000 for ( var name in dialogs )
\r
3001 dialogs[ name ].destroy();
\r
3007 // Extend the CKEDITOR.editor class with dialog specific functions.
\r
3008 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
\r
3009 /** @lends CKEDITOR.editor.prototype */
\r
3012 * Loads and opens a registered dialog.
\r
3013 * @param {String} dialogName The registered name of the dialog.
\r
3014 * @param {Function} callback The function to be invoked after dialog instance created.
\r
3015 * @see CKEDITOR.dialog.add
\r
3017 * CKEDITOR.instances.editor1.openDialog( 'smiley' );
\r
3018 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed. null if the dialog name is not registered.
\r
3020 openDialog : function( dialogName, callback )
\r
3022 if ( this.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
3024 var selection = this.getSelection();
\r
3025 selection && selection.lock();
\r
3028 var dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
3029 dialogSkin = this.skin.dialog;
\r
3031 if ( CKEDITOR.dialog._.currentTop === null )
\r
3032 showCover( this );
\r
3034 // If the dialogDefinition is already loaded, open it immediately.
\r
3035 if ( typeof dialogDefinitions == 'function' && dialogSkin._isLoaded )
\r
3037 var storedDialogs = this._.storedDialogs ||
\r
3038 ( this._.storedDialogs = {} );
\r
3040 var dialog = storedDialogs[ dialogName ] ||
\r
3041 ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
\r
3043 callback && callback.call( dialog, dialog );
\r
3048 else if ( dialogDefinitions == 'failed' )
\r
3051 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
\r
3056 function onDialogFileLoaded( success )
\r
3058 var dialogDefinition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
3059 skin = me.skin.dialog;
\r
3061 // Check if both skin part and definition is loaded.
\r
3062 if ( !skin._isLoaded || loadDefinition && typeof success == 'undefined' )
\r
3065 // In case of plugin error, mark it as loading failed.
\r
3066 if ( typeof dialogDefinition != 'function' )
\r
3067 CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';
\r
3069 me.openDialog( dialogName, callback );
\r
3072 if ( typeof dialogDefinitions == 'string' )
\r
3074 var loadDefinition = 1;
\r
3075 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ), onDialogFileLoaded, null, 0, 1 );
\r
3078 CKEDITOR.skins.load( this, 'dialog', onDialogFileLoaded );
\r
3085 CKEDITOR.plugins.add( 'dialog',
\r
3087 requires : [ 'dialogui' ]
\r
3090 // Dialog related configurations.
\r
3093 * The color of the dialog background cover. It should be a valid CSS color
\r
3095 * @name CKEDITOR.config.dialog_backgroundCoverColor
\r
3097 * @default 'white'
\r
3099 * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
\r
3103 * The opacity of the dialog background cover. It should be a number within the
\r
3104 * range [0.0, 1.0].
\r
3105 * @name CKEDITOR.config.dialog_backgroundCoverOpacity
\r
3109 * config.dialog_backgroundCoverOpacity = 0.7;
\r
3113 * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.
\r
3114 * @name CKEDITOR.config.dialog_startupFocusTab
\r
3118 * config.dialog_startupFocusTab = true;
\r
3122 * The distance of magnetic borders used in moving and resizing dialogs,
\r
3123 * measured in pixels.
\r
3124 * @name CKEDITOR.config.dialog_magnetDistance
\r
3128 * config.dialog_magnetDistance = 30;
\r
3132 * The guideline to follow when generating the dialog buttons. There are 3 possible options:
\r
3134 * <li>'OS' - the buttons will be displayed in the default order of the user's OS;</li>
\r
3135 * <li>'ltr' - for Left-To-Right order;</li>
\r
3136 * <li>'rtl' - for Right-To-Left order.</li>
\r
3138 * @name CKEDITOR.config.dialog_buttonsOrder
\r
3143 * config.dialog_buttonsOrder = 'rtl';
\r
3147 * The dialog contents to removed. It's a string composed by dialog name and tab name with a colon between them.
\r
3148 * Separate each pair with semicolon (see example).
\r
3149 * <b>Note: All names are case-sensitive.</b>
\r
3150 * <b>Note: Be cautious when specifying dialog tabs that are mandatory, like "info", dialog functionality might be broken because of this!</b>
\r
3151 * @name CKEDITOR.config.removeDialogTabs
\r
3156 * config.removeDialogTabs = 'flash:advanced;image:Link';
\r
3160 * Fired when a dialog definition is about to be used to create a dialog into
\r
3161 * an editor instance. This event makes it possible to customize the definition
\r
3162 * before creating it.
\r
3163 * <p>Note that this event is called only the first time a specific dialog is
\r
3164 * opened. Successive openings will use the cached dialog, and this event will
\r
3165 * not get fired.</p>
\r
3166 * @name CKEDITOR#dialogDefinition
\r
3168 * @param {CKEDITOR.dialog.definition} data The dialog defination that
\r
3169 * is being loaded.
\r
3170 * @param {CKEDITOR.editor} editor The editor instance that will use the
\r
3175 * Fired when a tab is going to be selected in a dialog
\r
3176 * @name CKEDITOR.dialog#selectPage
\r
3178 * @param {String} page The id of the page that it's gonna be selected.
\r
3179 * @param {String} currentPage The id of the current page.
\r
3183 * Fired when the user tries to dismiss a dialog
\r
3184 * @name CKEDITOR.dialog#cancel
\r
3186 * @param {Boolean} hide Whether the event should proceed or not.
\r
3190 * Fired when the user tries to confirm a dialog
\r
3191 * @name CKEDITOR.dialog#ok
\r
3193 * @param {Boolean} hide Whether the event should proceed or not.
\r
3197 * Fired when a dialog is shown
\r
3198 * @name CKEDITOR.dialog#show
\r
3203 * Fired when a dialog is shown
\r
3204 * @name CKEDITOR.editor#dialogShow
\r
3209 * Fired when a dialog is hidden
\r
3210 * @name CKEDITOR.dialog#hide
\r
3215 * Fired when a dialog is hidden
\r
3216 * @name CKEDITOR.editor#dialogHide
\r
3221 * Fired when a dialog is being resized. The event is fired on
\r
3222 * both the 'CKEDITOR.dialog' object and the dialog instance
\r
3223 * since 3.5.3, previously it's available only in the global object.
\r
3224 * @name CKEDITOR.dialog#resize
\r
3227 * @param {CKEDITOR.dialog} dialog The dialog being resized (if
\r
3228 * it's fired on the dialog itself, this parameter isn't sent).
\r
3229 * @param {String} skin The skin name.
\r
3230 * @param {Number} width The new width.
\r
3231 * @param {Number} height The new height.
\r