2 Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview The floating dialog plugin.
\r
11 * No resize for this dialog.
\r
14 CKEDITOR.DIALOG_RESIZE_NONE = 0;
\r
17 * Only allow horizontal resizing for this dialog, disable vertical resizing.
\r
20 CKEDITOR.DIALOG_RESIZE_WIDTH = 1;
\r
23 * Only allow vertical resizing for this dialog, disable horizontal resizing.
\r
26 CKEDITOR.DIALOG_RESIZE_HEIGHT = 2;
\r
29 * Allow the dialog to be resized in both directions.
\r
32 CKEDITOR.DIALOG_RESIZE_BOTH = 3;
\r
36 var cssLength = CKEDITOR.tools.cssLength;
\r
37 function isTabVisible( tabId )
\r
39 return !!this._.tabs[ tabId ][ 0 ].$.offsetHeight;
\r
42 function getPreviousVisibleTab()
\r
44 var tabId = this._.currentTabId,
\r
45 length = this._.tabIdList.length,
\r
46 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId ) + length;
\r
48 for ( var i = tabIndex - 1 ; i > tabIndex - length ; i-- )
\r
50 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
\r
51 return this._.tabIdList[ i % length ];
\r
57 function getNextVisibleTab()
\r
59 var tabId = this._.currentTabId,
\r
60 length = this._.tabIdList.length,
\r
61 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId );
\r
63 for ( var i = tabIndex + 1 ; i < tabIndex + length ; i++ )
\r
65 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
\r
66 return this._.tabIdList[ i % length ];
\r
73 function clearOrRecoverTextInputValue( container, isRecover )
\r
75 var inputs = container.$.getElementsByTagName( 'input' );
\r
76 for ( var i = 0, length = inputs.length; i < length ; i++ )
\r
78 var item = new CKEDITOR.dom.element( inputs[ i ] );
\r
80 if ( item.getAttribute( 'type' ).toLowerCase() == 'text' )
\r
84 item.setAttribute( 'value', item.getCustomData( 'fake_value' ) || '' );
\r
85 item.removeCustomData( 'fake_value' );
\r
89 item.setCustomData( 'fake_value', item.getAttribute( 'value' ) );
\r
90 item.setAttribute( 'value', '' );
\r
96 // Handle dialog element validation state UI changes.
\r
97 function handleFieldValidated( isValid, msg )
\r
99 var input = this.getInputElement();
\r
102 isValid ? input.removeAttribute( 'aria-invalid' )
\r
103 : input.setAttribute( 'aria-invalid', true );
\r
114 msg && alert( msg );
\r
116 this.fire( 'validated', { valid : isValid, msg : msg } );
\r
119 function resetField()
\r
121 var input = this.getInputElement();
\r
122 input && input.removeAttribute( 'aria-invalid' );
\r
127 * This is the base class for runtime dialog objects. An instance of this
\r
128 * class represents a single named dialog for a single editor instance.
\r
129 * @param {Object} editor The editor which created the dialog.
\r
130 * @param {String} dialogName The dialog's registered name.
\r
133 * var dialogObj = new CKEDITOR.dialog( editor, 'smiley' );
\r
135 CKEDITOR.dialog = function( editor, dialogName )
\r
137 // Load the dialog definition.
\r
138 var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
139 defaultDefinition = CKEDITOR.tools.clone( defaultDialogDefinition ),
\r
140 buttonsOrder = editor.config.dialog_buttonsOrder || 'OS',
\r
141 dir = editor.lang.dir,
\r
144 processed, stopPropagation;
\r
146 if ( ( buttonsOrder == 'OS' && CKEDITOR.env.mac ) || // The buttons in MacOS Apps are in reverse order (#4750)
\r
147 ( buttonsOrder == 'rtl' && dir == 'ltr' ) ||
\r
148 ( buttonsOrder == 'ltr' && dir == 'rtl' ) )
\r
149 defaultDefinition.buttons.reverse();
\r
152 // Completes the definition with the default values.
\r
153 definition = CKEDITOR.tools.extend( definition( editor ), defaultDefinition );
\r
155 // Clone a functionally independent copy for this dialog.
\r
156 definition = CKEDITOR.tools.clone( definition );
\r
158 // Create a complex definition object, extending it with the API
\r
160 definition = new definitionObject( this, definition );
\r
162 var doc = CKEDITOR.document;
\r
164 var themeBuilt = editor.theme.buildDialog( editor );
\r
166 // Initialize some basic parameters.
\r
170 element : themeBuilt.element,
\r
172 contentSize : { width : 0, height : 0 },
\r
173 size : { width : 0, height : 0 },
\r
178 // Initialize the tab and page map.
\r
181 currentTabId : null,
\r
182 currentTabIndex : null,
\r
185 tabBarMode : false,
\r
187 // Initialize the tab order array for input widgets.
\r
189 currentFocusIndex : 0,
\r
193 this.parts = themeBuilt.parts;
\r
195 CKEDITOR.tools.setTimeout( function()
\r
197 editor.fire( 'ariaWidget', this.parts.contents );
\r
201 // Set the startup styles for the dialog, avoiding it enlarging the
\r
202 // page size on the dialog creation.
\r
203 var startStyles = {
\r
204 position : CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed',
\r
206 visibility : 'hidden'
\r
209 startStyles[ dir == 'rtl' ? 'right' : 'left' ] = 0;
\r
210 this.parts.dialog.setStyles( startStyles );
\r
213 // Call the CKEDITOR.event constructor to initialize this instance.
\r
214 CKEDITOR.event.call( this );
\r
216 // Fire the "dialogDefinition" event, making it possible to customize
\r
217 // the dialog definition.
\r
218 this.definition = definition = CKEDITOR.fire( 'dialogDefinition',
\r
221 definition : definition
\r
223 , editor ).definition;
\r
225 // Cache tabs that should be removed.
\r
226 if ( !( 'removeDialogTabs' in editor._ ) && editor.config.removeDialogTabs )
\r
228 var removeContents = editor.config.removeDialogTabs.split( ';' );
\r
230 for ( i = 0; i < removeContents.length; i++ )
\r
232 var parts = removeContents[ i ].split( ':' );
\r
233 if ( parts.length == 2 )
\r
235 var removeDialogName = parts[ 0 ];
\r
236 if ( !tabsToRemove[ removeDialogName ] )
\r
237 tabsToRemove[ removeDialogName ] = [];
\r
238 tabsToRemove[ removeDialogName ].push( parts[ 1 ] );
\r
241 editor._.removeDialogTabs = tabsToRemove;
\r
244 // Remove tabs of this dialog.
\r
245 if ( editor._.removeDialogTabs && ( tabsToRemove = editor._.removeDialogTabs[ dialogName ] ) )
\r
247 for ( i = 0; i < tabsToRemove.length; i++ )
\r
248 definition.removeContents( tabsToRemove[ i ] );
\r
251 // Initialize load, show, hide, ok and cancel events.
\r
252 if ( definition.onLoad )
\r
253 this.on( 'load', definition.onLoad );
\r
255 if ( definition.onShow )
\r
256 this.on( 'show', definition.onShow );
\r
258 if ( definition.onHide )
\r
259 this.on( 'hide', definition.onHide );
\r
261 if ( definition.onOk )
\r
263 this.on( 'ok', function( evt )
\r
265 // Dialog confirm might probably introduce content changes (#5415).
\r
266 editor.fire( 'saveSnapshot' );
\r
267 setTimeout( function () { editor.fire( 'saveSnapshot' ); }, 0 );
\r
268 if ( definition.onOk.call( this, evt ) === false )
\r
269 evt.data.hide = false;
\r
273 if ( definition.onCancel )
\r
275 this.on( 'cancel', function( evt )
\r
277 if ( definition.onCancel.call( this, evt ) === false )
\r
278 evt.data.hide = false;
\r
284 // Iterates over all items inside all content in the dialog, calling a
\r
285 // function for each of them.
\r
286 var iterContents = function( func )
\r
288 var contents = me._.contents,
\r
291 for ( var i in contents )
\r
293 for ( var j in contents[i] )
\r
295 stop = func.call( this, contents[i][j] );
\r
302 this.on( 'ok', function( evt )
\r
304 iterContents( function( item )
\r
306 if ( item.validate )
\r
308 var retval = item.validate( this ),
\r
309 invalid = typeof ( retval ) == 'string' || retval === false;
\r
313 evt.data.hide = false;
\r
317 handleFieldValidated.call( item, !invalid, typeof retval == 'string' ? retval : undefined );
\r
321 }, this, null, 0 );
\r
323 this.on( 'cancel', function( evt )
\r
325 iterContents( function( item )
\r
327 if ( item.isChanged() )
\r
329 if ( !confirm( editor.lang.common.confirmCancel ) )
\r
330 evt.data.hide = false;
\r
334 }, this, null, 0 );
\r
336 this.parts.close.on( 'click', function( evt )
\r
338 if ( this.fire( 'cancel', { hide : true } ).hide !== false )
\r
340 evt.data.preventDefault();
\r
343 // Sort focus list according to tab order definitions.
\r
344 function setupFocus()
\r
346 var focusList = me._.focusList;
\r
347 focusList.sort( function( a, b )
\r
349 // Mimics browser tab order logics;
\r
350 if ( a.tabIndex != b.tabIndex )
\r
351 return b.tabIndex - a.tabIndex;
\r
352 // Sort is not stable in some browsers,
\r
353 // fall-back the comparator to 'focusIndex';
\r
355 return a.focusIndex - b.focusIndex;
\r
358 var size = focusList.length;
\r
359 for ( var i = 0; i < size; i++ )
\r
360 focusList[ i ].focusIndex = i;
\r
363 function changeFocus( offset )
\r
365 var focusList = me._.focusList;
\r
366 offset = offset || 0;
\r
368 if ( focusList.length < 1 )
\r
371 var current = me._.currentFocusIndex;
\r
373 // Trigger the 'blur' event of any input element before anything,
\r
374 // since certain UI updates may depend on it.
\r
377 focusList[ current ].getInputElement().$.blur();
\r
381 var startIndex = ( current + offset + focusList.length ) % focusList.length,
\r
382 currentIndex = startIndex;
\r
383 while ( offset && !focusList[ currentIndex ].isFocusable() )
\r
385 currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length;
\r
386 if ( currentIndex == startIndex )
\r
390 focusList[ currentIndex ].focus();
\r
392 // Select whole field content.
\r
393 if ( focusList[ currentIndex ].type == 'text' )
\r
394 focusList[ currentIndex ].select();
\r
397 this.changeFocus = changeFocus;
\r
400 function keydownHandler( evt )
\r
402 // If I'm not the top dialog, ignore.
\r
403 if ( me != CKEDITOR.dialog._.currentTop )
\r
406 var keystroke = evt.data.getKeystroke(),
\r
407 rtl = editor.lang.dir == 'rtl',
\r
410 processed = stopPropagation = 0;
\r
412 if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )
\r
414 var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
\r
416 // Handling Tab and Shift-Tab.
\r
417 if ( me._.tabBarMode )
\r
420 var nextId = shiftPressed ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );
\r
421 me.selectPage( nextId );
\r
422 me._.tabs[ nextId ][ 0 ].focus();
\r
426 // Change the focus of inputs.
\r
427 changeFocus( shiftPressed ? -1 : 1 );
\r
432 else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode && me.getPageCount() > 1 )
\r
434 // Alt-F10 puts focus into the current tab item in the tab bar.
\r
435 me._.tabBarMode = true;
\r
436 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
439 else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode )
\r
441 // Arrow keys - used for changing tabs.
\r
442 nextId = ( keystroke == ( rtl ? 39 : 37 ) ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) );
\r
443 me.selectPage( nextId );
\r
444 me._.tabs[ nextId ][ 0 ].focus();
\r
447 else if ( ( keystroke == 13 || keystroke == 32 ) && me._.tabBarMode )
\r
449 this.selectPage( this._.currentTabId );
\r
450 this._.tabBarMode = false;
\r
451 this._.currentFocusIndex = -1;
\r
455 // If user presses enter key in a text box, it implies clicking OK for the dialog.
\r
456 else if ( keystroke == 13 /*ENTER*/ )
\r
458 // Don't do that for a target that handles ENTER.
\r
459 var target = evt.data.getTarget();
\r
460 if ( !target.is( 'a', 'button', 'select' ) && ( !target.is( 'input' ) || target.$.type != 'button' ) )
\r
462 button = this.getButton( 'ok' );
\r
463 button && CKEDITOR.tools.setTimeout( button.click, 0, button );
\r
466 stopPropagation = 1; // Always block the propagation (#4269)
\r
468 else if ( keystroke == 27 /*ESC*/ )
\r
470 button = this.getButton( 'cancel' );
\r
472 // If there's a Cancel button, click it, else just fire the cancel event and hide the dialog.
\r
474 CKEDITOR.tools.setTimeout( button.click, 0, button );
\r
477 if ( this.fire( 'cancel', { hide : true } ).hide !== false )
\r
480 stopPropagation = 1; // Always block the propagation (#4269)
\r
485 keypressHandler( evt );
\r
488 function keypressHandler( evt )
\r
491 evt.data.preventDefault(1);
\r
492 else if ( stopPropagation )
\r
493 evt.data.stopPropagation();
\r
496 var dialogElement = this._.element;
\r
497 // Add the dialog keyboard handlers.
\r
498 this.on( 'show', function()
\r
500 dialogElement.on( 'keydown', keydownHandler, this );
\r
502 // Some browsers instead, don't cancel key events in the keydown, but in the
\r
503 // keypress. So we must do a longer trip in those cases. (#4531,#8985)
\r
504 if ( CKEDITOR.env.opera || CKEDITOR.env.gecko )
\r
505 dialogElement.on( 'keypress', keypressHandler, this );
\r
508 this.on( 'hide', function()
\r
510 dialogElement.removeListener( 'keydown', keydownHandler );
\r
511 if ( CKEDITOR.env.opera || CKEDITOR.env.gecko )
\r
512 dialogElement.removeListener( 'keypress', keypressHandler );
\r
514 // Reset fields state when closing dialog.
\r
515 iterContents( function( item ) { resetField.apply( item ); } );
\r
517 this.on( 'iframeAdded', function( evt )
\r
519 var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );
\r
520 doc.on( 'keydown', keydownHandler, this, null, 0 );
\r
523 // Auto-focus logic in dialog.
\r
524 this.on( 'show', function()
\r
526 // Setup tabIndex on showing the dialog instead of on loading
\r
527 // to allow dynamic tab order happen in dialog definition.
\r
530 if ( editor.config.dialog_startupFocusTab
\r
531 && me._.pageCount > 1 )
\r
533 me._.tabBarMode = true;
\r
534 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
536 else if ( !this._.hasFocus )
\r
538 this._.currentFocusIndex = -1;
\r
540 // Decide where to put the initial focus.
\r
541 if ( definition.onFocus )
\r
543 var initialFocus = definition.onFocus.call( this );
\r
544 // Focus the field that the user specified.
\r
545 initialFocus && initialFocus.focus();
\r
547 // Focus the first field in layout order.
\r
552 * IE BUG: If the initial focus went into a non-text element (e.g. button),
\r
553 * then IE would still leave the caret inside the editing area.
\r
555 if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
557 var $selection = editor.document.$.selection,
\r
558 $range = $selection.createRange();
\r
562 if ( $range.parentElement && $range.parentElement().ownerDocument == editor.document.$
\r
563 || $range.item && $range.item( 0 ).ownerDocument == editor.document.$ )
\r
565 var $myRange = document.body.createTextRange();
\r
566 $myRange.moveToElementText( this.getElement().getFirst().$ );
\r
567 $myRange.collapse( true );
\r
573 }, this, null, 0xffffffff );
\r
575 // IE6 BUG: Text fields and text areas are only half-rendered the first time the dialog appears in IE6 (#2661).
\r
576 // This is still needed after [2708] and [2709] because text fields in hidden TR tags are still broken.
\r
577 if ( CKEDITOR.env.ie6Compat )
\r
579 this.on( 'load', function( evt )
\r
581 var outer = this.getElement(),
\r
582 inner = outer.getFirst();
\r
584 inner.appendTo( outer );
\r
588 initDragAndDrop( this );
\r
589 initResizeHandles( this );
\r
591 // Insert the title.
\r
592 ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );
\r
594 // Insert the tabs and contents.
\r
595 for ( i = 0 ; i < definition.contents.length ; i++ )
\r
597 var page = definition.contents[i];
\r
598 page && this.addPage( page );
\r
601 this.parts[ 'tabs' ].on( 'click', function( evt )
\r
603 var target = evt.data.getTarget();
\r
604 // If we aren't inside a tab, bail out.
\r
605 if ( target.hasClass( 'cke_dialog_tab' ) )
\r
607 // Get the ID of the tab, without the 'cke_' prefix and the unique number suffix.
\r
608 var id = target.$.id;
\r
609 this.selectPage( id.substring( 4, id.lastIndexOf( '_' ) ) );
\r
611 if ( this._.tabBarMode )
\r
613 this._.tabBarMode = false;
\r
614 this._.currentFocusIndex = -1;
\r
617 evt.data.preventDefault();
\r
622 var buttonsHtml = [],
\r
623 buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this,
\r
626 className : 'cke_dialog_footer_buttons',
\r
628 children : definition.buttons
\r
629 }, buttonsHtml ).getChild();
\r
630 this.parts.footer.setHtml( buttonsHtml.join( '' ) );
\r
632 for ( i = 0 ; i < buttons.length ; i++ )
\r
633 this._.buttons[ buttons[i].id ] = buttons[i];
\r
636 // Focusable interface. Use it via dialog.addFocusable.
\r
637 function Focusable( dialog, element, index )
\r
639 this.element = element;
\r
640 this.focusIndex = index;
\r
641 // TODO: support tabIndex for focusables.
\r
643 this.isFocusable = function()
\r
645 return !element.getAttribute( 'disabled' ) && element.isVisible();
\r
647 this.focus = function()
\r
649 dialog._.currentFocusIndex = this.focusIndex;
\r
650 this.element.focus();
\r
653 element.on( 'keydown', function( e )
\r
655 if ( e.data.getKeystroke() in { 32:1, 13:1 } )
\r
656 this.fire( 'click' );
\r
658 element.on( 'focus', function()
\r
660 this.fire( 'mouseover' );
\r
662 element.on( 'blur', function()
\r
664 this.fire( 'mouseout' );
\r
668 CKEDITOR.dialog.prototype =
\r
670 destroy : function()
\r
673 this._.element.remove();
\r
677 * Resizes the dialog.
\r
678 * @param {Number} width The width of the dialog in pixels.
\r
679 * @param {Number} height The height of the dialog in pixels.
\r
682 * dialogObj.resize( 800, 640 );
\r
684 resize : (function()
\r
686 return function( width, height )
\r
688 if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )
\r
691 CKEDITOR.dialog.fire( 'resize',
\r
694 skin : this._.editor.skinName,
\r
697 }, this._.editor );
\r
699 this.fire( 'resize',
\r
701 skin : this._.editor.skinName,
\r
704 }, this._.editor );
\r
706 // Update dialog position when dimension get changed in RTL.
\r
707 if ( this._.editor.lang.dir == 'rtl' && this._.position )
\r
708 this._.position.x = CKEDITOR.document.getWindow().getViewPaneSize().width -
\r
709 this._.contentSize.width - parseInt( this._.element.getFirst().getStyle( 'right' ), 10 );
\r
711 this._.contentSize = { width : width, height : height };
\r
716 * Gets the current size of the dialog in pixels.
\r
717 * @returns {Object} An object with "width" and "height" properties.
\r
719 * var width = dialogObj.getSize().width;
\r
721 getSize : function()
\r
723 var element = this._.element.getFirst();
\r
724 return { width : element.$.offsetWidth || 0, height : element.$.offsetHeight || 0};
\r
728 * Moves the dialog to an (x, y) coordinate relative to the window.
\r
730 * @param {Number} x The target x-coordinate.
\r
731 * @param {Number} y The target y-coordinate.
\r
732 * @param {Boolean} save Flag indicate whether the dialog position should be remembered on next open up.
\r
734 * dialogObj.move( 10, 40 );
\r
739 return function( x, y, save )
\r
741 // The dialog may be fixed positioned or absolute positioned. Ask the
\r
742 // browser what is the current situation first.
\r
743 var element = this._.element.getFirst(),
\r
744 rtl = this._.editor.lang.dir == 'rtl';
\r
746 if ( isFixed === undefined )
\r
747 isFixed = element.getComputedStyle( 'position' ) == 'fixed';
\r
749 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
\r
752 // Save the current position.
\r
753 this._.position = { x : x, y : y };
\r
755 // If not fixed positioned, add scroll position to the coordinates.
\r
758 var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
\r
759 x += scrollPosition.x;
\r
760 y += scrollPosition.y;
\r
763 // Translate coordinate for RTL.
\r
766 var dialogSize = this.getSize(),
\r
767 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize();
\r
768 x = viewPaneSize.width - dialogSize.width - x;
\r
771 var styles = { 'top' : ( y > 0 ? y : 0 ) + 'px' };
\r
772 styles[ rtl ? 'right' : 'left' ] = ( x > 0 ? x : 0 ) + 'px';
\r
774 element.setStyles( styles );
\r
776 save && ( this._.moved = 1 );
\r
781 * Gets the dialog's position in the window.
\r
782 * @returns {Object} An object with "x" and "y" properties.
\r
784 * var dialogX = dialogObj.getPosition().x;
\r
786 getPosition : function(){ return CKEDITOR.tools.extend( {}, this._.position ); },
\r
789 * Shows the dialog box.
\r
791 * dialogObj.show();
\r
795 // Insert the dialog's element to the root document.
\r
796 var element = this._.element;
\r
797 var definition = this.definition;
\r
798 if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )
\r
799 element.appendTo( CKEDITOR.document.getBody() );
\r
801 element.setStyle( 'display', 'block' );
\r
803 // FIREFOX BUG: Fix vanishing caret for Firefox 2 or Gecko 1.8.
\r
804 if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
\r
806 var dialogElement = this.parts.dialog;
\r
807 dialogElement.setStyle( 'position', 'absolute' );
\r
808 setTimeout( function()
\r
810 dialogElement.setStyle( 'position', 'fixed' );
\r
815 // First, set the dialog to an appropriate size.
\r
816 this.resize( this._.contentSize && this._.contentSize.width || definition.width || definition.minWidth,
\r
817 this._.contentSize && this._.contentSize.height || definition.height || definition.minHeight );
\r
819 // Reset all inputs back to their default value.
\r
822 // Select the first tab by default.
\r
823 this.selectPage( this.definition.contents[0].id );
\r
826 if ( CKEDITOR.dialog._.currentZIndex === null )
\r
827 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;
\r
828 this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
\r
830 // Maintain the dialog ordering and dialog cover.
\r
831 if ( CKEDITOR.dialog._.currentTop === null )
\r
833 CKEDITOR.dialog._.currentTop = this;
\r
834 this._.parentDialog = null;
\r
835 showCover( this._.editor );
\r
840 this._.parentDialog = CKEDITOR.dialog._.currentTop;
\r
841 var parentElement = this._.parentDialog.getElement().getFirst();
\r
842 parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );
\r
843 CKEDITOR.dialog._.currentTop = this;
\r
846 element.on( 'keydown', accessKeyDownHandler );
\r
847 element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
849 // Reset the hasFocus state.
\r
850 this._.hasFocus = false;
\r
852 CKEDITOR.tools.setTimeout( function()
\r
855 this.parts.dialog.setStyle( 'visibility', '' );
\r
857 // Execute onLoad for the first show.
\r
858 this.fireOnce( 'load', {} );
\r
859 CKEDITOR.ui.fire( 'ready', this );
\r
861 this.fire( 'show', {} );
\r
862 this._.editor.fire( 'dialogShow', this );
\r
864 // Save the initial values of the dialog.
\r
865 this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } );
\r
872 * Rearrange the dialog to its previous position or the middle of the window.
\r
875 layout : function()
\r
877 var viewSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
878 dialogSize = this.getSize();
\r
880 this.move( this._.moved ? this._.position.x : ( viewSize.width - dialogSize.width ) / 2,
\r
881 this._.moved ? this._.position.y : ( viewSize.height - dialogSize.height ) / 2 );
\r
885 * Executes a function for each UI element.
\r
886 * @param {Function} fn Function to execute for each UI element.
\r
887 * @returns {CKEDITOR.dialog} The current dialog object.
\r
889 foreach : function( fn )
\r
891 for ( var i in this._.contents )
\r
893 for ( var j in this._.contents[i] )
\r
894 fn.call( this, this._.contents[i][j] );
\r
900 * Resets all input values in the dialog.
\r
902 * dialogObj.reset();
\r
903 * @returns {CKEDITOR.dialog} The current dialog object.
\r
905 reset : (function()
\r
907 var fn = function( widget ){ if ( widget.reset ) widget.reset( 1 ); };
\r
908 return function(){ this.foreach( fn ); return this; };
\r
913 * Calls the {@link CKEDITOR.dialog.definition.uiElement#setup} method of each of the UI elements, with the arguments passed through it.
\r
914 * It is usually being called when the dialog is opened, to put the initial value inside the field.
\r
916 * dialogObj.setupContent();
\r
918 * var timestamp = ( new Date() ).valueOf();
\r
919 * dialogObj.setupContent( timestamp );
\r
921 setupContent : function()
\r
923 var args = arguments;
\r
924 this.foreach( function( widget )
\r
926 if ( widget.setup )
\r
927 widget.setup.apply( widget, args );
\r
932 * Calls the {@link CKEDITOR.dialog.definition.uiElement#commit} method of each of the UI elements, with the arguments passed through it.
\r
933 * It is usually being called when the user confirms the dialog, to process the values.
\r
935 * dialogObj.commitContent();
\r
937 * var timestamp = ( new Date() ).valueOf();
\r
938 * dialogObj.commitContent( timestamp );
\r
940 commitContent : function()
\r
942 var args = arguments;
\r
943 this.foreach( function( widget )
\r
945 // Make sure IE triggers "change" event on last focused input before closing the dialog. (#7915)
\r
946 if ( CKEDITOR.env.ie && this._.currentFocusIndex == widget.focusIndex )
\r
947 widget.getInputElement().$.blur();
\r
949 if ( widget.commit )
\r
950 widget.commit.apply( widget, args );
\r
955 * Hides the dialog box.
\r
957 * dialogObj.hide();
\r
961 if ( !this.parts.dialog.isVisible() )
\r
964 this.fire( 'hide', {} );
\r
965 this._.editor.fire( 'dialogHide', this );
\r
966 // Reset the tab page.
\r
967 this.selectPage( this._.tabIdList[ 0 ] );
\r
968 var element = this._.element;
\r
969 element.setStyle( 'display', 'none' );
\r
970 this.parts.dialog.setStyle( 'visibility', 'hidden' );
\r
971 // Unregister all access keys associated with this dialog.
\r
972 unregisterAccessKey( this );
\r
974 // Close any child(top) dialogs first.
\r
975 while( CKEDITOR.dialog._.currentTop != this )
\r
976 CKEDITOR.dialog._.currentTop.hide();
\r
978 // Maintain dialog ordering and remove cover if needed.
\r
979 if ( !this._.parentDialog )
\r
983 var parentElement = this._.parentDialog.getElement().getFirst();
\r
984 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
\r
986 CKEDITOR.dialog._.currentTop = this._.parentDialog;
\r
988 // Deduct or clear the z-index.
\r
989 if ( !this._.parentDialog )
\r
991 CKEDITOR.dialog._.currentZIndex = null;
\r
993 // Remove access key handlers.
\r
994 element.removeListener( 'keydown', accessKeyDownHandler );
\r
995 element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
997 var editor = this._.editor;
\r
1000 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
1002 var selection = editor.getSelection();
\r
1003 selection && selection.unlock( true );
\r
1007 CKEDITOR.dialog._.currentZIndex -= 10;
\r
1009 delete this._.parentDialog;
\r
1010 // Reset the initial values of the dialog.
\r
1011 this.foreach( function( contentObj ) { contentObj.resetInitValue && contentObj.resetInitValue(); } );
\r
1015 * Adds a tabbed page into the dialog.
\r
1016 * @param {Object} contents Content definition.
\r
1019 addPage : function( contents )
\r
1021 var pageHtml = [],
\r
1022 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
\r
1023 elements = contents.elements,
\r
1024 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this,
\r
1027 className : 'cke_dialog_page_contents',
\r
1028 children : contents.elements,
\r
1029 expand : !!contents.expand,
\r
1030 padding : contents.padding,
\r
1031 style : contents.style || 'width: 100%;height:100%'
\r
1034 // Create the HTML for the tab and the content block.
\r
1035 var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
\r
1036 page.setAttribute( 'role', 'tabpanel' );
\r
1038 var env = CKEDITOR.env;
\r
1039 var tabId = 'cke_' + contents.id + '_' + CKEDITOR.tools.getNextNumber(),
\r
1040 tab = CKEDITOR.dom.element.createFromHtml( [
\r
1041 '<a class="cke_dialog_tab"',
\r
1042 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),
\r
1044 ( !!contents.hidden ? ' style="display:none"' : '' ),
\r
1045 ' id="', tabId, '"',
\r
1046 env.gecko && env.version >= 10900 && !env.hc ? '' : ' href="javascript:void(0)"',
\r
1048 ' hidefocus="true"',
\r
1054 page.setAttribute( 'aria-labelledby', tabId );
\r
1056 // Take records for the tabs and elements created.
\r
1057 this._.tabs[ contents.id ] = [ tab, page ];
\r
1058 this._.tabIdList.push( contents.id );
\r
1059 !contents.hidden && this._.pageCount++;
\r
1060 this._.lastTab = tab;
\r
1061 this.updateStyle();
\r
1063 var contentMap = this._.contents[ contents.id ] = {},
\r
1065 children = vbox.getChild();
\r
1067 while ( ( cursor = children.shift() ) )
\r
1069 contentMap[ cursor.id ] = cursor;
\r
1070 if ( typeof( cursor.getChild ) == 'function' )
\r
1071 children.push.apply( children, cursor.getChild() );
\r
1074 // Attach the DOM nodes.
\r
1076 page.setAttribute( 'name', contents.id );
\r
1077 page.appendTo( this.parts.contents );
\r
1079 tab.unselectable();
\r
1080 this.parts.tabs.append( tab );
\r
1082 // Add access key handlers if access key is defined.
\r
1083 if ( contents.accessKey )
\r
1085 registerAccessKey( this, this, 'CTRL+' + contents.accessKey,
\r
1086 tabAccessKeyDown, tabAccessKeyUp );
\r
1087 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;
\r
1092 * Activates a tab page in the dialog by its id.
\r
1093 * @param {String} id The id of the dialog tab to be activated.
\r
1095 * dialogObj.selectPage( 'tab_1' );
\r
1097 selectPage : function( id )
\r
1099 if ( this._.currentTabId == id )
\r
1102 // Returning true means that the event has been canceled
\r
1103 if ( this.fire( 'selectPage', { page : id, currentPage : this._.currentTabId } ) === true )
\r
1106 // Hide the non-selected tabs and pages.
\r
1107 for ( var i in this._.tabs )
\r
1109 var tab = this._.tabs[i][0],
\r
1110 page = this._.tabs[i][1];
\r
1113 tab.removeClass( 'cke_dialog_tab_selected' );
\r
1116 page.setAttribute( 'aria-hidden', i != id );
\r
1119 var selected = this._.tabs[ id ];
\r
1120 selected[ 0 ].addClass( 'cke_dialog_tab_selected' );
\r
1122 // [IE] an invisible input[type='text'] will enlarge it's width
\r
1123 // if it's value is long when it shows, so we clear it's value
\r
1124 // before it shows and then recover it (#5649)
\r
1125 if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat )
\r
1127 clearOrRecoverTextInputValue( selected[ 1 ] );
\r
1128 selected[ 1 ].show();
\r
1129 setTimeout( function()
\r
1131 clearOrRecoverTextInputValue( selected[ 1 ], 1 );
\r
1135 selected[ 1 ].show();
\r
1137 this._.currentTabId = id;
\r
1138 this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
\r
1141 // Dialog state-specific style updates.
\r
1142 updateStyle : function()
\r
1144 // If only a single page shown, a different style is used in the central pane.
\r
1145 this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );
\r
1149 * Hides a page's tab away from the dialog.
\r
1150 * @param {String} id The page's Id.
\r
1152 * dialog.hidePage( 'tab_3' );
\r
1154 hidePage : function( id )
\r
1156 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
1157 if ( !tab || this._.pageCount == 1 || !tab.isVisible() )
\r
1159 // Switch to other tab first when we're hiding the active tab.
\r
1160 else if ( id == this._.currentTabId )
\r
1161 this.selectPage( getPreviousVisibleTab.call( this ) );
\r
1164 this._.pageCount--;
\r
1165 this.updateStyle();
\r
1169 * Unhides a page's tab.
\r
1170 * @param {String} id The page's Id.
\r
1172 * dialog.showPage( 'tab_2' );
\r
1174 showPage : function( id )
\r
1176 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
1180 this._.pageCount++;
\r
1181 this.updateStyle();
\r
1185 * Gets the root DOM element of the dialog.
\r
1186 * @returns {CKEDITOR.dom.element} The <span> element containing this dialog.
\r
1188 * var dialogElement = dialogObj.getElement().getFirst();
\r
1189 * dialogElement.setStyle( 'padding', '5px' );
\r
1191 getElement : function()
\r
1193 return this._.element;
\r
1197 * Gets the name of the dialog.
\r
1198 * @returns {String} The name of this dialog.
\r
1200 * var dialogName = dialogObj.getName();
\r
1202 getName : function()
\r
1204 return this._.name;
\r
1208 * Gets a dialog UI element object from a dialog page.
\r
1209 * @param {String} pageId id of dialog page.
\r
1210 * @param {String} elementId id of UI element.
\r
1212 * dialogObj.getContentElement( 'tabId', 'elementId' ).setValue( 'Example' );
\r
1213 * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.
\r
1215 getContentElement : function( pageId, elementId )
\r
1217 var page = this._.contents[ pageId ];
\r
1218 return page && page[ elementId ];
\r
1222 * Gets the value of a dialog UI element.
\r
1223 * @param {String} pageId id of dialog page.
\r
1224 * @param {String} elementId id of UI element.
\r
1226 * alert( dialogObj.getValueOf( 'tabId', 'elementId' ) );
\r
1227 * @returns {Object} The value of the UI element.
\r
1229 getValueOf : function( pageId, elementId )
\r
1231 return this.getContentElement( pageId, elementId ).getValue();
\r
1235 * Sets the value of a dialog UI element.
\r
1236 * @param {String} pageId id of the dialog page.
\r
1237 * @param {String} elementId id of the UI element.
\r
1238 * @param {Object} value The new value of the UI element.
\r
1240 * dialogObj.setValueOf( 'tabId', 'elementId', 'Example' );
\r
1242 setValueOf : function( pageId, elementId, value )
\r
1244 return this.getContentElement( pageId, elementId ).setValue( value );
\r
1248 * Gets the UI element of a button in the dialog's button row.
\r
1249 * @param {String} id The id of the button.
\r
1251 * @returns {CKEDITOR.ui.dialog.button} The button object.
\r
1253 getButton : function( id )
\r
1255 return this._.buttons[ id ];
\r
1259 * Simulates a click to a dialog button in the dialog's button row.
\r
1260 * @param {String} id The id of the button.
\r
1262 * @returns The return value of the dialog's "click" event.
\r
1264 click : function( id )
\r
1266 return this._.buttons[ id ].click();
\r
1270 * Disables a dialog button.
\r
1271 * @param {String} id The id of the button.
\r
1274 disableButton : function( id )
\r
1276 return this._.buttons[ id ].disable();
\r
1280 * Enables a dialog button.
\r
1281 * @param {String} id The id of the button.
\r
1284 enableButton : function( id )
\r
1286 return this._.buttons[ id ].enable();
\r
1290 * Gets the number of pages in the dialog.
\r
1291 * @returns {Number} Page count.
\r
1293 getPageCount : function()
\r
1295 return this._.pageCount;
\r
1299 * Gets the editor instance which opened this dialog.
\r
1300 * @returns {CKEDITOR.editor} Parent editor instances.
\r
1302 getParentEditor : function()
\r
1304 return this._.editor;
\r
1308 * Gets the element that was selected when opening the dialog, if any.
\r
1309 * @returns {CKEDITOR.dom.element} The element that was selected, or null.
\r
1311 getSelectedElement : function()
\r
1313 return this.getParentEditor().getSelection().getSelectedElement();
\r
1317 * Adds element to dialog's focusable list.
\r
1319 * @param {CKEDITOR.dom.element} element
\r
1320 * @param {Number} [index]
\r
1322 addFocusable: function( element, index ) {
\r
1323 if ( typeof index == 'undefined' )
\r
1325 index = this._.focusList.length;
\r
1326 this._.focusList.push( new Focusable( this, element, index ) );
\r
1330 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );
\r
1331 for ( var i = index + 1 ; i < this._.focusList.length ; i++ )
\r
1332 this._.focusList[ i ].focusIndex++;
\r
1337 CKEDITOR.tools.extend( CKEDITOR.dialog,
\r
1339 * @lends CKEDITOR.dialog
\r
1343 * Registers a dialog.
\r
1344 * @param {String} name The dialog's name.
\r
1345 * @param {Function|String} dialogDefinition
\r
1346 * A function returning the dialog's definition, or the URL to the .js file holding the function.
\r
1347 * The function should accept an argument "editor" which is the current editor instance, and
\r
1348 * return an object conforming to {@link CKEDITOR.dialog.definition}.
\r
1349 * @see CKEDITOR.dialog.definition
\r
1351 * // Full sample plugin, which does not only register a dialog window but also adds an item to the context menu.
\r
1352 * // To open the dialog window, choose "Open dialog" in the context menu.
\r
1353 * CKEDITOR.plugins.add( 'myplugin',
\r
1355 * init: function( editor )
\r
1357 * editor.addCommand( 'mydialog',new CKEDITOR.dialogCommand( 'mydialog' ) );
\r
1359 * if ( editor.contextMenu )
\r
1361 * editor.addMenuGroup( 'mygroup', 10 );
\r
1362 * editor.addMenuItem( 'My Dialog',
\r
1364 * label : 'Open dialog',
\r
1365 * command : 'mydialog',
\r
1366 * group : 'mygroup'
\r
1368 * editor.contextMenu.addListener( function( element )
\r
1370 * return { 'My Dialog' : CKEDITOR.TRISTATE_OFF };
\r
1374 * <strong>CKEDITOR.dialog.add</strong>( 'mydialog', function( api )
\r
1376 * // CKEDITOR.dialog.definition
\r
1377 * var <strong>dialogDefinition</strong> =
\r
1379 * title : 'Sample dialog',
\r
1381 * minHeight : 130,
\r
1385 * label : 'Label',
\r
1386 * title : 'Title',
\r
1393 * html : '<p>This is some sample HTML content.</p>'
\r
1396 * type : 'textarea',
\r
1397 * id : 'textareaId',
\r
1404 * buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ],
\r
1405 * onOk : function() {
\r
1406 * // "this" is now a CKEDITOR.dialog object.
\r
1407 * // Accessing dialog elements:
\r
1408 * var textareaObj = this.<strong>getContentElement</strong>( 'tab1', 'textareaId' );
\r
1409 * alert( "You have entered: " + textareaObj.getValue() );
\r
1413 * return dialogDefinition;
\r
1418 * CKEDITOR.replace( 'editor1', { extraPlugins : 'myplugin' } );
\r
1420 add : function( name, dialogDefinition )
\r
1422 // Avoid path registration from multiple instances override definition.
\r
1423 if ( !this._.dialogDefinitions[name]
\r
1424 || typeof dialogDefinition == 'function' )
\r
1425 this._.dialogDefinitions[name] = dialogDefinition;
\r
1428 exists : function( name )
\r
1430 return !!this._.dialogDefinitions[ name ];
\r
1433 getCurrent : function()
\r
1435 return CKEDITOR.dialog._.currentTop;
\r
1439 * The default OK button for dialogs. Fires the "ok" event and closes the dialog if the event succeeds.
\r
1445 okButton : (function()
\r
1447 var retval = function( editor, override )
\r
1449 override = override || {};
\r
1450 return CKEDITOR.tools.extend( {
\r
1453 label : editor.lang.common.ok,
\r
1454 'class' : 'cke_dialog_ui_button_ok',
\r
1455 onClick : function( evt )
\r
1457 var dialog = evt.data.dialog;
\r
1458 if ( dialog.fire( 'ok', { hide : true } ).hide !== false )
\r
1461 }, override, true );
\r
1463 retval.type = 'button';
\r
1464 retval.override = function( override )
\r
1466 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1467 { type : 'button' }, true );
\r
1473 * The default cancel button for dialogs. Fires the "cancel" event and closes the dialog if no UI element value changed.
\r
1479 cancelButton : (function()
\r
1481 var retval = function( editor, override )
\r
1483 override = override || {};
\r
1484 return CKEDITOR.tools.extend( {
\r
1487 label : editor.lang.common.cancel,
\r
1488 'class' : 'cke_dialog_ui_button_cancel',
\r
1489 onClick : function( evt )
\r
1491 var dialog = evt.data.dialog;
\r
1492 if ( dialog.fire( 'cancel', { hide : true } ).hide !== false )
\r
1495 }, override, true );
\r
1497 retval.type = 'button';
\r
1498 retval.override = function( override )
\r
1500 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1501 { type : 'button' }, true );
\r
1507 * Registers a dialog UI element.
\r
1508 * @param {String} typeName The name of the UI element.
\r
1509 * @param {Function} builder The function to build the UI element.
\r
1512 addUIElement : function( typeName, builder )
\r
1514 this._.uiElementBuilders[ typeName ] = builder;
\r
1518 CKEDITOR.dialog._ =
\r
1520 uiElementBuilders : {},
\r
1522 dialogDefinitions : {},
\r
1524 currentTop : null,
\r
1526 currentZIndex : null
\r
1529 // "Inherit" (copy actually) from CKEDITOR.event.
\r
1530 CKEDITOR.event.implementOn( CKEDITOR.dialog );
\r
1531 CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype, true );
\r
1533 var defaultDialogDefinition =
\r
1535 resizable : CKEDITOR.DIALOG_RESIZE_BOTH,
\r
1538 buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
\r
1541 // Tool function used to return an item from an array based on its id
\r
1543 var getById = function( array, id, recurse )
\r
1545 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1547 if ( item.id == id )
\r
1549 if ( recurse && item[ recurse ] )
\r
1551 var retval = getById( item[ recurse ], id, recurse ) ;
\r
1559 // Tool function used to add an item into an array.
\r
1560 var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound )
\r
1562 if ( nextSiblingId )
\r
1564 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1566 if ( item.id == nextSiblingId )
\r
1568 array.splice( i, 0, newItem );
\r
1572 if ( recurse && item[ recurse ] )
\r
1574 var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
\r
1580 if ( nullIfNotFound )
\r
1584 array.push( newItem );
\r
1588 // Tool function used to remove an item from an array based on its id.
\r
1589 var removeById = function( array, id, recurse )
\r
1591 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1593 if ( item.id == id )
\r
1594 return array.splice( i, 1 );
\r
1595 if ( recurse && item[ recurse ] )
\r
1597 var retval = removeById( item[ recurse ], id, recurse );
\r
1606 * This class is not really part of the API. It is the "definition" property value
\r
1607 * passed to "dialogDefinition" event handlers.
\r
1609 * @name CKEDITOR.dialog.definitionObject
\r
1610 * @extends CKEDITOR.dialog.definition
\r
1612 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1614 * var definition = evt.data.definition;
\r
1615 * var content = definition.getContents( 'page1' );
\r
1619 var definitionObject = function( dialog, dialogDefinition )
\r
1621 // TODO : Check if needed.
\r
1622 this.dialog = dialog;
\r
1624 // Transform the contents entries in contentObjects.
\r
1625 var contents = dialogDefinition.contents;
\r
1626 for ( var i = 0, content ; ( content = contents[i] ) ; i++ )
\r
1627 contents[ i ] = content && new contentObject( dialog, content );
\r
1629 CKEDITOR.tools.extend( this, dialogDefinition );
\r
1632 definitionObject.prototype =
\r
1633 /** @lends CKEDITOR.dialog.definitionObject.prototype */
\r
1636 * Gets a content definition.
\r
1637 * @param {String} id The id of the content definition.
\r
1638 * @returns {CKEDITOR.dialog.definition.content} The content definition
\r
1641 getContents : function( id )
\r
1643 return getById( this.contents, id );
\r
1647 * Gets a button definition.
\r
1648 * @param {String} id The id of the button definition.
\r
1649 * @returns {CKEDITOR.dialog.definition.button} The button definition
\r
1652 getButton : function( id )
\r
1654 return getById( this.buttons, id );
\r
1658 * Adds a content definition object under this dialog definition.
\r
1659 * @param {CKEDITOR.dialog.definition.content} contentDefinition The
\r
1660 * content definition.
\r
1661 * @param {String} [nextSiblingId] The id of an existing content
\r
1662 * definition which the new content definition will be inserted
\r
1663 * before. Omit if the new content definition is to be inserted as
\r
1665 * @returns {CKEDITOR.dialog.definition.content} The inserted content
\r
1668 addContents : function( contentDefinition, nextSiblingId )
\r
1670 return addById( this.contents, contentDefinition, nextSiblingId );
\r
1674 * Adds a button definition object under this dialog definition.
\r
1675 * @param {CKEDITOR.dialog.definition.button} buttonDefinition The
\r
1676 * button definition.
\r
1677 * @param {String} [nextSiblingId] The id of an existing button
\r
1678 * definition which the new button definition will be inserted
\r
1679 * before. Omit if the new button definition is to be inserted as
\r
1681 * @returns {CKEDITOR.dialog.definition.button} The inserted button
\r
1684 addButton : function( buttonDefinition, nextSiblingId )
\r
1686 return addById( this.buttons, buttonDefinition, nextSiblingId );
\r
1690 * Removes a content definition from this dialog definition.
\r
1691 * @param {String} id The id of the content definition to be removed.
\r
1692 * @returns {CKEDITOR.dialog.definition.content} The removed content
\r
1695 removeContents : function( id )
\r
1697 removeById( this.contents, id );
\r
1701 * Removes a button definition from the dialog definition.
\r
1702 * @param {String} id The id of the button definition to be removed.
\r
1703 * @returns {CKEDITOR.dialog.definition.button} The removed button
\r
1706 removeButton : function( id )
\r
1708 removeById( this.buttons, id );
\r
1713 * This class is not really part of the API. It is the template of the
\r
1714 * objects representing content pages inside the
\r
1715 * CKEDITOR.dialog.definitionObject.
\r
1717 * @name CKEDITOR.dialog.definition.contentObject
\r
1719 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1721 * var definition = evt.data.definition;
\r
1722 * var content = definition.getContents( 'page1' );
\r
1723 * content.remove( 'textInput1' );
\r
1727 function contentObject( dialog, contentDefinition )
\r
1734 CKEDITOR.tools.extend( this, contentDefinition );
\r
1737 contentObject.prototype =
\r
1738 /** @lends CKEDITOR.dialog.definition.contentObject.prototype */
\r
1741 * Gets a UI element definition under the content definition.
\r
1742 * @param {String} id The id of the UI element definition.
\r
1743 * @returns {CKEDITOR.dialog.definition.uiElement}
\r
1745 get : function( id )
\r
1747 return getById( this.elements, id, 'children' );
\r
1751 * Adds a UI element definition to the content definition.
\r
1752 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition The
\r
1753 * UI elemnet definition to be added.
\r
1754 * @param {String} nextSiblingId The id of an existing UI element
\r
1755 * definition which the new UI element definition will be inserted
\r
1756 * before. Omit if the new button definition is to be inserted as
\r
1758 * @returns {CKEDITOR.dialog.definition.uiElement} The element
\r
1759 * definition inserted.
\r
1761 add : function( elementDefinition, nextSiblingId )
\r
1763 return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
\r
1767 * Removes a UI element definition from the content definition.
\r
1768 * @param {String} id The id of the UI element definition to be
\r
1770 * @returns {CKEDITOR.dialog.definition.uiElement} The element
\r
1771 * definition removed.
\r
1774 remove : function( id )
\r
1776 removeById( this.elements, id, 'children' );
\r
1780 function initDragAndDrop( dialog )
\r
1782 var lastCoords = null,
\r
1783 abstractDialogCoords = null,
\r
1784 element = dialog.getElement().getFirst(),
\r
1785 editor = dialog.getParentEditor(),
\r
1786 magnetDistance = editor.config.dialog_magnetDistance,
\r
1787 margins = editor.skin.margins || [ 0, 0, 0, 0 ];
\r
1789 if ( typeof magnetDistance == 'undefined' )
\r
1790 magnetDistance = 20;
\r
1792 function mouseMoveHandler( evt )
\r
1794 var dialogSize = dialog.getSize(),
\r
1795 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
1796 x = evt.data.$.screenX,
\r
1797 y = evt.data.$.screenY,
\r
1798 dx = x - lastCoords.x,
\r
1799 dy = y - lastCoords.y,
\r
1802 lastCoords = { x : x, y : y };
\r
1803 abstractDialogCoords.x += dx;
\r
1804 abstractDialogCoords.y += dy;
\r
1806 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
\r
1807 realX = - margins[3];
\r
1808 else if ( abstractDialogCoords.x - margins[1] > viewPaneSize.width - dialogSize.width - magnetDistance )
\r
1809 realX = viewPaneSize.width - dialogSize.width + ( editor.lang.dir == 'rtl' ? 0 : margins[1] );
\r
1811 realX = abstractDialogCoords.x;
\r
1813 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
\r
1814 realY = - margins[0];
\r
1815 else if ( abstractDialogCoords.y - margins[2] > viewPaneSize.height - dialogSize.height - magnetDistance )
\r
1816 realY = viewPaneSize.height - dialogSize.height + margins[2];
\r
1818 realY = abstractDialogCoords.y;
\r
1820 dialog.move( realX, realY, 1 );
\r
1822 evt.data.preventDefault();
\r
1825 function mouseUpHandler( evt )
\r
1827 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1828 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1830 if ( CKEDITOR.env.ie6Compat )
\r
1832 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1833 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1834 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1838 dialog.parts.title.on( 'mousedown', function( evt )
\r
1840 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
\r
1842 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
\r
1843 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
\r
1844 abstractDialogCoords = dialog.getPosition();
\r
1846 if ( CKEDITOR.env.ie6Compat )
\r
1848 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1849 coverDoc.on( 'mousemove', mouseMoveHandler );
\r
1850 coverDoc.on( 'mouseup', mouseUpHandler );
\r
1853 evt.data.preventDefault();
\r
1857 function initResizeHandles( dialog )
\r
1859 var def = dialog.definition,
\r
1860 resizable = def.resizable;
\r
1862 if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE )
\r
1865 var editor = dialog.getParentEditor();
\r
1866 var wrapperWidth, wrapperHeight,
\r
1867 viewSize, origin, startSize,
\r
1870 var mouseDownFn = CKEDITOR.tools.addFunction( function( $event )
\r
1872 startSize = dialog.getSize();
\r
1874 var content = dialog.parts.contents,
\r
1875 iframeDialog = content.$.getElementsByTagName( 'iframe' ).length;
\r
1877 // Shim to help capturing "mousemove" over iframe.
\r
1878 if ( iframeDialog )
\r
1880 dialogCover = CKEDITOR.dom.element.createFromHtml( '<div class="cke_dialog_resize_cover" style="height: 100%; position: absolute; width: 100%;"></div>' );
\r
1881 content.append( dialogCover );
\r
1884 // Calculate the offset between content and chrome size.
\r
1885 wrapperHeight = startSize.height - dialog.parts.contents.getSize( 'height', ! ( CKEDITOR.env.gecko || CKEDITOR.env.opera || CKEDITOR.env.ie && CKEDITOR.env.quirks ) );
\r
1886 wrapperWidth = startSize.width - dialog.parts.contents.getSize( 'width', 1 );
\r
1888 origin = { x : $event.screenX, y : $event.screenY };
\r
1890 viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
\r
1892 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
\r
1893 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
\r
1895 if ( CKEDITOR.env.ie6Compat )
\r
1897 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1898 coverDoc.on( 'mousemove', mouseMoveHandler );
\r
1899 coverDoc.on( 'mouseup', mouseUpHandler );
\r
1902 $event.preventDefault && $event.preventDefault();
\r
1905 // Prepend the grip to the dialog.
\r
1906 dialog.on( 'load', function()
\r
1908 var direction = '';
\r
1909 if ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH )
\r
1910 direction = ' cke_resizer_horizontal';
\r
1911 else if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT )
\r
1912 direction = ' cke_resizer_vertical';
\r
1913 var resizer = CKEDITOR.dom.element.createFromHtml( '<div' +
\r
1914 ' class="cke_resizer' + direction + ' cke_resizer_' + editor.lang.dir + '"' +
\r
1915 ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.resize ) + '"' +
\r
1916 ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event )"></div>' );
\r
1917 dialog.parts.footer.append( resizer, 1 );
\r
1919 editor.on( 'destroy', function() { CKEDITOR.tools.removeFunction( mouseDownFn ); } );
\r
1921 function mouseMoveHandler( evt )
\r
1923 var rtl = editor.lang.dir == 'rtl',
\r
1924 dx = ( evt.data.$.screenX - origin.x ) * ( rtl ? -1 : 1 ),
\r
1925 dy = evt.data.$.screenY - origin.y,
\r
1926 width = startSize.width,
\r
1927 height = startSize.height,
\r
1928 internalWidth = width + dx * ( dialog._.moved ? 1 : 2 ),
\r
1929 internalHeight = height + dy * ( dialog._.moved ? 1 : 2 ),
\r
1930 element = dialog._.element.getFirst(),
\r
1931 right = rtl && element.getComputedStyle( 'right' ),
\r
1932 position = dialog.getPosition();
\r
1934 if ( position.y + internalHeight > viewSize.height )
\r
1935 internalHeight = viewSize.height - position.y;
\r
1937 if ( ( rtl ? right : position.x ) + internalWidth > viewSize.width )
\r
1938 internalWidth = viewSize.width - ( rtl ? right : position.x );
\r
1940 // Make sure the dialog will not be resized to the wrong side when it's in the leftmost position for RTL.
\r
1941 if ( ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH || resizable == CKEDITOR.DIALOG_RESIZE_BOTH ) )
\r
1942 width = Math.max( def.minWidth || 0, internalWidth - wrapperWidth );
\r
1944 if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT || resizable == CKEDITOR.DIALOG_RESIZE_BOTH )
\r
1945 height = Math.max( def.minHeight || 0, internalHeight - wrapperHeight );
\r
1947 dialog.resize( width, height );
\r
1949 if ( !dialog._.moved )
\r
1952 evt.data.preventDefault();
\r
1955 function mouseUpHandler()
\r
1957 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1958 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1960 if ( dialogCover )
\r
1962 dialogCover.remove();
\r
1963 dialogCover = null;
\r
1966 if ( CKEDITOR.env.ie6Compat )
\r
1968 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1969 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1970 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1976 // Caching resuable covers and allowing only one cover
\r
1981 function cancelEvent( ev )
\r
1983 ev.data.preventDefault(1);
\r
1986 function showCover( editor )
\r
1988 var win = CKEDITOR.document.getWindow();
\r
1989 var config = editor.config,
\r
1990 backgroundColorStyle = config.dialog_backgroundCoverColor || 'white',
\r
1991 backgroundCoverOpacity = config.dialog_backgroundCoverOpacity,
\r
1992 baseFloatZIndex = config.baseFloatZIndex,
\r
1993 coverKey = CKEDITOR.tools.genKey(
\r
1994 backgroundColorStyle,
\r
1995 backgroundCoverOpacity,
\r
1996 baseFloatZIndex ),
\r
1997 coverElement = covers[ coverKey ];
\r
1999 if ( !coverElement )
\r
2002 '<div tabIndex="-1" style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),
\r
2003 '; z-index: ', baseFloatZIndex,
\r
2004 '; top: 0px; left: 0px; ',
\r
2005 ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),
\r
2006 '" class="cke_dialog_background_cover">'
\r
2009 if ( CKEDITOR.env.ie6Compat )
\r
2011 // Support for custom document.domain in IE.
\r
2012 var isCustomDomain = CKEDITOR.env.isCustomDomain(),
\r
2013 iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
\r
2017 ' hidefocus="true"' +
\r
2018 ' frameborder="0"' +
\r
2019 ' id="cke_dialog_background_iframe"' +
\r
2020 ' src="javascript:' );
\r
2022 html.push( 'void((function(){' +
\r
2023 'document.open();' +
\r
2024 ( isCustomDomain ? 'document.domain=\'' + document.domain + '\';' : '' ) +
\r
2025 'document.write( \'' + iframeHtml + '\' );' +
\r
2026 'document.close();' +
\r
2032 'position:absolute;' +
\r
2037 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
\r
2041 html.push( '</div>' );
\r
2043 coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
\r
2044 coverElement.setOpacity( backgroundCoverOpacity != undefined ? backgroundCoverOpacity : 0.5 );
\r
2046 coverElement.on( 'keydown', cancelEvent );
\r
2047 coverElement.on( 'keypress', cancelEvent );
\r
2048 coverElement.on( 'keyup', cancelEvent );
\r
2050 coverElement.appendTo( CKEDITOR.document.getBody() );
\r
2051 covers[ coverKey ] = coverElement;
\r
2054 coverElement. show();
\r
2056 currentCover = coverElement;
\r
2057 var resizeFunc = function()
\r
2059 var size = win.getViewPaneSize();
\r
2060 coverElement.setStyles(
\r
2062 width : size.width + 'px',
\r
2063 height : size.height + 'px'
\r
2067 var scrollFunc = function()
\r
2069 var pos = win.getScrollPosition(),
\r
2070 cursor = CKEDITOR.dialog._.currentTop;
\r
2071 coverElement.setStyles(
\r
2073 left : pos.x + 'px',
\r
2074 top : pos.y + 'px'
\r
2081 var dialogPos = cursor.getPosition();
\r
2082 cursor.move( dialogPos.x, dialogPos.y );
\r
2083 } while ( ( cursor = cursor._.parentDialog ) );
\r
2087 resizeCover = resizeFunc;
\r
2088 win.on( 'resize', resizeFunc );
\r
2090 // Using Safari/Mac, focus must be kept where it is (#7027)
\r
2091 if ( !( CKEDITOR.env.mac && CKEDITOR.env.webkit ) )
\r
2092 coverElement.focus();
\r
2094 if ( CKEDITOR.env.ie6Compat )
\r
2096 // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
\r
2097 // So we need to invent a really funny way to make it work.
\r
2098 var myScrollHandler = function()
\r
2101 arguments.callee.prevScrollHandler.apply( this, arguments );
\r
2103 win.$.setTimeout( function()
\r
2105 myScrollHandler.prevScrollHandler = window.onscroll || function(){};
\r
2106 window.onscroll = myScrollHandler;
\r
2112 function hideCover()
\r
2114 if ( !currentCover )
\r
2117 var win = CKEDITOR.document.getWindow();
\r
2118 currentCover.hide();
\r
2119 win.removeListener( 'resize', resizeCover );
\r
2121 if ( CKEDITOR.env.ie6Compat )
\r
2123 win.$.setTimeout( function()
\r
2125 var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
\r
2126 window.onscroll = prevScrollHandler || null;
\r
2129 resizeCover = null;
\r
2132 function removeCovers()
\r
2134 for ( var coverId in covers )
\r
2135 covers[ coverId ].remove();
\r
2139 var accessKeyProcessors = {};
\r
2141 var accessKeyDownHandler = function( evt )
\r
2143 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
2144 alt = evt.data.$.altKey,
\r
2145 shift = evt.data.$.shiftKey,
\r
2146 key = String.fromCharCode( evt.data.$.keyCode ),
\r
2147 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
2149 if ( !keyProcessor || !keyProcessor.length )
\r
2152 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
2153 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
2154 evt.data.preventDefault();
\r
2157 var accessKeyUpHandler = function( evt )
\r
2159 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
2160 alt = evt.data.$.altKey,
\r
2161 shift = evt.data.$.shiftKey,
\r
2162 key = String.fromCharCode( evt.data.$.keyCode ),
\r
2163 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
2165 if ( !keyProcessor || !keyProcessor.length )
\r
2168 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
2169 if ( keyProcessor.keyup )
\r
2171 keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
2172 evt.data.preventDefault();
\r
2176 var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc )
\r
2178 var procList = accessKeyProcessors[key] || ( accessKeyProcessors[key] = [] );
\r
2180 uiElement : uiElement,
\r
2183 keyup : upFunc || uiElement.accessKeyUp,
\r
2184 keydown : downFunc || uiElement.accessKeyDown
\r
2188 var unregisterAccessKey = function( obj )
\r
2190 for ( var i in accessKeyProcessors )
\r
2192 var list = accessKeyProcessors[i];
\r
2193 for ( var j = list.length - 1 ; j >= 0 ; j-- )
\r
2195 if ( list[j].dialog == obj || list[j].uiElement == obj )
\r
2196 list.splice( j, 1 );
\r
2198 if ( list.length === 0 )
\r
2199 delete accessKeyProcessors[i];
\r
2203 var tabAccessKeyUp = function( dialog, key )
\r
2205 if ( dialog._.accessKeyMap[key] )
\r
2206 dialog.selectPage( dialog._.accessKeyMap[key] );
\r
2209 var tabAccessKeyDown = function( dialog, key )
\r
2215 CKEDITOR.ui.dialog =
\r
2218 * The base class of all dialog UI elements.
\r
2220 * @param {CKEDITOR.dialog} dialog Parent dialog object.
\r
2221 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition Element
\r
2222 * definition. Accepted fields:
\r
2224 * <li><strong>id</strong> (Required) The id of the UI element. See {@link
\r
2225 * CKEDITOR.dialog#getContentElement}</li>
\r
2226 * <li><strong>type</strong> (Required) The type of the UI element. The
\r
2227 * value to this field specifies which UI element class will be used to
\r
2228 * generate the final widget.</li>
\r
2229 * <li><strong>title</strong> (Optional) The popup tooltip for the UI
\r
2231 * <li><strong>hidden</strong> (Optional) A flag that tells if the element
\r
2232 * should be initially visible.</li>
\r
2233 * <li><strong>className</strong> (Optional) Additional CSS class names
\r
2234 * to add to the UI element. Separated by space.</li>
\r
2235 * <li><strong>style</strong> (Optional) Additional CSS inline styles
\r
2236 * to add to the UI element. A semicolon (;) is required after the last
\r
2237 * style declaration.</li>
\r
2238 * <li><strong>accessKey</strong> (Optional) The alphanumeric access key
\r
2239 * for this element. Access keys are automatically prefixed by CTRL.</li>
\r
2240 * <li><strong>on*</strong> (Optional) Any UI element definition field that
\r
2241 * starts with <em>on</em> followed immediately by a capital letter and
\r
2242 * probably more letters is an event handler. Event handlers may be further
\r
2243 * divided into registered event handlers and DOM event handlers. Please
\r
2244 * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and
\r
2245 * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more
\r
2246 * information.</li>
\r
2248 * @param {Array} htmlList
\r
2249 * List of HTML code to be added to the dialog's content area.
\r
2250 * @param {Function|String} nodeNameArg
\r
2251 * A function returning a string, or a simple string for the node name for
\r
2252 * the root DOM node. Default is 'div'.
\r
2253 * @param {Function|Object} stylesArg
\r
2254 * A function returning an object, or a simple object for CSS styles applied
\r
2255 * to the DOM node. Default is empty object.
\r
2256 * @param {Function|Object} attributesArg
\r
2257 * A fucntion returning an object, or a simple object for attributes applied
\r
2258 * to the DOM node. Default is empty object.
\r
2259 * @param {Function|String} contentsArg
\r
2260 * A function returning a string, or a simple string for the HTML code inside
\r
2261 * the root DOM node. Default is empty string.
\r
2264 uiElement : function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg )
\r
2266 if ( arguments.length < 4 )
\r
2269 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',
\r
2270 html = [ '<', nodeName, ' ' ],
\r
2271 styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},
\r
2272 attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},
\r
2273 innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',
\r
2274 domId = this.domId = attributes.id || CKEDITOR.tools.getNextId() + '_uiElement',
\r
2275 id = this.id = elementDefinition.id,
\r
2278 // Set the id, a unique id is required for getElement() to work.
\r
2279 attributes.id = domId;
\r
2281 // Set the type and definition CSS class names.
\r
2283 if ( elementDefinition.type )
\r
2284 classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;
\r
2285 if ( elementDefinition.className )
\r
2286 classes[ elementDefinition.className ] = 1;
\r
2287 if ( elementDefinition.disabled )
\r
2288 classes[ 'cke_disabled' ] = 1;
\r
2290 var attributeClasses = ( attributes['class'] && attributes['class'].split ) ? attributes['class'].split( ' ' ) : [];
\r
2291 for ( i = 0 ; i < attributeClasses.length ; i++ )
\r
2293 if ( attributeClasses[i] )
\r
2294 classes[ attributeClasses[i] ] = 1;
\r
2296 var finalClasses = [];
\r
2297 for ( i in classes )
\r
2298 finalClasses.push( i );
\r
2299 attributes['class'] = finalClasses.join( ' ' );
\r
2301 // Set the popup tooltop.
\r
2302 if ( elementDefinition.title )
\r
2303 attributes.title = elementDefinition.title;
\r
2305 // Write the inline CSS styles.
\r
2306 var styleStr = ( elementDefinition.style || '' ).split( ';' );
\r
2308 // Element alignment support.
\r
2309 if ( elementDefinition.align )
\r
2311 var align = elementDefinition.align;
\r
2312 styles[ 'margin-left' ] = align == 'left' ? 0 : 'auto';
\r
2313 styles[ 'margin-right' ] = align == 'right' ? 0 : 'auto';
\r
2316 for ( i in styles )
\r
2317 styleStr.push( i + ':' + styles[i] );
\r
2318 if ( elementDefinition.hidden )
\r
2319 styleStr.push( 'display:none' );
\r
2320 for ( i = styleStr.length - 1 ; i >= 0 ; i-- )
\r
2322 if ( styleStr[i] === '' )
\r
2323 styleStr.splice( i, 1 );
\r
2325 if ( styleStr.length > 0 )
\r
2326 attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
\r
2328 // Write the attributes.
\r
2329 for ( i in attributes )
\r
2330 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '" ');
\r
2332 // Write the content HTML.
\r
2333 html.push( '>', innerHTML, '</', nodeName, '>' );
\r
2335 // Add contents to the parent HTML array.
\r
2336 htmlList.push( html.join( '' ) );
\r
2338 ( this._ || ( this._ = {} ) ).dialog = dialog;
\r
2340 // Override isChanged if it is defined in element definition.
\r
2341 if ( typeof( elementDefinition.isChanged ) == 'boolean' )
\r
2342 this.isChanged = function(){ return elementDefinition.isChanged; };
\r
2343 if ( typeof( elementDefinition.isChanged ) == 'function' )
\r
2344 this.isChanged = elementDefinition.isChanged;
\r
2346 // Overload 'get(set)Value' on definition.
\r
2347 if ( typeof( elementDefinition.setValue ) == 'function' )
\r
2349 this.setValue = CKEDITOR.tools.override( this.setValue, function( org )
\r
2351 return function( val ){ org.call( this, elementDefinition.setValue.call( this, val ) ); };
\r
2355 if ( typeof( elementDefinition.getValue ) == 'function' )
\r
2357 this.getValue = CKEDITOR.tools.override( this.getValue, function( org )
\r
2359 return function(){ return elementDefinition.getValue.call( this, org.call( this ) ); };
\r
2364 CKEDITOR.event.implementOn( this );
\r
2366 this.registerEvents( elementDefinition );
\r
2367 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
\r
2368 registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
\r
2371 dialog.on( 'load', function()
\r
2373 var input = me.getInputElement();
\r
2376 var focusClass = me.type in { 'checkbox' : 1, 'ratio' : 1 } && CKEDITOR.env.ie && CKEDITOR.env.version < 8 ? 'cke_dialog_ui_focused' : '';
\r
2377 input.on( 'focus', function()
\r
2379 dialog._.tabBarMode = false;
\r
2380 dialog._.hasFocus = true;
\r
2381 me.fire( 'focus' );
\r
2382 focusClass && this.addClass( focusClass );
\r
2386 input.on( 'blur', function()
\r
2388 me.fire( 'blur' );
\r
2389 focusClass && this.removeClass( focusClass );
\r
2394 // Register the object as a tab focus if it can be included.
\r
2395 if ( this.keyboardFocusable )
\r
2397 this.tabIndex = elementDefinition.tabIndex || 0;
\r
2399 this.focusIndex = dialog._.focusList.push( this ) - 1;
\r
2400 this.on( 'focus', function()
\r
2402 dialog._.currentFocusIndex = me.focusIndex;
\r
2406 // Completes this object with everything we have in the
\r
2408 CKEDITOR.tools.extend( this, elementDefinition );
\r
2412 * Horizontal layout box for dialog UI elements, auto-expends to available width of container.
\r
2414 * @extends CKEDITOR.ui.dialog.uiElement
\r
2415 * @param {CKEDITOR.dialog} dialog
\r
2416 * Parent dialog object.
\r
2417 * @param {Array} childObjList
\r
2418 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2420 * @param {Array} childHtmlList
\r
2421 * Array of HTML code that correspond to the HTML output of all the
\r
2422 * objects in childObjList.
\r
2423 * @param {Array} htmlList
\r
2424 * Array of HTML code that this element will output to.
\r
2425 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
\r
2426 * The element definition. Accepted fields:
\r
2428 * <li><strong>widths</strong> (Optional) The widths of child cells.</li>
\r
2429 * <li><strong>height</strong> (Optional) The height of the layout.</li>
\r
2430 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2432 * <li><strong>align</strong> (Optional) The alignment of the whole layout
\r
2437 hbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2439 if ( arguments.length < 4 )
\r
2442 this._ || ( this._ = {} );
\r
2444 var children = this._.children = childObjList,
\r
2445 widths = elementDefinition && elementDefinition.widths || null,
\r
2446 height = elementDefinition && elementDefinition.height || null,
\r
2450 var innerHTML = function()
\r
2452 var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];
\r
2453 for ( i = 0 ; i < childHtmlList.length ; i++ )
\r
2455 var className = 'cke_dialog_ui_hbox_child',
\r
2458 className = 'cke_dialog_ui_hbox_first';
\r
2459 if ( i == childHtmlList.length - 1 )
\r
2460 className = 'cke_dialog_ui_hbox_last';
\r
2461 html.push( '<td class="', className, '" role="presentation" ' );
\r
2465 styles.push( 'width:' + cssLength( widths[i] ) );
\r
2468 styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2470 styles.push( 'height:' + cssLength( height ) );
\r
2471 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2472 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
\r
2473 // In IE Quirks alignment has to be done on table cells. (#7324)
\r
2474 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && children[ i ].align )
\r
2475 styles.push( 'text-align:' + children[ i ].align );
\r
2476 if ( styles.length > 0 )
\r
2477 html.push( 'style="' + styles.join('; ') + '" ' );
\r
2478 html.push( '>', childHtmlList[i], '</td>' );
\r
2480 html.push( '</tr></tbody>' );
\r
2481 return html.join( '' );
\r
2484 var attribs = { role : 'presentation' };
\r
2485 elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );
\r
2487 CKEDITOR.ui.dialog.uiElement.call(
\r
2490 elementDefinition || { type : 'hbox' },
\r
2499 * Vertical layout box for dialog UI elements.
\r
2501 * @extends CKEDITOR.ui.dialog.hbox
\r
2502 * @param {CKEDITOR.dialog} dialog
\r
2503 * Parent dialog object.
\r
2504 * @param {Array} childObjList
\r
2505 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2507 * @param {Array} childHtmlList
\r
2508 * Array of HTML code that correspond to the HTML output of all the
\r
2509 * objects in childObjList.
\r
2510 * @param {Array} htmlList
\r
2511 * Array of HTML code that this element will output to.
\r
2512 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
\r
2513 * The element definition. Accepted fields:
\r
2515 * <li><strong>width</strong> (Optional) The width of the layout.</li>
\r
2516 * <li><strong>heights</strong> (Optional) The heights of individual cells.
\r
2518 * <li><strong>align</strong> (Optional) The alignment of the layout.</li>
\r
2519 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2521 * <li><strong>expand</strong> (Optional) Whether the layout should expand
\r
2522 * vertically to fill its container.</li>
\r
2526 vbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2528 if ( arguments.length < 3 )
\r
2531 this._ || ( this._ = {} );
\r
2533 var children = this._.children = childObjList,
\r
2534 width = elementDefinition && elementDefinition.width || null,
\r
2535 heights = elementDefinition && elementDefinition.heights || null;
\r
2537 var innerHTML = function()
\r
2539 var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];
\r
2540 html.push( 'style="' );
\r
2541 if ( elementDefinition && elementDefinition.expand )
\r
2542 html.push( 'height:100%;' );
\r
2543 html.push( 'width:' + cssLength( width || '100%' ), ';' );
\r
2545 html.push( 'align="', CKEDITOR.tools.htmlEncode(
\r
2546 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
\r
2548 html.push( '><tbody>' );
\r
2549 for ( var i = 0 ; i < childHtmlList.length ; i++ )
\r
2552 html.push( '<tr><td role="presentation" ' );
\r
2554 styles.push( 'width:' + cssLength( width || '100%' ) );
\r
2556 styles.push( 'height:' + cssLength( heights[i] ) );
\r
2557 else if ( elementDefinition && elementDefinition.expand )
\r
2558 styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2559 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2560 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
\r
2561 // In IE Quirks alignment has to be done on table cells. (#7324)
\r
2562 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && children[ i ].align )
\r
2563 styles.push( 'text-align:' + children[ i ].align );
\r
2564 if ( styles.length > 0 )
\r
2565 html.push( 'style="', styles.join( '; ' ), '" ' );
\r
2566 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[i], '</td></tr>' );
\r
2568 html.push( '</tbody></table>' );
\r
2569 return html.join( '' );
\r
2571 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type : 'vbox' }, htmlList, 'div', null, { role : 'presentation' }, innerHTML );
\r
2576 CKEDITOR.ui.dialog.uiElement.prototype =
\r
2579 * Gets the root DOM element of this dialog UI object.
\r
2580 * @returns {CKEDITOR.dom.element} Root DOM element of UI object.
\r
2582 * uiElement.getElement().hide();
\r
2584 getElement : function()
\r
2586 return CKEDITOR.document.getById( this.domId );
\r
2590 * Gets the DOM element that the user inputs values.
\r
2591 * This function is used by setValue(), getValue() and focus(). It should
\r
2592 * be overrided in child classes where the input element isn't the root
\r
2594 * @returns {CKEDITOR.dom.element} The element where the user input values.
\r
2596 * var rawValue = textInput.getInputElement().$.value;
\r
2598 getInputElement : function()
\r
2600 return this.getElement();
\r
2604 * Gets the parent dialog object containing this UI element.
\r
2605 * @returns {CKEDITOR.dialog} Parent dialog object.
\r
2607 * var dialog = uiElement.getDialog();
\r
2609 getDialog : function()
\r
2611 return this._.dialog;
\r
2615 * Sets the value of this dialog UI object.
\r
2616 * @param {Object} value The new value.
\r
2617 * @param {Boolean} noChangeEvent Internal commit, to supress 'change' event on this element.
\r
2618 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2620 * uiElement.setValue( 'Dingo' );
\r
2622 setValue : function( value, noChangeEvent )
\r
2624 this.getInputElement().setValue( value );
\r
2625 !noChangeEvent && this.fire( 'change', { value : value } );
\r
2630 * Gets the current value of this dialog UI object.
\r
2631 * @returns {Object} The current value.
\r
2633 * var myValue = uiElement.getValue();
\r
2635 getValue : function()
\r
2637 return this.getInputElement().getValue();
\r
2641 * Tells whether the UI object's value has changed.
\r
2642 * @returns {Boolean} true if changed, false if not changed.
\r
2644 * if ( uiElement.isChanged() )
\r
2645 * confirm( 'Value changed! Continue?' );
\r
2647 isChanged : function()
\r
2649 // Override in input classes.
\r
2654 * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
\r
2655 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2657 * focus : function()
\r
2659 * this.selectParentTab();
\r
2660 * // do something else.
\r
2663 selectParentTab : function()
\r
2665 var element = this.getInputElement(),
\r
2668 while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 )
\r
2671 // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
\r
2675 tabId = cursor.getAttribute( 'name' );
\r
2676 // Avoid duplicate select.
\r
2677 if ( this._.dialog._.currentTabId != tabId )
\r
2678 this._.dialog.selectPage( tabId );
\r
2683 * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
\r
2684 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2686 * uiElement.focus();
\r
2688 focus : function()
\r
2690 this.selectParentTab().getInputElement().focus();
\r
2695 * Registers the on* event handlers defined in the element definition.
\r
2696 * The default behavior of this function is:
\r
2699 * If the on* event is defined in the class's eventProcesors list,
\r
2700 * then the registration is delegated to the corresponding function
\r
2701 * in the eventProcessors list.
\r
2704 * If the on* event is not defined in the eventProcessors list, then
\r
2705 * register the event handler under the corresponding DOM event of
\r
2706 * the UI element's input DOM element (as defined by the return value
\r
2707 * of {@link CKEDITOR.ui.dialog.uiElement#getInputElement}).
\r
2710 * This function is only called at UI element instantiation, but can
\r
2711 * be overridded in child classes if they require more flexibility.
\r
2712 * @param {CKEDITOR.dialog.definition.uiElement} definition The UI element
\r
2714 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2717 registerEvents : function( definition )
\r
2719 var regex = /^on([A-Z]\w+)/,
\r
2722 var registerDomEvent = function( uiElement, dialog, eventName, func )
\r
2724 dialog.on( 'load', function()
\r
2726 uiElement.getInputElement().on( eventName, func, uiElement );
\r
2730 for ( var i in definition )
\r
2732 if ( !( match = i.match( regex ) ) )
\r
2734 if ( this.eventProcessors[i] )
\r
2735 this.eventProcessors[i].call( this, this._.dialog, definition[i] );
\r
2737 registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
\r
2744 * The event processor list used by
\r
2745 * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element
\r
2746 * instantiation. The default list defines three on* events:
\r
2748 * <li>onLoad - Called when the element's parent dialog opens for the
\r
2750 * <li>onShow - Called whenever the element's parent dialog opens.</li>
\r
2751 * <li>onHide - Called whenever the element's parent dialog closes.</li>
\r
2756 * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick
\r
2757 * // handlers in the UI element's definitions.
\r
2758 * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},
\r
2759 * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
\r
2760 * { onClick : function( dialog, func ) { this.on( 'click', func ); } },
\r
2761 * true );
\r
2765 onLoad : function( dialog, func )
\r
2767 dialog.on( 'load', func, this );
\r
2770 onShow : function( dialog, func )
\r
2772 dialog.on( 'show', func, this );
\r
2775 onHide : function( dialog, func )
\r
2777 dialog.on( 'hide', func, this );
\r
2782 * The default handler for a UI element's access key down event, which
\r
2783 * tries to put focus to the UI element.<br />
\r
2784 * Can be overridded in child classes for more sophisticaed behavior.
\r
2785 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2786 * @param {String} key The key combination pressed. Since access keys
\r
2787 * are defined to always include the CTRL key, its value should always
\r
2788 * include a 'CTRL+' prefix.
\r
2791 accessKeyDown : function( dialog, key )
\r
2797 * The default handler for a UI element's access key up event, which
\r
2798 * does nothing.<br />
\r
2799 * Can be overridded in child classes for more sophisticated behavior.
\r
2800 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2801 * @param {String} key The key combination pressed. Since access keys
\r
2802 * are defined to always include the CTRL key, its value should always
\r
2803 * include a 'CTRL+' prefix.
\r
2806 accessKeyUp : function( dialog, key )
\r
2811 * Disables a UI element.
\r
2814 disable : function()
\r
2816 var element = this.getElement(),
\r
2817 input = this.getInputElement();
\r
2818 input.setAttribute( 'disabled', 'true' );
\r
2819 element.addClass( 'cke_disabled' );
\r
2823 * Enables a UI element.
\r
2826 enable : function()
\r
2828 var element = this.getElement(),
\r
2829 input = this.getInputElement();
\r
2830 input.removeAttribute( 'disabled' );
\r
2831 element.removeClass( 'cke_disabled' );
\r
2835 * Determines whether an UI element is enabled or not.
\r
2836 * @returns {Boolean} Whether the UI element is enabled.
\r
2839 isEnabled : function()
\r
2841 return !this.getElement().hasClass( 'cke_disabled' );
\r
2845 * Determines whether an UI element is visible or not.
\r
2846 * @returns {Boolean} Whether the UI element is visible.
\r
2849 isVisible : function()
\r
2851 return this.getInputElement().isVisible();
\r
2855 * Determines whether an UI element is focus-able or not.
\r
2856 * Focus-able is defined as being both visible and enabled.
\r
2857 * @returns {Boolean} Whether the UI element can be focused.
\r
2860 isFocusable : function()
\r
2862 if ( !this.isEnabled() || !this.isVisible() )
\r
2868 CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
\r
2870 * @lends CKEDITOR.ui.dialog.hbox.prototype
\r
2874 * Gets a child UI element inside this container.
\r
2875 * @param {Array|Number} indices An array or a single number to indicate the child's
\r
2876 * position in the container's descendant tree. Omit to get all the children in an array.
\r
2877 * @returns {Array|CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container
\r
2878 * if no argument given, or the specified UI element if indices is given.
\r
2880 * var checkbox = hbox.getChild( [0,1] );
\r
2881 * checkbox.setValue( true );
\r
2883 getChild : function( indices )
\r
2885 // If no arguments, return a clone of the children array.
\r
2886 if ( arguments.length < 1 )
\r
2887 return this._.children.concat();
\r
2889 // If indices isn't array, make it one.
\r
2890 if ( !indices.splice )
\r
2891 indices = [ indices ];
\r
2893 // Retrieve the child element according to tree position.
\r
2894 if ( indices.length < 2 )
\r
2895 return this._.children[ indices[0] ];
\r
2897 return ( this._.children[ indices[0] ] && this._.children[ indices[0] ].getChild ) ?
\r
2898 this._.children[ indices[0] ].getChild( indices.slice( 1, indices.length ) ) :
\r
2903 CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
\r
2909 var commonBuilder = {
\r
2910 build : function( dialog, elementDefinition, output )
\r
2912 var children = elementDefinition.children,
\r
2914 childHtmlList = [],
\r
2915 childObjList = [];
\r
2916 for ( var i = 0 ; ( i < children.length && ( child = children[i] ) ) ; i++ )
\r
2918 var childHtml = [];
\r
2919 childHtmlList.push( childHtml );
\r
2920 childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
\r
2922 return new CKEDITOR.ui.dialog[elementDefinition.type]( dialog, childObjList, childHtmlList, output, elementDefinition );
\r
2926 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
\r
2927 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
\r
2931 * Generic dialog command. It opens a specific dialog when executed.
\r
2933 * @augments CKEDITOR.commandDefinition
\r
2934 * @param {string} dialogName The name of the dialog to open when executing
\r
2937 * // Register the "link" command, which opens the "link" dialog.
\r
2938 * editor.addCommand( 'link', <b>new CKEDITOR.dialogCommand( 'link' )</b> );
\r
2940 CKEDITOR.dialogCommand = function( dialogName )
\r
2942 this.dialogName = dialogName;
\r
2945 CKEDITOR.dialogCommand.prototype =
\r
2948 exec : function( editor )
\r
2950 // Special treatment for Opera. (#8031)
\r
2951 CKEDITOR.env.opera ?
\r
2952 CKEDITOR.tools.setTimeout( function() { editor.openDialog( this.dialogName ); }, 0, this )
\r
2953 : editor.openDialog( this.dialogName );
\r
2956 // Dialog commands just open a dialog ui, thus require no undo logic,
\r
2957 // undo support should dedicate to specific dialog implementation.
\r
2960 editorFocus : CKEDITOR.env.ie || CKEDITOR.env.webkit
\r
2965 var notEmptyRegex = /^([a]|[^a])+$/,
\r
2966 integerRegex = /^\d*$/,
\r
2967 numberRegex = /^\d*(?:\.\d+)?$/,
\r
2968 htmlLengthRegex = /^(((\d*(\.\d+))|(\d*))(px|\%)?)?$/,
\r
2969 cssLengthRegex = /^(((\d*(\.\d+))|(\d*))(px|em|ex|in|cm|mm|pt|pc|\%)?)?$/i,
\r
2970 inlineStyleRegex = /^(\s*[\w-]+\s*:\s*[^:;]+(?:;|$))*$/;
\r
2972 CKEDITOR.VALIDATE_OR = 1;
\r
2973 CKEDITOR.VALIDATE_AND = 2;
\r
2975 CKEDITOR.dialog.validate =
\r
2977 functions : function()
\r
2979 var args = arguments;
\r
2983 * It's important for validate functions to be able to accept the value
\r
2984 * as argument in addition to this.getValue(), so that it is possible to
\r
2985 * combine validate functions together to make more sophisticated
\r
2988 var value = this && this.getValue ? this.getValue() : args[ 0 ];
\r
2990 var msg = undefined,
\r
2991 relation = CKEDITOR.VALIDATE_AND,
\r
2992 functions = [], i;
\r
2994 for ( i = 0 ; i < args.length ; i++ )
\r
2996 if ( typeof( args[i] ) == 'function' )
\r
2997 functions.push( args[i] );
\r
3002 if ( i < args.length && typeof( args[i] ) == 'string' )
\r
3008 if ( i < args.length && typeof( args[i]) == 'number' )
\r
3009 relation = args[i];
\r
3011 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );
\r
3012 for ( i = 0 ; i < functions.length ; i++ )
\r
3014 if ( relation == CKEDITOR.VALIDATE_AND )
\r
3015 passed = passed && functions[i]( value );
\r
3017 passed = passed || functions[i]( value );
\r
3020 return !passed ? msg : true;
\r
3024 regex : function( regex, msg )
\r
3027 * Can be greatly shortened by deriving from functions validator if code size
\r
3028 * turns out to be more important than performance.
\r
3032 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
3033 return !regex.test( value ) ? msg : true;
\r
3037 notEmpty : function( msg )
\r
3039 return this.regex( notEmptyRegex, msg );
\r
3042 integer : function( msg )
\r
3044 return this.regex( integerRegex, msg );
\r
3047 'number' : function( msg )
\r
3049 return this.regex( numberRegex, msg );
\r
3052 'cssLength' : function( msg )
\r
3054 return this.functions( function( val ){ return cssLengthRegex.test( CKEDITOR.tools.trim( val ) ); }, msg );
\r
3057 'htmlLength' : function( msg )
\r
3059 return this.functions( function( val ){ return htmlLengthRegex.test( CKEDITOR.tools.trim( val ) ); }, msg );
\r
3062 'inlineStyle' : function( msg )
\r
3064 return this.functions( function( val ){ return inlineStyleRegex.test( CKEDITOR.tools.trim( val ) ); }, msg );
\r
3067 equals : function( value, msg )
\r
3069 return this.functions( function( val ){ return val == value; }, msg );
\r
3072 notEqual : function( value, msg )
\r
3074 return this.functions( function( val ){ return val != value; }, msg );
\r
3078 CKEDITOR.on( 'instanceDestroyed', function( evt )
\r
3080 // Remove dialog cover on last instance destroy.
\r
3081 if ( CKEDITOR.tools.isEmpty( CKEDITOR.instances ) )
\r
3083 var currentTopDialog;
\r
3084 while ( ( currentTopDialog = CKEDITOR.dialog._.currentTop ) )
\r
3085 currentTopDialog.hide();
\r
3089 var dialogs = evt.editor._.storedDialogs;
\r
3090 for ( var name in dialogs )
\r
3091 dialogs[ name ].destroy();
\r
3097 // Extend the CKEDITOR.editor class with dialog specific functions.
\r
3098 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
\r
3099 /** @lends CKEDITOR.editor.prototype */
\r
3102 * Loads and opens a registered dialog.
\r
3103 * @param {String} dialogName The registered name of the dialog.
\r
3104 * @param {Function} callback The function to be invoked after dialog instance created.
\r
3105 * @see CKEDITOR.dialog.add
\r
3107 * CKEDITOR.instances.editor1.openDialog( 'smiley' );
\r
3108 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed. null if the dialog name is not registered.
\r
3110 openDialog : function( dialogName, callback )
\r
3112 if ( this.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
3114 var selection = this.getSelection();
\r
3115 selection && selection.lock();
\r
3118 var dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
3119 dialogSkin = this.skin.dialog;
\r
3121 if ( CKEDITOR.dialog._.currentTop === null )
\r
3122 showCover( this );
\r
3124 // If the dialogDefinition is already loaded, open it immediately.
\r
3125 if ( typeof dialogDefinitions == 'function' && dialogSkin._isLoaded )
\r
3127 var storedDialogs = this._.storedDialogs ||
\r
3128 ( this._.storedDialogs = {} );
\r
3130 var dialog = storedDialogs[ dialogName ] ||
\r
3131 ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
\r
3133 callback && callback.call( dialog, dialog );
\r
3138 else if ( dialogDefinitions == 'failed' )
\r
3141 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
\r
3146 function onDialogFileLoaded( success )
\r
3148 var dialogDefinition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
3149 skin = me.skin.dialog;
\r
3151 // Check if both skin part and definition is loaded.
\r
3152 if ( !skin._isLoaded || loadDefinition && typeof success == 'undefined' )
\r
3155 // In case of plugin error, mark it as loading failed.
\r
3156 if ( typeof dialogDefinition != 'function' )
\r
3157 CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';
\r
3159 me.openDialog( dialogName, callback );
\r
3162 if ( typeof dialogDefinitions == 'string' )
\r
3164 var loadDefinition = 1;
\r
3165 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ), onDialogFileLoaded, null, 0, 1 );
\r
3168 CKEDITOR.skins.load( this, 'dialog', onDialogFileLoaded );
\r
3175 CKEDITOR.plugins.add( 'dialog',
\r
3177 requires : [ 'dialogui' ]
\r
3180 // Dialog related configurations.
\r
3183 * The color of the dialog background cover. It should be a valid CSS color
\r
3185 * @name CKEDITOR.config.dialog_backgroundCoverColor
\r
3187 * @default 'white'
\r
3189 * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
\r
3193 * The opacity of the dialog background cover. It should be a number within the
\r
3194 * range [0.0, 1.0].
\r
3195 * @name CKEDITOR.config.dialog_backgroundCoverOpacity
\r
3199 * config.dialog_backgroundCoverOpacity = 0.7;
\r
3203 * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.
\r
3204 * @name CKEDITOR.config.dialog_startupFocusTab
\r
3208 * config.dialog_startupFocusTab = true;
\r
3212 * The distance of magnetic borders used in moving and resizing dialogs,
\r
3213 * measured in pixels.
\r
3214 * @name CKEDITOR.config.dialog_magnetDistance
\r
3218 * config.dialog_magnetDistance = 30;
\r
3222 * The guideline to follow when generating the dialog buttons. There are 3 possible options:
\r
3224 * <li>'OS' - the buttons will be displayed in the default order of the user's OS;</li>
\r
3225 * <li>'ltr' - for Left-To-Right order;</li>
\r
3226 * <li>'rtl' - for Right-To-Left order.</li>
\r
3228 * @name CKEDITOR.config.dialog_buttonsOrder
\r
3233 * config.dialog_buttonsOrder = 'rtl';
\r
3237 * The dialog contents to removed. It's a string composed by dialog name and tab name with a colon between them.
\r
3238 * Separate each pair with semicolon (see example).
\r
3239 * <b>Note: All names are case-sensitive.</b>
\r
3240 * <b>Note: Be cautious when specifying dialog tabs that are mandatory, like "info", dialog functionality might be broken because of this!</b>
\r
3241 * @name CKEDITOR.config.removeDialogTabs
\r
3246 * config.removeDialogTabs = 'flash:advanced;image:Link';
\r
3250 * Fired when a dialog definition is about to be used to create a dialog into
\r
3251 * an editor instance. This event makes it possible to customize the definition
\r
3252 * before creating it.
\r
3253 * <p>Note that this event is called only the first time a specific dialog is
\r
3254 * opened. Successive openings will use the cached dialog, and this event will
\r
3255 * not get fired.</p>
\r
3256 * @name CKEDITOR#dialogDefinition
\r
3258 * @param {CKEDITOR.dialog.definition} data The dialog defination that
\r
3259 * is being loaded.
\r
3260 * @param {CKEDITOR.editor} editor The editor instance that will use the
\r
3265 * Fired when a tab is going to be selected in a dialog
\r
3266 * @name CKEDITOR.dialog#selectPage
\r
3268 * @param {String} page The id of the page that it's gonna be selected.
\r
3269 * @param {String} currentPage The id of the current page.
\r
3273 * Fired when the user tries to dismiss a dialog
\r
3274 * @name CKEDITOR.dialog#cancel
\r
3276 * @param {Boolean} hide Whether the event should proceed or not.
\r
3280 * Fired when the user tries to confirm a dialog
\r
3281 * @name CKEDITOR.dialog#ok
\r
3283 * @param {Boolean} hide Whether the event should proceed or not.
\r
3287 * Fired when a dialog is shown
\r
3288 * @name CKEDITOR.dialog#show
\r
3293 * Fired when a dialog is shown
\r
3294 * @name CKEDITOR.editor#dialogShow
\r
3299 * Fired when a dialog is hidden
\r
3300 * @name CKEDITOR.dialog#hide
\r
3305 * Fired when a dialog is hidden
\r
3306 * @name CKEDITOR.editor#dialogHide
\r
3311 * Fired when a dialog is being resized. The event is fired on
\r
3312 * both the 'CKEDITOR.dialog' object and the dialog instance
\r
3313 * since 3.5.3, previously it's available only in the global object.
\r
3314 * @name CKEDITOR.dialog#resize
\r
3317 * @param {CKEDITOR.dialog} dialog The dialog being resized (if
\r
3318 * it's fired on the dialog itself, this parameter isn't sent).
\r
3319 * @param {String} skin The skin name.
\r
3320 * @param {Number} width The new width.
\r
3321 * @param {Number} height The new height.
\r