2 Copyright (c) 2003-2009, 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
10 CKEDITOR.plugins.add( 'dialog',
\r
12 requires : [ 'dialogui' ]
\r
16 * No resize for this dialog.
\r
19 CKEDITOR.DIALOG_RESIZE_NONE = 0;
\r
22 * Only allow horizontal resizing for this dialog, disable vertical resizing.
\r
25 CKEDITOR.DIALOG_RESIZE_WIDTH = 1;
\r
28 * Only allow vertical resizing for this dialog, disable horizontal resizing.
\r
31 CKEDITOR.DIALOG_RESIZE_HEIGHT = 2;
\r
34 * Allow the dialog to be resized in both directions.
\r
37 CKEDITOR.DIALOG_RESIZE_BOTH = 3;
\r
41 function isTabVisible( tabId )
\r
43 return !!this._.tabs[ tabId ][ 0 ].$.offsetHeight;
\r
46 function getPreviousVisibleTab()
\r
48 var tabId = this._.currentTabId,
\r
49 length = this._.tabIdList.length,
\r
50 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId ) + length;
\r
52 for ( var i = tabIndex - 1 ; i > tabIndex - length ; i-- )
\r
54 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
\r
55 return this._.tabIdList[ i % length ];
\r
61 function getNextVisibleTab()
\r
63 var tabId = this._.currentTabId,
\r
64 length = this._.tabIdList.length,
\r
65 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId );
\r
67 for ( var i = tabIndex + 1 ; i < tabIndex + length ; i++ )
\r
69 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
\r
70 return this._.tabIdList[ i % length ];
\r
76 // Stores dialog related data from skin definitions. e.g. margin sizes.
\r
80 * This is the base class for runtime dialog objects. An instance of this
\r
81 * class represents a single named dialog for a single editor instance.
\r
82 * @param {Object} editor The editor which created the dialog.
\r
83 * @param {String} dialogName The dialog's registered name.
\r
86 * var dialogObj = new CKEDITOR.dialog( editor, 'smiley' );
\r
88 CKEDITOR.dialog = function( editor, dialogName )
\r
90 // Load the dialog definition.
\r
91 var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];
\r
93 // Completes the definition with the default values.
\r
94 definition = CKEDITOR.tools.extend( definition( editor ), defaultDialogDefinition );
\r
96 // Clone a functionally independent copy for this dialog.
\r
97 definition = CKEDITOR.tools.clone( definition );
\r
99 // Create a complex definition object, extending it with the API
\r
101 definition = new definitionObject( this, definition );
\r
103 // Fire the "dialogDefinition" event, making it possible to customize
\r
104 // the dialog definition.
\r
105 this.definition = definition = CKEDITOR.fire( 'dialogDefinition',
\r
108 definition : definition
\r
110 , editor ).definition;
\r
112 var doc = CKEDITOR.document;
\r
114 var themeBuilt = editor.theme.buildDialog( editor );
\r
116 // Initialize some basic parameters.
\r
120 element : themeBuilt.element,
\r
122 contentSize : { width : 0, height : 0 },
\r
123 size : { width : 0, height : 0 },
\r
124 updateSize : false,
\r
129 // Initialize the tab and page map.
\r
132 currentTabId : null,
\r
133 currentTabIndex : null,
\r
136 tabBarMode : false,
\r
138 // Initialize the tab order array for input widgets.
\r
140 currentFocusIndex : 0,
\r
144 this.parts = themeBuilt.parts;
\r
146 // Set the startup styles for the dialog, avoiding it enlarging the
\r
147 // page size on the dialog creation.
\r
148 this.parts.dialog.setStyles(
\r
150 position : CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed',
\r
153 visibility : 'hidden'
\r
156 // Call the CKEDITOR.event constructor to initialize this instance.
\r
157 CKEDITOR.event.call( this );
\r
159 // Initialize load, show, hide, ok and cancel events.
\r
160 if ( definition.onLoad )
\r
161 this.on( 'load', definition.onLoad );
\r
163 if ( definition.onShow )
\r
164 this.on( 'show', definition.onShow );
\r
166 if ( definition.onHide )
\r
167 this.on( 'hide', definition.onHide );
\r
169 if ( definition.onOk )
\r
171 this.on( 'ok', function( evt )
\r
173 if ( definition.onOk.call( this, evt ) === false )
\r
174 evt.data.hide = false;
\r
178 if ( definition.onCancel )
\r
180 this.on( 'cancel', function( evt )
\r
182 if ( definition.onCancel.call( this, evt ) === false )
\r
183 evt.data.hide = false;
\r
189 // Iterates over all items inside all content in the dialog, calling a
\r
190 // function for each of them.
\r
191 var iterContents = function( func )
\r
193 var contents = me._.contents,
\r
196 for ( var i in contents )
\r
198 for ( var j in contents[i] )
\r
200 stop = func.call( this, contents[i][j] );
\r
207 this.on( 'ok', function( evt )
\r
209 iterContents( function( item )
\r
211 if ( item.validate )
\r
213 var isValid = item.validate( this );
\r
215 if ( typeof isValid == 'string' )
\r
221 if ( isValid === false )
\r
228 evt.data.hide = false;
\r
234 }, this, null, 0 );
\r
236 this.on( 'cancel', function( evt )
\r
238 iterContents( function( item )
\r
240 if ( item.isChanged() )
\r
242 if ( !confirm( editor.lang.common.confirmCancel ) )
\r
243 evt.data.hide = false;
\r
247 }, this, null, 0 );
\r
249 this.parts.close.on( 'click', function( evt )
\r
251 if ( this.fire( 'cancel', { hide : true } ).hide !== false )
\r
255 function changeFocus( forward )
\r
257 var focusList = me._.focusList,
\r
258 offset = forward ? 1 : -1;
\r
259 if ( focusList.length < 1 )
\r
262 var startIndex = ( me._.currentFocusIndex + offset + focusList.length ) % focusList.length,
\r
263 currentIndex = startIndex;
\r
264 while ( !focusList[ currentIndex ].isFocusable() )
\r
266 currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length;
\r
267 if ( currentIndex == startIndex )
\r
270 focusList[ currentIndex ].focus();
\r
272 // Select whole field content.
\r
273 if ( focusList[ currentIndex ].type == 'text' )
\r
274 focusList[ currentIndex ].select();
\r
279 function focusKeydownHandler( evt )
\r
281 // If I'm not the top dialog, ignore.
\r
282 if ( me != CKEDITOR.dialog._.currentTop )
\r
285 var keystroke = evt.data.getKeystroke();
\r
288 if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )
\r
290 var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
\r
292 // Handling Tab and Shift-Tab.
\r
293 if ( me._.tabBarMode )
\r
296 var nextId = shiftPressed ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );
\r
297 me.selectPage( nextId );
\r
298 me._.tabs[ nextId ][ 0 ].focus();
\r
302 // Change the focus of inputs.
\r
303 changeFocus( !shiftPressed );
\r
308 else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode )
\r
310 // Alt-F10 puts focus into the current tab item in the tab bar.
\r
311 me._.tabBarMode = true;
\r
312 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
315 else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode )
\r
317 // Arrow keys - used for changing tabs.
\r
318 nextId = ( keystroke == 37 ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) );
\r
319 me.selectPage( nextId );
\r
320 me._.tabs[ nextId ][ 0 ].focus();
\r
327 evt.data.preventDefault();
\r
331 function focusKeyPressHandler( evt )
\r
333 processed && evt.data.preventDefault();
\r
336 // Add the dialog keyboard handlers.
\r
337 this.on( 'show', function()
\r
339 CKEDITOR.document.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
340 // Some browsers instead, don't cancel key events in the keydown, but in the
\r
341 // keypress. So we must do a longer trip in those cases. (#4531)
\r
342 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
343 CKEDITOR.document.on( 'keypress', focusKeyPressHandler, this );
\r
345 if ( CKEDITOR.env.ie6Compat )
\r
347 var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
\r
348 coverDoc.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
351 this.on( 'hide', function()
\r
353 CKEDITOR.document.removeListener( 'keydown', focusKeydownHandler );
\r
354 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
355 CKEDITOR.document.removeListener( 'keypress', focusKeyPressHandler );
\r
357 this.on( 'iframeAdded', function( evt )
\r
359 var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );
\r
360 doc.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
363 // Auto-focus logic in dialog.
\r
364 this.on( 'show', function()
\r
366 if ( !this._.hasFocus )
\r
368 this._.currentFocusIndex = -1;
\r
369 changeFocus( true );
\r
372 * IE BUG: If the initial focus went into a non-text element (e.g. button),
\r
373 * then IE would still leave the caret inside the editing area.
\r
375 if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
377 var $selection = editor.document.$.selection,
\r
378 $range = $selection.createRange();
\r
382 if ( $range.parentElement && $range.parentElement().ownerDocument == editor.document.$
\r
383 || $range.item && $range.item( 0 ).ownerDocument == editor.document.$ )
\r
385 var $myRange = document.body.createTextRange();
\r
386 $myRange.moveToElementText( this.getElement().getFirst().$ );
\r
387 $myRange.collapse( true );
\r
393 }, this, null, 0xffffffff );
\r
395 // IE6 BUG: Text fields and text areas are only half-rendered the first time the dialog appears in IE6 (#2661).
\r
396 // This is still needed after [2708] and [2709] because text fields in hidden TR tags are still broken.
\r
397 if ( CKEDITOR.env.ie6Compat )
\r
399 this.on( 'load', function( evt )
\r
401 var outer = this.getElement(),
\r
402 inner = outer.getFirst();
\r
404 inner.appendTo( outer );
\r
408 initDragAndDrop( this );
\r
409 initResizeHandles( this );
\r
411 // Insert the title.
\r
412 ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );
\r
414 // Insert the tabs and contents.
\r
415 for ( var i = 0 ; i < definition.contents.length ; i++ )
\r
416 this.addPage( definition.contents[i] );
\r
418 var tabRegex = /cke_dialog_tab(\s|$|_)/,
\r
419 tabOuterRegex = /cke_dialog_tab(\s|$)/;
\r
420 this.parts['tabs'].on( 'click', function( evt )
\r
422 var target = evt.data.getTarget(), firstNode = target, id, page;
\r
424 // If we aren't inside a tab, bail out.
\r
425 if ( !( tabRegex.test( target.$.className ) || target.getName() == 'a' ) )
\r
428 // Find the outer <td> container of the tab.
\r
429 id = target.$.id.substr( 0, target.$.id.lastIndexOf( '_' ) );
\r
430 this.selectPage( id );
\r
432 if ( this._.tabBarMode )
\r
434 this._.tabBarMode = false;
\r
435 this._.currentFocusIndex = -1;
\r
436 changeFocus( true );
\r
439 evt.data.preventDefault();
\r
443 var buttonsHtml = [],
\r
444 buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this,
\r
447 className : 'cke_dialog_footer_buttons',
\r
449 children : definition.buttons
\r
450 }, buttonsHtml ).getChild();
\r
451 this.parts.footer.setHtml( buttonsHtml.join( '' ) );
\r
453 for ( i = 0 ; i < buttons.length ; i++ )
\r
454 this._.buttons[ buttons[i].id ] = buttons[i];
\r
456 CKEDITOR.skins.load( editor, 'dialog' );
\r
459 // Focusable interface. Use it via dialog.addFocusable.
\r
460 function Focusable( dialog, element, index )
\r
462 this.element = element;
\r
463 this.focusIndex = index;
\r
464 this.isFocusable = function()
\r
466 return !element.getAttribute( 'disabled' ) && element.isVisible();
\r
468 this.focus = function()
\r
470 dialog._.currentFocusIndex = this.focusIndex;
\r
471 this.element.focus();
\r
474 element.on( 'keydown', function( e )
\r
476 if ( e.data.getKeystroke() in { 32:1, 13:1 } )
\r
477 this.fire( 'click' );
\r
479 element.on( 'focus', function()
\r
481 this.fire( 'mouseover' );
\r
483 element.on( 'blur', function()
\r
485 this.fire( 'mouseout' );
\r
489 CKEDITOR.dialog.prototype =
\r
492 * Resizes the dialog.
\r
493 * @param {Number} width The width of the dialog in pixels.
\r
494 * @param {Number} height The height of the dialog in pixels.
\r
497 * dialogObj.resize( 800, 640 );
\r
499 resize : (function()
\r
501 return function( width, height )
\r
503 if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )
\r
506 CKEDITOR.dialog.fire( 'resize',
\r
509 skin : this._.editor.skinName,
\r
512 }, this._.editor );
\r
514 this._.contentSize = { width : width, height : height };
\r
515 this._.updateSize = true;
\r
520 * Gets the current size of the dialog in pixels.
\r
521 * @returns {Object} An object with "width" and "height" properties.
\r
523 * var width = dialogObj.getSize().width;
\r
525 getSize : function()
\r
527 if ( !this._.updateSize )
\r
528 return this._.size;
\r
529 var element = this._.element.getFirst();
\r
530 var size = this._.size = { width : element.$.offsetWidth || 0, height : element.$.offsetHeight || 0};
\r
532 // If either the offsetWidth or offsetHeight is 0, the element isn't visible.
\r
533 this._.updateSize = !size.width || !size.height;
\r
539 * Moves the dialog to an (x, y) coordinate relative to the window.
\r
541 * @param {Number} x The target x-coordinate.
\r
542 * @param {Number} y The target y-coordinate.
\r
544 * dialogObj.move( 10, 40 );
\r
549 return function( x, y )
\r
551 // The dialog may be fixed positioned or absolute positioned. Ask the
\r
552 // browser what is the current situation first.
\r
553 var element = this._.element.getFirst();
\r
554 if ( isFixed === undefined )
\r
555 isFixed = element.getComputedStyle( 'position' ) == 'fixed';
\r
557 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
\r
560 // Save the current position.
\r
561 this._.position = { x : x, y : y };
\r
563 // If not fixed positioned, add scroll position to the coordinates.
\r
566 var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
\r
567 x += scrollPosition.x;
\r
568 y += scrollPosition.y;
\r
573 'left' : ( x > 0 ? x : 0 ) + 'px',
\r
574 'top' : ( y > 0 ? y : 0 ) + 'px'
\r
580 * Gets the dialog's position in the window.
\r
581 * @returns {Object} An object with "x" and "y" properties.
\r
583 * var dialogX = dialogObj.getPosition().x;
\r
585 getPosition : function(){ return CKEDITOR.tools.extend( {}, this._.position ); },
\r
588 * Shows the dialog box.
\r
590 * dialogObj.show();
\r
594 var editor = this._.editor;
\r
595 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
597 var selection = editor.getSelection();
\r
598 selection && selection.lock();
\r
601 // Insert the dialog's element to the root document.
\r
602 var element = this._.element;
\r
603 var definition = this.definition;
\r
604 if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )
\r
605 element.appendTo( CKEDITOR.document.getBody() );
\r
609 // FIREFOX BUG: Fix vanishing caret for Firefox 2 or Gecko 1.8.
\r
610 if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
\r
612 var dialogElement = this.parts.dialog;
\r
613 dialogElement.setStyle( 'position', 'absolute' );
\r
614 setTimeout( function()
\r
616 dialogElement.setStyle( 'position', 'fixed' );
\r
621 // First, set the dialog to an appropriate size.
\r
622 this.resize( definition.minWidth, definition.minHeight );
\r
624 // Select the first tab by default.
\r
625 this.selectPage( this.definition.contents[0].id );
\r
627 // Reset all inputs back to their default value.
\r
631 if ( CKEDITOR.dialog._.currentZIndex === null )
\r
632 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;
\r
633 this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
\r
635 // Maintain the dialog ordering and dialog cover.
\r
636 // Also register key handlers if first dialog.
\r
637 if ( CKEDITOR.dialog._.currentTop === null )
\r
639 CKEDITOR.dialog._.currentTop = this;
\r
640 this._.parentDialog = null;
\r
641 addCover( this._.editor );
\r
643 element.on( 'keydown', accessKeyDownHandler );
\r
644 element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
646 // Prevent some keys from bubbling up. (#4269)
\r
647 for ( var event in { keyup :1, keydown :1, keypress :1 } )
\r
648 element.on( event, preventKeyBubbling );
\r
652 this._.parentDialog = CKEDITOR.dialog._.currentTop;
\r
653 var parentElement = this._.parentDialog.getElement().getFirst();
\r
654 parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );
\r
655 CKEDITOR.dialog._.currentTop = this;
\r
658 // Register the Esc hotkeys.
\r
659 registerAccessKey( this, this, '\x1b', null, function()
\r
661 this.getButton( 'cancel' ) && this.getButton( 'cancel' ).click();
\r
664 // Reset the hasFocus state.
\r
665 this._.hasFocus = false;
\r
667 // Rearrange the dialog to the middle of the window.
\r
668 CKEDITOR.tools.setTimeout( function()
\r
670 var viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
\r
671 var dialogSize = this.getSize();
\r
673 // We're using definition size for initial position because of
\r
674 // offten corrupted data in offsetWidth at this point. (#4084)
\r
675 this.move( ( viewSize.width - definition.minWidth ) / 2, ( viewSize.height - dialogSize.height ) / 2 );
\r
677 this.parts.dialog.setStyle( 'visibility', '' );
\r
679 // Execute onLoad for the first show.
\r
680 this.fireOnce( 'load', {} );
\r
681 this.fire( 'show', {} );
\r
683 // Save the initial values of the dialog.
\r
684 this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } );
\r
691 * Executes a function for each UI element.
\r
692 * @param {Function} fn Function to execute for each UI element.
\r
693 * @returns {CKEDITOR.dialog} The current dialog object.
\r
695 foreach : function( fn )
\r
697 for ( var i in this._.contents )
\r
699 for ( var j in this._.contents[i] )
\r
700 fn( this._.contents[i][j]);
\r
706 * Resets all input values in the dialog.
\r
708 * dialogObj.reset();
\r
709 * @returns {CKEDITOR.dialog} The current dialog object.
\r
711 reset : (function()
\r
713 var fn = function( widget ){ if ( widget.reset ) widget.reset(); };
\r
714 return function(){ this.foreach( fn ); return this; };
\r
717 setupContent : function()
\r
719 var args = arguments;
\r
720 this.foreach( function( widget )
\r
722 if ( widget.setup )
\r
723 widget.setup.apply( widget, args );
\r
727 commitContent : function()
\r
729 var args = arguments;
\r
730 this.foreach( function( widget )
\r
732 if ( widget.commit )
\r
733 widget.commit.apply( widget, args );
\r
738 * Hides the dialog box.
\r
740 * dialogObj.hide();
\r
744 this.fire( 'hide', {} );
\r
746 // Remove the dialog's element from the root document.
\r
747 var element = this._.element;
\r
748 if ( !element.getParent() )
\r
752 this.parts.dialog.setStyle( 'visibility', 'hidden' );
\r
754 // Unregister all access keys associated with this dialog.
\r
755 unregisterAccessKey( this );
\r
757 // Maintain dialog ordering and remove cover if needed.
\r
758 if ( !this._.parentDialog )
\r
762 var parentElement = this._.parentDialog.getElement().getFirst();
\r
763 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
\r
765 CKEDITOR.dialog._.currentTop = this._.parentDialog;
\r
767 // Deduct or clear the z-index.
\r
768 if ( !this._.parentDialog )
\r
770 CKEDITOR.dialog._.currentZIndex = null;
\r
772 // Remove access key handlers.
\r
773 element.removeListener( 'keydown', accessKeyDownHandler );
\r
774 element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
776 // Remove bubbling-prevention handler. (#4269)
\r
777 for ( var event in { keyup :1, keydown :1, keypress :1 } )
\r
778 element.removeListener( event, preventKeyBubbling );
\r
780 var editor = this._.editor;
\r
783 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
785 var selection = editor.getSelection();
\r
786 selection && selection.unlock( true );
\r
790 CKEDITOR.dialog._.currentZIndex -= 10;
\r
793 // Reset the initial values of the dialog.
\r
794 this.foreach( function( contentObj ) { contentObj.resetInitValue && contentObj.resetInitValue(); } );
\r
798 * Adds a tabbed page into the dialog.
\r
799 * @param {Object} contents Content definition.
\r
802 addPage : function( contents )
\r
805 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
\r
806 elements = contents.elements,
\r
807 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this,
\r
810 className : 'cke_dialog_page_contents',
\r
811 children : contents.elements,
\r
812 expand : !!contents.expand,
\r
813 padding : contents.padding,
\r
814 style : contents.style || 'width: 100%;'
\r
817 // Create the HTML for the tab and the content block.
\r
818 var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
\r
819 var tab = CKEDITOR.dom.element.createFromHtml( [
\r
820 '<a class="cke_dialog_tab"',
\r
821 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),
\r
823 ( !!contents.hidden ? ' style="display:none"' : '' ),
\r
824 ' id="', contents.id + '_', CKEDITOR.tools.getNextNumber(), '"' +
\r
825 ' href="javascript:void(0)"',
\r
826 ' hidefocus="true">',
\r
831 // If only a single page exist, a different style is used in the central pane.
\r
832 if ( this._.pageCount === 0 )
\r
833 this.parts.dialog.addClass( 'cke_single_page' );
\r
835 this.parts.dialog.removeClass( 'cke_single_page' );
\r
837 // Take records for the tabs and elements created.
\r
838 this._.tabs[ contents.id ] = [ tab, page ];
\r
839 this._.tabIdList.push( contents.id );
\r
840 this._.pageCount++;
\r
841 this._.lastTab = tab;
\r
843 var contentMap = this._.contents[ contents.id ] = {},
\r
845 children = vbox.getChild();
\r
847 while ( ( cursor = children.shift() ) )
\r
849 contentMap[ cursor.id ] = cursor;
\r
850 if ( typeof( cursor.getChild ) == 'function' )
\r
851 children.push.apply( children, cursor.getChild() );
\r
854 // Attach the DOM nodes.
\r
856 page.setAttribute( 'name', contents.id );
\r
857 page.appendTo( this.parts.contents );
\r
859 tab.unselectable();
\r
860 this.parts.tabs.append( tab );
\r
862 // Add access key handlers if access key is defined.
\r
863 if ( contents.accessKey )
\r
865 registerAccessKey( this, this, 'CTRL+' + contents.accessKey,
\r
866 tabAccessKeyDown, tabAccessKeyUp );
\r
867 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;
\r
872 * Activates a tab page in the dialog by its id.
\r
873 * @param {String} id The id of the dialog tab to be activated.
\r
875 * dialogObj.selectPage( 'tab_1' );
\r
877 selectPage : function( id )
\r
879 // Hide the non-selected tabs and pages.
\r
880 for ( var i in this._.tabs )
\r
882 var tab = this._.tabs[i][0],
\r
883 page = this._.tabs[i][1];
\r
886 tab.removeClass( 'cke_dialog_tab_selected' );
\r
891 var selected = this._.tabs[id];
\r
892 selected[0].addClass( 'cke_dialog_tab_selected' );
\r
893 selected[1].show();
\r
894 this._.currentTabId = id;
\r
895 this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
\r
899 * Hides a page's tab away from the dialog.
\r
900 * @param {String} id The page's Id.
\r
902 * dialog.hidePage( 'tab_3' );
\r
904 hidePage : function( id )
\r
906 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
913 * Unhides a page's tab.
\r
914 * @param {String} id The page's Id.
\r
916 * dialog.showPage( 'tab_2' );
\r
918 showPage : function( id )
\r
920 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
927 * Gets the root DOM element of the dialog.
\r
928 * @returns {CKEDITOR.dom.element} The <span> element containing this dialog.
\r
930 * var dialogElement = dialogObj.getElement().getFirst();
\r
931 * dialogElement.setStyle( 'padding', '5px' );
\r
933 getElement : function()
\r
935 return this._.element;
\r
939 * Gets the name of the dialog.
\r
940 * @returns {String} The name of this dialog.
\r
942 * var dialogName = dialogObj.getName();
\r
944 getName : function()
\r
946 return this._.name;
\r
950 * Gets a dialog UI element object from a dialog page.
\r
951 * @param {String} pageId id of dialog page.
\r
952 * @param {String} elementId id of UI element.
\r
954 * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.
\r
956 getContentElement : function( pageId, elementId )
\r
958 return this._.contents[pageId][elementId];
\r
962 * Gets the value of a dialog UI element.
\r
963 * @param {String} pageId id of dialog page.
\r
964 * @param {String} elementId id of UI element.
\r
966 * @returns {Object} The value of the UI element.
\r
968 getValueOf : function( pageId, elementId )
\r
970 return this.getContentElement( pageId, elementId ).getValue();
\r
974 * Sets the value of a dialog UI element.
\r
975 * @param {String} pageId id of the dialog page.
\r
976 * @param {String} elementId id of the UI element.
\r
977 * @param {Object} value The new value of the UI element.
\r
980 setValueOf : function( pageId, elementId, value )
\r
982 return this.getContentElement( pageId, elementId ).setValue( value );
\r
986 * Gets the UI element of a button in the dialog's button row.
\r
987 * @param {String} id The id of the button.
\r
989 * @returns {CKEDITOR.ui.dialog.button} The button object.
\r
991 getButton : function( id )
\r
993 return this._.buttons[ id ];
\r
997 * Simulates a click to a dialog button in the dialog's button row.
\r
998 * @param {String} id The id of the button.
\r
1000 * @returns The return value of the dialog's "click" event.
\r
1002 click : function( id )
\r
1004 return this._.buttons[ id ].click();
\r
1008 * Disables a dialog button.
\r
1009 * @param {String} id The id of the button.
\r
1012 disableButton : function( id )
\r
1014 return this._.buttons[ id ].disable();
\r
1018 * Enables a dialog button.
\r
1019 * @param {String} id The id of the button.
\r
1022 enableButton : function( id )
\r
1024 return this._.buttons[ id ].enable();
\r
1028 * Gets the number of pages in the dialog.
\r
1029 * @returns {Number} Page count.
\r
1031 getPageCount : function()
\r
1033 return this._.pageCount;
\r
1037 * Gets the editor instance which opened this dialog.
\r
1038 * @returns {CKEDITOR.editor} Parent editor instances.
\r
1040 getParentEditor : function()
\r
1042 return this._.editor;
\r
1046 * Gets the element that was selected when opening the dialog, if any.
\r
1047 * @returns {CKEDITOR.dom.element} The element that was selected, or null.
\r
1049 getSelectedElement : function()
\r
1051 return this.getParentEditor().getSelection().getSelectedElement();
\r
1055 * Adds element to dialog's focusable list.
\r
1057 * @param {CKEDITOR.dom.element} element
\r
1058 * @param {Number} [index]
\r
1060 addFocusable: function( element, index ) {
\r
1061 if ( typeof index == 'undefined' )
\r
1063 index = this._.focusList.length;
\r
1064 this._.focusList.push( new Focusable( this, element, index ) );
\r
1068 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );
\r
1069 for ( var i = index + 1 ; i < this._.focusList.length ; i++ )
\r
1070 this._.focusList[ i ].focusIndex++;
\r
1075 CKEDITOR.tools.extend( CKEDITOR.dialog,
\r
1077 * @lends CKEDITOR.dialog
\r
1081 * Registers a dialog.
\r
1082 * @param {String} name The dialog's name.
\r
1083 * @param {Function|String} dialogDefinition
\r
1084 * A function returning the dialog's definition, or the URL to the .js file holding the function.
\r
1085 * The function should accept an argument "editor" which is the current editor instance, and
\r
1086 * return an object conforming to {@link CKEDITOR.dialog.dialogDefinition}.
\r
1088 * @see CKEDITOR.dialog.dialogDefinition
\r
1090 add : function( name, dialogDefinition )
\r
1092 // Avoid path registration from multiple instances override definition.
\r
1093 if ( !this._.dialogDefinitions[name]
\r
1094 || typeof dialogDefinition == 'function' )
\r
1095 this._.dialogDefinitions[name] = dialogDefinition;
\r
1098 exists : function( name )
\r
1100 return !!this._.dialogDefinitions[ name ];
\r
1103 getCurrent : function()
\r
1105 return CKEDITOR.dialog._.currentTop;
\r
1109 * The default OK button for dialogs. Fires the "ok" event and closes the dialog if the event succeeds.
\r
1115 okButton : (function()
\r
1117 var retval = function( editor, override )
\r
1119 override = override || {};
\r
1120 return CKEDITOR.tools.extend( {
\r
1123 label : editor.lang.common.ok,
\r
1124 'class' : 'cke_dialog_ui_button_ok',
\r
1125 onClick : function( evt )
\r
1127 var dialog = evt.data.dialog;
\r
1128 if ( dialog.fire( 'ok', { hide : true } ).hide !== false )
\r
1131 }, override, true );
\r
1133 retval.type = 'button';
\r
1134 retval.override = function( override )
\r
1136 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1137 { type : 'button' }, true );
\r
1143 * The default cancel button for dialogs. Fires the "cancel" event and closes the dialog if no UI element value changed.
\r
1149 cancelButton : (function()
\r
1151 var retval = function( editor, override )
\r
1153 override = override || {};
\r
1154 return CKEDITOR.tools.extend( {
\r
1157 label : editor.lang.common.cancel,
\r
1158 'class' : 'cke_dialog_ui_button_cancel',
\r
1159 onClick : function( evt )
\r
1161 var dialog = evt.data.dialog;
\r
1162 if ( dialog.fire( 'cancel', { hide : true } ).hide !== false )
\r
1165 }, override, true );
\r
1167 retval.type = 'button';
\r
1168 retval.override = function( override )
\r
1170 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1171 { type : 'button' }, true );
\r
1177 * Registers a dialog UI element.
\r
1178 * @param {String} typeName The name of the UI element.
\r
1179 * @param {Function} builder The function to build the UI element.
\r
1182 addUIElement : function( typeName, builder )
\r
1184 this._.uiElementBuilders[ typeName ] = builder;
\r
1188 CKEDITOR.dialog._ =
\r
1190 uiElementBuilders : {},
\r
1192 dialogDefinitions : {},
\r
1194 currentTop : null,
\r
1196 currentZIndex : null
\r
1199 // "Inherit" (copy actually) from CKEDITOR.event.
\r
1200 CKEDITOR.event.implementOn( CKEDITOR.dialog );
\r
1201 CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype, true );
\r
1203 var defaultDialogDefinition =
\r
1205 resizable : CKEDITOR.DIALOG_RESIZE_NONE,
\r
1208 buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
\r
1211 // Tool function used to return an item from an array based on its id
\r
1213 var getById = function( array, id, recurse )
\r
1215 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1217 if ( item.id == id )
\r
1219 if ( recurse && item[ recurse ] )
\r
1221 var retval = getById( item[ recurse ], id, recurse ) ;
\r
1229 // Tool function used to add an item into an array.
\r
1230 var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound )
\r
1232 if ( nextSiblingId )
\r
1234 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1236 if ( item.id == nextSiblingId )
\r
1238 array.splice( i, 0, newItem );
\r
1242 if ( recurse && item[ recurse ] )
\r
1244 var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
\r
1250 if ( nullIfNotFound )
\r
1254 array.push( newItem );
\r
1258 // Tool function used to remove an item from an array based on its id.
\r
1259 var removeById = function( array, id, recurse )
\r
1261 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1263 if ( item.id == id )
\r
1264 return array.splice( i, 1 );
\r
1265 if ( recurse && item[ recurse ] )
\r
1267 var retval = removeById( item[ recurse ], id, recurse );
\r
1276 * This class is not really part of the API. It is the "definition" property value
\r
1277 * passed to "dialogDefinition" event handlers.
\r
1279 * @name CKEDITOR.dialog.dialogDefinitionObject
\r
1280 * @extends CKEDITOR.dialog.dialogDefinition
\r
1282 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1284 * var definition = evt.data.definition;
\r
1285 * var content = definition.getContents( 'page1' );
\r
1289 var definitionObject = function( dialog, dialogDefinition )
\r
1291 // TODO : Check if needed.
\r
1292 this.dialog = dialog;
\r
1294 // Transform the contents entries in contentObjects.
\r
1295 var contents = dialogDefinition.contents;
\r
1296 for ( var i = 0, content ; ( content = contents[i] ) ; i++ )
\r
1297 contents[ i ] = new contentObject( dialog, content );
\r
1299 CKEDITOR.tools.extend( this, dialogDefinition );
\r
1302 definitionObject.prototype =
\r
1303 /** @lends CKEDITOR.dialog.dialogDefinitionObject.prototype */
\r
1306 * Gets a content definition.
\r
1307 * @param {String} id The id of the content definition.
\r
1308 * @returns {CKEDITOR.dialog.contentDefinition} The content definition
\r
1311 getContents : function( id )
\r
1313 return getById( this.contents, id );
\r
1317 * Gets a button definition.
\r
1318 * @param {String} id The id of the button definition.
\r
1319 * @returns {CKEDITOR.dialog.buttonDefinition} The button definition
\r
1322 getButton : function( id )
\r
1324 return getById( this.buttons, id );
\r
1328 * Adds a content definition object under this dialog definition.
\r
1329 * @param {CKEDITOR.dialog.contentDefinition} contentDefinition The
\r
1330 * content definition.
\r
1331 * @param {String} [nextSiblingId] The id of an existing content
\r
1332 * definition which the new content definition will be inserted
\r
1333 * before. Omit if the new content definition is to be inserted as
\r
1335 * @returns {CKEDITOR.dialog.contentDefinition} The inserted content
\r
1338 addContents : function( contentDefinition, nextSiblingId )
\r
1340 return addById( this.contents, contentDefinition, nextSiblingId );
\r
1344 * Adds a button definition object under this dialog definition.
\r
1345 * @param {CKEDITOR.dialog.buttonDefinition} buttonDefinition The
\r
1346 * button definition.
\r
1347 * @param {String} [nextSiblingId] The id of an existing button
\r
1348 * definition which the new button definition will be inserted
\r
1349 * before. Omit if the new button definition is to be inserted as
\r
1351 * @returns {CKEDITOR.dialog.buttonDefinition} The inserted button
\r
1354 addButton : function( buttonDefinition, nextSiblingId )
\r
1356 return addById( this.buttons, buttonDefinition, nextSiblingId );
\r
1360 * Removes a content definition from this dialog definition.
\r
1361 * @param {String} id The id of the content definition to be removed.
\r
1362 * @returns {CKEDITOR.dialog.contentDefinition} The removed content
\r
1365 removeContents : function( id )
\r
1367 removeById( this.contents, id );
\r
1371 * Removes a button definition from the dialog definition.
\r
1372 * @param {String} id The id of the button definition to be removed.
\r
1373 * @returns {CKEDITOR.dialog.buttonDefinition} The removed button
\r
1376 removeButton : function( id )
\r
1378 removeById( this.buttons, id );
\r
1383 * This class is not really part of the API. It is the template of the
\r
1384 * objects representing content pages inside the
\r
1385 * CKEDITOR.dialog.dialogDefinitionObject.
\r
1387 * @name CKEDITOR.dialog.contentDefinitionObject
\r
1389 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1391 * var definition = evt.data.definition;
\r
1392 * var content = definition.getContents( 'page1' );
\r
1393 * content.remove( 'textInput1' );
\r
1397 function contentObject( dialog, contentDefinition )
\r
1404 CKEDITOR.tools.extend( this, contentDefinition );
\r
1407 contentObject.prototype =
\r
1408 /** @lends CKEDITOR.dialog.contentDefinitionObject.prototype */
\r
1411 * Gets a UI element definition under the content definition.
\r
1412 * @param {String} id The id of the UI element definition.
\r
1413 * @returns {CKEDITOR.dialog.uiElementDefinition}
\r
1415 get : function( id )
\r
1417 return getById( this.elements, id, 'children' );
\r
1421 * Adds a UI element definition to the content definition.
\r
1422 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition The
\r
1423 * UI elemnet definition to be added.
\r
1424 * @param {String} nextSiblingId The id of an existing UI element
\r
1425 * definition which the new UI element definition will be inserted
\r
1426 * before. Omit if the new button definition is to be inserted as
\r
1428 * @returns {CKEDITOR.dialog.uiElementDefinition} The element
\r
1429 * definition inserted.
\r
1431 add : function( elementDefinition, nextSiblingId )
\r
1433 return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
\r
1437 * Removes a UI element definition from the content definition.
\r
1438 * @param {String} id The id of the UI element definition to be
\r
1440 * @returns {CKEDITOR.dialog.uiElementDefinition} The element
\r
1441 * definition removed.
\r
1444 remove : function( id )
\r
1446 removeById( this.elements, id, 'children' );
\r
1450 function initDragAndDrop( dialog )
\r
1452 var lastCoords = null,
\r
1453 abstractDialogCoords = null,
\r
1454 element = dialog.getElement().getFirst(),
\r
1455 editor = dialog.getParentEditor(),
\r
1456 magnetDistance = editor.config.dialog_magnetDistance,
\r
1457 margins = skinData[ editor.skinName ].margins || [ 0, 0, 0, 0 ];
\r
1459 if ( typeof magnetDistance == 'undefined' )
\r
1460 magnetDistance = 20;
\r
1462 function mouseMoveHandler( evt )
\r
1464 var dialogSize = dialog.getSize(),
\r
1465 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
1466 x = evt.data.$.screenX,
\r
1467 y = evt.data.$.screenY,
\r
1468 dx = x - lastCoords.x,
\r
1469 dy = y - lastCoords.y,
\r
1472 lastCoords = { x : x, y : y };
\r
1473 abstractDialogCoords.x += dx;
\r
1474 abstractDialogCoords.y += dy;
\r
1476 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
\r
1477 realX = - margins[3];
\r
1478 else if ( abstractDialogCoords.x - margins[1] > viewPaneSize.width - dialogSize.width - magnetDistance )
\r
1479 realX = viewPaneSize.width - dialogSize.width + margins[1];
\r
1481 realX = abstractDialogCoords.x;
\r
1483 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
\r
1484 realY = - margins[0];
\r
1485 else if ( abstractDialogCoords.y - margins[2] > viewPaneSize.height - dialogSize.height - magnetDistance )
\r
1486 realY = viewPaneSize.height - dialogSize.height + margins[2];
\r
1488 realY = abstractDialogCoords.y;
\r
1490 dialog.move( realX, realY );
\r
1492 evt.data.preventDefault();
\r
1495 function mouseUpHandler( evt )
\r
1497 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1498 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1500 if ( CKEDITOR.env.ie6Compat )
\r
1502 var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
\r
1503 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1504 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1508 dialog.parts.title.on( 'mousedown', function( evt )
\r
1510 dialog._.updateSize = true;
\r
1512 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
\r
1514 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
\r
1515 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
\r
1516 abstractDialogCoords = dialog.getPosition();
\r
1518 if ( CKEDITOR.env.ie6Compat )
\r
1520 var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
\r
1521 coverDoc.on( 'mousemove', mouseMoveHandler );
\r
1522 coverDoc.on( 'mouseup', mouseUpHandler );
\r
1525 evt.data.preventDefault();
\r
1529 function initResizeHandles( dialog )
\r
1531 var definition = dialog.definition,
\r
1532 minWidth = definition.minWidth || 0,
\r
1533 minHeight = definition.minHeight || 0,
\r
1534 resizable = definition.resizable,
\r
1535 margins = skinData[ dialog.getParentEditor().skinName ].margins || [ 0, 0, 0, 0 ];
\r
1537 function topSizer( coords, dy )
\r
1542 function rightSizer( coords, dx )
\r
1547 function bottomSizer( coords, dy )
\r
1552 function leftSizer( coords, dx )
\r
1557 var lastCoords = null,
\r
1558 abstractDialogCoords = null,
\r
1559 magnetDistance = dialog._.editor.config.magnetDistance,
\r
1560 parts = [ 'tl', 't', 'tr', 'l', 'r', 'bl', 'b', 'br' ];
\r
1562 function mouseDownHandler( evt )
\r
1564 var partName = evt.listenerData.part, size = dialog.getSize();
\r
1565 abstractDialogCoords = dialog.getPosition();
\r
1566 CKEDITOR.tools.extend( abstractDialogCoords,
\r
1568 x2 : abstractDialogCoords.x + size.width,
\r
1569 y2 : abstractDialogCoords.y + size.height
\r
1571 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
\r
1573 CKEDITOR.document.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } );
\r
1574 CKEDITOR.document.on( 'mouseup', mouseUpHandler, dialog, { part : partName } );
\r
1576 if ( CKEDITOR.env.ie6Compat )
\r
1578 var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
\r
1579 coverDoc.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } );
\r
1580 coverDoc.on( 'mouseup', mouseUpHandler, dialog, { part : partName } );
\r
1583 evt.data.preventDefault();
\r
1586 function mouseMoveHandler( evt )
\r
1588 var x = evt.data.$.screenX,
\r
1589 y = evt.data.$.screenY,
\r
1590 dx = x - lastCoords.x,
\r
1591 dy = y - lastCoords.y,
\r
1592 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
1593 partName = evt.listenerData.part;
\r
1595 if ( partName.search( 't' ) != -1 )
\r
1596 topSizer( abstractDialogCoords, dy );
\r
1597 if ( partName.search( 'l' ) != -1 )
\r
1598 leftSizer( abstractDialogCoords, dx );
\r
1599 if ( partName.search( 'b' ) != -1 )
\r
1600 bottomSizer( abstractDialogCoords, dy );
\r
1601 if ( partName.search( 'r' ) != -1 )
\r
1602 rightSizer( abstractDialogCoords, dx );
\r
1604 lastCoords = { x : x, y : y };
\r
1606 var realX, realY, realX2, realY2;
\r
1608 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
\r
1609 realX = - margins[3];
\r
1610 else if ( partName.search( 'l' ) != -1 && abstractDialogCoords.x2 - abstractDialogCoords.x < minWidth + magnetDistance )
\r
1611 realX = abstractDialogCoords.x2 - minWidth;
\r
1613 realX = abstractDialogCoords.x;
\r
1615 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
\r
1616 realY = - margins[0];
\r
1617 else if ( partName.search( 't' ) != -1 && abstractDialogCoords.y2 - abstractDialogCoords.y < minHeight + magnetDistance )
\r
1618 realY = abstractDialogCoords.y2 - minHeight;
\r
1620 realY = abstractDialogCoords.y;
\r
1622 if ( abstractDialogCoords.x2 - margins[1] > viewPaneSize.width - magnetDistance )
\r
1623 realX2 = viewPaneSize.width + margins[1] ;
\r
1624 else if ( partName.search( 'r' ) != -1 && abstractDialogCoords.x2 - abstractDialogCoords.x < minWidth + magnetDistance )
\r
1625 realX2 = abstractDialogCoords.x + minWidth;
\r
1627 realX2 = abstractDialogCoords.x2;
\r
1629 if ( abstractDialogCoords.y2 - margins[2] > viewPaneSize.height - magnetDistance )
\r
1630 realY2= viewPaneSize.height + margins[2] ;
\r
1631 else if ( partName.search( 'b' ) != -1 && abstractDialogCoords.y2 - abstractDialogCoords.y < minHeight + magnetDistance )
\r
1632 realY2 = abstractDialogCoords.y + minHeight;
\r
1634 realY2 = abstractDialogCoords.y2 ;
\r
1636 dialog.move( realX, realY );
\r
1637 dialog.resize( realX2 - realX, realY2 - realY );
\r
1639 evt.data.preventDefault();
\r
1642 function mouseUpHandler( evt )
\r
1644 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1645 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1647 if ( CKEDITOR.env.ie6Compat )
\r
1649 var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
\r
1650 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1651 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1655 // TODO : Simplify the resize logic, having just a single resize grip <div>.
\r
1656 // var widthTest = /[lr]/,
\r
1657 // heightTest = /[tb]/;
\r
1658 // for ( var i = 0 ; i < parts.length ; i++ )
\r
1660 // var element = dialog.parts[ parts[i] + '_resize' ];
\r
1661 // if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE ||
\r
1662 // resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT && widthTest.test( parts[i] ) ||
\r
1663 // resizable == CKEDITOR.DIALOG_RESIZE_WIDTH && heightTest.test( parts[i] ) )
\r
1665 // element.hide();
\r
1668 // element.on( 'mousedown', mouseDownHandler, dialog, { part : parts[i] } );
\r
1675 var addCover = function( editor )
\r
1677 var win = CKEDITOR.document.getWindow();
\r
1679 if ( !coverElement )
\r
1681 var backgroundColorStyle = editor.config.dialog_backgroundCoverColor || 'white';
\r
1684 '<div style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),
\r
1685 '; z-index: ', editor.config.baseFloatZIndex,
\r
1686 '; top: 0px; left: 0px; ',
\r
1687 ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),
\r
1688 '" id="cke_dialog_background_cover">'
\r
1692 if ( CKEDITOR.env.ie6Compat )
\r
1694 // Support for custom document.domain in IE.
\r
1695 var isCustomDomain = CKEDITOR.env.isCustomDomain(),
\r
1696 iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
\r
1700 ' hidefocus="true"' +
\r
1701 ' frameborder="0"' +
\r
1702 ' id="cke_dialog_background_iframe"' +
\r
1703 ' src="javascript:' );
\r
1705 html.push( 'void((function(){' +
\r
1706 'document.open();' +
\r
1707 ( isCustomDomain ? 'document.domain=\'' + document.domain + '\';' : '' ) +
\r
1708 'document.write( \'' + iframeHtml + '\' );' +
\r
1709 'document.close();' +
\r
1715 'position:absolute;' +
\r
1720 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
\r
1724 html.push( '</div>' );
\r
1726 coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
\r
1729 var element = coverElement;
\r
1731 var resizeFunc = function()
\r
1733 var size = win.getViewPaneSize();
\r
1734 element.setStyles(
\r
1736 width : size.width + 'px',
\r
1737 height : size.height + 'px'
\r
1741 var scrollFunc = function()
\r
1743 var pos = win.getScrollPosition(),
\r
1744 cursor = CKEDITOR.dialog._.currentTop;
\r
1745 element.setStyles(
\r
1747 left : pos.x + 'px',
\r
1748 top : pos.y + 'px'
\r
1753 var dialogPos = cursor.getPosition();
\r
1754 cursor.move( dialogPos.x, dialogPos.y );
\r
1755 } while( ( cursor = cursor._.parentDialog ) );
\r
1758 resizeCover = resizeFunc;
\r
1759 win.on( 'resize', resizeFunc );
\r
1761 if ( CKEDITOR.env.ie6Compat )
\r
1763 // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
\r
1764 // So we need to invent a really funny way to make it work.
\r
1765 var myScrollHandler = function()
\r
1768 arguments.callee.prevScrollHandler.apply( this, arguments );
\r
1770 win.$.setTimeout( function()
\r
1772 myScrollHandler.prevScrollHandler = window.onscroll || function(){};
\r
1773 window.onscroll = myScrollHandler;
\r
1778 var opacity = editor.config.dialog_backgroundCoverOpacity;
\r
1779 element.setOpacity( typeof opacity != 'undefined' ? opacity : 0.5 );
\r
1781 element.appendTo( CKEDITOR.document.getBody() );
\r
1784 var removeCover = function()
\r
1786 if ( !coverElement )
\r
1789 var win = CKEDITOR.document.getWindow();
\r
1790 coverElement.remove();
\r
1791 win.removeListener( 'resize', resizeCover );
\r
1793 if ( CKEDITOR.env.ie6Compat )
\r
1795 win.$.setTimeout( function()
\r
1797 var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
\r
1798 window.onscroll = prevScrollHandler || null;
\r
1801 resizeCover = null;
\r
1804 var accessKeyProcessors = {};
\r
1806 var accessKeyDownHandler = function( evt )
\r
1808 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
1809 alt = evt.data.$.altKey,
\r
1810 shift = evt.data.$.shiftKey,
\r
1811 key = String.fromCharCode( evt.data.$.keyCode ),
\r
1812 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
1814 if ( !keyProcessor || !keyProcessor.length )
\r
1817 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
1818 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
1819 evt.data.preventDefault();
\r
1822 var accessKeyUpHandler = function( evt )
\r
1824 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
1825 alt = evt.data.$.altKey,
\r
1826 shift = evt.data.$.shiftKey,
\r
1827 key = String.fromCharCode( evt.data.$.keyCode ),
\r
1828 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
1830 if ( !keyProcessor || !keyProcessor.length )
\r
1833 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
1834 if ( keyProcessor.keyup )
\r
1836 keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
1837 evt.data.preventDefault();
\r
1841 var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc )
\r
1843 var procList = accessKeyProcessors[key] || ( accessKeyProcessors[key] = [] );
\r
1845 uiElement : uiElement,
\r
1848 keyup : upFunc || uiElement.accessKeyUp,
\r
1849 keydown : downFunc || uiElement.accessKeyDown
\r
1853 var unregisterAccessKey = function( obj )
\r
1855 for ( var i in accessKeyProcessors )
\r
1857 var list = accessKeyProcessors[i];
\r
1858 for ( var j = list.length - 1 ; j >= 0 ; j-- )
\r
1860 if ( list[j].dialog == obj || list[j].uiElement == obj )
\r
1861 list.splice( j, 1 );
\r
1863 if ( list.length === 0 )
\r
1864 delete accessKeyProcessors[i];
\r
1868 var tabAccessKeyUp = function( dialog, key )
\r
1870 if ( dialog._.accessKeyMap[key] )
\r
1871 dialog.selectPage( dialog._.accessKeyMap[key] );
\r
1874 var tabAccessKeyDown = function( dialog, key )
\r
1879 var preventKeyBubblingKeys = { 27 :1, 13 :1 };
\r
1880 var preventKeyBubbling = function( e )
\r
1882 if ( e.data.getKeystroke() in preventKeyBubblingKeys )
\r
1883 e.data.stopPropagation();
\r
1888 CKEDITOR.ui.dialog =
\r
1891 * The base class of all dialog UI elements.
\r
1893 * @param {CKEDITOR.dialog} dialog Parent dialog object.
\r
1894 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition Element
\r
1895 * definition. Accepted fields:
\r
1897 * <li><strong>id</strong> (Required) The id of the UI element. See {@link
\r
1898 * CKEDITOR.dialog#getContentElement}</li>
\r
1899 * <li><strong>type</strong> (Required) The type of the UI element. The
\r
1900 * value to this field specifies which UI element class will be used to
\r
1901 * generate the final widget.</li>
\r
1902 * <li><strong>title</strong> (Optional) The popup tooltip for the UI
\r
1904 * <li><strong>hidden</strong> (Optional) A flag that tells if the element
\r
1905 * should be initially visible.</li>
\r
1906 * <li><strong>className</strong> (Optional) Additional CSS class names
\r
1907 * to add to the UI element. Separated by space.</li>
\r
1908 * <li><strong>style</strong> (Optional) Additional CSS inline styles
\r
1909 * to add to the UI element. A semicolon (;) is required after the last
\r
1910 * style declaration.</li>
\r
1911 * <li><strong>accessKey</strong> (Optional) The alphanumeric access key
\r
1912 * for this element. Access keys are automatically prefixed by CTRL.</li>
\r
1913 * <li><strong>on*</strong> (Optional) Any UI element definition field that
\r
1914 * starts with <em>on</em> followed immediately by a capital letter and
\r
1915 * probably more letters is an event handler. Event handlers may be further
\r
1916 * divided into registered event handlers and DOM event handlers. Please
\r
1917 * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and
\r
1918 * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more
\r
1919 * information.</li>
\r
1921 * @param {Array} htmlList
\r
1922 * List of HTML code to be added to the dialog's content area.
\r
1923 * @param {Function|String} nodeNameArg
\r
1924 * A function returning a string, or a simple string for the node name for
\r
1925 * the root DOM node. Default is 'div'.
\r
1926 * @param {Function|Object} stylesArg
\r
1927 * A function returning an object, or a simple object for CSS styles applied
\r
1928 * to the DOM node. Default is empty object.
\r
1929 * @param {Function|Object} attributesArg
\r
1930 * A fucntion returning an object, or a simple object for attributes applied
\r
1931 * to the DOM node. Default is empty object.
\r
1932 * @param {Function|String} contentsArg
\r
1933 * A function returning a string, or a simple string for the HTML code inside
\r
1934 * the root DOM node. Default is empty string.
\r
1937 uiElement : function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg )
\r
1939 if ( arguments.length < 4 )
\r
1942 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',
\r
1943 html = [ '<', nodeName, ' ' ],
\r
1944 styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},
\r
1945 attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},
\r
1946 innerHTML = ( contentsArg && contentsArg.call ? contentsArg( dialog, elementDefinition ) : contentsArg ) || '',
\r
1947 domId = this.domId = attributes.id || CKEDITOR.tools.getNextNumber() + '_uiElement',
\r
1948 id = this.id = elementDefinition.id,
\r
1951 // Set the id, a unique id is required for getElement() to work.
\r
1952 attributes.id = domId;
\r
1954 // Set the type and definition CSS class names.
\r
1956 if ( elementDefinition.type )
\r
1957 classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;
\r
1958 if ( elementDefinition.className )
\r
1959 classes[ elementDefinition.className ] = 1;
\r
1960 var attributeClasses = ( attributes['class'] && attributes['class'].split ) ? attributes['class'].split( ' ' ) : [];
\r
1961 for ( i = 0 ; i < attributeClasses.length ; i++ )
\r
1963 if ( attributeClasses[i] )
\r
1964 classes[ attributeClasses[i] ] = 1;
\r
1966 var finalClasses = [];
\r
1967 for ( i in classes )
\r
1968 finalClasses.push( i );
\r
1969 attributes['class'] = finalClasses.join( ' ' );
\r
1971 // Set the popup tooltop.
\r
1972 if ( elementDefinition.title )
\r
1973 attributes.title = elementDefinition.title;
\r
1975 // Write the inline CSS styles.
\r
1976 var styleStr = ( elementDefinition.style || '' ).split( ';' );
\r
1977 for ( i in styles )
\r
1978 styleStr.push( i + ':' + styles[i] );
\r
1979 if ( elementDefinition.hidden )
\r
1980 styleStr.push( 'display:none' );
\r
1981 for ( i = styleStr.length - 1 ; i >= 0 ; i-- )
\r
1983 if ( styleStr[i] === '' )
\r
1984 styleStr.splice( i, 1 );
\r
1986 if ( styleStr.length > 0 )
\r
1987 attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
\r
1989 // Write the attributes.
\r
1990 for ( i in attributes )
\r
1991 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '" ');
\r
1993 // Write the content HTML.
\r
1994 html.push( '>', innerHTML, '</', nodeName, '>' );
\r
1996 // Add contents to the parent HTML array.
\r
1997 htmlList.push( html.join( '' ) );
\r
1999 ( this._ || ( this._ = {} ) ).dialog = dialog;
\r
2001 // Override isChanged if it is defined in element definition.
\r
2002 if ( typeof( elementDefinition.isChanged ) == 'boolean' )
\r
2003 this.isChanged = function(){ return elementDefinition.isChanged; };
\r
2004 if ( typeof( elementDefinition.isChanged ) == 'function' )
\r
2005 this.isChanged = elementDefinition.isChanged;
\r
2008 CKEDITOR.event.implementOn( this );
\r
2010 this.registerEvents( elementDefinition );
\r
2011 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
\r
2012 registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
\r
2015 dialog.on( 'load', function()
\r
2017 if ( me.getInputElement() )
\r
2019 me.getInputElement().on( 'focus', function()
\r
2021 dialog._.tabBarMode = false;
\r
2022 dialog._.hasFocus = true;
\r
2023 me.fire( 'focus' );
\r
2028 // Register the object as a tab focus if it can be included.
\r
2029 if ( this.keyboardFocusable )
\r
2031 this.focusIndex = dialog._.focusList.push( this ) - 1;
\r
2032 this.on( 'focus', function()
\r
2034 dialog._.currentFocusIndex = me.focusIndex;
\r
2038 // Completes this object with everything we have in the
\r
2040 CKEDITOR.tools.extend( this, elementDefinition );
\r
2044 * Horizontal layout box for dialog UI elements, auto-expends to available width of container.
\r
2046 * @extends CKEDITOR.ui.dialog.uiElement
\r
2047 * @param {CKEDITOR.dialog} dialog
\r
2048 * Parent dialog object.
\r
2049 * @param {Array} childObjList
\r
2050 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2052 * @param {Array} childHtmlList
\r
2053 * Array of HTML code that correspond to the HTML output of all the
\r
2054 * objects in childObjList.
\r
2055 * @param {Array} htmlList
\r
2056 * Array of HTML code that this element will output to.
\r
2057 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
2058 * The element definition. Accepted fields:
\r
2060 * <li><strong>widths</strong> (Optional) The widths of child cells.</li>
\r
2061 * <li><strong>height</strong> (Optional) The height of the layout.</li>
\r
2062 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2064 * <li><strong>align</strong> (Optional) The alignment of the whole layout
\r
2069 hbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2071 if ( arguments.length < 4 )
\r
2074 this._ || ( this._ = {} );
\r
2076 var children = this._.children = childObjList,
\r
2077 widths = elementDefinition && elementDefinition.widths || null,
\r
2078 height = elementDefinition && elementDefinition.height || null,
\r
2082 var innerHTML = function()
\r
2084 var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];
\r
2085 for ( i = 0 ; i < childHtmlList.length ; i++ )
\r
2087 var className = 'cke_dialog_ui_hbox_child',
\r
2090 className = 'cke_dialog_ui_hbox_first';
\r
2091 if ( i == childHtmlList.length - 1 )
\r
2092 className = 'cke_dialog_ui_hbox_last';
\r
2093 html.push( '<td class="', className, '" ' );
\r
2097 styles.push( 'width:' + CKEDITOR.tools.cssLength( widths[i] ) );
\r
2100 styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2102 styles.push( 'height:' + CKEDITOR.tools.cssLength( height ) );
\r
2103 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2104 styles.push( 'padding:' + CKEDITOR.tools.cssLength( elementDefinition.padding ) );
\r
2105 if ( styles.length > 0 )
\r
2106 html.push( 'style="' + styles.join('; ') + '" ' );
\r
2107 html.push( '>', childHtmlList[i], '</td>' );
\r
2109 html.push( '</tr></tbody>' );
\r
2110 return html.join( '' );
\r
2113 CKEDITOR.ui.dialog.uiElement.call(
\r
2116 elementDefinition || { type : 'hbox' },
\r
2120 elementDefinition && elementDefinition.align && { align : elementDefinition.align } || null,
\r
2125 * Vertical layout box for dialog UI elements.
\r
2127 * @extends CKEDITOR.ui.dialog.hbox
\r
2128 * @param {CKEDITOR.dialog} dialog
\r
2129 * Parent dialog object.
\r
2130 * @param {Array} childObjList
\r
2131 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2133 * @param {Array} childHtmlList
\r
2134 * Array of HTML code that correspond to the HTML output of all the
\r
2135 * objects in childObjList.
\r
2136 * @param {Array} htmlList
\r
2137 * Array of HTML code that this element will output to.
\r
2138 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
2139 * The element definition. Accepted fields:
\r
2141 * <li><strong>width</strong> (Optional) The width of the layout.</li>
\r
2142 * <li><strong>heights</strong> (Optional) The heights of individual cells.
\r
2144 * <li><strong>align</strong> (Optional) The alignment of the layout.</li>
\r
2145 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2147 * <li><strong>expand</strong> (Optional) Whether the layout should expand
\r
2148 * vertically to fill its container.</li>
\r
2152 vbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2154 if (arguments.length < 3 )
\r
2157 this._ || ( this._ = {} );
\r
2159 var children = this._.children = childObjList,
\r
2160 width = elementDefinition && elementDefinition.width || null,
\r
2161 heights = elementDefinition && elementDefinition.heights || null;
\r
2163 var innerHTML = function()
\r
2165 var html = [ '<table cellspacing="0" border="0" ' ];
\r
2166 html.push( 'style="' );
\r
2167 if ( elementDefinition && elementDefinition.expand )
\r
2168 html.push( 'height:100%;' );
\r
2169 html.push( 'width:' + CKEDITOR.tools.cssLength( width || '100%' ), ';' );
\r
2171 html.push( 'align="', CKEDITOR.tools.htmlEncode(
\r
2172 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
\r
2174 html.push( '><tbody>' );
\r
2175 for ( var i = 0 ; i < childHtmlList.length ; i++ )
\r
2178 html.push( '<tr><td ' );
\r
2180 styles.push( 'width:' + CKEDITOR.tools.cssLength( width || '100%' ) );
\r
2182 styles.push( 'height:' + CKEDITOR.tools.cssLength( heights[i] ) );
\r
2183 else if ( elementDefinition && elementDefinition.expand )
\r
2184 styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2185 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2186 styles.push( 'padding:' + CKEDITOR.tools.cssLength( elementDefinition.padding ) );
\r
2187 if ( styles.length > 0 )
\r
2188 html.push( 'style="', styles.join( '; ' ), '" ' );
\r
2189 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[i], '</td></tr>' );
\r
2191 html.push( '</tbody></table>' );
\r
2192 return html.join( '' );
\r
2194 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type : 'vbox' }, htmlList, 'div', null, null, innerHTML );
\r
2199 CKEDITOR.ui.dialog.uiElement.prototype =
\r
2202 * Gets the root DOM element of this dialog UI object.
\r
2203 * @returns {CKEDITOR.dom.element} Root DOM element of UI object.
\r
2205 * uiElement.getElement().hide();
\r
2207 getElement : function()
\r
2209 return CKEDITOR.document.getById( this.domId );
\r
2213 * Gets the DOM element that the user inputs values.
\r
2214 * This function is used by setValue(), getValue() and focus(). It should
\r
2215 * be overrided in child classes where the input element isn't the root
\r
2217 * @returns {CKEDITOR.dom.element} The element where the user input values.
\r
2219 * var rawValue = textInput.getInputElement().$.value;
\r
2221 getInputElement : function()
\r
2223 return this.getElement();
\r
2227 * Gets the parent dialog object containing this UI element.
\r
2228 * @returns {CKEDITOR.dialog} Parent dialog object.
\r
2230 * var dialog = uiElement.getDialog();
\r
2232 getDialog : function()
\r
2234 return this._.dialog;
\r
2238 * Sets the value of this dialog UI object.
\r
2239 * @param {Object} value The new value.
\r
2240 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2242 * uiElement.setValue( 'Dingo' );
\r
2244 setValue : function( value )
\r
2246 this.getInputElement().setValue( value );
\r
2247 this.fire( 'change', { value : value } );
\r
2252 * Gets the current value of this dialog UI object.
\r
2253 * @returns {Object} The current value.
\r
2255 * var myValue = uiElement.getValue();
\r
2257 getValue : function()
\r
2259 return this.getInputElement().getValue();
\r
2263 * Tells whether the UI object's value has changed.
\r
2264 * @returns {Boolean} true if changed, false if not changed.
\r
2266 * if ( uiElement.isChanged() )
\r
2267 * confirm( 'Value changed! Continue?' );
\r
2269 isChanged : function()
\r
2271 // Override in input classes.
\r
2276 * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
\r
2277 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2279 * focus : function()
\r
2281 * this.selectParentTab();
\r
2282 * // do something else.
\r
2285 selectParentTab : function()
\r
2287 var element = this.getInputElement(),
\r
2290 while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 )
\r
2293 // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
\r
2297 tabId = cursor.getAttribute( 'name' );
\r
2298 // Avoid duplicate select.
\r
2299 if ( this._.dialog._.currentTabId != tabId )
\r
2300 this._.dialog.selectPage( tabId );
\r
2305 * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
\r
2306 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2308 * uiElement.focus();
\r
2310 focus : function()
\r
2312 this.selectParentTab().getInputElement().focus();
\r
2317 * Registers the on* event handlers defined in the element definition.
\r
2318 * The default behavior of this function is:
\r
2321 * If the on* event is defined in the class's eventProcesors list,
\r
2322 * then the registration is delegated to the corresponding function
\r
2323 * in the eventProcessors list.
\r
2326 * If the on* event is not defined in the eventProcessors list, then
\r
2327 * register the event handler under the corresponding DOM event of
\r
2328 * the UI element's input DOM element (as defined by the return value
\r
2329 * of {@link CKEDITOR.ui.dialog.uiElement#getInputElement}).
\r
2332 * This function is only called at UI element instantiation, but can
\r
2333 * be overridded in child classes if they require more flexibility.
\r
2334 * @param {CKEDITOR.dialog.uiElementDefinition} definition The UI element
\r
2336 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2339 registerEvents : function( definition )
\r
2341 var regex = /^on([A-Z]\w+)/,
\r
2344 var registerDomEvent = function( uiElement, dialog, eventName, func )
\r
2346 dialog.on( 'load', function()
\r
2348 uiElement.getInputElement().on( eventName, func, uiElement );
\r
2352 for ( var i in definition )
\r
2354 if ( !( match = i.match( regex ) ) )
\r
2356 if ( this.eventProcessors[i] )
\r
2357 this.eventProcessors[i].call( this, this._.dialog, definition[i] );
\r
2359 registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
\r
2366 * The event processor list used by
\r
2367 * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element
\r
2368 * instantiation. The default list defines three on* events:
\r
2370 * <li>onLoad - Called when the element's parent dialog opens for the
\r
2372 * <li>onShow - Called whenever the element's parent dialog opens.</li>
\r
2373 * <li>onHide - Called whenever the element's parent dialog closes.</li>
\r
2378 * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick
\r
2379 * // handlers in the UI element's definitions.
\r
2380 * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},
\r
2381 * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
\r
2382 * { onClick : function( dialog, func ) { this.on( 'click', func ); } },
\r
2383 * true );
\r
2387 onLoad : function( dialog, func )
\r
2389 dialog.on( 'load', func, this );
\r
2392 onShow : function( dialog, func )
\r
2394 dialog.on( 'show', func, this );
\r
2397 onHide : function( dialog, func )
\r
2399 dialog.on( 'hide', func, this );
\r
2404 * The default handler for a UI element's access key down event, which
\r
2405 * tries to put focus to the UI element.<br />
\r
2406 * Can be overridded in child classes for more sophisticaed behavior.
\r
2407 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2408 * @param {String} key The key combination pressed. Since access keys
\r
2409 * are defined to always include the CTRL key, its value should always
\r
2410 * include a 'CTRL+' prefix.
\r
2413 accessKeyDown : function( dialog, key )
\r
2419 * The default handler for a UI element's access key up event, which
\r
2420 * does nothing.<br />
\r
2421 * Can be overridded in child classes for more sophisticated behavior.
\r
2422 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2423 * @param {String} key The key combination pressed. Since access keys
\r
2424 * are defined to always include the CTRL key, its value should always
\r
2425 * include a 'CTRL+' prefix.
\r
2428 accessKeyUp : function( dialog, key )
\r
2433 * Disables a UI element.
\r
2436 disable : function()
\r
2438 var element = this.getInputElement();
\r
2439 element.setAttribute( 'disabled', 'true' );
\r
2440 element.addClass( 'cke_disabled' );
\r
2444 * Enables a UI element.
\r
2447 enable : function()
\r
2449 var element = this.getInputElement();
\r
2450 element.removeAttribute( 'disabled' );
\r
2451 element.removeClass( 'cke_disabled' );
\r
2455 * Determines whether an UI element is enabled or not.
\r
2456 * @returns {Boolean} Whether the UI element is enabled.
\r
2459 isEnabled : function()
\r
2461 return !this.getInputElement().getAttribute( 'disabled' );
\r
2465 * Determines whether an UI element is visible or not.
\r
2466 * @returns {Boolean} Whether the UI element is visible.
\r
2469 isVisible : function()
\r
2471 return this.getInputElement().isVisible();
\r
2475 * Determines whether an UI element is focus-able or not.
\r
2476 * Focus-able is defined as being both visible and enabled.
\r
2477 * @returns {Boolean} Whether the UI element can be focused.
\r
2480 isFocusable : function()
\r
2482 if ( !this.isEnabled() || !this.isVisible() )
\r
2488 CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
\r
2490 * @lends CKEDITOR.ui.dialog.hbox.prototype
\r
2494 * Gets a child UI element inside this container.
\r
2495 * @param {Array|Number} indices An array or a single number to indicate the child's
\r
2496 * position in the container's descendant tree. Omit to get all the children in an array.
\r
2497 * @returns {Array|CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container
\r
2498 * if no argument given, or the specified UI element if indices is given.
\r
2500 * var checkbox = hbox.getChild( [0,1] );
\r
2501 * checkbox.setValue( true );
\r
2503 getChild : function( indices )
\r
2505 // If no arguments, return a clone of the children array.
\r
2506 if ( arguments.length < 1 )
\r
2507 return this._.children.concat();
\r
2509 // If indices isn't array, make it one.
\r
2510 if ( !indices.splice )
\r
2511 indices = [ indices ];
\r
2513 // Retrieve the child element according to tree position.
\r
2514 if ( indices.length < 2 )
\r
2515 return this._.children[ indices[0] ];
\r
2517 return ( this._.children[ indices[0] ] && this._.children[ indices[0] ].getChild ) ?
\r
2518 this._.children[ indices[0] ].getChild( indices.slice( 1, indices.length ) ) :
\r
2523 CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
\r
2529 var commonBuilder = {
\r
2530 build : function( dialog, elementDefinition, output )
\r
2532 var children = elementDefinition.children,
\r
2534 childHtmlList = [],
\r
2535 childObjList = [];
\r
2536 for ( var i = 0 ; ( i < children.length && ( child = children[i] ) ) ; i++ )
\r
2538 var childHtml = [];
\r
2539 childHtmlList.push( childHtml );
\r
2540 childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
\r
2542 return new CKEDITOR.ui.dialog[elementDefinition.type]( dialog, childObjList, childHtmlList, output, elementDefinition );
\r
2546 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
\r
2547 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
\r
2551 * Generic dialog command. It opens a specific dialog when executed.
\r
2553 * @augments CKEDITOR.commandDefinition
\r
2554 * @param {string} dialogName The name of the dialog to open when executing
\r
2557 * // Register the "link" command, which opens the "link" dialog.
\r
2558 * editor.addCommand( 'link', <b>new CKEDITOR.dialogCommand( 'link' )</b> );
\r
2560 CKEDITOR.dialogCommand = function( dialogName )
\r
2562 this.dialogName = dialogName;
\r
2565 CKEDITOR.dialogCommand.prototype =
\r
2568 exec : function( editor )
\r
2570 editor.openDialog( this.dialogName );
\r
2572 // Dialog commands just open a dialog ui, thus require no undo logic,
\r
2573 // undo support should dedicate to specific dialog implementation.
\r
2579 var notEmptyRegex = /^([a]|[^a])+$/,
\r
2580 integerRegex = /^\d*$/,
\r
2581 numberRegex = /^\d*(?:\.\d+)?$/;
\r
2583 CKEDITOR.VALIDATE_OR = 1;
\r
2584 CKEDITOR.VALIDATE_AND = 2;
\r
2586 CKEDITOR.dialog.validate =
\r
2588 functions : function()
\r
2593 * It's important for validate functions to be able to accept the value
\r
2594 * as argument in addition to this.getValue(), so that it is possible to
\r
2595 * combine validate functions together to make more sophisticated
\r
2598 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
2600 var msg = undefined,
\r
2601 relation = CKEDITOR.VALIDATE_AND,
\r
2602 functions = [], i;
\r
2604 for ( i = 0 ; i < arguments.length ; i++ )
\r
2606 if ( typeof( arguments[i] ) == 'function' )
\r
2607 functions.push( arguments[i] );
\r
2612 if ( i < arguments.length && typeof( arguments[i] ) == 'string' )
\r
2614 msg = arguments[i];
\r
2618 if ( i < arguments.length && typeof( arguments[i]) == 'number' )
\r
2619 relation = arguments[i];
\r
2621 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );
\r
2622 for ( i = 0 ; i < functions.length ; i++ )
\r
2624 if ( relation == CKEDITOR.VALIDATE_AND )
\r
2625 passed = passed && functions[i]( value );
\r
2627 passed = passed || functions[i]( value );
\r
2632 if ( msg !== undefined )
\r
2634 if ( this && ( this.select || this.focus ) )
\r
2635 ( this.select || this.focus )();
\r
2643 regex : function( regex, msg )
\r
2646 * Can be greatly shortened by deriving from functions validator if code size
\r
2647 * turns out to be more important than performance.
\r
2651 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
2652 if ( !regex.test( value ) )
\r
2654 if ( msg !== undefined )
\r
2656 if ( this && ( this.select || this.focus ) )
\r
2658 if ( this.select )
\r
2669 notEmpty : function( msg )
\r
2671 return this.regex( notEmptyRegex, msg );
\r
2674 integer : function( msg )
\r
2676 return this.regex( integerRegex, msg );
\r
2679 'number' : function( msg )
\r
2681 return this.regex( numberRegex, msg );
\r
2684 equals : function( value, msg )
\r
2686 return this.functions( function( val ){ return val == value; }, msg );
\r
2689 notEqual : function( value, msg )
\r
2691 return this.functions( function( val ){ return val != value; }, msg );
\r
2696 // Grab the margin data from skin definition and store it away.
\r
2697 CKEDITOR.skins.add = ( function()
\r
2699 var original = CKEDITOR.skins.add;
\r
2700 return function( skinName, skinDefinition )
\r
2702 skinData[ skinName ] = { margins : skinDefinition.margins };
\r
2703 return original.apply( this, arguments );
\r
2708 // Extend the CKEDITOR.editor class with dialog specific functions.
\r
2709 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
\r
2710 /** @lends CKEDITOR.editor.prototype */
\r
2713 * Loads and opens a registered dialog.
\r
2714 * @param {String} dialogName The registered name of the dialog.
\r
2715 * @see CKEDITOR.dialog.add
\r
2717 * CKEDITOR.instances.editor1.openDialog( 'smiley' );
\r
2718 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed. null if the dialog name is not registered.
\r
2720 openDialog : function( dialogName )
\r
2722 var dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];
\r
2724 // If the dialogDefinition is already loaded, open it immediately.
\r
2725 if ( typeof dialogDefinitions == 'function' )
\r
2727 var storedDialogs = this._.storedDialogs ||
\r
2728 ( this._.storedDialogs = {} );
\r
2730 var dialog = storedDialogs[ dialogName ] ||
\r
2731 ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
\r
2737 else if ( dialogDefinitions == 'failed' )
\r
2738 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
\r
2740 // Not loaded? Load the .js file first.
\r
2741 var body = CKEDITOR.document.getBody(),
\r
2742 cursor = body.$.style.cursor,
\r
2745 body.setStyle( 'cursor', 'wait' );
\r
2746 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ), function()
\r
2748 // In case of plugin error, mark it as loading failed.
\r
2749 if ( typeof CKEDITOR.dialog._.dialogDefinitions[ dialogName ] != 'function' )
\r
2750 CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';
\r
2751 me.openDialog( dialogName );
\r
2752 body.setStyle( 'cursor', cursor );
\r
2759 // Dialog related configurations.
\r
2762 * The color of the dialog background cover. It should be a valid CSS color
\r
2764 * @name CKEDITOR.config.dialog_backgroundCoverColor
\r
2766 * @default 'white'
\r
2768 * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
\r
2772 * The opacity of the dialog background cover. It should be a number within the
\r
2773 * range [0.0, 1.0].
\r
2774 * @name CKEDITOR.config.dialog_backgroundCoverOpacity
\r
2778 * config.dialog_backgroundCoverOpacity = 0.7;
\r
2782 * The distance of magnetic borders used in moving and resizing dialogs,
\r
2783 * measured in pixels.
\r
2784 * @name CKEDITOR.config.dialog_magnetDistance
\r
2788 * config.dialog_magnetDistance = 30;
\r