2 Copyright (c) 2003-2010, 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 function isTabVisible( tabId )
\r
38 return !!this._.tabs[ tabId ][ 0 ].$.offsetHeight;
\r
41 function getPreviousVisibleTab()
\r
43 var tabId = this._.currentTabId,
\r
44 length = this._.tabIdList.length,
\r
45 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId ) + length;
\r
47 for ( var i = tabIndex - 1 ; i > tabIndex - length ; i-- )
\r
49 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
\r
50 return this._.tabIdList[ i % length ];
\r
56 function getNextVisibleTab()
\r
58 var tabId = this._.currentTabId,
\r
59 length = this._.tabIdList.length,
\r
60 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId );
\r
62 for ( var i = tabIndex + 1 ; i < tabIndex + length ; i++ )
\r
64 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
\r
65 return this._.tabIdList[ i % length ];
\r
72 function clearOrRecoverTextInputValue( container, isRecover )
\r
74 var inputs = container.$.getElementsByTagName( 'input' );
\r
75 for ( var i = 0, length = inputs.length; i < length ; i++ )
\r
77 var item = new CKEDITOR.dom.element( inputs[ i ] );
\r
79 if ( item.getAttribute( 'type' ).toLowerCase() == 'text' )
\r
83 item.setAttribute( 'value', item.getCustomData( 'fake_value' ) || '' );
\r
84 item.removeCustomData( 'fake_value' );
\r
88 item.setCustomData( 'fake_value', item.getAttribute( 'value' ) );
\r
89 item.setAttribute( 'value', '' );
\r
96 * This is the base class for runtime dialog objects. An instance of this
\r
97 * class represents a single named dialog for a single editor instance.
\r
98 * @param {Object} editor The editor which created the dialog.
\r
99 * @param {String} dialogName The dialog's registered name.
\r
102 * var dialogObj = new CKEDITOR.dialog( editor, 'smiley' );
\r
104 CKEDITOR.dialog = function( editor, dialogName )
\r
106 // Load the dialog definition.
\r
107 var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];
\r
109 // Completes the definition with the default values.
\r
110 definition = CKEDITOR.tools.extend( definition( editor ), defaultDialogDefinition );
\r
112 // Clone a functionally independent copy for this dialog.
\r
113 definition = CKEDITOR.tools.clone( definition );
\r
115 // Create a complex definition object, extending it with the API
\r
117 definition = new definitionObject( this, definition );
\r
120 var doc = CKEDITOR.document;
\r
122 var themeBuilt = editor.theme.buildDialog( editor );
\r
124 // Initialize some basic parameters.
\r
128 element : themeBuilt.element,
\r
130 contentSize : { width : 0, height : 0 },
\r
131 size : { width : 0, height : 0 },
\r
132 updateSize : false,
\r
137 // Initialize the tab and page map.
\r
140 currentTabId : null,
\r
141 currentTabIndex : null,
\r
144 tabBarMode : false,
\r
146 // Initialize the tab order array for input widgets.
\r
148 currentFocusIndex : 0,
\r
152 this.parts = themeBuilt.parts;
\r
154 CKEDITOR.tools.setTimeout( function()
\r
156 editor.fire( 'ariaWidget', this.parts.contents );
\r
160 // Set the startup styles for the dialog, avoiding it enlarging the
\r
161 // page size on the dialog creation.
\r
162 this.parts.dialog.setStyles(
\r
164 position : CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed',
\r
167 visibility : 'hidden'
\r
170 // Call the CKEDITOR.event constructor to initialize this instance.
\r
171 CKEDITOR.event.call( this );
\r
173 // Fire the "dialogDefinition" event, making it possible to customize
\r
174 // the dialog definition.
\r
175 this.definition = definition = CKEDITOR.fire( 'dialogDefinition',
\r
178 definition : definition
\r
180 , editor ).definition;
\r
181 // Initialize load, show, hide, ok and cancel events.
\r
182 if ( definition.onLoad )
\r
183 this.on( 'load', definition.onLoad );
\r
185 if ( definition.onShow )
\r
186 this.on( 'show', definition.onShow );
\r
188 if ( definition.onHide )
\r
189 this.on( 'hide', definition.onHide );
\r
191 if ( definition.onOk )
\r
193 this.on( 'ok', function( evt )
\r
195 // Dialog confirm might probably introduce content changes (#5415).
\r
196 editor.fire( 'saveSnapshot' );
\r
197 setTimeout( function () { editor.fire( 'saveSnapshot' ); }, 0 );
\r
198 if ( definition.onOk.call( this, evt ) === false )
\r
199 evt.data.hide = false;
\r
203 if ( definition.onCancel )
\r
205 this.on( 'cancel', function( evt )
\r
207 if ( definition.onCancel.call( this, evt ) === false )
\r
208 evt.data.hide = false;
\r
214 // Iterates over all items inside all content in the dialog, calling a
\r
215 // function for each of them.
\r
216 var iterContents = function( func )
\r
218 var contents = me._.contents,
\r
221 for ( var i in contents )
\r
223 for ( var j in contents[i] )
\r
225 stop = func.call( this, contents[i][j] );
\r
232 this.on( 'ok', function( evt )
\r
234 iterContents( function( item )
\r
236 if ( item.validate )
\r
238 var isValid = item.validate( this );
\r
240 if ( typeof isValid == 'string' )
\r
246 if ( isValid === false )
\r
253 evt.data.hide = false;
\r
259 }, this, null, 0 );
\r
261 this.on( 'cancel', function( evt )
\r
263 iterContents( function( item )
\r
265 if ( item.isChanged() )
\r
267 if ( !confirm( editor.lang.common.confirmCancel ) )
\r
268 evt.data.hide = false;
\r
272 }, this, null, 0 );
\r
274 this.parts.close.on( 'click', function( evt )
\r
276 if ( this.fire( 'cancel', { hide : true } ).hide !== false )
\r
278 evt.data.preventDefault();
\r
281 // Sort focus list according to tab order definitions.
\r
282 function setupFocus()
\r
284 var focusList = me._.focusList;
\r
285 focusList.sort( function( a, b )
\r
287 // Mimics browser tab order logics;
\r
288 if ( a.tabIndex != b.tabIndex )
\r
289 return b.tabIndex - a.tabIndex;
\r
290 // Sort is not stable in some browsers,
\r
291 // fall-back the comparator to 'focusIndex';
\r
293 return a.focusIndex - b.focusIndex;
\r
296 var size = focusList.length;
\r
297 for ( var i = 0; i < size; i++ )
\r
298 focusList[ i ].focusIndex = i;
\r
301 function changeFocus( forward )
\r
303 var focusList = me._.focusList,
\r
304 offset = forward ? 1 : -1;
\r
305 if ( focusList.length < 1 )
\r
308 var current = me._.currentFocusIndex;
\r
310 // Trigger the 'blur' event of any input element before anything,
\r
311 // since certain UI updates may depend on it.
\r
314 focusList[ current ].getInputElement().$.blur();
\r
318 var startIndex = ( current + offset + focusList.length ) % focusList.length,
\r
319 currentIndex = startIndex;
\r
320 while ( !focusList[ currentIndex ].isFocusable() )
\r
322 currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length;
\r
323 if ( currentIndex == startIndex )
\r
326 focusList[ currentIndex ].focus();
\r
328 // Select whole field content.
\r
329 if ( focusList[ currentIndex ].type == 'text' )
\r
330 focusList[ currentIndex ].select();
\r
333 this.changeFocus = changeFocus;
\r
337 function focusKeydownHandler( evt )
\r
339 // If I'm not the top dialog, ignore.
\r
340 if ( me != CKEDITOR.dialog._.currentTop )
\r
343 var keystroke = evt.data.getKeystroke(),
\r
344 rtl = editor.lang.dir == 'rtl';
\r
347 if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )
\r
349 var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
\r
351 // Handling Tab and Shift-Tab.
\r
352 if ( me._.tabBarMode )
\r
355 var nextId = shiftPressed ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );
\r
356 me.selectPage( nextId );
\r
357 me._.tabs[ nextId ][ 0 ].focus();
\r
361 // Change the focus of inputs.
\r
362 changeFocus( !shiftPressed );
\r
367 else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode && me.getPageCount() > 1 )
\r
369 // Alt-F10 puts focus into the current tab item in the tab bar.
\r
370 me._.tabBarMode = true;
\r
371 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
374 else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode )
\r
376 // Arrow keys - used for changing tabs.
\r
377 nextId = ( keystroke == ( rtl ? 39 : 37 ) ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) );
\r
378 me.selectPage( nextId );
\r
379 me._.tabs[ nextId ][ 0 ].focus();
\r
382 else if ( ( keystroke == 13 || keystroke == 32 ) && me._.tabBarMode )
\r
384 this.selectPage( this._.currentTabId );
\r
385 this._.tabBarMode = false;
\r
386 this._.currentFocusIndex = -1;
\r
387 changeFocus( true );
\r
394 evt.data.preventDefault();
\r
398 function focusKeyPressHandler( evt )
\r
400 processed && evt.data.preventDefault();
\r
403 var dialogElement = this._.element;
\r
404 // Add the dialog keyboard handlers.
\r
405 this.on( 'show', function()
\r
407 dialogElement.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
408 // Some browsers instead, don't cancel key events in the keydown, but in the
\r
409 // keypress. So we must do a longer trip in those cases. (#4531)
\r
410 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
411 dialogElement.on( 'keypress', focusKeyPressHandler, this );
\r
414 this.on( 'hide', function()
\r
416 dialogElement.removeListener( 'keydown', focusKeydownHandler );
\r
417 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
418 dialogElement.removeListener( 'keypress', focusKeyPressHandler );
\r
420 this.on( 'iframeAdded', function( evt )
\r
422 var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );
\r
423 doc.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
426 // Auto-focus logic in dialog.
\r
427 this.on( 'show', function()
\r
429 // Setup tabIndex on showing the dialog instead of on loading
\r
430 // to allow dynamic tab order happen in dialog definition.
\r
433 if ( editor.config.dialog_startupFocusTab
\r
434 && me._.pageCount > 1 )
\r
436 me._.tabBarMode = true;
\r
437 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
439 else if ( !this._.hasFocus )
\r
441 this._.currentFocusIndex = -1;
\r
443 // Decide where to put the initial focus.
\r
444 if ( definition.onFocus )
\r
446 var initialFocus = definition.onFocus.call( this );
\r
447 // Focus the field that the user specified.
\r
448 initialFocus && initialFocus.focus();
\r
450 // Focus the first field in layout order.
\r
452 changeFocus( true );
\r
455 * IE BUG: If the initial focus went into a non-text element (e.g. button),
\r
456 * then IE would still leave the caret inside the editing area.
\r
458 if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
460 var $selection = editor.document.$.selection,
\r
461 $range = $selection.createRange();
\r
465 if ( $range.parentElement && $range.parentElement().ownerDocument == editor.document.$
\r
466 || $range.item && $range.item( 0 ).ownerDocument == editor.document.$ )
\r
468 var $myRange = document.body.createTextRange();
\r
469 $myRange.moveToElementText( this.getElement().getFirst().$ );
\r
470 $myRange.collapse( true );
\r
476 }, this, null, 0xffffffff );
\r
478 // IE6 BUG: Text fields and text areas are only half-rendered the first time the dialog appears in IE6 (#2661).
\r
479 // This is still needed after [2708] and [2709] because text fields in hidden TR tags are still broken.
\r
480 if ( CKEDITOR.env.ie6Compat )
\r
482 this.on( 'load', function( evt )
\r
484 var outer = this.getElement(),
\r
485 inner = outer.getFirst();
\r
487 inner.appendTo( outer );
\r
491 initDragAndDrop( this );
\r
492 initResizeHandles( this );
\r
494 // Insert the title.
\r
495 ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );
\r
497 // Insert the tabs and contents.
\r
498 for ( var i = 0 ; i < definition.contents.length ; i++ )
\r
500 var page = definition.contents[i];
\r
501 page && this.addPage( page );
\r
504 this.parts['tabs'].on( 'click', function( evt )
\r
506 var target = evt.data.getTarget();
\r
507 // If we aren't inside a tab, bail out.
\r
508 if ( target.hasClass( 'cke_dialog_tab' ) )
\r
510 // Get the ID of the tab, without the 'cke_' prefix and the unique number suffix.
\r
511 var id = target.$.id;
\r
512 this.selectPage( id.substring( 4, id.lastIndexOf( '_' ) ) );
\r
514 if ( this._.tabBarMode )
\r
516 this._.tabBarMode = false;
\r
517 this._.currentFocusIndex = -1;
\r
518 changeFocus( true );
\r
520 evt.data.preventDefault();
\r
525 var buttonsHtml = [],
\r
526 buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this,
\r
529 className : 'cke_dialog_footer_buttons',
\r
531 children : definition.buttons
\r
532 }, buttonsHtml ).getChild();
\r
533 this.parts.footer.setHtml( buttonsHtml.join( '' ) );
\r
535 for ( i = 0 ; i < buttons.length ; i++ )
\r
536 this._.buttons[ buttons[i].id ] = buttons[i];
\r
539 // Focusable interface. Use it via dialog.addFocusable.
\r
540 function Focusable( dialog, element, index )
\r
542 this.element = element;
\r
543 this.focusIndex = index;
\r
544 // TODO: support tabIndex for focusables.
\r
546 this.isFocusable = function()
\r
548 return !element.getAttribute( 'disabled' ) && element.isVisible();
\r
550 this.focus = function()
\r
552 dialog._.currentFocusIndex = this.focusIndex;
\r
553 this.element.focus();
\r
556 element.on( 'keydown', function( e )
\r
558 if ( e.data.getKeystroke() in { 32:1, 13:1 } )
\r
559 this.fire( 'click' );
\r
561 element.on( 'focus', function()
\r
563 this.fire( 'mouseover' );
\r
565 element.on( 'blur', function()
\r
567 this.fire( 'mouseout' );
\r
571 CKEDITOR.dialog.prototype =
\r
573 destroy : function()
\r
576 this._.element.remove();
\r
580 * Resizes the dialog.
\r
581 * @param {Number} width The width of the dialog in pixels.
\r
582 * @param {Number} height The height of the dialog in pixels.
\r
585 * dialogObj.resize( 800, 640 );
\r
587 resize : (function()
\r
589 return function( width, height )
\r
591 if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )
\r
594 CKEDITOR.dialog.fire( 'resize',
\r
597 skin : this._.editor.skinName,
\r
600 }, this._.editor );
\r
602 this._.contentSize = { width : width, height : height };
\r
603 this._.updateSize = true;
\r
608 * Gets the current size of the dialog in pixels.
\r
609 * @returns {Object} An object with "width" and "height" properties.
\r
611 * var width = dialogObj.getSize().width;
\r
613 getSize : function()
\r
615 if ( !this._.updateSize )
\r
616 return this._.size;
\r
617 var element = this._.element.getFirst();
\r
618 var size = this._.size = { width : element.$.offsetWidth || 0, height : element.$.offsetHeight || 0};
\r
620 // If either the offsetWidth or offsetHeight is 0, the element isn't visible.
\r
621 this._.updateSize = !size.width || !size.height;
\r
627 * Moves the dialog to an (x, y) coordinate relative to the window.
\r
629 * @param {Number} x The target x-coordinate.
\r
630 * @param {Number} y The target y-coordinate.
\r
632 * dialogObj.move( 10, 40 );
\r
637 return function( x, y )
\r
639 // The dialog may be fixed positioned or absolute positioned. Ask the
\r
640 // browser what is the current situation first.
\r
641 var element = this._.element.getFirst();
\r
642 if ( isFixed === undefined )
\r
643 isFixed = element.getComputedStyle( 'position' ) == 'fixed';
\r
645 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
\r
648 // Save the current position.
\r
649 this._.position = { x : x, y : y };
\r
651 // If not fixed positioned, add scroll position to the coordinates.
\r
654 var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
\r
655 x += scrollPosition.x;
\r
656 y += scrollPosition.y;
\r
661 'left' : ( x > 0 ? x : 0 ) + 'px',
\r
662 'top' : ( y > 0 ? y : 0 ) + 'px'
\r
668 * Gets the dialog's position in the window.
\r
669 * @returns {Object} An object with "x" and "y" properties.
\r
671 * var dialogX = dialogObj.getPosition().x;
\r
673 getPosition : function(){ return CKEDITOR.tools.extend( {}, this._.position ); },
\r
676 * Shows the dialog box.
\r
678 * dialogObj.show();
\r
682 var editor = this._.editor;
\r
683 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
685 var selection = editor.getSelection();
\r
686 selection && selection.lock();
\r
689 // Insert the dialog's element to the root document.
\r
690 var element = this._.element;
\r
691 var definition = this.definition;
\r
692 if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )
\r
693 element.appendTo( CKEDITOR.document.getBody() );
\r
695 element.setStyle( 'display', 'block' );
\r
697 // FIREFOX BUG: Fix vanishing caret for Firefox 2 or Gecko 1.8.
\r
698 if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
\r
700 var dialogElement = this.parts.dialog;
\r
701 dialogElement.setStyle( 'position', 'absolute' );
\r
702 setTimeout( function()
\r
704 dialogElement.setStyle( 'position', 'fixed' );
\r
709 // First, set the dialog to an appropriate size.
\r
710 this.resize( definition.minWidth, definition.minHeight );
\r
712 // Reset all inputs back to their default value.
\r
715 // Select the first tab by default.
\r
716 this.selectPage( this.definition.contents[0].id );
\r
719 if ( CKEDITOR.dialog._.currentZIndex === null )
\r
720 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;
\r
721 this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
\r
723 // Maintain the dialog ordering and dialog cover.
\r
724 // Also register key handlers if first dialog.
\r
725 if ( CKEDITOR.dialog._.currentTop === null )
\r
727 CKEDITOR.dialog._.currentTop = this;
\r
728 this._.parentDialog = null;
\r
729 showCover( this._.editor );
\r
731 element.on( 'keydown', accessKeyDownHandler );
\r
732 element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
734 // Prevent some keys from bubbling up. (#4269)
\r
735 for ( var event in { keyup :1, keydown :1, keypress :1 } )
\r
736 element.on( event, preventKeyBubbling );
\r
740 this._.parentDialog = CKEDITOR.dialog._.currentTop;
\r
741 var parentElement = this._.parentDialog.getElement().getFirst();
\r
742 parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );
\r
743 CKEDITOR.dialog._.currentTop = this;
\r
746 // Register the Esc hotkeys.
\r
747 registerAccessKey( this, this, '\x1b', null, function()
\r
749 this.getButton( 'cancel' ) && this.getButton( 'cancel' ).click();
\r
752 // Reset the hasFocus state.
\r
753 this._.hasFocus = false;
\r
755 // Rearrange the dialog to the middle of the window.
\r
756 CKEDITOR.tools.setTimeout( function()
\r
758 var viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
\r
759 var dialogSize = this.getSize();
\r
761 // We're using definition size for initial position because of
\r
762 // offten corrupted data in offsetWidth at this point. (#4084)
\r
763 this.move( ( viewSize.width - definition.minWidth ) / 2, ( viewSize.height - dialogSize.height ) / 2 );
\r
765 this.parts.dialog.setStyle( 'visibility', '' );
\r
767 // Execute onLoad for the first show.
\r
768 this.fireOnce( 'load', {} );
\r
769 this.fire( 'show', {} );
\r
770 this._.editor.fire( 'dialogShow', this );
\r
772 // Save the initial values of the dialog.
\r
773 this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } );
\r
780 * Executes a function for each UI element.
\r
781 * @param {Function} fn Function to execute for each UI element.
\r
782 * @returns {CKEDITOR.dialog} The current dialog object.
\r
784 foreach : function( fn )
\r
786 for ( var i in this._.contents )
\r
788 for ( var j in this._.contents[i] )
\r
789 fn( this._.contents[i][j] );
\r
795 * Resets all input values in the dialog.
\r
797 * dialogObj.reset();
\r
798 * @returns {CKEDITOR.dialog} The current dialog object.
\r
800 reset : (function()
\r
802 var fn = function( widget ){ if ( widget.reset ) widget.reset( 1 ); };
\r
803 return function(){ this.foreach( fn ); return this; };
\r
806 setupContent : function()
\r
808 var args = arguments;
\r
809 this.foreach( function( widget )
\r
811 if ( widget.setup )
\r
812 widget.setup.apply( widget, args );
\r
816 commitContent : function()
\r
818 var args = arguments;
\r
819 this.foreach( function( widget )
\r
821 if ( widget.commit )
\r
822 widget.commit.apply( widget, args );
\r
827 * Hides the dialog box.
\r
829 * dialogObj.hide();
\r
833 if ( !this.parts.dialog.isVisible() )
\r
836 this.fire( 'hide', {} );
\r
837 this._.editor.fire( 'dialogHide', this );
\r
838 var element = this._.element;
\r
839 element.setStyle( 'display', 'none' );
\r
840 this.parts.dialog.setStyle( 'visibility', 'hidden' );
\r
841 // Unregister all access keys associated with this dialog.
\r
842 unregisterAccessKey( this );
\r
844 // Close any child(top) dialogs first.
\r
845 while( CKEDITOR.dialog._.currentTop != this )
\r
846 CKEDITOR.dialog._.currentTop.hide();
\r
848 // Maintain dialog ordering and remove cover if needed.
\r
849 if ( !this._.parentDialog )
\r
853 var parentElement = this._.parentDialog.getElement().getFirst();
\r
854 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
\r
856 CKEDITOR.dialog._.currentTop = this._.parentDialog;
\r
858 // Deduct or clear the z-index.
\r
859 if ( !this._.parentDialog )
\r
861 CKEDITOR.dialog._.currentZIndex = null;
\r
863 // Remove access key handlers.
\r
864 element.removeListener( 'keydown', accessKeyDownHandler );
\r
865 element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
867 // Remove bubbling-prevention handler. (#4269)
\r
868 for ( var event in { keyup :1, keydown :1, keypress :1 } )
\r
869 element.removeListener( event, preventKeyBubbling );
\r
871 var editor = this._.editor;
\r
874 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
876 var selection = editor.getSelection();
\r
877 selection && selection.unlock( true );
\r
881 CKEDITOR.dialog._.currentZIndex -= 10;
\r
883 delete this._.parentDialog;
\r
884 // Reset the initial values of the dialog.
\r
885 this.foreach( function( contentObj ) { contentObj.resetInitValue && contentObj.resetInitValue(); } );
\r
889 * Adds a tabbed page into the dialog.
\r
890 * @param {Object} contents Content definition.
\r
893 addPage : function( contents )
\r
896 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
\r
897 elements = contents.elements,
\r
898 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this,
\r
901 className : 'cke_dialog_page_contents',
\r
902 children : contents.elements,
\r
903 expand : !!contents.expand,
\r
904 padding : contents.padding,
\r
905 style : contents.style || 'width: 100%; height: 100%;'
\r
908 // Create the HTML for the tab and the content block.
\r
909 var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
\r
910 page.setAttribute( 'role', 'tabpanel' );
\r
912 var env = CKEDITOR.env;
\r
913 var tabId = 'cke_' + contents.id + '_' + CKEDITOR.tools.getNextNumber(),
\r
914 tab = CKEDITOR.dom.element.createFromHtml( [
\r
915 '<a class="cke_dialog_tab"',
\r
916 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),
\r
918 ( !!contents.hidden ? ' style="display:none"' : '' ),
\r
919 ' id="', tabId, '"',
\r
920 env.gecko && env.version >= 10900 && !env.hc ? '' : ' href="javascript:void(0)"',
\r
922 ' hidefocus="true"',
\r
928 page.setAttribute( 'aria-labelledby', tabId );
\r
930 // Take records for the tabs and elements created.
\r
931 this._.tabs[ contents.id ] = [ tab, page ];
\r
932 this._.tabIdList.push( contents.id );
\r
933 !contents.hidden && this._.pageCount++;
\r
934 this._.lastTab = tab;
\r
935 this.updateStyle();
\r
937 var contentMap = this._.contents[ contents.id ] = {},
\r
939 children = vbox.getChild();
\r
941 while ( ( cursor = children.shift() ) )
\r
943 contentMap[ cursor.id ] = cursor;
\r
944 if ( typeof( cursor.getChild ) == 'function' )
\r
945 children.push.apply( children, cursor.getChild() );
\r
948 // Attach the DOM nodes.
\r
950 page.setAttribute( 'name', contents.id );
\r
951 page.appendTo( this.parts.contents );
\r
953 tab.unselectable();
\r
954 this.parts.tabs.append( tab );
\r
956 // Add access key handlers if access key is defined.
\r
957 if ( contents.accessKey )
\r
959 registerAccessKey( this, this, 'CTRL+' + contents.accessKey,
\r
960 tabAccessKeyDown, tabAccessKeyUp );
\r
961 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;
\r
966 * Activates a tab page in the dialog by its id.
\r
967 * @param {String} id The id of the dialog tab to be activated.
\r
969 * dialogObj.selectPage( 'tab_1' );
\r
971 selectPage : function( id )
\r
973 if ( this._.currentTabId == id )
\r
976 // Returning true means that the event has been canceled
\r
977 if ( this.fire( 'selectPage', { page : id, currentPage : this._.currentTabId } ) === true )
\r
980 // Hide the non-selected tabs and pages.
\r
981 for ( var i in this._.tabs )
\r
983 var tab = this._.tabs[i][0],
\r
984 page = this._.tabs[i][1];
\r
987 tab.removeClass( 'cke_dialog_tab_selected' );
\r
990 page.setAttribute( 'aria-hidden', i != id );
\r
993 var selected = this._.tabs[id];
\r
994 selected[0].addClass( 'cke_dialog_tab_selected' );
\r
996 // [IE] a unvisible input[type='text'] will enlarge it's width
\r
997 // if it's value is long when it show( #5649 )
\r
998 // so we clear it's value before it shows and then recover it
\r
999 if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat )
\r
1001 clearOrRecoverTextInputValue( selected[1] );
\r
1002 selected[1].show();
\r
1003 setTimeout( function()
\r
1005 clearOrRecoverTextInputValue( selected[1], true );
\r
1010 selected[1].show();
\r
1014 this._.currentTabId = id;
\r
1015 this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
\r
1018 // Dialog state-specific style updates.
\r
1019 updateStyle : function()
\r
1021 // If only a single page shown, a different style is used in the central pane.
\r
1022 this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );
\r
1026 * Hides a page's tab away from the dialog.
\r
1027 * @param {String} id The page's Id.
\r
1029 * dialog.hidePage( 'tab_3' );
\r
1031 hidePage : function( id )
\r
1033 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
1034 if ( !tab || this._.pageCount == 1 )
\r
1036 // Switch to other tab first when we're hiding the active tab.
\r
1037 else if ( id == this._.currentTabId )
\r
1038 this.selectPage( getPreviousVisibleTab.call( this ) );
\r
1041 this._.pageCount--;
\r
1042 this.updateStyle();
\r
1046 * Unhides a page's tab.
\r
1047 * @param {String} id The page's Id.
\r
1049 * dialog.showPage( 'tab_2' );
\r
1051 showPage : function( id )
\r
1053 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
1057 this._.pageCount++;
\r
1058 this.updateStyle();
\r
1062 * Gets the root DOM element of the dialog.
\r
1063 * @returns {CKEDITOR.dom.element} The <span> element containing this dialog.
\r
1065 * var dialogElement = dialogObj.getElement().getFirst();
\r
1066 * dialogElement.setStyle( 'padding', '5px' );
\r
1068 getElement : function()
\r
1070 return this._.element;
\r
1074 * Gets the name of the dialog.
\r
1075 * @returns {String} The name of this dialog.
\r
1077 * var dialogName = dialogObj.getName();
\r
1079 getName : function()
\r
1081 return this._.name;
\r
1085 * Gets a dialog UI element object from a dialog page.
\r
1086 * @param {String} pageId id of dialog page.
\r
1087 * @param {String} elementId id of UI element.
\r
1089 * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.
\r
1091 getContentElement : function( pageId, elementId )
\r
1093 var page = this._.contents[ pageId ];
\r
1094 return page && page[ elementId ];
\r
1098 * Gets the value of a dialog UI element.
\r
1099 * @param {String} pageId id of dialog page.
\r
1100 * @param {String} elementId id of UI element.
\r
1102 * @returns {Object} The value of the UI element.
\r
1104 getValueOf : function( pageId, elementId )
\r
1106 return this.getContentElement( pageId, elementId ).getValue();
\r
1110 * Sets the value of a dialog UI element.
\r
1111 * @param {String} pageId id of the dialog page.
\r
1112 * @param {String} elementId id of the UI element.
\r
1113 * @param {Object} value The new value of the UI element.
\r
1116 setValueOf : function( pageId, elementId, value )
\r
1118 return this.getContentElement( pageId, elementId ).setValue( value );
\r
1122 * Gets the UI element of a button in the dialog's button row.
\r
1123 * @param {String} id The id of the button.
\r
1125 * @returns {CKEDITOR.ui.dialog.button} The button object.
\r
1127 getButton : function( id )
\r
1129 return this._.buttons[ id ];
\r
1133 * Simulates a click to a dialog button in the dialog's button row.
\r
1134 * @param {String} id The id of the button.
\r
1136 * @returns The return value of the dialog's "click" event.
\r
1138 click : function( id )
\r
1140 return this._.buttons[ id ].click();
\r
1144 * Disables a dialog button.
\r
1145 * @param {String} id The id of the button.
\r
1148 disableButton : function( id )
\r
1150 return this._.buttons[ id ].disable();
\r
1154 * Enables a dialog button.
\r
1155 * @param {String} id The id of the button.
\r
1158 enableButton : function( id )
\r
1160 return this._.buttons[ id ].enable();
\r
1164 * Gets the number of pages in the dialog.
\r
1165 * @returns {Number} Page count.
\r
1167 getPageCount : function()
\r
1169 return this._.pageCount;
\r
1173 * Gets the editor instance which opened this dialog.
\r
1174 * @returns {CKEDITOR.editor} Parent editor instances.
\r
1176 getParentEditor : function()
\r
1178 return this._.editor;
\r
1182 * Gets the element that was selected when opening the dialog, if any.
\r
1183 * @returns {CKEDITOR.dom.element} The element that was selected, or null.
\r
1185 getSelectedElement : function()
\r
1187 return this.getParentEditor().getSelection().getSelectedElement();
\r
1191 * Adds element to dialog's focusable list.
\r
1193 * @param {CKEDITOR.dom.element} element
\r
1194 * @param {Number} [index]
\r
1196 addFocusable: function( element, index ) {
\r
1197 if ( typeof index == 'undefined' )
\r
1199 index = this._.focusList.length;
\r
1200 this._.focusList.push( new Focusable( this, element, index ) );
\r
1204 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );
\r
1205 for ( var i = index + 1 ; i < this._.focusList.length ; i++ )
\r
1206 this._.focusList[ i ].focusIndex++;
\r
1211 CKEDITOR.tools.extend( CKEDITOR.dialog,
\r
1213 * @lends CKEDITOR.dialog
\r
1217 * Registers a dialog.
\r
1218 * @param {String} name The dialog's name.
\r
1219 * @param {Function|String} dialogDefinition
\r
1220 * A function returning the dialog's definition, or the URL to the .js file holding the function.
\r
1221 * The function should accept an argument "editor" which is the current editor instance, and
\r
1222 * return an object conforming to {@link CKEDITOR.dialog.dialogDefinition}.
\r
1224 * @see CKEDITOR.dialog.dialogDefinition
\r
1226 add : function( name, dialogDefinition )
\r
1228 // Avoid path registration from multiple instances override definition.
\r
1229 if ( !this._.dialogDefinitions[name]
\r
1230 || typeof dialogDefinition == 'function' )
\r
1231 this._.dialogDefinitions[name] = dialogDefinition;
\r
1234 exists : function( name )
\r
1236 return !!this._.dialogDefinitions[ name ];
\r
1239 getCurrent : function()
\r
1241 return CKEDITOR.dialog._.currentTop;
\r
1245 * The default OK button for dialogs. Fires the "ok" event and closes the dialog if the event succeeds.
\r
1251 okButton : (function()
\r
1253 var retval = function( editor, override )
\r
1255 override = override || {};
\r
1256 return CKEDITOR.tools.extend( {
\r
1259 label : editor.lang.common.ok,
\r
1260 'class' : 'cke_dialog_ui_button_ok',
\r
1261 onClick : function( evt )
\r
1263 var dialog = evt.data.dialog;
\r
1264 if ( dialog.fire( 'ok', { hide : true } ).hide !== false )
\r
1267 }, override, true );
\r
1269 retval.type = 'button';
\r
1270 retval.override = function( override )
\r
1272 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1273 { type : 'button' }, true );
\r
1279 * The default cancel button for dialogs. Fires the "cancel" event and closes the dialog if no UI element value changed.
\r
1285 cancelButton : (function()
\r
1287 var retval = function( editor, override )
\r
1289 override = override || {};
\r
1290 return CKEDITOR.tools.extend( {
\r
1293 label : editor.lang.common.cancel,
\r
1294 'class' : 'cke_dialog_ui_button_cancel',
\r
1295 onClick : function( evt )
\r
1297 var dialog = evt.data.dialog;
\r
1298 if ( dialog.fire( 'cancel', { hide : true } ).hide !== false )
\r
1301 }, override, true );
\r
1303 retval.type = 'button';
\r
1304 retval.override = function( override )
\r
1306 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1307 { type : 'button' }, true );
\r
1313 * Registers a dialog UI element.
\r
1314 * @param {String} typeName The name of the UI element.
\r
1315 * @param {Function} builder The function to build the UI element.
\r
1318 addUIElement : function( typeName, builder )
\r
1320 this._.uiElementBuilders[ typeName ] = builder;
\r
1324 CKEDITOR.dialog._ =
\r
1326 uiElementBuilders : {},
\r
1328 dialogDefinitions : {},
\r
1330 currentTop : null,
\r
1332 currentZIndex : null
\r
1335 // "Inherit" (copy actually) from CKEDITOR.event.
\r
1336 CKEDITOR.event.implementOn( CKEDITOR.dialog );
\r
1337 CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype, true );
\r
1339 var defaultDialogDefinition =
\r
1341 resizable : CKEDITOR.DIALOG_RESIZE_BOTH,
\r
1344 buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
\r
1347 // The buttons in MacOS Apps are in reverse order #4750
\r
1348 CKEDITOR.env.mac && defaultDialogDefinition.buttons.reverse();
\r
1350 // Tool function used to return an item from an array based on its id
\r
1352 var getById = function( array, id, recurse )
\r
1354 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1356 if ( item.id == id )
\r
1358 if ( recurse && item[ recurse ] )
\r
1360 var retval = getById( item[ recurse ], id, recurse ) ;
\r
1368 // Tool function used to add an item into an array.
\r
1369 var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound )
\r
1371 if ( nextSiblingId )
\r
1373 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1375 if ( item.id == nextSiblingId )
\r
1377 array.splice( i, 0, newItem );
\r
1381 if ( recurse && item[ recurse ] )
\r
1383 var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
\r
1389 if ( nullIfNotFound )
\r
1393 array.push( newItem );
\r
1397 // Tool function used to remove an item from an array based on its id.
\r
1398 var removeById = function( array, id, recurse )
\r
1400 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1402 if ( item.id == id )
\r
1403 return array.splice( i, 1 );
\r
1404 if ( recurse && item[ recurse ] )
\r
1406 var retval = removeById( item[ recurse ], id, recurse );
\r
1415 * This class is not really part of the API. It is the "definition" property value
\r
1416 * passed to "dialogDefinition" event handlers.
\r
1418 * @name CKEDITOR.dialog.dialogDefinitionObject
\r
1419 * @extends CKEDITOR.dialog.dialogDefinition
\r
1421 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1423 * var definition = evt.data.definition;
\r
1424 * var content = definition.getContents( 'page1' );
\r
1428 var definitionObject = function( dialog, dialogDefinition )
\r
1430 // TODO : Check if needed.
\r
1431 this.dialog = dialog;
\r
1433 // Transform the contents entries in contentObjects.
\r
1434 var contents = dialogDefinition.contents;
\r
1435 for ( var i = 0, content ; ( content = contents[i] ) ; i++ )
\r
1436 contents[ i ] = content && new contentObject( dialog, content );
\r
1438 CKEDITOR.tools.extend( this, dialogDefinition );
\r
1441 definitionObject.prototype =
\r
1442 /** @lends CKEDITOR.dialog.dialogDefinitionObject.prototype */
\r
1445 * Gets a content definition.
\r
1446 * @param {String} id The id of the content definition.
\r
1447 * @returns {CKEDITOR.dialog.contentDefinition} The content definition
\r
1450 getContents : function( id )
\r
1452 return getById( this.contents, id );
\r
1456 * Gets a button definition.
\r
1457 * @param {String} id The id of the button definition.
\r
1458 * @returns {CKEDITOR.dialog.buttonDefinition} The button definition
\r
1461 getButton : function( id )
\r
1463 return getById( this.buttons, id );
\r
1467 * Adds a content definition object under this dialog definition.
\r
1468 * @param {CKEDITOR.dialog.contentDefinition} contentDefinition The
\r
1469 * content definition.
\r
1470 * @param {String} [nextSiblingId] The id of an existing content
\r
1471 * definition which the new content definition will be inserted
\r
1472 * before. Omit if the new content definition is to be inserted as
\r
1474 * @returns {CKEDITOR.dialog.contentDefinition} The inserted content
\r
1477 addContents : function( contentDefinition, nextSiblingId )
\r
1479 return addById( this.contents, contentDefinition, nextSiblingId );
\r
1483 * Adds a button definition object under this dialog definition.
\r
1484 * @param {CKEDITOR.dialog.buttonDefinition} buttonDefinition The
\r
1485 * button definition.
\r
1486 * @param {String} [nextSiblingId] The id of an existing button
\r
1487 * definition which the new button definition will be inserted
\r
1488 * before. Omit if the new button definition is to be inserted as
\r
1490 * @returns {CKEDITOR.dialog.buttonDefinition} The inserted button
\r
1493 addButton : function( buttonDefinition, nextSiblingId )
\r
1495 return addById( this.buttons, buttonDefinition, nextSiblingId );
\r
1499 * Removes a content definition from this dialog definition.
\r
1500 * @param {String} id The id of the content definition to be removed.
\r
1501 * @returns {CKEDITOR.dialog.contentDefinition} The removed content
\r
1504 removeContents : function( id )
\r
1506 removeById( this.contents, id );
\r
1510 * Removes a button definition from the dialog definition.
\r
1511 * @param {String} id The id of the button definition to be removed.
\r
1512 * @returns {CKEDITOR.dialog.buttonDefinition} The removed button
\r
1515 removeButton : function( id )
\r
1517 removeById( this.buttons, id );
\r
1522 * This class is not really part of the API. It is the template of the
\r
1523 * objects representing content pages inside the
\r
1524 * CKEDITOR.dialog.dialogDefinitionObject.
\r
1526 * @name CKEDITOR.dialog.contentDefinitionObject
\r
1528 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1530 * var definition = evt.data.definition;
\r
1531 * var content = definition.getContents( 'page1' );
\r
1532 * content.remove( 'textInput1' );
\r
1536 function contentObject( dialog, contentDefinition )
\r
1543 CKEDITOR.tools.extend( this, contentDefinition );
\r
1546 contentObject.prototype =
\r
1547 /** @lends CKEDITOR.dialog.contentDefinitionObject.prototype */
\r
1550 * Gets a UI element definition under the content definition.
\r
1551 * @param {String} id The id of the UI element definition.
\r
1552 * @returns {CKEDITOR.dialog.uiElementDefinition}
\r
1554 get : function( id )
\r
1556 return getById( this.elements, id, 'children' );
\r
1560 * Adds a UI element definition to the content definition.
\r
1561 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition The
\r
1562 * UI elemnet definition to be added.
\r
1563 * @param {String} nextSiblingId The id of an existing UI element
\r
1564 * definition which the new UI element definition will be inserted
\r
1565 * before. Omit if the new button definition is to be inserted as
\r
1567 * @returns {CKEDITOR.dialog.uiElementDefinition} The element
\r
1568 * definition inserted.
\r
1570 add : function( elementDefinition, nextSiblingId )
\r
1572 return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
\r
1576 * Removes a UI element definition from the content definition.
\r
1577 * @param {String} id The id of the UI element definition to be
\r
1579 * @returns {CKEDITOR.dialog.uiElementDefinition} The element
\r
1580 * definition removed.
\r
1583 remove : function( id )
\r
1585 removeById( this.elements, id, 'children' );
\r
1589 function initDragAndDrop( dialog )
\r
1591 var lastCoords = null,
\r
1592 abstractDialogCoords = null,
\r
1593 element = dialog.getElement().getFirst(),
\r
1594 editor = dialog.getParentEditor(),
\r
1595 magnetDistance = editor.config.dialog_magnetDistance,
\r
1596 margins = editor.skin.margins || [ 0, 0, 0, 0 ];
\r
1598 if ( typeof magnetDistance == 'undefined' )
\r
1599 magnetDistance = 20;
\r
1601 function mouseMoveHandler( evt )
\r
1603 var dialogSize = dialog.getSize(),
\r
1604 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
1605 x = evt.data.$.screenX,
\r
1606 y = evt.data.$.screenY,
\r
1607 dx = x - lastCoords.x,
\r
1608 dy = y - lastCoords.y,
\r
1611 lastCoords = { x : x, y : y };
\r
1612 abstractDialogCoords.x += dx;
\r
1613 abstractDialogCoords.y += dy;
\r
1615 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
\r
1616 realX = - margins[3];
\r
1617 else if ( abstractDialogCoords.x - margins[1] > viewPaneSize.width - dialogSize.width - magnetDistance )
\r
1618 realX = viewPaneSize.width - dialogSize.width + margins[1];
\r
1620 realX = abstractDialogCoords.x;
\r
1622 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
\r
1623 realY = - margins[0];
\r
1624 else if ( abstractDialogCoords.y - margins[2] > viewPaneSize.height - dialogSize.height - magnetDistance )
\r
1625 realY = viewPaneSize.height - dialogSize.height + margins[2];
\r
1627 realY = abstractDialogCoords.y;
\r
1629 dialog.move( realX, realY );
\r
1631 evt.data.preventDefault();
\r
1634 function mouseUpHandler( evt )
\r
1636 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1637 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1639 if ( CKEDITOR.env.ie6Compat )
\r
1641 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1642 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1643 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1647 dialog.parts.title.on( 'mousedown', function( evt )
\r
1649 dialog._.updateSize = true;
\r
1651 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
\r
1653 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
\r
1654 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
\r
1655 abstractDialogCoords = dialog.getPosition();
\r
1657 if ( CKEDITOR.env.ie6Compat )
\r
1659 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1660 coverDoc.on( 'mousemove', mouseMoveHandler );
\r
1661 coverDoc.on( 'mouseup', mouseUpHandler );
\r
1664 evt.data.preventDefault();
\r
1668 function initResizeHandles( dialog )
\r
1670 var definition = dialog.definition,
\r
1671 minWidth = definition.minWidth || 0,
\r
1672 minHeight = definition.minHeight || 0,
\r
1673 resizable = definition.resizable,
\r
1674 margins = dialog.getParentEditor().skin.margins || [ 0, 0, 0, 0 ];
\r
1676 function topSizer( coords, dy )
\r
1681 function rightSizer( coords, dx )
\r
1686 function bottomSizer( coords, dy )
\r
1691 function leftSizer( coords, dx )
\r
1696 var lastCoords = null,
\r
1697 abstractDialogCoords = null,
\r
1698 magnetDistance = dialog._.editor.config.magnetDistance,
\r
1699 parts = [ 'tl', 't', 'tr', 'l', 'r', 'bl', 'b', 'br' ];
\r
1701 function mouseDownHandler( evt )
\r
1703 var partName = evt.listenerData.part, size = dialog.getSize();
\r
1704 abstractDialogCoords = dialog.getPosition();
\r
1705 CKEDITOR.tools.extend( abstractDialogCoords,
\r
1707 x2 : abstractDialogCoords.x + size.width,
\r
1708 y2 : abstractDialogCoords.y + size.height
\r
1710 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
\r
1712 CKEDITOR.document.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } );
\r
1713 CKEDITOR.document.on( 'mouseup', mouseUpHandler, dialog, { part : partName } );
\r
1715 if ( CKEDITOR.env.ie6Compat )
\r
1717 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1718 coverDoc.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } );
\r
1719 coverDoc.on( 'mouseup', mouseUpHandler, dialog, { part : partName } );
\r
1722 evt.data.preventDefault();
\r
1725 function mouseMoveHandler( evt )
\r
1727 var x = evt.data.$.screenX,
\r
1728 y = evt.data.$.screenY,
\r
1729 dx = x - lastCoords.x,
\r
1730 dy = y - lastCoords.y,
\r
1731 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
1732 partName = evt.listenerData.part;
\r
1734 if ( partName.search( 't' ) != -1 )
\r
1735 topSizer( abstractDialogCoords, dy );
\r
1736 if ( partName.search( 'l' ) != -1 )
\r
1737 leftSizer( abstractDialogCoords, dx );
\r
1738 if ( partName.search( 'b' ) != -1 )
\r
1739 bottomSizer( abstractDialogCoords, dy );
\r
1740 if ( partName.search( 'r' ) != -1 )
\r
1741 rightSizer( abstractDialogCoords, dx );
\r
1743 lastCoords = { x : x, y : y };
\r
1745 var realX, realY, realX2, realY2;
\r
1747 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
\r
1748 realX = - margins[3];
\r
1749 else if ( partName.search( 'l' ) != -1 && abstractDialogCoords.x2 - abstractDialogCoords.x < minWidth + magnetDistance )
\r
1750 realX = abstractDialogCoords.x2 - minWidth;
\r
1752 realX = abstractDialogCoords.x;
\r
1754 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
\r
1755 realY = - margins[0];
\r
1756 else if ( partName.search( 't' ) != -1 && abstractDialogCoords.y2 - abstractDialogCoords.y < minHeight + magnetDistance )
\r
1757 realY = abstractDialogCoords.y2 - minHeight;
\r
1759 realY = abstractDialogCoords.y;
\r
1761 if ( abstractDialogCoords.x2 - margins[1] > viewPaneSize.width - magnetDistance )
\r
1762 realX2 = viewPaneSize.width + margins[1] ;
\r
1763 else if ( partName.search( 'r' ) != -1 && abstractDialogCoords.x2 - abstractDialogCoords.x < minWidth + magnetDistance )
\r
1764 realX2 = abstractDialogCoords.x + minWidth;
\r
1766 realX2 = abstractDialogCoords.x2;
\r
1768 if ( abstractDialogCoords.y2 - margins[2] > viewPaneSize.height - magnetDistance )
\r
1769 realY2= viewPaneSize.height + margins[2] ;
\r
1770 else if ( partName.search( 'b' ) != -1 && abstractDialogCoords.y2 - abstractDialogCoords.y < minHeight + magnetDistance )
\r
1771 realY2 = abstractDialogCoords.y + minHeight;
\r
1773 realY2 = abstractDialogCoords.y2 ;
\r
1775 dialog.move( realX, realY );
\r
1776 dialog.resize( realX2 - realX, realY2 - realY );
\r
1778 evt.data.preventDefault();
\r
1781 function mouseUpHandler( evt )
\r
1783 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1784 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1786 if ( CKEDITOR.env.ie6Compat )
\r
1788 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1789 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1790 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1794 // TODO : Simplify the resize logic, having just a single resize grip <div>.
\r
1795 // var widthTest = /[lr]/,
\r
1796 // heightTest = /[tb]/;
\r
1797 // for ( var i = 0 ; i < parts.length ; i++ )
\r
1799 // var element = dialog.parts[ parts[i] + '_resize' ];
\r
1800 // if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE ||
\r
1801 // resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT && widthTest.test( parts[i] ) ||
\r
1802 // resizable == CKEDITOR.DIALOG_RESIZE_WIDTH && heightTest.test( parts[i] ) )
\r
1804 // element.hide();
\r
1807 // element.on( 'mousedown', mouseDownHandler, dialog, { part : parts[i] } );
\r
1812 // Caching resuable covers and allowing only one cover
\r
1817 function showCover( editor )
\r
1819 var win = CKEDITOR.document.getWindow();
\r
1820 var backgroundColorStyle = editor.config.dialog_backgroundCoverColor || 'white',
\r
1821 backgroundCoverOpacity = editor.config.dialog_backgroundCoverOpacity,
\r
1822 baseFloatZIndex = editor.config.baseFloatZIndex,
\r
1823 coverKey = CKEDITOR.tools.genKey(
\r
1824 backgroundColorStyle,
\r
1825 backgroundCoverOpacity,
\r
1826 baseFloatZIndex ),
\r
1827 coverElement = covers[ coverKey ];
\r
1829 if ( !coverElement )
\r
1832 '<div style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),
\r
1833 '; z-index: ', baseFloatZIndex,
\r
1834 '; top: 0px; left: 0px; ',
\r
1835 ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),
\r
1836 '" class="cke_dialog_background_cover">'
\r
1839 if ( CKEDITOR.env.ie6Compat )
\r
1841 // Support for custom document.domain in IE.
\r
1842 var isCustomDomain = CKEDITOR.env.isCustomDomain(),
\r
1843 iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
\r
1847 ' hidefocus="true"' +
\r
1848 ' frameborder="0"' +
\r
1849 ' id="cke_dialog_background_iframe"' +
\r
1850 ' src="javascript:' );
\r
1852 html.push( 'void((function(){' +
\r
1853 'document.open();' +
\r
1854 ( isCustomDomain ? 'document.domain=\'' + document.domain + '\';' : '' ) +
\r
1855 'document.write( \'' + iframeHtml + '\' );' +
\r
1856 'document.close();' +
\r
1862 'position:absolute;' +
\r
1867 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
\r
1871 html.push( '</div>' );
\r
1873 coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
\r
1874 coverElement.setOpacity( backgroundCoverOpacity != undefined ? backgroundCoverOpacity : 0.5 );
\r
1876 coverElement.appendTo( CKEDITOR.document.getBody() );
\r
1877 covers[ coverKey ] = coverElement;
\r
1880 coverElement. show();
\r
1882 currentCover = coverElement;
\r
1883 var resizeFunc = function()
\r
1885 var size = win.getViewPaneSize();
\r
1886 coverElement.setStyles(
\r
1888 width : size.width + 'px',
\r
1889 height : size.height + 'px'
\r
1893 var scrollFunc = function()
\r
1895 var pos = win.getScrollPosition(),
\r
1896 cursor = CKEDITOR.dialog._.currentTop;
\r
1897 coverElement.setStyles(
\r
1899 left : pos.x + 'px',
\r
1900 top : pos.y + 'px'
\r
1905 var dialogPos = cursor.getPosition();
\r
1906 cursor.move( dialogPos.x, dialogPos.y );
\r
1907 } while ( ( cursor = cursor._.parentDialog ) );
\r
1910 resizeCover = resizeFunc;
\r
1911 win.on( 'resize', resizeFunc );
\r
1913 if ( CKEDITOR.env.ie6Compat )
\r
1915 // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
\r
1916 // So we need to invent a really funny way to make it work.
\r
1917 var myScrollHandler = function()
\r
1920 arguments.callee.prevScrollHandler.apply( this, arguments );
\r
1922 win.$.setTimeout( function()
\r
1924 myScrollHandler.prevScrollHandler = window.onscroll || function(){};
\r
1925 window.onscroll = myScrollHandler;
\r
1931 function hideCover()
\r
1933 if ( !currentCover )
\r
1936 var win = CKEDITOR.document.getWindow();
\r
1937 currentCover.hide();
\r
1938 win.removeListener( 'resize', resizeCover );
\r
1940 if ( CKEDITOR.env.ie6Compat )
\r
1942 win.$.setTimeout( function()
\r
1944 var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
\r
1945 window.onscroll = prevScrollHandler || null;
\r
1948 resizeCover = null;
\r
1951 function removeCovers()
\r
1953 for ( var coverId in covers )
\r
1954 covers[ coverId ].remove();
\r
1958 var accessKeyProcessors = {};
\r
1960 var accessKeyDownHandler = function( evt )
\r
1962 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
1963 alt = evt.data.$.altKey,
\r
1964 shift = evt.data.$.shiftKey,
\r
1965 key = String.fromCharCode( evt.data.$.keyCode ),
\r
1966 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
1968 if ( !keyProcessor || !keyProcessor.length )
\r
1971 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
1972 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
1973 evt.data.preventDefault();
\r
1976 var accessKeyUpHandler = function( evt )
\r
1978 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
1979 alt = evt.data.$.altKey,
\r
1980 shift = evt.data.$.shiftKey,
\r
1981 key = String.fromCharCode( evt.data.$.keyCode ),
\r
1982 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
1984 if ( !keyProcessor || !keyProcessor.length )
\r
1987 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
1988 if ( keyProcessor.keyup )
\r
1990 keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
1991 evt.data.preventDefault();
\r
1995 var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc )
\r
1997 var procList = accessKeyProcessors[key] || ( accessKeyProcessors[key] = [] );
\r
1999 uiElement : uiElement,
\r
2002 keyup : upFunc || uiElement.accessKeyUp,
\r
2003 keydown : downFunc || uiElement.accessKeyDown
\r
2007 var unregisterAccessKey = function( obj )
\r
2009 for ( var i in accessKeyProcessors )
\r
2011 var list = accessKeyProcessors[i];
\r
2012 for ( var j = list.length - 1 ; j >= 0 ; j-- )
\r
2014 if ( list[j].dialog == obj || list[j].uiElement == obj )
\r
2015 list.splice( j, 1 );
\r
2017 if ( list.length === 0 )
\r
2018 delete accessKeyProcessors[i];
\r
2022 var tabAccessKeyUp = function( dialog, key )
\r
2024 if ( dialog._.accessKeyMap[key] )
\r
2025 dialog.selectPage( dialog._.accessKeyMap[key] );
\r
2028 var tabAccessKeyDown = function( dialog, key )
\r
2033 var preventKeyBubblingKeys = { 27 :1, 13 :1 };
\r
2034 var preventKeyBubbling = function( e )
\r
2036 if ( e.data.getKeystroke() in preventKeyBubblingKeys )
\r
2037 e.data.stopPropagation();
\r
2042 CKEDITOR.ui.dialog =
\r
2045 * The base class of all dialog UI elements.
\r
2047 * @param {CKEDITOR.dialog} dialog Parent dialog object.
\r
2048 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition Element
\r
2049 * definition. Accepted fields:
\r
2051 * <li><strong>id</strong> (Required) The id of the UI element. See {@link
\r
2052 * CKEDITOR.dialog#getContentElement}</li>
\r
2053 * <li><strong>type</strong> (Required) The type of the UI element. The
\r
2054 * value to this field specifies which UI element class will be used to
\r
2055 * generate the final widget.</li>
\r
2056 * <li><strong>title</strong> (Optional) The popup tooltip for the UI
\r
2058 * <li><strong>hidden</strong> (Optional) A flag that tells if the element
\r
2059 * should be initially visible.</li>
\r
2060 * <li><strong>className</strong> (Optional) Additional CSS class names
\r
2061 * to add to the UI element. Separated by space.</li>
\r
2062 * <li><strong>style</strong> (Optional) Additional CSS inline styles
\r
2063 * to add to the UI element. A semicolon (;) is required after the last
\r
2064 * style declaration.</li>
\r
2065 * <li><strong>accessKey</strong> (Optional) The alphanumeric access key
\r
2066 * for this element. Access keys are automatically prefixed by CTRL.</li>
\r
2067 * <li><strong>on*</strong> (Optional) Any UI element definition field that
\r
2068 * starts with <em>on</em> followed immediately by a capital letter and
\r
2069 * probably more letters is an event handler. Event handlers may be further
\r
2070 * divided into registered event handlers and DOM event handlers. Please
\r
2071 * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and
\r
2072 * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more
\r
2073 * information.</li>
\r
2075 * @param {Array} htmlList
\r
2076 * List of HTML code to be added to the dialog's content area.
\r
2077 * @param {Function|String} nodeNameArg
\r
2078 * A function returning a string, or a simple string for the node name for
\r
2079 * the root DOM node. Default is 'div'.
\r
2080 * @param {Function|Object} stylesArg
\r
2081 * A function returning an object, or a simple object for CSS styles applied
\r
2082 * to the DOM node. Default is empty object.
\r
2083 * @param {Function|Object} attributesArg
\r
2084 * A fucntion returning an object, or a simple object for attributes applied
\r
2085 * to the DOM node. Default is empty object.
\r
2086 * @param {Function|String} contentsArg
\r
2087 * A function returning a string, or a simple string for the HTML code inside
\r
2088 * the root DOM node. Default is empty string.
\r
2091 uiElement : function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg )
\r
2093 if ( arguments.length < 4 )
\r
2096 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',
\r
2097 html = [ '<', nodeName, ' ' ],
\r
2098 styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},
\r
2099 attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},
\r
2100 innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',
\r
2101 domId = this.domId = attributes.id || CKEDITOR.tools.getNextId() + '_uiElement',
\r
2102 id = this.id = elementDefinition.id,
\r
2105 // Set the id, a unique id is required for getElement() to work.
\r
2106 attributes.id = domId;
\r
2108 // Set the type and definition CSS class names.
\r
2110 if ( elementDefinition.type )
\r
2111 classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;
\r
2112 if ( elementDefinition.className )
\r
2113 classes[ elementDefinition.className ] = 1;
\r
2114 var attributeClasses = ( attributes['class'] && attributes['class'].split ) ? attributes['class'].split( ' ' ) : [];
\r
2115 for ( i = 0 ; i < attributeClasses.length ; i++ )
\r
2117 if ( attributeClasses[i] )
\r
2118 classes[ attributeClasses[i] ] = 1;
\r
2120 var finalClasses = [];
\r
2121 for ( i in classes )
\r
2122 finalClasses.push( i );
\r
2123 attributes['class'] = finalClasses.join( ' ' );
\r
2125 // Set the popup tooltop.
\r
2126 if ( elementDefinition.title )
\r
2127 attributes.title = elementDefinition.title;
\r
2129 // Write the inline CSS styles.
\r
2130 var styleStr = ( elementDefinition.style || '' ).split( ';' );
\r
2131 for ( i in styles )
\r
2132 styleStr.push( i + ':' + styles[i] );
\r
2133 if ( elementDefinition.hidden )
\r
2134 styleStr.push( 'display:none' );
\r
2135 for ( i = styleStr.length - 1 ; i >= 0 ; i-- )
\r
2137 if ( styleStr[i] === '' )
\r
2138 styleStr.splice( i, 1 );
\r
2140 if ( styleStr.length > 0 )
\r
2141 attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
\r
2143 // Write the attributes.
\r
2144 for ( i in attributes )
\r
2145 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '" ');
\r
2147 // Write the content HTML.
\r
2148 html.push( '>', innerHTML, '</', nodeName, '>' );
\r
2150 // Add contents to the parent HTML array.
\r
2151 htmlList.push( html.join( '' ) );
\r
2153 ( this._ || ( this._ = {} ) ).dialog = dialog;
\r
2155 // Override isChanged if it is defined in element definition.
\r
2156 if ( typeof( elementDefinition.isChanged ) == 'boolean' )
\r
2157 this.isChanged = function(){ return elementDefinition.isChanged; };
\r
2158 if ( typeof( elementDefinition.isChanged ) == 'function' )
\r
2159 this.isChanged = elementDefinition.isChanged;
\r
2162 CKEDITOR.event.implementOn( this );
\r
2164 this.registerEvents( elementDefinition );
\r
2165 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
\r
2166 registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
\r
2169 dialog.on( 'load', function()
\r
2171 if ( me.getInputElement() )
\r
2173 me.getInputElement().on( 'focus', function()
\r
2175 dialog._.tabBarMode = false;
\r
2176 dialog._.hasFocus = true;
\r
2177 me.fire( 'focus' );
\r
2182 // Register the object as a tab focus if it can be included.
\r
2183 if ( this.keyboardFocusable )
\r
2185 this.tabIndex = elementDefinition.tabIndex || 0;
\r
2187 this.focusIndex = dialog._.focusList.push( this ) - 1;
\r
2188 this.on( 'focus', function()
\r
2190 dialog._.currentFocusIndex = me.focusIndex;
\r
2194 // Completes this object with everything we have in the
\r
2196 CKEDITOR.tools.extend( this, elementDefinition );
\r
2200 * Horizontal layout box for dialog UI elements, auto-expends to available width of container.
\r
2202 * @extends CKEDITOR.ui.dialog.uiElement
\r
2203 * @param {CKEDITOR.dialog} dialog
\r
2204 * Parent dialog object.
\r
2205 * @param {Array} childObjList
\r
2206 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2208 * @param {Array} childHtmlList
\r
2209 * Array of HTML code that correspond to the HTML output of all the
\r
2210 * objects in childObjList.
\r
2211 * @param {Array} htmlList
\r
2212 * Array of HTML code that this element will output to.
\r
2213 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
2214 * The element definition. Accepted fields:
\r
2216 * <li><strong>widths</strong> (Optional) The widths of child cells.</li>
\r
2217 * <li><strong>height</strong> (Optional) The height of the layout.</li>
\r
2218 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2220 * <li><strong>align</strong> (Optional) The alignment of the whole layout
\r
2225 hbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2227 if ( arguments.length < 4 )
\r
2230 this._ || ( this._ = {} );
\r
2232 var children = this._.children = childObjList,
\r
2233 widths = elementDefinition && elementDefinition.widths || null,
\r
2234 height = elementDefinition && elementDefinition.height || null,
\r
2238 var innerHTML = function()
\r
2240 var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];
\r
2241 for ( i = 0 ; i < childHtmlList.length ; i++ )
\r
2243 var className = 'cke_dialog_ui_hbox_child',
\r
2246 className = 'cke_dialog_ui_hbox_first';
\r
2247 if ( i == childHtmlList.length - 1 )
\r
2248 className = 'cke_dialog_ui_hbox_last';
\r
2249 html.push( '<td class="', className, '" role="presentation" ' );
\r
2253 styles.push( 'width:' + CKEDITOR.tools.cssLength( widths[i] ) );
\r
2256 styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2258 styles.push( 'height:' + CKEDITOR.tools.cssLength( height ) );
\r
2259 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2260 styles.push( 'padding:' + CKEDITOR.tools.cssLength( elementDefinition.padding ) );
\r
2261 if ( styles.length > 0 )
\r
2262 html.push( 'style="' + styles.join('; ') + '" ' );
\r
2263 html.push( '>', childHtmlList[i], '</td>' );
\r
2265 html.push( '</tr></tbody>' );
\r
2266 return html.join( '' );
\r
2269 var attribs = { role : 'presentation' };
\r
2270 elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );
\r
2272 CKEDITOR.ui.dialog.uiElement.call(
\r
2275 elementDefinition || { type : 'hbox' },
\r
2284 * Vertical layout box for dialog UI elements.
\r
2286 * @extends CKEDITOR.ui.dialog.hbox
\r
2287 * @param {CKEDITOR.dialog} dialog
\r
2288 * Parent dialog object.
\r
2289 * @param {Array} childObjList
\r
2290 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2292 * @param {Array} childHtmlList
\r
2293 * Array of HTML code that correspond to the HTML output of all the
\r
2294 * objects in childObjList.
\r
2295 * @param {Array} htmlList
\r
2296 * Array of HTML code that this element will output to.
\r
2297 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
2298 * The element definition. Accepted fields:
\r
2300 * <li><strong>width</strong> (Optional) The width of the layout.</li>
\r
2301 * <li><strong>heights</strong> (Optional) The heights of individual cells.
\r
2303 * <li><strong>align</strong> (Optional) The alignment of the layout.</li>
\r
2304 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2306 * <li><strong>expand</strong> (Optional) Whether the layout should expand
\r
2307 * vertically to fill its container.</li>
\r
2311 vbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2313 if (arguments.length < 3 )
\r
2316 this._ || ( this._ = {} );
\r
2318 var children = this._.children = childObjList,
\r
2319 width = elementDefinition && elementDefinition.width || null,
\r
2320 heights = elementDefinition && elementDefinition.heights || null;
\r
2322 var innerHTML = function()
\r
2324 var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];
\r
2325 html.push( 'style="' );
\r
2326 if ( elementDefinition && elementDefinition.expand )
\r
2327 html.push( 'height:100%;' );
\r
2328 html.push( 'width:' + CKEDITOR.tools.cssLength( width || '100%' ), ';' );
\r
2330 html.push( 'align="', CKEDITOR.tools.htmlEncode(
\r
2331 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
\r
2333 html.push( '><tbody>' );
\r
2334 for ( var i = 0 ; i < childHtmlList.length ; i++ )
\r
2337 html.push( '<tr><td role="presentation" ' );
\r
2339 styles.push( 'width:' + CKEDITOR.tools.cssLength( width || '100%' ) );
\r
2341 styles.push( 'height:' + CKEDITOR.tools.cssLength( heights[i] ) );
\r
2342 else if ( elementDefinition && elementDefinition.expand )
\r
2343 styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2344 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2345 styles.push( 'padding:' + CKEDITOR.tools.cssLength( elementDefinition.padding ) );
\r
2346 if ( styles.length > 0 )
\r
2347 html.push( 'style="', styles.join( '; ' ), '" ' );
\r
2348 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[i], '</td></tr>' );
\r
2350 html.push( '</tbody></table>' );
\r
2351 return html.join( '' );
\r
2353 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type : 'vbox' }, htmlList, 'div', null, { role : 'presentation' }, innerHTML );
\r
2358 CKEDITOR.ui.dialog.uiElement.prototype =
\r
2361 * Gets the root DOM element of this dialog UI object.
\r
2362 * @returns {CKEDITOR.dom.element} Root DOM element of UI object.
\r
2364 * uiElement.getElement().hide();
\r
2366 getElement : function()
\r
2368 return CKEDITOR.document.getById( this.domId );
\r
2372 * Gets the DOM element that the user inputs values.
\r
2373 * This function is used by setValue(), getValue() and focus(). It should
\r
2374 * be overrided in child classes where the input element isn't the root
\r
2376 * @returns {CKEDITOR.dom.element} The element where the user input values.
\r
2378 * var rawValue = textInput.getInputElement().$.value;
\r
2380 getInputElement : function()
\r
2382 return this.getElement();
\r
2386 * Gets the parent dialog object containing this UI element.
\r
2387 * @returns {CKEDITOR.dialog} Parent dialog object.
\r
2389 * var dialog = uiElement.getDialog();
\r
2391 getDialog : function()
\r
2393 return this._.dialog;
\r
2397 * Sets the value of this dialog UI object.
\r
2398 * @param {Object} value The new value.
\r
2399 * @param {Boolean} noChangeEvent Internal commit, to supress 'change' event on this element.
\r
2400 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2402 * uiElement.setValue( 'Dingo' );
\r
2404 setValue : function( value, noChangeEvent )
\r
2406 this.getInputElement().setValue( value );
\r
2407 !noChangeEvent && this.fire( 'change', { value : value } );
\r
2412 * Gets the current value of this dialog UI object.
\r
2413 * @returns {Object} The current value.
\r
2415 * var myValue = uiElement.getValue();
\r
2417 getValue : function()
\r
2419 return this.getInputElement().getValue();
\r
2423 * Tells whether the UI object's value has changed.
\r
2424 * @returns {Boolean} true if changed, false if not changed.
\r
2426 * if ( uiElement.isChanged() )
\r
2427 * confirm( 'Value changed! Continue?' );
\r
2429 isChanged : function()
\r
2431 // Override in input classes.
\r
2436 * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
\r
2437 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2439 * focus : function()
\r
2441 * this.selectParentTab();
\r
2442 * // do something else.
\r
2445 selectParentTab : function()
\r
2447 var element = this.getInputElement(),
\r
2450 while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 )
\r
2453 // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
\r
2457 tabId = cursor.getAttribute( 'name' );
\r
2458 // Avoid duplicate select.
\r
2459 if ( this._.dialog._.currentTabId != tabId )
\r
2460 this._.dialog.selectPage( tabId );
\r
2465 * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
\r
2466 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2468 * uiElement.focus();
\r
2470 focus : function()
\r
2472 this.selectParentTab().getInputElement().focus();
\r
2477 * Registers the on* event handlers defined in the element definition.
\r
2478 * The default behavior of this function is:
\r
2481 * If the on* event is defined in the class's eventProcesors list,
\r
2482 * then the registration is delegated to the corresponding function
\r
2483 * in the eventProcessors list.
\r
2486 * If the on* event is not defined in the eventProcessors list, then
\r
2487 * register the event handler under the corresponding DOM event of
\r
2488 * the UI element's input DOM element (as defined by the return value
\r
2489 * of {@link CKEDITOR.ui.dialog.uiElement#getInputElement}).
\r
2492 * This function is only called at UI element instantiation, but can
\r
2493 * be overridded in child classes if they require more flexibility.
\r
2494 * @param {CKEDITOR.dialog.uiElementDefinition} definition The UI element
\r
2496 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2499 registerEvents : function( definition )
\r
2501 var regex = /^on([A-Z]\w+)/,
\r
2504 var registerDomEvent = function( uiElement, dialog, eventName, func )
\r
2506 dialog.on( 'load', function()
\r
2508 uiElement.getInputElement().on( eventName, func, uiElement );
\r
2512 for ( var i in definition )
\r
2514 if ( !( match = i.match( regex ) ) )
\r
2516 if ( this.eventProcessors[i] )
\r
2517 this.eventProcessors[i].call( this, this._.dialog, definition[i] );
\r
2519 registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
\r
2526 * The event processor list used by
\r
2527 * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element
\r
2528 * instantiation. The default list defines three on* events:
\r
2530 * <li>onLoad - Called when the element's parent dialog opens for the
\r
2532 * <li>onShow - Called whenever the element's parent dialog opens.</li>
\r
2533 * <li>onHide - Called whenever the element's parent dialog closes.</li>
\r
2538 * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick
\r
2539 * // handlers in the UI element's definitions.
\r
2540 * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},
\r
2541 * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
\r
2542 * { onClick : function( dialog, func ) { this.on( 'click', func ); } },
\r
2543 * true );
\r
2547 onLoad : function( dialog, func )
\r
2549 dialog.on( 'load', func, this );
\r
2552 onShow : function( dialog, func )
\r
2554 dialog.on( 'show', func, this );
\r
2557 onHide : function( dialog, func )
\r
2559 dialog.on( 'hide', func, this );
\r
2564 * The default handler for a UI element's access key down event, which
\r
2565 * tries to put focus to the UI element.<br />
\r
2566 * Can be overridded in child classes for more sophisticaed behavior.
\r
2567 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2568 * @param {String} key The key combination pressed. Since access keys
\r
2569 * are defined to always include the CTRL key, its value should always
\r
2570 * include a 'CTRL+' prefix.
\r
2573 accessKeyDown : function( dialog, key )
\r
2579 * The default handler for a UI element's access key up event, which
\r
2580 * does nothing.<br />
\r
2581 * Can be overridded in child classes for more sophisticated behavior.
\r
2582 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2583 * @param {String} key The key combination pressed. Since access keys
\r
2584 * are defined to always include the CTRL key, its value should always
\r
2585 * include a 'CTRL+' prefix.
\r
2588 accessKeyUp : function( dialog, key )
\r
2593 * Disables a UI element.
\r
2596 disable : function()
\r
2598 var element = this.getInputElement();
\r
2599 element.setAttribute( 'disabled', 'true' );
\r
2600 element.addClass( 'cke_disabled' );
\r
2604 * Enables a UI element.
\r
2607 enable : function()
\r
2609 var element = this.getInputElement();
\r
2610 element.removeAttribute( 'disabled' );
\r
2611 element.removeClass( 'cke_disabled' );
\r
2615 * Determines whether an UI element is enabled or not.
\r
2616 * @returns {Boolean} Whether the UI element is enabled.
\r
2619 isEnabled : function()
\r
2621 return !this.getInputElement().getAttribute( 'disabled' );
\r
2625 * Determines whether an UI element is visible or not.
\r
2626 * @returns {Boolean} Whether the UI element is visible.
\r
2629 isVisible : function()
\r
2631 return this.getInputElement().isVisible();
\r
2635 * Determines whether an UI element is focus-able or not.
\r
2636 * Focus-able is defined as being both visible and enabled.
\r
2637 * @returns {Boolean} Whether the UI element can be focused.
\r
2640 isFocusable : function()
\r
2642 if ( !this.isEnabled() || !this.isVisible() )
\r
2648 CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
\r
2650 * @lends CKEDITOR.ui.dialog.hbox.prototype
\r
2654 * Gets a child UI element inside this container.
\r
2655 * @param {Array|Number} indices An array or a single number to indicate the child's
\r
2656 * position in the container's descendant tree. Omit to get all the children in an array.
\r
2657 * @returns {Array|CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container
\r
2658 * if no argument given, or the specified UI element if indices is given.
\r
2660 * var checkbox = hbox.getChild( [0,1] );
\r
2661 * checkbox.setValue( true );
\r
2663 getChild : function( indices )
\r
2665 // If no arguments, return a clone of the children array.
\r
2666 if ( arguments.length < 1 )
\r
2667 return this._.children.concat();
\r
2669 // If indices isn't array, make it one.
\r
2670 if ( !indices.splice )
\r
2671 indices = [ indices ];
\r
2673 // Retrieve the child element according to tree position.
\r
2674 if ( indices.length < 2 )
\r
2675 return this._.children[ indices[0] ];
\r
2677 return ( this._.children[ indices[0] ] && this._.children[ indices[0] ].getChild ) ?
\r
2678 this._.children[ indices[0] ].getChild( indices.slice( 1, indices.length ) ) :
\r
2683 CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
\r
2689 var commonBuilder = {
\r
2690 build : function( dialog, elementDefinition, output )
\r
2692 var children = elementDefinition.children,
\r
2694 childHtmlList = [],
\r
2695 childObjList = [];
\r
2696 for ( var i = 0 ; ( i < children.length && ( child = children[i] ) ) ; i++ )
\r
2698 var childHtml = [];
\r
2699 childHtmlList.push( childHtml );
\r
2700 childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
\r
2702 return new CKEDITOR.ui.dialog[elementDefinition.type]( dialog, childObjList, childHtmlList, output, elementDefinition );
\r
2706 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
\r
2707 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
\r
2711 * Generic dialog command. It opens a specific dialog when executed.
\r
2713 * @augments CKEDITOR.commandDefinition
\r
2714 * @param {string} dialogName The name of the dialog to open when executing
\r
2717 * // Register the "link" command, which opens the "link" dialog.
\r
2718 * editor.addCommand( 'link', <b>new CKEDITOR.dialogCommand( 'link' )</b> );
\r
2720 CKEDITOR.dialogCommand = function( dialogName )
\r
2722 this.dialogName = dialogName;
\r
2725 CKEDITOR.dialogCommand.prototype =
\r
2728 exec : function( editor )
\r
2730 editor.openDialog( this.dialogName );
\r
2733 // Dialog commands just open a dialog ui, thus require no undo logic,
\r
2734 // undo support should dedicate to specific dialog implementation.
\r
2737 editorFocus : CKEDITOR.env.ie || CKEDITOR.env.webkit
\r
2742 var notEmptyRegex = /^([a]|[^a])+$/,
\r
2743 integerRegex = /^\d*$/,
\r
2744 numberRegex = /^\d*(?:\.\d+)?$/;
\r
2746 CKEDITOR.VALIDATE_OR = 1;
\r
2747 CKEDITOR.VALIDATE_AND = 2;
\r
2749 CKEDITOR.dialog.validate =
\r
2751 functions : function()
\r
2756 * It's important for validate functions to be able to accept the value
\r
2757 * as argument in addition to this.getValue(), so that it is possible to
\r
2758 * combine validate functions together to make more sophisticated
\r
2761 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
2763 var msg = undefined,
\r
2764 relation = CKEDITOR.VALIDATE_AND,
\r
2765 functions = [], i;
\r
2767 for ( i = 0 ; i < arguments.length ; i++ )
\r
2769 if ( typeof( arguments[i] ) == 'function' )
\r
2770 functions.push( arguments[i] );
\r
2775 if ( i < arguments.length && typeof( arguments[i] ) == 'string' )
\r
2777 msg = arguments[i];
\r
2781 if ( i < arguments.length && typeof( arguments[i]) == 'number' )
\r
2782 relation = arguments[i];
\r
2784 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );
\r
2785 for ( i = 0 ; i < functions.length ; i++ )
\r
2787 if ( relation == CKEDITOR.VALIDATE_AND )
\r
2788 passed = passed && functions[i]( value );
\r
2790 passed = passed || functions[i]( value );
\r
2795 if ( msg !== undefined )
\r
2797 if ( this && ( this.select || this.focus ) )
\r
2798 ( this.select || this.focus )();
\r
2806 regex : function( regex, msg )
\r
2809 * Can be greatly shortened by deriving from functions validator if code size
\r
2810 * turns out to be more important than performance.
\r
2814 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
2815 if ( !regex.test( value ) )
\r
2817 if ( msg !== undefined )
\r
2819 if ( this && ( this.select || this.focus ) )
\r
2821 if ( this.select )
\r
2832 notEmpty : function( msg )
\r
2834 return this.regex( notEmptyRegex, msg );
\r
2837 integer : function( msg )
\r
2839 return this.regex( integerRegex, msg );
\r
2842 'number' : function( msg )
\r
2844 return this.regex( numberRegex, msg );
\r
2847 equals : function( value, msg )
\r
2849 return this.functions( function( val ){ return val == value; }, msg );
\r
2852 notEqual : function( value, msg )
\r
2854 return this.functions( function( val ){ return val != value; }, msg );
\r
2858 CKEDITOR.on( 'instanceDestroyed', function( evt )
\r
2860 // Remove dialog cover on last instance destroy.
\r
2861 if ( CKEDITOR.tools.isEmpty( CKEDITOR.instances ) )
\r
2863 var currentTopDialog;
\r
2864 while ( ( currentTopDialog = CKEDITOR.dialog._.currentTop ) )
\r
2865 currentTopDialog.hide();
\r
2869 var dialogs = evt.editor._.storedDialogs;
\r
2870 for ( var name in dialogs )
\r
2871 dialogs[ name ].destroy();
\r
2878 // Extend the CKEDITOR.editor class with dialog specific functions.
\r
2879 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
\r
2880 /** @lends CKEDITOR.editor.prototype */
\r
2883 * Loads and opens a registered dialog.
\r
2884 * @param {String} dialogName The registered name of the dialog.
\r
2885 * @param {Function} callback The function to be invoked after dialog instance created.
\r
2886 * @see CKEDITOR.dialog.add
\r
2888 * CKEDITOR.instances.editor1.openDialog( 'smiley' );
\r
2889 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed. null if the dialog name is not registered.
\r
2891 openDialog : function( dialogName, callback )
\r
2893 var dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
2894 dialogSkin = this.skin.dialog;
\r
2896 // If the dialogDefinition is already loaded, open it immediately.
\r
2897 if ( typeof dialogDefinitions == 'function' && dialogSkin._isLoaded )
\r
2899 var storedDialogs = this._.storedDialogs ||
\r
2900 ( this._.storedDialogs = {} );
\r
2902 var dialog = storedDialogs[ dialogName ] ||
\r
2903 ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
\r
2905 callback && callback.call( dialog, dialog );
\r
2910 else if ( dialogDefinitions == 'failed' )
\r
2911 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
\r
2913 // Not loaded? Load the .js file first.
\r
2914 var body = CKEDITOR.document.getBody(),
\r
2915 cursor = body.$.style.cursor,
\r
2918 body.setStyle( 'cursor', 'wait' );
\r
2920 function onDialogFileLoaded( success )
\r
2922 var dialogDefinition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
2923 skin = me.skin.dialog;
\r
2925 // Check if both skin part and definition is loaded.
\r
2926 if ( !skin._isLoaded || loadDefinition && typeof success == 'undefined' )
\r
2929 // In case of plugin error, mark it as loading failed.
\r
2930 if ( typeof dialogDefinition != 'function' )
\r
2931 CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';
\r
2933 me.openDialog( dialogName, callback );
\r
2934 body.setStyle( 'cursor', cursor );
\r
2937 if ( typeof dialogDefinitions == 'string' )
\r
2939 var loadDefinition = 1;
\r
2940 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ), onDialogFileLoaded );
\r
2943 CKEDITOR.skins.load( this, 'dialog', onDialogFileLoaded );
\r
2949 CKEDITOR.plugins.add( 'dialog',
\r
2951 requires : [ 'dialogui' ]
\r
2954 // Dialog related configurations.
\r
2957 * The color of the dialog background cover. It should be a valid CSS color
\r
2959 * @name CKEDITOR.config.dialog_backgroundCoverColor
\r
2961 * @default 'white'
\r
2963 * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
\r
2967 * The opacity of the dialog background cover. It should be a number within the
\r
2968 * range [0.0, 1.0].
\r
2969 * @name CKEDITOR.config.dialog_backgroundCoverOpacity
\r
2973 * config.dialog_backgroundCoverOpacity = 0.7;
\r
2977 * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.
\r
2978 * @name CKEDITOR.config.dialog_startupFocusTab
\r
2982 * config.dialog_startupFocusTab = true;
\r
2986 * The distance of magnetic borders used in moving and resizing dialogs,
\r
2987 * measured in pixels.
\r
2988 * @name CKEDITOR.config.dialog_magnetDistance
\r
2992 * config.dialog_magnetDistance = 30;
\r
2996 * Fired when a dialog definition is about to be used to create a dialog into
\r
2997 * an editor instance. This event makes it possible to customize the definition
\r
2998 * before creating it.
\r
2999 * <p>Note that this event is called only the first time a specific dialog is
\r
3000 * opened. Successive openings will use the cached dialog, and this event will
\r
3001 * not get fired.</p>
\r
3002 * @name CKEDITOR#dialogDefinition
\r
3004 * @param {CKEDITOR.dialog.dialogDefinition} data The dialog defination that
\r
3005 * is being loaded.
\r
3006 * @param {CKEDITOR.editor} editor The editor instance that will use the
\r
3011 * Fired when a tab is going to be selected in a dialog
\r
3012 * @name dialog#selectPage
\r
3014 * @param String page The id of the page that it's gonna be selected.
\r
3015 * @param String currentPage The id of the current page.
\r