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 * This is the base class for runtime dialog objects. An instance of this
\r
73 * class represents a single named dialog for a single editor instance.
\r
74 * @param {Object} editor The editor which created the dialog.
\r
75 * @param {String} dialogName The dialog's registered name.
\r
78 * var dialogObj = new CKEDITOR.dialog( editor, 'smiley' );
\r
80 CKEDITOR.dialog = function( editor, dialogName )
\r
82 // Load the dialog definition.
\r
83 var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];
\r
85 // Completes the definition with the default values.
\r
86 definition = CKEDITOR.tools.extend( definition( editor ), defaultDialogDefinition );
\r
88 // Clone a functionally independent copy for this dialog.
\r
89 definition = CKEDITOR.tools.clone( definition );
\r
91 // Create a complex definition object, extending it with the API
\r
93 definition = new definitionObject( this, definition );
\r
96 var doc = CKEDITOR.document;
\r
98 var themeBuilt = editor.theme.buildDialog( editor );
\r
100 // Initialize some basic parameters.
\r
104 element : themeBuilt.element,
\r
106 contentSize : { width : 0, height : 0 },
\r
107 size : { width : 0, height : 0 },
\r
108 updateSize : false,
\r
113 // Initialize the tab and page map.
\r
116 currentTabId : null,
\r
117 currentTabIndex : null,
\r
120 tabBarMode : false,
\r
122 // Initialize the tab order array for input widgets.
\r
124 currentFocusIndex : 0,
\r
128 this.parts = themeBuilt.parts;
\r
130 CKEDITOR.tools.setTimeout( function()
\r
132 editor.fire( 'ariaWidget', this.parts.contents );
\r
136 // Set the startup styles for the dialog, avoiding it enlarging the
\r
137 // page size on the dialog creation.
\r
138 this.parts.dialog.setStyles(
\r
140 position : CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed',
\r
143 visibility : 'hidden'
\r
146 // Call the CKEDITOR.event constructor to initialize this instance.
\r
147 CKEDITOR.event.call( this );
\r
149 // Fire the "dialogDefinition" event, making it possible to customize
\r
150 // the dialog definition.
\r
151 this.definition = definition = CKEDITOR.fire( 'dialogDefinition',
\r
154 definition : definition
\r
156 , editor ).definition;
\r
157 // Initialize load, show, hide, ok and cancel events.
\r
158 if ( definition.onLoad )
\r
159 this.on( 'load', definition.onLoad );
\r
161 if ( definition.onShow )
\r
162 this.on( 'show', definition.onShow );
\r
164 if ( definition.onHide )
\r
165 this.on( 'hide', definition.onHide );
\r
167 if ( definition.onOk )
\r
169 this.on( 'ok', function( evt )
\r
171 if ( definition.onOk.call( this, evt ) === false )
\r
172 evt.data.hide = false;
\r
176 if ( definition.onCancel )
\r
178 this.on( 'cancel', function( evt )
\r
180 if ( definition.onCancel.call( this, evt ) === false )
\r
181 evt.data.hide = false;
\r
187 // Iterates over all items inside all content in the dialog, calling a
\r
188 // function for each of them.
\r
189 var iterContents = function( func )
\r
191 var contents = me._.contents,
\r
194 for ( var i in contents )
\r
196 for ( var j in contents[i] )
\r
198 stop = func.call( this, contents[i][j] );
\r
205 this.on( 'ok', function( evt )
\r
207 iterContents( function( item )
\r
209 if ( item.validate )
\r
211 var isValid = item.validate( this );
\r
213 if ( typeof isValid == 'string' )
\r
219 if ( isValid === false )
\r
226 evt.data.hide = false;
\r
232 }, this, null, 0 );
\r
234 this.on( 'cancel', function( evt )
\r
236 iterContents( function( item )
\r
238 if ( item.isChanged() )
\r
240 if ( !confirm( editor.lang.common.confirmCancel ) )
\r
241 evt.data.hide = false;
\r
245 }, this, null, 0 );
\r
247 this.parts.close.on( 'click', function( evt )
\r
249 if ( this.fire( 'cancel', { hide : true } ).hide !== false )
\r
251 evt.data.preventDefault();
\r
254 // Sort focus list according to tab order definitions.
\r
255 function setupFocus()
\r
257 var focusList = me._.focusList;
\r
258 focusList.sort( function( a, b )
\r
260 // Mimics browser tab order logics;
\r
261 if ( a.tabIndex != b.tabIndex )
\r
262 return b.tabIndex - a.tabIndex;
\r
263 // Sort is not stable in some browsers,
\r
264 // fall-back the comparator to 'focusIndex';
\r
266 return a.focusIndex - b.focusIndex;
\r
269 var size = focusList.length;
\r
270 for ( var i = 0; i < size; i++ )
\r
271 focusList[ i ].focusIndex = i;
\r
274 function changeFocus( forward )
\r
276 var focusList = me._.focusList,
\r
277 offset = forward ? 1 : -1;
\r
278 if ( focusList.length < 1 )
\r
281 var current = me._.currentFocusIndex;
\r
283 // Trigger the 'blur' event of any input element before anything,
\r
284 // since certain UI updates may depend on it.
\r
287 focusList[ current ].getInputElement().$.blur();
\r
291 var startIndex = ( current + offset + focusList.length ) % focusList.length,
\r
292 currentIndex = startIndex;
\r
293 while ( !focusList[ currentIndex ].isFocusable() )
\r
295 currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length;
\r
296 if ( currentIndex == startIndex )
\r
299 focusList[ currentIndex ].focus();
\r
301 // Select whole field content.
\r
302 if ( focusList[ currentIndex ].type == 'text' )
\r
303 focusList[ currentIndex ].select();
\r
306 this.changeFocus = changeFocus;
\r
310 function focusKeydownHandler( evt )
\r
312 // If I'm not the top dialog, ignore.
\r
313 if ( me != CKEDITOR.dialog._.currentTop )
\r
316 var keystroke = evt.data.getKeystroke(),
\r
317 rtl = editor.lang.dir == 'rtl';
\r
320 if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )
\r
322 var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
\r
324 // Handling Tab and Shift-Tab.
\r
325 if ( me._.tabBarMode )
\r
328 var nextId = shiftPressed ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );
\r
329 me.selectPage( nextId );
\r
330 me._.tabs[ nextId ][ 0 ].focus();
\r
334 // Change the focus of inputs.
\r
335 changeFocus( !shiftPressed );
\r
340 else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode && me.getPageCount() > 1 )
\r
342 // Alt-F10 puts focus into the current tab item in the tab bar.
\r
343 me._.tabBarMode = true;
\r
344 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
347 else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode )
\r
349 // Arrow keys - used for changing tabs.
\r
350 nextId = ( keystroke == ( rtl ? 39 : 37 ) ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) );
\r
351 me.selectPage( nextId );
\r
352 me._.tabs[ nextId ][ 0 ].focus();
\r
355 else if ( ( keystroke == 13 || keystroke == 32 ) && me._.tabBarMode )
\r
357 this.selectPage( this._.currentTabId );
\r
358 this._.tabBarMode = false;
\r
359 this._.currentFocusIndex = -1;
\r
360 changeFocus( true );
\r
367 evt.data.preventDefault();
\r
371 function focusKeyPressHandler( evt )
\r
373 processed && evt.data.preventDefault();
\r
376 var dialogElement = this._.element;
\r
377 // Add the dialog keyboard handlers.
\r
378 this.on( 'show', function()
\r
380 dialogElement.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
381 // Some browsers instead, don't cancel key events in the keydown, but in the
\r
382 // keypress. So we must do a longer trip in those cases. (#4531)
\r
383 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
384 dialogElement.on( 'keypress', focusKeyPressHandler, this );
\r
387 this.on( 'hide', function()
\r
389 dialogElement.removeListener( 'keydown', focusKeydownHandler );
\r
390 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
391 dialogElement.removeListener( 'keypress', focusKeyPressHandler );
\r
393 this.on( 'iframeAdded', function( evt )
\r
395 var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );
\r
396 doc.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
399 // Auto-focus logic in dialog.
\r
400 this.on( 'show', function()
\r
402 // Setup tabIndex on showing the dialog instead of on loading
\r
403 // to allow dynamic tab order happen in dialog definition.
\r
406 if ( editor.config.dialog_startupFocusTab
\r
407 && me._.tabIdList.length > 1 )
\r
409 me._.tabBarMode = true;
\r
410 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
412 else if ( !this._.hasFocus )
\r
414 this._.currentFocusIndex = -1;
\r
416 // Decide where to put the initial focus.
\r
417 if ( definition.onFocus )
\r
419 var initialFocus = definition.onFocus.call( this );
\r
420 // Focus the field that the user specified.
\r
421 initialFocus && initialFocus.focus();
\r
423 // Focus the first field in layout order.
\r
425 changeFocus( true );
\r
428 * IE BUG: If the initial focus went into a non-text element (e.g. button),
\r
429 * then IE would still leave the caret inside the editing area.
\r
431 if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
433 var $selection = editor.document.$.selection,
\r
434 $range = $selection.createRange();
\r
438 if ( $range.parentElement && $range.parentElement().ownerDocument == editor.document.$
\r
439 || $range.item && $range.item( 0 ).ownerDocument == editor.document.$ )
\r
441 var $myRange = document.body.createTextRange();
\r
442 $myRange.moveToElementText( this.getElement().getFirst().$ );
\r
443 $myRange.collapse( true );
\r
449 }, this, null, 0xffffffff );
\r
451 // IE6 BUG: Text fields and text areas are only half-rendered the first time the dialog appears in IE6 (#2661).
\r
452 // This is still needed after [2708] and [2709] because text fields in hidden TR tags are still broken.
\r
453 if ( CKEDITOR.env.ie6Compat )
\r
455 this.on( 'load', function( evt )
\r
457 var outer = this.getElement(),
\r
458 inner = outer.getFirst();
\r
460 inner.appendTo( outer );
\r
464 initDragAndDrop( this );
\r
465 initResizeHandles( this );
\r
467 // Insert the title.
\r
468 ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );
\r
470 // Insert the tabs and contents.
\r
471 for ( var i = 0 ; i < definition.contents.length ; i++ )
\r
472 this.addPage( definition.contents[i] );
\r
474 this.parts['tabs'].on( 'click', function( evt )
\r
476 var target = evt.data.getTarget();
\r
477 // If we aren't inside a tab, bail out.
\r
478 if ( target.hasClass( 'cke_dialog_tab' ) )
\r
480 var id = target.$.id;
\r
481 this.selectPage( id.substr( 0, id.lastIndexOf( '_' ) ) );
\r
482 if ( this._.tabBarMode )
\r
484 this._.tabBarMode = false;
\r
485 this._.currentFocusIndex = -1;
\r
486 changeFocus( true );
\r
488 evt.data.preventDefault();
\r
493 var buttonsHtml = [],
\r
494 buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this,
\r
497 className : 'cke_dialog_footer_buttons',
\r
499 children : definition.buttons
\r
500 }, buttonsHtml ).getChild();
\r
501 this.parts.footer.setHtml( buttonsHtml.join( '' ) );
\r
503 for ( i = 0 ; i < buttons.length ; i++ )
\r
504 this._.buttons[ buttons[i].id ] = buttons[i];
\r
507 // Focusable interface. Use it via dialog.addFocusable.
\r
508 function Focusable( dialog, element, index )
\r
510 this.element = element;
\r
511 this.focusIndex = index;
\r
512 // TODO: support tabIndex for focusables.
\r
514 this.isFocusable = function()
\r
516 return !element.getAttribute( 'disabled' ) && element.isVisible();
\r
518 this.focus = function()
\r
520 dialog._.currentFocusIndex = this.focusIndex;
\r
521 this.element.focus();
\r
524 element.on( 'keydown', function( e )
\r
526 if ( e.data.getKeystroke() in { 32:1, 13:1 } )
\r
527 this.fire( 'click' );
\r
529 element.on( 'focus', function()
\r
531 this.fire( 'mouseover' );
\r
533 element.on( 'blur', function()
\r
535 this.fire( 'mouseout' );
\r
539 CKEDITOR.dialog.prototype =
\r
541 destroy : function()
\r
544 this._.element.remove();
\r
548 * Resizes the dialog.
\r
549 * @param {Number} width The width of the dialog in pixels.
\r
550 * @param {Number} height The height of the dialog in pixels.
\r
553 * dialogObj.resize( 800, 640 );
\r
555 resize : (function()
\r
557 return function( width, height )
\r
559 if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )
\r
562 CKEDITOR.dialog.fire( 'resize',
\r
565 skin : this._.editor.skinName,
\r
568 }, this._.editor );
\r
570 this._.contentSize = { width : width, height : height };
\r
571 this._.updateSize = true;
\r
576 * Gets the current size of the dialog in pixels.
\r
577 * @returns {Object} An object with "width" and "height" properties.
\r
579 * var width = dialogObj.getSize().width;
\r
581 getSize : function()
\r
583 if ( !this._.updateSize )
\r
584 return this._.size;
\r
585 var element = this._.element.getFirst();
\r
586 var size = this._.size = { width : element.$.offsetWidth || 0, height : element.$.offsetHeight || 0};
\r
588 // If either the offsetWidth or offsetHeight is 0, the element isn't visible.
\r
589 this._.updateSize = !size.width || !size.height;
\r
595 * Moves the dialog to an (x, y) coordinate relative to the window.
\r
597 * @param {Number} x The target x-coordinate.
\r
598 * @param {Number} y The target y-coordinate.
\r
600 * dialogObj.move( 10, 40 );
\r
605 return function( x, y )
\r
607 // The dialog may be fixed positioned or absolute positioned. Ask the
\r
608 // browser what is the current situation first.
\r
609 var element = this._.element.getFirst();
\r
610 if ( isFixed === undefined )
\r
611 isFixed = element.getComputedStyle( 'position' ) == 'fixed';
\r
613 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
\r
616 // Save the current position.
\r
617 this._.position = { x : x, y : y };
\r
619 // If not fixed positioned, add scroll position to the coordinates.
\r
622 var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
\r
623 x += scrollPosition.x;
\r
624 y += scrollPosition.y;
\r
629 'left' : ( x > 0 ? x : 0 ) + 'px',
\r
630 'top' : ( y > 0 ? y : 0 ) + 'px'
\r
636 * Gets the dialog's position in the window.
\r
637 * @returns {Object} An object with "x" and "y" properties.
\r
639 * var dialogX = dialogObj.getPosition().x;
\r
641 getPosition : function(){ return CKEDITOR.tools.extend( {}, this._.position ); },
\r
644 * Shows the dialog box.
\r
646 * dialogObj.show();
\r
650 var editor = this._.editor;
\r
651 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
653 var selection = editor.getSelection();
\r
654 selection && selection.lock();
\r
657 // Insert the dialog's element to the root document.
\r
658 var element = this._.element;
\r
659 var definition = this.definition;
\r
660 if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )
\r
661 element.appendTo( CKEDITOR.document.getBody() );
\r
663 element.setStyle( 'display', 'block' );
\r
665 // FIREFOX BUG: Fix vanishing caret for Firefox 2 or Gecko 1.8.
\r
666 if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
\r
668 var dialogElement = this.parts.dialog;
\r
669 dialogElement.setStyle( 'position', 'absolute' );
\r
670 setTimeout( function()
\r
672 dialogElement.setStyle( 'position', 'fixed' );
\r
677 // First, set the dialog to an appropriate size.
\r
678 this.resize( definition.minWidth, definition.minHeight );
\r
680 // Select the first tab by default.
\r
681 this.selectPage( this.definition.contents[0].id );
\r
683 // Reset all inputs back to their default value.
\r
687 if ( CKEDITOR.dialog._.currentZIndex === null )
\r
688 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;
\r
689 this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
\r
691 // Maintain the dialog ordering and dialog cover.
\r
692 // Also register key handlers if first dialog.
\r
693 if ( CKEDITOR.dialog._.currentTop === null )
\r
695 CKEDITOR.dialog._.currentTop = this;
\r
696 this._.parentDialog = null;
\r
697 showCover( this._.editor );
\r
699 element.on( 'keydown', accessKeyDownHandler );
\r
700 element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
702 // Prevent some keys from bubbling up. (#4269)
\r
703 for ( var event in { keyup :1, keydown :1, keypress :1 } )
\r
704 element.on( event, preventKeyBubbling );
\r
708 this._.parentDialog = CKEDITOR.dialog._.currentTop;
\r
709 var parentElement = this._.parentDialog.getElement().getFirst();
\r
710 parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );
\r
711 CKEDITOR.dialog._.currentTop = this;
\r
714 // Register the Esc hotkeys.
\r
715 registerAccessKey( this, this, '\x1b', null, function()
\r
717 this.getButton( 'cancel' ) && this.getButton( 'cancel' ).click();
\r
720 // Reset the hasFocus state.
\r
721 this._.hasFocus = false;
\r
723 // Rearrange the dialog to the middle of the window.
\r
724 CKEDITOR.tools.setTimeout( function()
\r
726 var viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
\r
727 var dialogSize = this.getSize();
\r
729 // We're using definition size for initial position because of
\r
730 // offten corrupted data in offsetWidth at this point. (#4084)
\r
731 this.move( ( viewSize.width - definition.minWidth ) / 2, ( viewSize.height - dialogSize.height ) / 2 );
\r
733 this.parts.dialog.setStyle( 'visibility', '' );
\r
735 // Execute onLoad for the first show.
\r
736 this.fireOnce( 'load', {} );
\r
737 this.fire( 'show', {} );
\r
738 this._.editor.fire( 'dialogShow', this );
\r
740 // Save the initial values of the dialog.
\r
741 this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } );
\r
748 * Executes a function for each UI element.
\r
749 * @param {Function} fn Function to execute for each UI element.
\r
750 * @returns {CKEDITOR.dialog} The current dialog object.
\r
752 foreach : function( fn )
\r
754 for ( var i in this._.contents )
\r
756 for ( var j in this._.contents[i] )
\r
757 fn( this._.contents[i][j]);
\r
763 * Resets all input values in the dialog.
\r
765 * dialogObj.reset();
\r
766 * @returns {CKEDITOR.dialog} The current dialog object.
\r
768 reset : (function()
\r
770 var fn = function( widget ){ if ( widget.reset ) widget.reset(); };
\r
771 return function(){ this.foreach( fn ); return this; };
\r
774 setupContent : function()
\r
776 var args = arguments;
\r
777 this.foreach( function( widget )
\r
779 if ( widget.setup )
\r
780 widget.setup.apply( widget, args );
\r
784 commitContent : function()
\r
786 var args = arguments;
\r
787 this.foreach( function( widget )
\r
789 if ( widget.commit )
\r
790 widget.commit.apply( widget, args );
\r
795 * Hides the dialog box.
\r
797 * dialogObj.hide();
\r
801 if ( !this.parts.dialog.isVisible() )
\r
804 this.fire( 'hide', {} );
\r
805 this._.editor.fire( 'dialogHide', this );
\r
806 var element = this._.element;
\r
807 element.setStyle( 'display', 'none' );
\r
808 this.parts.dialog.setStyle( 'visibility', 'hidden' );
\r
809 // Unregister all access keys associated with this dialog.
\r
810 unregisterAccessKey( this );
\r
812 // Close any child(top) dialogs first.
\r
813 while( CKEDITOR.dialog._.currentTop != this )
\r
814 CKEDITOR.dialog._.currentTop.hide();
\r
816 // Maintain dialog ordering and remove cover if needed.
\r
817 if ( !this._.parentDialog )
\r
821 var parentElement = this._.parentDialog.getElement().getFirst();
\r
822 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
\r
824 CKEDITOR.dialog._.currentTop = this._.parentDialog;
\r
826 // Deduct or clear the z-index.
\r
827 if ( !this._.parentDialog )
\r
829 CKEDITOR.dialog._.currentZIndex = null;
\r
831 // Remove access key handlers.
\r
832 element.removeListener( 'keydown', accessKeyDownHandler );
\r
833 element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
835 // Remove bubbling-prevention handler. (#4269)
\r
836 for ( var event in { keyup :1, keydown :1, keypress :1 } )
\r
837 element.removeListener( event, preventKeyBubbling );
\r
839 var editor = this._.editor;
\r
842 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
844 var selection = editor.getSelection();
\r
845 selection && selection.unlock( true );
\r
849 CKEDITOR.dialog._.currentZIndex -= 10;
\r
851 delete this._.parentDialog;
\r
852 // Reset the initial values of the dialog.
\r
853 this.foreach( function( contentObj ) { contentObj.resetInitValue && contentObj.resetInitValue(); } );
\r
857 * Adds a tabbed page into the dialog.
\r
858 * @param {Object} contents Content definition.
\r
861 addPage : function( contents )
\r
864 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
\r
865 elements = contents.elements,
\r
866 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this,
\r
869 className : 'cke_dialog_page_contents',
\r
870 children : contents.elements,
\r
871 expand : !!contents.expand,
\r
872 padding : contents.padding,
\r
873 style : contents.style || 'width: 100%; height: 100%;'
\r
876 // Create the HTML for the tab and the content block.
\r
877 var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
\r
878 page.setAttribute( 'role', 'tabpanel' );
\r
880 var env = CKEDITOR.env;
\r
881 var tabId = contents.id + '_' + CKEDITOR.tools.getNextNumber(),
\r
882 tab = CKEDITOR.dom.element.createFromHtml( [
\r
883 '<a class="cke_dialog_tab"',
\r
884 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),
\r
886 ( !!contents.hidden ? ' style="display:none"' : '' ),
\r
887 ' id="', tabId, '"',
\r
888 env.gecko && env.version >= 10900 && !env.hc ? '' : ' href="javascript:void(0)"',
\r
890 ' hidefocus="true"',
\r
896 page.setAttribute( 'aria-labelledby', tabId );
\r
898 // Take records for the tabs and elements created.
\r
899 this._.tabs[ contents.id ] = [ tab, page ];
\r
900 this._.tabIdList.push( contents.id );
\r
901 !contents.hidden && this._.pageCount++;
\r
902 this._.lastTab = tab;
\r
903 this.updateStyle();
\r
905 var contentMap = this._.contents[ contents.id ] = {},
\r
907 children = vbox.getChild();
\r
909 while ( ( cursor = children.shift() ) )
\r
911 contentMap[ cursor.id ] = cursor;
\r
912 if ( typeof( cursor.getChild ) == 'function' )
\r
913 children.push.apply( children, cursor.getChild() );
\r
916 // Attach the DOM nodes.
\r
918 page.setAttribute( 'name', contents.id );
\r
919 page.appendTo( this.parts.contents );
\r
921 tab.unselectable();
\r
922 this.parts.tabs.append( tab );
\r
924 // Add access key handlers if access key is defined.
\r
925 if ( contents.accessKey )
\r
927 registerAccessKey( this, this, 'CTRL+' + contents.accessKey,
\r
928 tabAccessKeyDown, tabAccessKeyUp );
\r
929 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;
\r
934 * Activates a tab page in the dialog by its id.
\r
935 * @param {String} id The id of the dialog tab to be activated.
\r
937 * dialogObj.selectPage( 'tab_1' );
\r
939 selectPage : function( id )
\r
941 // Hide the non-selected tabs and pages.
\r
942 for ( var i in this._.tabs )
\r
944 var tab = this._.tabs[i][0],
\r
945 page = this._.tabs[i][1];
\r
948 tab.removeClass( 'cke_dialog_tab_selected' );
\r
951 page.setAttribute( 'aria-hidden', i != id );
\r
954 var selected = this._.tabs[id];
\r
955 selected[0].addClass( 'cke_dialog_tab_selected' );
\r
956 selected[1].show();
\r
957 this._.currentTabId = id;
\r
958 this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
\r
961 // Dialog state-specific style updates.
\r
962 updateStyle : function()
\r
964 // If only a single page shown, a different style is used in the central pane.
\r
965 this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );
\r
969 * Hides a page's tab away from the dialog.
\r
970 * @param {String} id The page's Id.
\r
972 * dialog.hidePage( 'tab_3' );
\r
974 hidePage : function( id )
\r
976 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
977 if ( !tab || this._.pageCount == 1 )
\r
979 // Switch to other tab first when we're hiding the active tab.
\r
980 else if ( id == this._.currentTabId )
\r
981 this.selectPage( getPreviousVisibleTab.call( this ) );
\r
984 this._.pageCount--;
\r
985 this.updateStyle();
\r
989 * Unhides a page's tab.
\r
990 * @param {String} id The page's Id.
\r
992 * dialog.showPage( 'tab_2' );
\r
994 showPage : function( id )
\r
996 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
1000 this._.pageCount++;
\r
1001 this.updateStyle();
\r
1005 * Gets the root DOM element of the dialog.
\r
1006 * @returns {CKEDITOR.dom.element} The <span> element containing this dialog.
\r
1008 * var dialogElement = dialogObj.getElement().getFirst();
\r
1009 * dialogElement.setStyle( 'padding', '5px' );
\r
1011 getElement : function()
\r
1013 return this._.element;
\r
1017 * Gets the name of the dialog.
\r
1018 * @returns {String} The name of this dialog.
\r
1020 * var dialogName = dialogObj.getName();
\r
1022 getName : function()
\r
1024 return this._.name;
\r
1028 * Gets a dialog UI element object from a dialog page.
\r
1029 * @param {String} pageId id of dialog page.
\r
1030 * @param {String} elementId id of UI element.
\r
1032 * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.
\r
1034 getContentElement : function( pageId, elementId )
\r
1036 var page = this._.contents[ pageId ];
\r
1037 return page && page[ elementId ];
\r
1041 * Gets the value of a dialog UI element.
\r
1042 * @param {String} pageId id of dialog page.
\r
1043 * @param {String} elementId id of UI element.
\r
1045 * @returns {Object} The value of the UI element.
\r
1047 getValueOf : function( pageId, elementId )
\r
1049 return this.getContentElement( pageId, elementId ).getValue();
\r
1053 * Sets the value of a dialog UI element.
\r
1054 * @param {String} pageId id of the dialog page.
\r
1055 * @param {String} elementId id of the UI element.
\r
1056 * @param {Object} value The new value of the UI element.
\r
1059 setValueOf : function( pageId, elementId, value )
\r
1061 return this.getContentElement( pageId, elementId ).setValue( value );
\r
1065 * Gets the UI element of a button in the dialog's button row.
\r
1066 * @param {String} id The id of the button.
\r
1068 * @returns {CKEDITOR.ui.dialog.button} The button object.
\r
1070 getButton : function( id )
\r
1072 return this._.buttons[ id ];
\r
1076 * Simulates a click to a dialog button in the dialog's button row.
\r
1077 * @param {String} id The id of the button.
\r
1079 * @returns The return value of the dialog's "click" event.
\r
1081 click : function( id )
\r
1083 return this._.buttons[ id ].click();
\r
1087 * Disables a dialog button.
\r
1088 * @param {String} id The id of the button.
\r
1091 disableButton : function( id )
\r
1093 return this._.buttons[ id ].disable();
\r
1097 * Enables a dialog button.
\r
1098 * @param {String} id The id of the button.
\r
1101 enableButton : function( id )
\r
1103 return this._.buttons[ id ].enable();
\r
1107 * Gets the number of pages in the dialog.
\r
1108 * @returns {Number} Page count.
\r
1110 getPageCount : function()
\r
1112 return this._.pageCount;
\r
1116 * Gets the editor instance which opened this dialog.
\r
1117 * @returns {CKEDITOR.editor} Parent editor instances.
\r
1119 getParentEditor : function()
\r
1121 return this._.editor;
\r
1125 * Gets the element that was selected when opening the dialog, if any.
\r
1126 * @returns {CKEDITOR.dom.element} The element that was selected, or null.
\r
1128 getSelectedElement : function()
\r
1130 return this.getParentEditor().getSelection().getSelectedElement();
\r
1134 * Adds element to dialog's focusable list.
\r
1136 * @param {CKEDITOR.dom.element} element
\r
1137 * @param {Number} [index]
\r
1139 addFocusable: function( element, index ) {
\r
1140 if ( typeof index == 'undefined' )
\r
1142 index = this._.focusList.length;
\r
1143 this._.focusList.push( new Focusable( this, element, index ) );
\r
1147 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );
\r
1148 for ( var i = index + 1 ; i < this._.focusList.length ; i++ )
\r
1149 this._.focusList[ i ].focusIndex++;
\r
1154 CKEDITOR.tools.extend( CKEDITOR.dialog,
\r
1156 * @lends CKEDITOR.dialog
\r
1160 * Registers a dialog.
\r
1161 * @param {String} name The dialog's name.
\r
1162 * @param {Function|String} dialogDefinition
\r
1163 * A function returning the dialog's definition, or the URL to the .js file holding the function.
\r
1164 * The function should accept an argument "editor" which is the current editor instance, and
\r
1165 * return an object conforming to {@link CKEDITOR.dialog.dialogDefinition}.
\r
1167 * @see CKEDITOR.dialog.dialogDefinition
\r
1169 add : function( name, dialogDefinition )
\r
1171 // Avoid path registration from multiple instances override definition.
\r
1172 if ( !this._.dialogDefinitions[name]
\r
1173 || typeof dialogDefinition == 'function' )
\r
1174 this._.dialogDefinitions[name] = dialogDefinition;
\r
1177 exists : function( name )
\r
1179 return !!this._.dialogDefinitions[ name ];
\r
1182 getCurrent : function()
\r
1184 return CKEDITOR.dialog._.currentTop;
\r
1188 * The default OK button for dialogs. Fires the "ok" event and closes the dialog if the event succeeds.
\r
1194 okButton : (function()
\r
1196 var retval = function( editor, override )
\r
1198 override = override || {};
\r
1199 return CKEDITOR.tools.extend( {
\r
1202 label : editor.lang.common.ok,
\r
1203 'class' : 'cke_dialog_ui_button_ok',
\r
1204 onClick : function( evt )
\r
1206 var dialog = evt.data.dialog;
\r
1207 if ( dialog.fire( 'ok', { hide : true } ).hide !== false )
\r
1210 }, override, true );
\r
1212 retval.type = 'button';
\r
1213 retval.override = function( override )
\r
1215 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1216 { type : 'button' }, true );
\r
1222 * The default cancel button for dialogs. Fires the "cancel" event and closes the dialog if no UI element value changed.
\r
1228 cancelButton : (function()
\r
1230 var retval = function( editor, override )
\r
1232 override = override || {};
\r
1233 return CKEDITOR.tools.extend( {
\r
1236 label : editor.lang.common.cancel,
\r
1237 'class' : 'cke_dialog_ui_button_cancel',
\r
1238 onClick : function( evt )
\r
1240 var dialog = evt.data.dialog;
\r
1241 if ( dialog.fire( 'cancel', { hide : true } ).hide !== false )
\r
1244 }, override, true );
\r
1246 retval.type = 'button';
\r
1247 retval.override = function( override )
\r
1249 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1250 { type : 'button' }, true );
\r
1256 * Registers a dialog UI element.
\r
1257 * @param {String} typeName The name of the UI element.
\r
1258 * @param {Function} builder The function to build the UI element.
\r
1261 addUIElement : function( typeName, builder )
\r
1263 this._.uiElementBuilders[ typeName ] = builder;
\r
1267 CKEDITOR.dialog._ =
\r
1269 uiElementBuilders : {},
\r
1271 dialogDefinitions : {},
\r
1273 currentTop : null,
\r
1275 currentZIndex : null
\r
1278 // "Inherit" (copy actually) from CKEDITOR.event.
\r
1279 CKEDITOR.event.implementOn( CKEDITOR.dialog );
\r
1280 CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype, true );
\r
1282 var defaultDialogDefinition =
\r
1284 resizable : CKEDITOR.DIALOG_RESIZE_BOTH,
\r
1287 buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
\r
1290 // The buttons in MacOS Apps are in reverse order #4750
\r
1291 CKEDITOR.env.mac && defaultDialogDefinition.buttons.reverse();
\r
1293 // Tool function used to return an item from an array based on its id
\r
1295 var getById = function( array, id, recurse )
\r
1297 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1299 if ( item.id == id )
\r
1301 if ( recurse && item[ recurse ] )
\r
1303 var retval = getById( item[ recurse ], id, recurse ) ;
\r
1311 // Tool function used to add an item into an array.
\r
1312 var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound )
\r
1314 if ( nextSiblingId )
\r
1316 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1318 if ( item.id == nextSiblingId )
\r
1320 array.splice( i, 0, newItem );
\r
1324 if ( recurse && item[ recurse ] )
\r
1326 var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
\r
1332 if ( nullIfNotFound )
\r
1336 array.push( newItem );
\r
1340 // Tool function used to remove an item from an array based on its id.
\r
1341 var removeById = function( array, id, recurse )
\r
1343 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1345 if ( item.id == id )
\r
1346 return array.splice( i, 1 );
\r
1347 if ( recurse && item[ recurse ] )
\r
1349 var retval = removeById( item[ recurse ], id, recurse );
\r
1358 * This class is not really part of the API. It is the "definition" property value
\r
1359 * passed to "dialogDefinition" event handlers.
\r
1361 * @name CKEDITOR.dialog.dialogDefinitionObject
\r
1362 * @extends CKEDITOR.dialog.dialogDefinition
\r
1364 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1366 * var definition = evt.data.definition;
\r
1367 * var content = definition.getContents( 'page1' );
\r
1371 var definitionObject = function( dialog, dialogDefinition )
\r
1373 // TODO : Check if needed.
\r
1374 this.dialog = dialog;
\r
1376 // Transform the contents entries in contentObjects.
\r
1377 var contents = dialogDefinition.contents;
\r
1378 for ( var i = 0, content ; ( content = contents[i] ) ; i++ )
\r
1379 contents[ i ] = new contentObject( dialog, content );
\r
1381 CKEDITOR.tools.extend( this, dialogDefinition );
\r
1384 definitionObject.prototype =
\r
1385 /** @lends CKEDITOR.dialog.dialogDefinitionObject.prototype */
\r
1388 * Gets a content definition.
\r
1389 * @param {String} id The id of the content definition.
\r
1390 * @returns {CKEDITOR.dialog.contentDefinition} The content definition
\r
1393 getContents : function( id )
\r
1395 return getById( this.contents, id );
\r
1399 * Gets a button definition.
\r
1400 * @param {String} id The id of the button definition.
\r
1401 * @returns {CKEDITOR.dialog.buttonDefinition} The button definition
\r
1404 getButton : function( id )
\r
1406 return getById( this.buttons, id );
\r
1410 * Adds a content definition object under this dialog definition.
\r
1411 * @param {CKEDITOR.dialog.contentDefinition} contentDefinition The
\r
1412 * content definition.
\r
1413 * @param {String} [nextSiblingId] The id of an existing content
\r
1414 * definition which the new content definition will be inserted
\r
1415 * before. Omit if the new content definition is to be inserted as
\r
1417 * @returns {CKEDITOR.dialog.contentDefinition} The inserted content
\r
1420 addContents : function( contentDefinition, nextSiblingId )
\r
1422 return addById( this.contents, contentDefinition, nextSiblingId );
\r
1426 * Adds a button definition object under this dialog definition.
\r
1427 * @param {CKEDITOR.dialog.buttonDefinition} buttonDefinition The
\r
1428 * button definition.
\r
1429 * @param {String} [nextSiblingId] The id of an existing button
\r
1430 * definition which the new button definition will be inserted
\r
1431 * before. Omit if the new button definition is to be inserted as
\r
1433 * @returns {CKEDITOR.dialog.buttonDefinition} The inserted button
\r
1436 addButton : function( buttonDefinition, nextSiblingId )
\r
1438 return addById( this.buttons, buttonDefinition, nextSiblingId );
\r
1442 * Removes a content definition from this dialog definition.
\r
1443 * @param {String} id The id of the content definition to be removed.
\r
1444 * @returns {CKEDITOR.dialog.contentDefinition} The removed content
\r
1447 removeContents : function( id )
\r
1449 removeById( this.contents, id );
\r
1453 * Removes a button definition from the dialog definition.
\r
1454 * @param {String} id The id of the button definition to be removed.
\r
1455 * @returns {CKEDITOR.dialog.buttonDefinition} The removed button
\r
1458 removeButton : function( id )
\r
1460 removeById( this.buttons, id );
\r
1465 * This class is not really part of the API. It is the template of the
\r
1466 * objects representing content pages inside the
\r
1467 * CKEDITOR.dialog.dialogDefinitionObject.
\r
1469 * @name CKEDITOR.dialog.contentDefinitionObject
\r
1471 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1473 * var definition = evt.data.definition;
\r
1474 * var content = definition.getContents( 'page1' );
\r
1475 * content.remove( 'textInput1' );
\r
1479 function contentObject( dialog, contentDefinition )
\r
1486 CKEDITOR.tools.extend( this, contentDefinition );
\r
1489 contentObject.prototype =
\r
1490 /** @lends CKEDITOR.dialog.contentDefinitionObject.prototype */
\r
1493 * Gets a UI element definition under the content definition.
\r
1494 * @param {String} id The id of the UI element definition.
\r
1495 * @returns {CKEDITOR.dialog.uiElementDefinition}
\r
1497 get : function( id )
\r
1499 return getById( this.elements, id, 'children' );
\r
1503 * Adds a UI element definition to the content definition.
\r
1504 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition The
\r
1505 * UI elemnet definition to be added.
\r
1506 * @param {String} nextSiblingId The id of an existing UI element
\r
1507 * definition which the new UI element definition will be inserted
\r
1508 * before. Omit if the new button definition is to be inserted as
\r
1510 * @returns {CKEDITOR.dialog.uiElementDefinition} The element
\r
1511 * definition inserted.
\r
1513 add : function( elementDefinition, nextSiblingId )
\r
1515 return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
\r
1519 * Removes a UI element definition from the content definition.
\r
1520 * @param {String} id The id of the UI element definition to be
\r
1522 * @returns {CKEDITOR.dialog.uiElementDefinition} The element
\r
1523 * definition removed.
\r
1526 remove : function( id )
\r
1528 removeById( this.elements, id, 'children' );
\r
1532 function initDragAndDrop( dialog )
\r
1534 var lastCoords = null,
\r
1535 abstractDialogCoords = null,
\r
1536 element = dialog.getElement().getFirst(),
\r
1537 editor = dialog.getParentEditor(),
\r
1538 magnetDistance = editor.config.dialog_magnetDistance,
\r
1539 margins = editor.skin.margins || [ 0, 0, 0, 0 ];
\r
1541 if ( typeof magnetDistance == 'undefined' )
\r
1542 magnetDistance = 20;
\r
1544 function mouseMoveHandler( evt )
\r
1546 var dialogSize = dialog.getSize(),
\r
1547 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
1548 x = evt.data.$.screenX,
\r
1549 y = evt.data.$.screenY,
\r
1550 dx = x - lastCoords.x,
\r
1551 dy = y - lastCoords.y,
\r
1554 lastCoords = { x : x, y : y };
\r
1555 abstractDialogCoords.x += dx;
\r
1556 abstractDialogCoords.y += dy;
\r
1558 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
\r
1559 realX = - margins[3];
\r
1560 else if ( abstractDialogCoords.x - margins[1] > viewPaneSize.width - dialogSize.width - magnetDistance )
\r
1561 realX = viewPaneSize.width - dialogSize.width + margins[1];
\r
1563 realX = abstractDialogCoords.x;
\r
1565 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
\r
1566 realY = - margins[0];
\r
1567 else if ( abstractDialogCoords.y - margins[2] > viewPaneSize.height - dialogSize.height - magnetDistance )
\r
1568 realY = viewPaneSize.height - dialogSize.height + margins[2];
\r
1570 realY = abstractDialogCoords.y;
\r
1572 dialog.move( realX, realY );
\r
1574 evt.data.preventDefault();
\r
1577 function mouseUpHandler( evt )
\r
1579 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1580 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1582 if ( CKEDITOR.env.ie6Compat )
\r
1584 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1585 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1586 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1590 dialog.parts.title.on( 'mousedown', function( evt )
\r
1592 dialog._.updateSize = true;
\r
1594 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
\r
1596 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
\r
1597 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
\r
1598 abstractDialogCoords = dialog.getPosition();
\r
1600 if ( CKEDITOR.env.ie6Compat )
\r
1602 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1603 coverDoc.on( 'mousemove', mouseMoveHandler );
\r
1604 coverDoc.on( 'mouseup', mouseUpHandler );
\r
1607 evt.data.preventDefault();
\r
1611 function initResizeHandles( dialog )
\r
1613 var definition = dialog.definition,
\r
1614 minWidth = definition.minWidth || 0,
\r
1615 minHeight = definition.minHeight || 0,
\r
1616 resizable = definition.resizable,
\r
1617 margins = dialog.getParentEditor().skin.margins || [ 0, 0, 0, 0 ];
\r
1619 function topSizer( coords, dy )
\r
1624 function rightSizer( coords, dx )
\r
1629 function bottomSizer( coords, dy )
\r
1634 function leftSizer( coords, dx )
\r
1639 var lastCoords = null,
\r
1640 abstractDialogCoords = null,
\r
1641 magnetDistance = dialog._.editor.config.magnetDistance,
\r
1642 parts = [ 'tl', 't', 'tr', 'l', 'r', 'bl', 'b', 'br' ];
\r
1644 function mouseDownHandler( evt )
\r
1646 var partName = evt.listenerData.part, size = dialog.getSize();
\r
1647 abstractDialogCoords = dialog.getPosition();
\r
1648 CKEDITOR.tools.extend( abstractDialogCoords,
\r
1650 x2 : abstractDialogCoords.x + size.width,
\r
1651 y2 : abstractDialogCoords.y + size.height
\r
1653 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
\r
1655 CKEDITOR.document.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } );
\r
1656 CKEDITOR.document.on( 'mouseup', mouseUpHandler, dialog, { part : partName } );
\r
1658 if ( CKEDITOR.env.ie6Compat )
\r
1660 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1661 coverDoc.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } );
\r
1662 coverDoc.on( 'mouseup', mouseUpHandler, dialog, { part : partName } );
\r
1665 evt.data.preventDefault();
\r
1668 function mouseMoveHandler( evt )
\r
1670 var x = evt.data.$.screenX,
\r
1671 y = evt.data.$.screenY,
\r
1672 dx = x - lastCoords.x,
\r
1673 dy = y - lastCoords.y,
\r
1674 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
1675 partName = evt.listenerData.part;
\r
1677 if ( partName.search( 't' ) != -1 )
\r
1678 topSizer( abstractDialogCoords, dy );
\r
1679 if ( partName.search( 'l' ) != -1 )
\r
1680 leftSizer( abstractDialogCoords, dx );
\r
1681 if ( partName.search( 'b' ) != -1 )
\r
1682 bottomSizer( abstractDialogCoords, dy );
\r
1683 if ( partName.search( 'r' ) != -1 )
\r
1684 rightSizer( abstractDialogCoords, dx );
\r
1686 lastCoords = { x : x, y : y };
\r
1688 var realX, realY, realX2, realY2;
\r
1690 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
\r
1691 realX = - margins[3];
\r
1692 else if ( partName.search( 'l' ) != -1 && abstractDialogCoords.x2 - abstractDialogCoords.x < minWidth + magnetDistance )
\r
1693 realX = abstractDialogCoords.x2 - minWidth;
\r
1695 realX = abstractDialogCoords.x;
\r
1697 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
\r
1698 realY = - margins[0];
\r
1699 else if ( partName.search( 't' ) != -1 && abstractDialogCoords.y2 - abstractDialogCoords.y < minHeight + magnetDistance )
\r
1700 realY = abstractDialogCoords.y2 - minHeight;
\r
1702 realY = abstractDialogCoords.y;
\r
1704 if ( abstractDialogCoords.x2 - margins[1] > viewPaneSize.width - magnetDistance )
\r
1705 realX2 = viewPaneSize.width + margins[1] ;
\r
1706 else if ( partName.search( 'r' ) != -1 && abstractDialogCoords.x2 - abstractDialogCoords.x < minWidth + magnetDistance )
\r
1707 realX2 = abstractDialogCoords.x + minWidth;
\r
1709 realX2 = abstractDialogCoords.x2;
\r
1711 if ( abstractDialogCoords.y2 - margins[2] > viewPaneSize.height - magnetDistance )
\r
1712 realY2= viewPaneSize.height + margins[2] ;
\r
1713 else if ( partName.search( 'b' ) != -1 && abstractDialogCoords.y2 - abstractDialogCoords.y < minHeight + magnetDistance )
\r
1714 realY2 = abstractDialogCoords.y + minHeight;
\r
1716 realY2 = abstractDialogCoords.y2 ;
\r
1718 dialog.move( realX, realY );
\r
1719 dialog.resize( realX2 - realX, realY2 - realY );
\r
1721 evt.data.preventDefault();
\r
1724 function mouseUpHandler( evt )
\r
1726 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1727 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1729 if ( CKEDITOR.env.ie6Compat )
\r
1731 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1732 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1733 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1737 // TODO : Simplify the resize logic, having just a single resize grip <div>.
\r
1738 // var widthTest = /[lr]/,
\r
1739 // heightTest = /[tb]/;
\r
1740 // for ( var i = 0 ; i < parts.length ; i++ )
\r
1742 // var element = dialog.parts[ parts[i] + '_resize' ];
\r
1743 // if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE ||
\r
1744 // resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT && widthTest.test( parts[i] ) ||
\r
1745 // resizable == CKEDITOR.DIALOG_RESIZE_WIDTH && heightTest.test( parts[i] ) )
\r
1747 // element.hide();
\r
1750 // element.on( 'mousedown', mouseDownHandler, dialog, { part : parts[i] } );
\r
1755 // Caching resuable covers and allowing only one cover
\r
1760 function showCover( editor )
\r
1762 var win = CKEDITOR.document.getWindow();
\r
1763 var backgroundColorStyle = editor.config.dialog_backgroundCoverColor || 'white',
\r
1764 backgroundCoverOpacity = editor.config.dialog_backgroundCoverOpacity,
\r
1765 baseFloatZIndex = editor.config.baseFloatZIndex,
\r
1766 coverKey = CKEDITOR.tools.genKey(
\r
1767 backgroundColorStyle,
\r
1768 backgroundCoverOpacity,
\r
1769 baseFloatZIndex ),
\r
1770 coverElement = covers[ coverKey ];
\r
1772 if ( !coverElement )
\r
1775 '<div style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),
\r
1776 '; z-index: ', baseFloatZIndex,
\r
1777 '; top: 0px; left: 0px; ',
\r
1778 ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),
\r
1779 '" class="cke_dialog_background_cover">'
\r
1782 if ( CKEDITOR.env.ie6Compat )
\r
1784 // Support for custom document.domain in IE.
\r
1785 var isCustomDomain = CKEDITOR.env.isCustomDomain(),
\r
1786 iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
\r
1790 ' hidefocus="true"' +
\r
1791 ' frameborder="0"' +
\r
1792 ' id="cke_dialog_background_iframe"' +
\r
1793 ' src="javascript:' );
\r
1795 html.push( 'void((function(){' +
\r
1796 'document.open();' +
\r
1797 ( isCustomDomain ? 'document.domain=\'' + document.domain + '\';' : '' ) +
\r
1798 'document.write( \'' + iframeHtml + '\' );' +
\r
1799 'document.close();' +
\r
1805 'position:absolute;' +
\r
1810 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
\r
1814 html.push( '</div>' );
\r
1816 coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
\r
1817 coverElement.setOpacity( backgroundCoverOpacity != undefined ? backgroundCoverOpacity : 0.5 );
\r
1819 coverElement.appendTo( CKEDITOR.document.getBody() );
\r
1820 covers[ coverKey ] = coverElement;
\r
1823 coverElement. show();
\r
1825 currentCover = coverElement;
\r
1826 var resizeFunc = function()
\r
1828 var size = win.getViewPaneSize();
\r
1829 coverElement.setStyles(
\r
1831 width : size.width + 'px',
\r
1832 height : size.height + 'px'
\r
1836 var scrollFunc = function()
\r
1838 var pos = win.getScrollPosition(),
\r
1839 cursor = CKEDITOR.dialog._.currentTop;
\r
1840 coverElement.setStyles(
\r
1842 left : pos.x + 'px',
\r
1843 top : pos.y + 'px'
\r
1848 var dialogPos = cursor.getPosition();
\r
1849 cursor.move( dialogPos.x, dialogPos.y );
\r
1850 } while ( ( cursor = cursor._.parentDialog ) );
\r
1853 resizeCover = resizeFunc;
\r
1854 win.on( 'resize', resizeFunc );
\r
1856 if ( CKEDITOR.env.ie6Compat )
\r
1858 // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
\r
1859 // So we need to invent a really funny way to make it work.
\r
1860 var myScrollHandler = function()
\r
1863 arguments.callee.prevScrollHandler.apply( this, arguments );
\r
1865 win.$.setTimeout( function()
\r
1867 myScrollHandler.prevScrollHandler = window.onscroll || function(){};
\r
1868 window.onscroll = myScrollHandler;
\r
1874 function hideCover()
\r
1876 if ( !currentCover )
\r
1879 var win = CKEDITOR.document.getWindow();
\r
1880 currentCover.hide();
\r
1881 win.removeListener( 'resize', resizeCover );
\r
1883 if ( CKEDITOR.env.ie6Compat )
\r
1885 win.$.setTimeout( function()
\r
1887 var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
\r
1888 window.onscroll = prevScrollHandler || null;
\r
1891 resizeCover = null;
\r
1894 function removeCovers()
\r
1896 for ( var coverId in covers )
\r
1897 covers[ coverId ].remove();
\r
1901 var accessKeyProcessors = {};
\r
1903 var accessKeyDownHandler = function( evt )
\r
1905 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
1906 alt = evt.data.$.altKey,
\r
1907 shift = evt.data.$.shiftKey,
\r
1908 key = String.fromCharCode( evt.data.$.keyCode ),
\r
1909 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
1911 if ( !keyProcessor || !keyProcessor.length )
\r
1914 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
1915 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
1916 evt.data.preventDefault();
\r
1919 var accessKeyUpHandler = function( evt )
\r
1921 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
1922 alt = evt.data.$.altKey,
\r
1923 shift = evt.data.$.shiftKey,
\r
1924 key = String.fromCharCode( evt.data.$.keyCode ),
\r
1925 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
1927 if ( !keyProcessor || !keyProcessor.length )
\r
1930 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
1931 if ( keyProcessor.keyup )
\r
1933 keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
1934 evt.data.preventDefault();
\r
1938 var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc )
\r
1940 var procList = accessKeyProcessors[key] || ( accessKeyProcessors[key] = [] );
\r
1942 uiElement : uiElement,
\r
1945 keyup : upFunc || uiElement.accessKeyUp,
\r
1946 keydown : downFunc || uiElement.accessKeyDown
\r
1950 var unregisterAccessKey = function( obj )
\r
1952 for ( var i in accessKeyProcessors )
\r
1954 var list = accessKeyProcessors[i];
\r
1955 for ( var j = list.length - 1 ; j >= 0 ; j-- )
\r
1957 if ( list[j].dialog == obj || list[j].uiElement == obj )
\r
1958 list.splice( j, 1 );
\r
1960 if ( list.length === 0 )
\r
1961 delete accessKeyProcessors[i];
\r
1965 var tabAccessKeyUp = function( dialog, key )
\r
1967 if ( dialog._.accessKeyMap[key] )
\r
1968 dialog.selectPage( dialog._.accessKeyMap[key] );
\r
1971 var tabAccessKeyDown = function( dialog, key )
\r
1976 var preventKeyBubblingKeys = { 27 :1, 13 :1 };
\r
1977 var preventKeyBubbling = function( e )
\r
1979 if ( e.data.getKeystroke() in preventKeyBubblingKeys )
\r
1980 e.data.stopPropagation();
\r
1985 CKEDITOR.ui.dialog =
\r
1988 * The base class of all dialog UI elements.
\r
1990 * @param {CKEDITOR.dialog} dialog Parent dialog object.
\r
1991 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition Element
\r
1992 * definition. Accepted fields:
\r
1994 * <li><strong>id</strong> (Required) The id of the UI element. See {@link
\r
1995 * CKEDITOR.dialog#getContentElement}</li>
\r
1996 * <li><strong>type</strong> (Required) The type of the UI element. The
\r
1997 * value to this field specifies which UI element class will be used to
\r
1998 * generate the final widget.</li>
\r
1999 * <li><strong>title</strong> (Optional) The popup tooltip for the UI
\r
2001 * <li><strong>hidden</strong> (Optional) A flag that tells if the element
\r
2002 * should be initially visible.</li>
\r
2003 * <li><strong>className</strong> (Optional) Additional CSS class names
\r
2004 * to add to the UI element. Separated by space.</li>
\r
2005 * <li><strong>style</strong> (Optional) Additional CSS inline styles
\r
2006 * to add to the UI element. A semicolon (;) is required after the last
\r
2007 * style declaration.</li>
\r
2008 * <li><strong>accessKey</strong> (Optional) The alphanumeric access key
\r
2009 * for this element. Access keys are automatically prefixed by CTRL.</li>
\r
2010 * <li><strong>on*</strong> (Optional) Any UI element definition field that
\r
2011 * starts with <em>on</em> followed immediately by a capital letter and
\r
2012 * probably more letters is an event handler. Event handlers may be further
\r
2013 * divided into registered event handlers and DOM event handlers. Please
\r
2014 * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and
\r
2015 * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more
\r
2016 * information.</li>
\r
2018 * @param {Array} htmlList
\r
2019 * List of HTML code to be added to the dialog's content area.
\r
2020 * @param {Function|String} nodeNameArg
\r
2021 * A function returning a string, or a simple string for the node name for
\r
2022 * the root DOM node. Default is 'div'.
\r
2023 * @param {Function|Object} stylesArg
\r
2024 * A function returning an object, or a simple object for CSS styles applied
\r
2025 * to the DOM node. Default is empty object.
\r
2026 * @param {Function|Object} attributesArg
\r
2027 * A fucntion returning an object, or a simple object for attributes applied
\r
2028 * to the DOM node. Default is empty object.
\r
2029 * @param {Function|String} contentsArg
\r
2030 * A function returning a string, or a simple string for the HTML code inside
\r
2031 * the root DOM node. Default is empty string.
\r
2034 uiElement : function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg )
\r
2036 if ( arguments.length < 4 )
\r
2039 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',
\r
2040 html = [ '<', nodeName, ' ' ],
\r
2041 styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},
\r
2042 attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},
\r
2043 innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',
\r
2044 domId = this.domId = attributes.id || CKEDITOR.tools.getNextNumber() + '_uiElement',
\r
2045 id = this.id = elementDefinition.id,
\r
2048 // Set the id, a unique id is required for getElement() to work.
\r
2049 attributes.id = domId;
\r
2051 // Set the type and definition CSS class names.
\r
2053 if ( elementDefinition.type )
\r
2054 classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;
\r
2055 if ( elementDefinition.className )
\r
2056 classes[ elementDefinition.className ] = 1;
\r
2057 var attributeClasses = ( attributes['class'] && attributes['class'].split ) ? attributes['class'].split( ' ' ) : [];
\r
2058 for ( i = 0 ; i < attributeClasses.length ; i++ )
\r
2060 if ( attributeClasses[i] )
\r
2061 classes[ attributeClasses[i] ] = 1;
\r
2063 var finalClasses = [];
\r
2064 for ( i in classes )
\r
2065 finalClasses.push( i );
\r
2066 attributes['class'] = finalClasses.join( ' ' );
\r
2068 // Set the popup tooltop.
\r
2069 if ( elementDefinition.title )
\r
2070 attributes.title = elementDefinition.title;
\r
2072 // Write the inline CSS styles.
\r
2073 var styleStr = ( elementDefinition.style || '' ).split( ';' );
\r
2074 for ( i in styles )
\r
2075 styleStr.push( i + ':' + styles[i] );
\r
2076 if ( elementDefinition.hidden )
\r
2077 styleStr.push( 'display:none' );
\r
2078 for ( i = styleStr.length - 1 ; i >= 0 ; i-- )
\r
2080 if ( styleStr[i] === '' )
\r
2081 styleStr.splice( i, 1 );
\r
2083 if ( styleStr.length > 0 )
\r
2084 attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
\r
2086 // Write the attributes.
\r
2087 for ( i in attributes )
\r
2088 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '" ');
\r
2090 // Write the content HTML.
\r
2091 html.push( '>', innerHTML, '</', nodeName, '>' );
\r
2093 // Add contents to the parent HTML array.
\r
2094 htmlList.push( html.join( '' ) );
\r
2096 ( this._ || ( this._ = {} ) ).dialog = dialog;
\r
2098 // Override isChanged if it is defined in element definition.
\r
2099 if ( typeof( elementDefinition.isChanged ) == 'boolean' )
\r
2100 this.isChanged = function(){ return elementDefinition.isChanged; };
\r
2101 if ( typeof( elementDefinition.isChanged ) == 'function' )
\r
2102 this.isChanged = elementDefinition.isChanged;
\r
2105 CKEDITOR.event.implementOn( this );
\r
2107 this.registerEvents( elementDefinition );
\r
2108 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
\r
2109 registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
\r
2112 dialog.on( 'load', function()
\r
2114 if ( me.getInputElement() )
\r
2116 me.getInputElement().on( 'focus', function()
\r
2118 dialog._.tabBarMode = false;
\r
2119 dialog._.hasFocus = true;
\r
2120 me.fire( 'focus' );
\r
2125 // Register the object as a tab focus if it can be included.
\r
2126 if ( this.keyboardFocusable )
\r
2128 this.tabIndex = elementDefinition.tabIndex || 0;
\r
2130 this.focusIndex = dialog._.focusList.push( this ) - 1;
\r
2131 this.on( 'focus', function()
\r
2133 dialog._.currentFocusIndex = me.focusIndex;
\r
2137 // Completes this object with everything we have in the
\r
2139 CKEDITOR.tools.extend( this, elementDefinition );
\r
2143 * Horizontal layout box for dialog UI elements, auto-expends to available width of container.
\r
2145 * @extends CKEDITOR.ui.dialog.uiElement
\r
2146 * @param {CKEDITOR.dialog} dialog
\r
2147 * Parent dialog object.
\r
2148 * @param {Array} childObjList
\r
2149 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2151 * @param {Array} childHtmlList
\r
2152 * Array of HTML code that correspond to the HTML output of all the
\r
2153 * objects in childObjList.
\r
2154 * @param {Array} htmlList
\r
2155 * Array of HTML code that this element will output to.
\r
2156 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
2157 * The element definition. Accepted fields:
\r
2159 * <li><strong>widths</strong> (Optional) The widths of child cells.</li>
\r
2160 * <li><strong>height</strong> (Optional) The height of the layout.</li>
\r
2161 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2163 * <li><strong>align</strong> (Optional) The alignment of the whole layout
\r
2168 hbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2170 if ( arguments.length < 4 )
\r
2173 this._ || ( this._ = {} );
\r
2175 var children = this._.children = childObjList,
\r
2176 widths = elementDefinition && elementDefinition.widths || null,
\r
2177 height = elementDefinition && elementDefinition.height || null,
\r
2181 var innerHTML = function()
\r
2183 var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];
\r
2184 for ( i = 0 ; i < childHtmlList.length ; i++ )
\r
2186 var className = 'cke_dialog_ui_hbox_child',
\r
2189 className = 'cke_dialog_ui_hbox_first';
\r
2190 if ( i == childHtmlList.length - 1 )
\r
2191 className = 'cke_dialog_ui_hbox_last';
\r
2192 html.push( '<td class="', className, '" role="presentation" ' );
\r
2196 styles.push( 'width:' + CKEDITOR.tools.cssLength( widths[i] ) );
\r
2199 styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2201 styles.push( 'height:' + CKEDITOR.tools.cssLength( height ) );
\r
2202 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2203 styles.push( 'padding:' + CKEDITOR.tools.cssLength( elementDefinition.padding ) );
\r
2204 if ( styles.length > 0 )
\r
2205 html.push( 'style="' + styles.join('; ') + '" ' );
\r
2206 html.push( '>', childHtmlList[i], '</td>' );
\r
2208 html.push( '</tr></tbody>' );
\r
2209 return html.join( '' );
\r
2212 var attribs = { role : 'presentation' };
\r
2213 elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );
\r
2215 CKEDITOR.ui.dialog.uiElement.call(
\r
2218 elementDefinition || { type : 'hbox' },
\r
2227 * Vertical layout box for dialog UI elements.
\r
2229 * @extends CKEDITOR.ui.dialog.hbox
\r
2230 * @param {CKEDITOR.dialog} dialog
\r
2231 * Parent dialog object.
\r
2232 * @param {Array} childObjList
\r
2233 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2235 * @param {Array} childHtmlList
\r
2236 * Array of HTML code that correspond to the HTML output of all the
\r
2237 * objects in childObjList.
\r
2238 * @param {Array} htmlList
\r
2239 * Array of HTML code that this element will output to.
\r
2240 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
2241 * The element definition. Accepted fields:
\r
2243 * <li><strong>width</strong> (Optional) The width of the layout.</li>
\r
2244 * <li><strong>heights</strong> (Optional) The heights of individual cells.
\r
2246 * <li><strong>align</strong> (Optional) The alignment of the layout.</li>
\r
2247 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2249 * <li><strong>expand</strong> (Optional) Whether the layout should expand
\r
2250 * vertically to fill its container.</li>
\r
2254 vbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2256 if (arguments.length < 3 )
\r
2259 this._ || ( this._ = {} );
\r
2261 var children = this._.children = childObjList,
\r
2262 width = elementDefinition && elementDefinition.width || null,
\r
2263 heights = elementDefinition && elementDefinition.heights || null;
\r
2265 var innerHTML = function()
\r
2267 var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];
\r
2268 html.push( 'style="' );
\r
2269 if ( elementDefinition && elementDefinition.expand )
\r
2270 html.push( 'height:100%;' );
\r
2271 html.push( 'width:' + CKEDITOR.tools.cssLength( width || '100%' ), ';' );
\r
2273 html.push( 'align="', CKEDITOR.tools.htmlEncode(
\r
2274 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
\r
2276 html.push( '><tbody>' );
\r
2277 for ( var i = 0 ; i < childHtmlList.length ; i++ )
\r
2280 html.push( '<tr><td role="presentation" ' );
\r
2282 styles.push( 'width:' + CKEDITOR.tools.cssLength( width || '100%' ) );
\r
2284 styles.push( 'height:' + CKEDITOR.tools.cssLength( heights[i] ) );
\r
2285 else if ( elementDefinition && elementDefinition.expand )
\r
2286 styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2287 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2288 styles.push( 'padding:' + CKEDITOR.tools.cssLength( elementDefinition.padding ) );
\r
2289 if ( styles.length > 0 )
\r
2290 html.push( 'style="', styles.join( '; ' ), '" ' );
\r
2291 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[i], '</td></tr>' );
\r
2293 html.push( '</tbody></table>' );
\r
2294 return html.join( '' );
\r
2296 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type : 'vbox' }, htmlList, 'div', null, { role : 'presentation' }, innerHTML );
\r
2301 CKEDITOR.ui.dialog.uiElement.prototype =
\r
2304 * Gets the root DOM element of this dialog UI object.
\r
2305 * @returns {CKEDITOR.dom.element} Root DOM element of UI object.
\r
2307 * uiElement.getElement().hide();
\r
2309 getElement : function()
\r
2311 return CKEDITOR.document.getById( this.domId );
\r
2315 * Gets the DOM element that the user inputs values.
\r
2316 * This function is used by setValue(), getValue() and focus(). It should
\r
2317 * be overrided in child classes where the input element isn't the root
\r
2319 * @returns {CKEDITOR.dom.element} The element where the user input values.
\r
2321 * var rawValue = textInput.getInputElement().$.value;
\r
2323 getInputElement : function()
\r
2325 return this.getElement();
\r
2329 * Gets the parent dialog object containing this UI element.
\r
2330 * @returns {CKEDITOR.dialog} Parent dialog object.
\r
2332 * var dialog = uiElement.getDialog();
\r
2334 getDialog : function()
\r
2336 return this._.dialog;
\r
2340 * Sets the value of this dialog UI object.
\r
2341 * @param {Object} value The new value.
\r
2342 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2344 * uiElement.setValue( 'Dingo' );
\r
2346 setValue : function( value )
\r
2348 this.getInputElement().setValue( value );
\r
2349 this.fire( 'change', { value : value } );
\r
2354 * Gets the current value of this dialog UI object.
\r
2355 * @returns {Object} The current value.
\r
2357 * var myValue = uiElement.getValue();
\r
2359 getValue : function()
\r
2361 return this.getInputElement().getValue();
\r
2365 * Tells whether the UI object's value has changed.
\r
2366 * @returns {Boolean} true if changed, false if not changed.
\r
2368 * if ( uiElement.isChanged() )
\r
2369 * confirm( 'Value changed! Continue?' );
\r
2371 isChanged : function()
\r
2373 // Override in input classes.
\r
2378 * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
\r
2379 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2381 * focus : function()
\r
2383 * this.selectParentTab();
\r
2384 * // do something else.
\r
2387 selectParentTab : function()
\r
2389 var element = this.getInputElement(),
\r
2392 while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 )
\r
2395 // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
\r
2399 tabId = cursor.getAttribute( 'name' );
\r
2400 // Avoid duplicate select.
\r
2401 if ( this._.dialog._.currentTabId != tabId )
\r
2402 this._.dialog.selectPage( tabId );
\r
2407 * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
\r
2408 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2410 * uiElement.focus();
\r
2412 focus : function()
\r
2414 this.selectParentTab().getInputElement().focus();
\r
2419 * Registers the on* event handlers defined in the element definition.
\r
2420 * The default behavior of this function is:
\r
2423 * If the on* event is defined in the class's eventProcesors list,
\r
2424 * then the registration is delegated to the corresponding function
\r
2425 * in the eventProcessors list.
\r
2428 * If the on* event is not defined in the eventProcessors list, then
\r
2429 * register the event handler under the corresponding DOM event of
\r
2430 * the UI element's input DOM element (as defined by the return value
\r
2431 * of {@link CKEDITOR.ui.dialog.uiElement#getInputElement}).
\r
2434 * This function is only called at UI element instantiation, but can
\r
2435 * be overridded in child classes if they require more flexibility.
\r
2436 * @param {CKEDITOR.dialog.uiElementDefinition} definition The UI element
\r
2438 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2441 registerEvents : function( definition )
\r
2443 var regex = /^on([A-Z]\w+)/,
\r
2446 var registerDomEvent = function( uiElement, dialog, eventName, func )
\r
2448 dialog.on( 'load', function()
\r
2450 uiElement.getInputElement().on( eventName, func, uiElement );
\r
2454 for ( var i in definition )
\r
2456 if ( !( match = i.match( regex ) ) )
\r
2458 if ( this.eventProcessors[i] )
\r
2459 this.eventProcessors[i].call( this, this._.dialog, definition[i] );
\r
2461 registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
\r
2468 * The event processor list used by
\r
2469 * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element
\r
2470 * instantiation. The default list defines three on* events:
\r
2472 * <li>onLoad - Called when the element's parent dialog opens for the
\r
2474 * <li>onShow - Called whenever the element's parent dialog opens.</li>
\r
2475 * <li>onHide - Called whenever the element's parent dialog closes.</li>
\r
2480 * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick
\r
2481 * // handlers in the UI element's definitions.
\r
2482 * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},
\r
2483 * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
\r
2484 * { onClick : function( dialog, func ) { this.on( 'click', func ); } },
\r
2485 * true );
\r
2489 onLoad : function( dialog, func )
\r
2491 dialog.on( 'load', func, this );
\r
2494 onShow : function( dialog, func )
\r
2496 dialog.on( 'show', func, this );
\r
2499 onHide : function( dialog, func )
\r
2501 dialog.on( 'hide', func, this );
\r
2506 * The default handler for a UI element's access key down event, which
\r
2507 * tries to put focus to the UI element.<br />
\r
2508 * Can be overridded in child classes for more sophisticaed behavior.
\r
2509 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2510 * @param {String} key The key combination pressed. Since access keys
\r
2511 * are defined to always include the CTRL key, its value should always
\r
2512 * include a 'CTRL+' prefix.
\r
2515 accessKeyDown : function( dialog, key )
\r
2521 * The default handler for a UI element's access key up event, which
\r
2522 * does nothing.<br />
\r
2523 * Can be overridded in child classes for more sophisticated behavior.
\r
2524 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2525 * @param {String} key The key combination pressed. Since access keys
\r
2526 * are defined to always include the CTRL key, its value should always
\r
2527 * include a 'CTRL+' prefix.
\r
2530 accessKeyUp : function( dialog, key )
\r
2535 * Disables a UI element.
\r
2538 disable : function()
\r
2540 var element = this.getInputElement();
\r
2541 element.setAttribute( 'disabled', 'true' );
\r
2542 element.addClass( 'cke_disabled' );
\r
2546 * Enables a UI element.
\r
2549 enable : function()
\r
2551 var element = this.getInputElement();
\r
2552 element.removeAttribute( 'disabled' );
\r
2553 element.removeClass( 'cke_disabled' );
\r
2557 * Determines whether an UI element is enabled or not.
\r
2558 * @returns {Boolean} Whether the UI element is enabled.
\r
2561 isEnabled : function()
\r
2563 return !this.getInputElement().getAttribute( 'disabled' );
\r
2567 * Determines whether an UI element is visible or not.
\r
2568 * @returns {Boolean} Whether the UI element is visible.
\r
2571 isVisible : function()
\r
2573 return this.getInputElement().isVisible();
\r
2577 * Determines whether an UI element is focus-able or not.
\r
2578 * Focus-able is defined as being both visible and enabled.
\r
2579 * @returns {Boolean} Whether the UI element can be focused.
\r
2582 isFocusable : function()
\r
2584 if ( !this.isEnabled() || !this.isVisible() )
\r
2590 CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
\r
2592 * @lends CKEDITOR.ui.dialog.hbox.prototype
\r
2596 * Gets a child UI element inside this container.
\r
2597 * @param {Array|Number} indices An array or a single number to indicate the child's
\r
2598 * position in the container's descendant tree. Omit to get all the children in an array.
\r
2599 * @returns {Array|CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container
\r
2600 * if no argument given, or the specified UI element if indices is given.
\r
2602 * var checkbox = hbox.getChild( [0,1] );
\r
2603 * checkbox.setValue( true );
\r
2605 getChild : function( indices )
\r
2607 // If no arguments, return a clone of the children array.
\r
2608 if ( arguments.length < 1 )
\r
2609 return this._.children.concat();
\r
2611 // If indices isn't array, make it one.
\r
2612 if ( !indices.splice )
\r
2613 indices = [ indices ];
\r
2615 // Retrieve the child element according to tree position.
\r
2616 if ( indices.length < 2 )
\r
2617 return this._.children[ indices[0] ];
\r
2619 return ( this._.children[ indices[0] ] && this._.children[ indices[0] ].getChild ) ?
\r
2620 this._.children[ indices[0] ].getChild( indices.slice( 1, indices.length ) ) :
\r
2625 CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
\r
2631 var commonBuilder = {
\r
2632 build : function( dialog, elementDefinition, output )
\r
2634 var children = elementDefinition.children,
\r
2636 childHtmlList = [],
\r
2637 childObjList = [];
\r
2638 for ( var i = 0 ; ( i < children.length && ( child = children[i] ) ) ; i++ )
\r
2640 var childHtml = [];
\r
2641 childHtmlList.push( childHtml );
\r
2642 childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
\r
2644 return new CKEDITOR.ui.dialog[elementDefinition.type]( dialog, childObjList, childHtmlList, output, elementDefinition );
\r
2648 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
\r
2649 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
\r
2653 * Generic dialog command. It opens a specific dialog when executed.
\r
2655 * @augments CKEDITOR.commandDefinition
\r
2656 * @param {string} dialogName The name of the dialog to open when executing
\r
2659 * // Register the "link" command, which opens the "link" dialog.
\r
2660 * editor.addCommand( 'link', <b>new CKEDITOR.dialogCommand( 'link' )</b> );
\r
2662 CKEDITOR.dialogCommand = function( dialogName )
\r
2664 this.dialogName = dialogName;
\r
2667 CKEDITOR.dialogCommand.prototype =
\r
2670 exec : function( editor )
\r
2672 editor.openDialog( this.dialogName );
\r
2675 // Dialog commands just open a dialog ui, thus require no undo logic,
\r
2676 // undo support should dedicate to specific dialog implementation.
\r
2679 editorFocus : CKEDITOR.env.ie || CKEDITOR.env.webkit
\r
2684 var notEmptyRegex = /^([a]|[^a])+$/,
\r
2685 integerRegex = /^\d*$/,
\r
2686 numberRegex = /^\d*(?:\.\d+)?$/;
\r
2688 CKEDITOR.VALIDATE_OR = 1;
\r
2689 CKEDITOR.VALIDATE_AND = 2;
\r
2691 CKEDITOR.dialog.validate =
\r
2693 functions : function()
\r
2698 * It's important for validate functions to be able to accept the value
\r
2699 * as argument in addition to this.getValue(), so that it is possible to
\r
2700 * combine validate functions together to make more sophisticated
\r
2703 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
2705 var msg = undefined,
\r
2706 relation = CKEDITOR.VALIDATE_AND,
\r
2707 functions = [], i;
\r
2709 for ( i = 0 ; i < arguments.length ; i++ )
\r
2711 if ( typeof( arguments[i] ) == 'function' )
\r
2712 functions.push( arguments[i] );
\r
2717 if ( i < arguments.length && typeof( arguments[i] ) == 'string' )
\r
2719 msg = arguments[i];
\r
2723 if ( i < arguments.length && typeof( arguments[i]) == 'number' )
\r
2724 relation = arguments[i];
\r
2726 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );
\r
2727 for ( i = 0 ; i < functions.length ; i++ )
\r
2729 if ( relation == CKEDITOR.VALIDATE_AND )
\r
2730 passed = passed && functions[i]( value );
\r
2732 passed = passed || functions[i]( value );
\r
2737 if ( msg !== undefined )
\r
2739 if ( this && ( this.select || this.focus ) )
\r
2740 ( this.select || this.focus )();
\r
2748 regex : function( regex, msg )
\r
2751 * Can be greatly shortened by deriving from functions validator if code size
\r
2752 * turns out to be more important than performance.
\r
2756 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
2757 if ( !regex.test( value ) )
\r
2759 if ( msg !== undefined )
\r
2761 if ( this && ( this.select || this.focus ) )
\r
2763 if ( this.select )
\r
2774 notEmpty : function( msg )
\r
2776 return this.regex( notEmptyRegex, msg );
\r
2779 integer : function( msg )
\r
2781 return this.regex( integerRegex, msg );
\r
2784 'number' : function( msg )
\r
2786 return this.regex( numberRegex, msg );
\r
2789 equals : function( value, msg )
\r
2791 return this.functions( function( val ){ return val == value; }, msg );
\r
2794 notEqual : function( value, msg )
\r
2796 return this.functions( function( val ){ return val != value; }, msg );
\r
2800 CKEDITOR.on( 'instanceDestroyed', function( evt )
\r
2802 // Remove dialog cover on last instance destroy.
\r
2803 if ( CKEDITOR.tools.isEmpty( CKEDITOR.instances ) )
\r
2805 var currentTopDialog;
\r
2806 while ( ( currentTopDialog = CKEDITOR.dialog._.currentTop ) )
\r
2807 currentTopDialog.hide();
\r
2811 var dialogs = evt.editor._.storedDialogs;
\r
2812 for ( var name in dialogs )
\r
2813 dialogs[ name ].destroy();
\r
2820 // Extend the CKEDITOR.editor class with dialog specific functions.
\r
2821 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
\r
2822 /** @lends CKEDITOR.editor.prototype */
\r
2825 * Loads and opens a registered dialog.
\r
2826 * @param {String} dialogName The registered name of the dialog.
\r
2827 * @param {Function} callback The function to be invoked after dialog instance created.
\r
2828 * @see CKEDITOR.dialog.add
\r
2830 * CKEDITOR.instances.editor1.openDialog( 'smiley' );
\r
2831 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed. null if the dialog name is not registered.
\r
2833 openDialog : function( dialogName, callback )
\r
2835 var dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
2836 dialogSkin = this.skin.dialog;
\r
2838 // If the dialogDefinition is already loaded, open it immediately.
\r
2839 if ( typeof dialogDefinitions == 'function' && dialogSkin._isLoaded )
\r
2841 var storedDialogs = this._.storedDialogs ||
\r
2842 ( this._.storedDialogs = {} );
\r
2844 var dialog = storedDialogs[ dialogName ] ||
\r
2845 ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
\r
2847 callback && callback.call( dialog, dialog );
\r
2852 else if ( dialogDefinitions == 'failed' )
\r
2853 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
\r
2855 // Not loaded? Load the .js file first.
\r
2856 var body = CKEDITOR.document.getBody(),
\r
2857 cursor = body.$.style.cursor,
\r
2860 body.setStyle( 'cursor', 'wait' );
\r
2862 function onDialogFileLoaded( success )
\r
2864 var dialogDefinition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
2865 skin = me.skin.dialog;
\r
2867 // Check if both skin part and definition is loaded.
\r
2868 if ( !skin._isLoaded || loadDefinition && typeof success == 'undefined' )
\r
2871 // In case of plugin error, mark it as loading failed.
\r
2872 if ( typeof dialogDefinition != 'function' )
\r
2873 CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';
\r
2875 me.openDialog( dialogName, callback );
\r
2876 body.setStyle( 'cursor', cursor );
\r
2879 if ( typeof dialogDefinitions == 'string' )
\r
2881 var loadDefinition = 1;
\r
2882 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ), onDialogFileLoaded );
\r
2885 CKEDITOR.skins.load( this, 'dialog', onDialogFileLoaded );
\r
2891 CKEDITOR.plugins.add( 'dialog',
\r
2893 requires : [ 'dialogui' ]
\r
2896 // Dialog related configurations.
\r
2899 * The color of the dialog background cover. It should be a valid CSS color
\r
2901 * @name CKEDITOR.config.dialog_backgroundCoverColor
\r
2903 * @default 'white'
\r
2905 * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
\r
2909 * The opacity of the dialog background cover. It should be a number within the
\r
2910 * range [0.0, 1.0].
\r
2911 * @name CKEDITOR.config.dialog_backgroundCoverOpacity
\r
2915 * config.dialog_backgroundCoverOpacity = 0.7;
\r
2919 * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.
\r
2920 * @name CKEDITOR.config.dialog_startupFocusTab
\r
2924 * config.dialog_startupFocusTab = true;
\r
2928 * The distance of magnetic borders used in moving and resizing dialogs,
\r
2929 * measured in pixels.
\r
2930 * @name CKEDITOR.config.dialog_magnetDistance
\r
2934 * config.dialog_magnetDistance = 30;
\r
2938 * Fired when a dialog definition is about to be used to create a dialog into
\r
2939 * an editor instance. This event makes it possible to customize the definition
\r
2940 * before creating it.
\r
2941 * <p>Note that this event is called only the first time a specific dialog is
\r
2942 * opened. Successive openings will use the cached dialog, and this event will
\r
2943 * not get fired.</p>
\r
2944 * @name CKEDITOR#dialogDefinition
\r
2946 * @param {CKEDITOR.dialog.dialogDefinition} data The dialog defination that
\r
2947 * is being loaded.
\r
2948 * @param {CKEDITOR.editor} editor The editor instance that will use the
\r