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', 'textarea' ) && ( !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 // Re-layout the dialog on window resize.
\r
669 function resizeWithWindow( dialog )
\r
671 var win = CKEDITOR.document.getWindow();
\r
672 function resizeHandler() { dialog.layout(); }
\r
673 win.on( 'resize', resizeHandler );
\r
674 dialog.on( 'hide', function() { win.removeListener( 'resize', resizeHandler ); } );
\r
677 CKEDITOR.dialog.prototype =
\r
679 destroy : function()
\r
682 this._.element.remove();
\r
686 * Resizes the dialog.
\r
687 * @param {Number} width The width of the dialog in pixels.
\r
688 * @param {Number} height The height of the dialog in pixels.
\r
691 * dialogObj.resize( 800, 640 );
\r
693 resize : (function()
\r
695 return function( width, height )
\r
697 if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )
\r
700 CKEDITOR.dialog.fire( 'resize',
\r
703 skin : this._.editor.skinName,
\r
706 }, this._.editor );
\r
708 this.fire( 'resize',
\r
710 skin : this._.editor.skinName,
\r
713 }, this._.editor );
\r
715 // Update dialog position when dimension get changed in RTL.
\r
716 if ( this._.editor.lang.dir == 'rtl' && this._.position )
\r
717 this._.position.x = CKEDITOR.document.getWindow().getViewPaneSize().width -
\r
718 this._.contentSize.width - parseInt( this._.element.getFirst().getStyle( 'right' ), 10 );
\r
720 this._.contentSize = { width : width, height : height };
\r
725 * Gets the current size of the dialog in pixels.
\r
726 * @returns {Object} An object with "width" and "height" properties.
\r
728 * var width = dialogObj.getSize().width;
\r
730 getSize : function()
\r
732 var element = this._.element.getFirst();
\r
733 return { width : element.$.offsetWidth || 0, height : element.$.offsetHeight || 0};
\r
737 * Moves the dialog to an (x, y) coordinate relative to the window.
\r
739 * @param {Number} x The target x-coordinate.
\r
740 * @param {Number} y The target y-coordinate.
\r
741 * @param {Boolean} save Flag indicate whether the dialog position should be remembered on next open up.
\r
743 * dialogObj.move( 10, 40 );
\r
745 move : function( x, y, save )
\r
747 // The dialog may be fixed positioned or absolute positioned. Ask the
\r
748 // browser what is the current situation first.
\r
749 var element = this._.element.getFirst(),
\r
750 rtl = this._.editor.lang.dir == 'rtl';
\r
752 var isFixed = element.getComputedStyle( 'position' ) == 'fixed';
\r
754 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
\r
757 // Save the current position.
\r
758 this._.position = { x : x, y : y };
\r
760 // If not fixed positioned, add scroll position to the coordinates.
\r
763 var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
\r
764 x += scrollPosition.x;
\r
765 y += scrollPosition.y;
\r
768 // Translate coordinate for RTL.
\r
771 var dialogSize = this.getSize(),
\r
772 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize();
\r
773 x = viewPaneSize.width - dialogSize.width - x;
\r
776 var styles = { 'top' : ( y > 0 ? y : 0 ) + 'px' };
\r
777 styles[ rtl ? 'right' : 'left' ] = ( x > 0 ? x : 0 ) + 'px';
\r
779 element.setStyles( styles );
\r
781 save && ( this._.moved = 1 );
\r
785 * Gets the dialog's position in the window.
\r
786 * @returns {Object} An object with "x" and "y" properties.
\r
788 * var dialogX = dialogObj.getPosition().x;
\r
790 getPosition : function(){ return CKEDITOR.tools.extend( {}, this._.position ); },
\r
793 * Shows the dialog box.
\r
795 * dialogObj.show();
\r
799 // Insert the dialog's element to the root document.
\r
800 var element = this._.element;
\r
801 var definition = this.definition;
\r
802 if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )
\r
803 element.appendTo( CKEDITOR.document.getBody() );
\r
805 element.setStyle( 'display', 'block' );
\r
807 // FIREFOX BUG: Fix vanishing caret for Firefox 2 or Gecko 1.8.
\r
808 if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
\r
810 var dialogElement = this.parts.dialog;
\r
811 dialogElement.setStyle( 'position', 'absolute' );
\r
812 setTimeout( function()
\r
814 dialogElement.setStyle( 'position', 'fixed' );
\r
819 // First, set the dialog to an appropriate size.
\r
820 this.resize( this._.contentSize && this._.contentSize.width || definition.width || definition.minWidth,
\r
821 this._.contentSize && this._.contentSize.height || definition.height || definition.minHeight );
\r
823 // Reset all inputs back to their default value.
\r
826 // Select the first tab by default.
\r
827 this.selectPage( this.definition.contents[0].id );
\r
830 if ( CKEDITOR.dialog._.currentZIndex === null )
\r
831 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;
\r
832 this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
\r
834 // Maintain the dialog ordering and dialog cover.
\r
835 if ( CKEDITOR.dialog._.currentTop === null )
\r
837 CKEDITOR.dialog._.currentTop = this;
\r
838 this._.parentDialog = null;
\r
839 showCover( this._.editor );
\r
844 this._.parentDialog = CKEDITOR.dialog._.currentTop;
\r
845 var parentElement = this._.parentDialog.getElement().getFirst();
\r
846 parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );
\r
847 CKEDITOR.dialog._.currentTop = this;
\r
850 element.on( 'keydown', accessKeyDownHandler );
\r
851 element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
853 // Reset the hasFocus state.
\r
854 this._.hasFocus = false;
\r
856 CKEDITOR.tools.setTimeout( function()
\r
859 resizeWithWindow( this );
\r
861 this.parts.dialog.setStyle( 'visibility', '' );
\r
863 // Execute onLoad for the first show.
\r
864 this.fireOnce( 'load', {} );
\r
865 CKEDITOR.ui.fire( 'ready', this );
\r
867 this.fire( 'show', {} );
\r
868 this._.editor.fire( 'dialogShow', this );
\r
870 // Save the initial values of the dialog.
\r
871 this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } );
\r
878 * Rearrange the dialog to its previous position or the middle of the window.
\r
881 layout : function()
\r
883 var el = this.parts.dialog;
\r
884 var dialogSize = this.getSize();
\r
885 var win = CKEDITOR.document.getWindow(),
\r
886 viewSize = win.getViewPaneSize();
\r
888 var posX = ( viewSize.width - dialogSize.width ) / 2,
\r
889 posY = ( viewSize.height - dialogSize.height ) / 2;
\r
891 // Switch to absolute position when viewport is smaller than dialog size.
\r
892 if ( !CKEDITOR.env.ie6Compat )
\r
894 if ( dialogSize.height + ( posY > 0 ? posY : 0 ) > viewSize.height ||
\r
895 dialogSize.width + ( posX > 0 ? posX : 0 ) > viewSize.width )
\r
896 el.setStyle( 'position', 'absolute' );
\r
898 el.setStyle( 'position', 'fixed' );
\r
901 this.move( this._.moved ? this._.position.x : posX,
\r
902 this._.moved ? this._.position.y : posY );
\r
906 * Executes a function for each UI element.
\r
907 * @param {Function} fn Function to execute for each UI element.
\r
908 * @returns {CKEDITOR.dialog} The current dialog object.
\r
910 foreach : function( fn )
\r
912 for ( var i in this._.contents )
\r
914 for ( var j in this._.contents[i] )
\r
915 fn.call( this, this._.contents[i][j] );
\r
921 * Resets all input values in the dialog.
\r
923 * dialogObj.reset();
\r
924 * @returns {CKEDITOR.dialog} The current dialog object.
\r
926 reset : (function()
\r
928 var fn = function( widget ){ if ( widget.reset ) widget.reset( 1 ); };
\r
929 return function(){ this.foreach( fn ); return this; };
\r
934 * Calls the {@link CKEDITOR.dialog.definition.uiElement#setup} method of each of the UI elements, with the arguments passed through it.
\r
935 * It is usually being called when the dialog is opened, to put the initial value inside the field.
\r
937 * dialogObj.setupContent();
\r
939 * var timestamp = ( new Date() ).valueOf();
\r
940 * dialogObj.setupContent( timestamp );
\r
942 setupContent : function()
\r
944 var args = arguments;
\r
945 this.foreach( function( widget )
\r
947 if ( widget.setup )
\r
948 widget.setup.apply( widget, args );
\r
953 * Calls the {@link CKEDITOR.dialog.definition.uiElement#commit} method of each of the UI elements, with the arguments passed through it.
\r
954 * It is usually being called when the user confirms the dialog, to process the values.
\r
956 * dialogObj.commitContent();
\r
958 * var timestamp = ( new Date() ).valueOf();
\r
959 * dialogObj.commitContent( timestamp );
\r
961 commitContent : function()
\r
963 var args = arguments;
\r
964 this.foreach( function( widget )
\r
966 // Make sure IE triggers "change" event on last focused input before closing the dialog. (#7915)
\r
967 if ( CKEDITOR.env.ie && this._.currentFocusIndex == widget.focusIndex )
\r
968 widget.getInputElement().$.blur();
\r
970 if ( widget.commit )
\r
971 widget.commit.apply( widget, args );
\r
976 * Hides the dialog box.
\r
978 * dialogObj.hide();
\r
982 if ( !this.parts.dialog.isVisible() )
\r
985 this.fire( 'hide', {} );
\r
986 this._.editor.fire( 'dialogHide', this );
\r
987 // Reset the tab page.
\r
988 this.selectPage( this._.tabIdList[ 0 ] );
\r
989 var element = this._.element;
\r
990 element.setStyle( 'display', 'none' );
\r
991 this.parts.dialog.setStyle( 'visibility', 'hidden' );
\r
992 // Unregister all access keys associated with this dialog.
\r
993 unregisterAccessKey( this );
\r
995 // Close any child(top) dialogs first.
\r
996 while( CKEDITOR.dialog._.currentTop != this )
\r
997 CKEDITOR.dialog._.currentTop.hide();
\r
999 // Maintain dialog ordering and remove cover if needed.
\r
1000 if ( !this._.parentDialog )
\r
1004 var parentElement = this._.parentDialog.getElement().getFirst();
\r
1005 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
\r
1007 CKEDITOR.dialog._.currentTop = this._.parentDialog;
\r
1009 // Deduct or clear the z-index.
\r
1010 if ( !this._.parentDialog )
\r
1012 CKEDITOR.dialog._.currentZIndex = null;
\r
1014 // Remove access key handlers.
\r
1015 element.removeListener( 'keydown', accessKeyDownHandler );
\r
1016 element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
1018 var editor = this._.editor;
\r
1021 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
1023 var selection = editor.getSelection();
\r
1024 selection && selection.unlock( true );
\r
1028 CKEDITOR.dialog._.currentZIndex -= 10;
\r
1030 delete this._.parentDialog;
\r
1031 // Reset the initial values of the dialog.
\r
1032 this.foreach( function( contentObj ) { contentObj.resetInitValue && contentObj.resetInitValue(); } );
\r
1036 * Adds a tabbed page into the dialog.
\r
1037 * @param {Object} contents Content definition.
\r
1040 addPage : function( contents )
\r
1042 var pageHtml = [],
\r
1043 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
\r
1044 elements = contents.elements,
\r
1045 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this,
\r
1048 className : 'cke_dialog_page_contents',
\r
1049 children : contents.elements,
\r
1050 expand : !!contents.expand,
\r
1051 padding : contents.padding,
\r
1052 style : contents.style || 'width: 100%;height:100%'
\r
1055 // Create the HTML for the tab and the content block.
\r
1056 var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
\r
1057 page.setAttribute( 'role', 'tabpanel' );
\r
1059 var env = CKEDITOR.env;
\r
1060 var tabId = 'cke_' + contents.id + '_' + CKEDITOR.tools.getNextNumber(),
\r
1061 tab = CKEDITOR.dom.element.createFromHtml( [
\r
1062 '<a class="cke_dialog_tab"',
\r
1063 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),
\r
1065 ( !!contents.hidden ? ' style="display:none"' : '' ),
\r
1066 ' id="', tabId, '"',
\r
1067 env.gecko && env.version >= 10900 && !env.hc ? '' : ' href="javascript:void(0)"',
\r
1069 ' hidefocus="true"',
\r
1075 page.setAttribute( 'aria-labelledby', tabId );
\r
1077 // Take records for the tabs and elements created.
\r
1078 this._.tabs[ contents.id ] = [ tab, page ];
\r
1079 this._.tabIdList.push( contents.id );
\r
1080 !contents.hidden && this._.pageCount++;
\r
1081 this._.lastTab = tab;
\r
1082 this.updateStyle();
\r
1084 var contentMap = this._.contents[ contents.id ] = {},
\r
1086 children = vbox.getChild();
\r
1088 while ( ( cursor = children.shift() ) )
\r
1090 contentMap[ cursor.id ] = cursor;
\r
1091 if ( typeof( cursor.getChild ) == 'function' )
\r
1092 children.push.apply( children, cursor.getChild() );
\r
1095 // Attach the DOM nodes.
\r
1097 page.setAttribute( 'name', contents.id );
\r
1098 page.appendTo( this.parts.contents );
\r
1100 tab.unselectable();
\r
1101 this.parts.tabs.append( tab );
\r
1103 // Add access key handlers if access key is defined.
\r
1104 if ( contents.accessKey )
\r
1106 registerAccessKey( this, this, 'CTRL+' + contents.accessKey,
\r
1107 tabAccessKeyDown, tabAccessKeyUp );
\r
1108 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;
\r
1113 * Activates a tab page in the dialog by its id.
\r
1114 * @param {String} id The id of the dialog tab to be activated.
\r
1116 * dialogObj.selectPage( 'tab_1' );
\r
1118 selectPage : function( id )
\r
1120 if ( this._.currentTabId == id )
\r
1123 // Returning true means that the event has been canceled
\r
1124 if ( this.fire( 'selectPage', { page : id, currentPage : this._.currentTabId } ) === true )
\r
1127 // Hide the non-selected tabs and pages.
\r
1128 for ( var i in this._.tabs )
\r
1130 var tab = this._.tabs[i][0],
\r
1131 page = this._.tabs[i][1];
\r
1134 tab.removeClass( 'cke_dialog_tab_selected' );
\r
1137 page.setAttribute( 'aria-hidden', i != id );
\r
1140 var selected = this._.tabs[ id ];
\r
1141 selected[ 0 ].addClass( 'cke_dialog_tab_selected' );
\r
1143 // [IE] an invisible input[type='text'] will enlarge it's width
\r
1144 // if it's value is long when it shows, so we clear it's value
\r
1145 // before it shows and then recover it (#5649)
\r
1146 if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat )
\r
1148 clearOrRecoverTextInputValue( selected[ 1 ] );
\r
1149 selected[ 1 ].show();
\r
1150 setTimeout( function()
\r
1152 clearOrRecoverTextInputValue( selected[ 1 ], 1 );
\r
1156 selected[ 1 ].show();
\r
1158 this._.currentTabId = id;
\r
1159 this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
\r
1162 // Dialog state-specific style updates.
\r
1163 updateStyle : function()
\r
1165 // If only a single page shown, a different style is used in the central pane.
\r
1166 this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );
\r
1170 * Hides a page's tab away from the dialog.
\r
1171 * @param {String} id The page's Id.
\r
1173 * dialog.hidePage( 'tab_3' );
\r
1175 hidePage : function( id )
\r
1177 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
1178 if ( !tab || this._.pageCount == 1 || !tab.isVisible() )
\r
1180 // Switch to other tab first when we're hiding the active tab.
\r
1181 else if ( id == this._.currentTabId )
\r
1182 this.selectPage( getPreviousVisibleTab.call( this ) );
\r
1185 this._.pageCount--;
\r
1186 this.updateStyle();
\r
1190 * Unhides a page's tab.
\r
1191 * @param {String} id The page's Id.
\r
1193 * dialog.showPage( 'tab_2' );
\r
1195 showPage : function( id )
\r
1197 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
1201 this._.pageCount++;
\r
1202 this.updateStyle();
\r
1206 * Gets the root DOM element of the dialog.
\r
1207 * @returns {CKEDITOR.dom.element} The <span> element containing this dialog.
\r
1209 * var dialogElement = dialogObj.getElement().getFirst();
\r
1210 * dialogElement.setStyle( 'padding', '5px' );
\r
1212 getElement : function()
\r
1214 return this._.element;
\r
1218 * Gets the name of the dialog.
\r
1219 * @returns {String} The name of this dialog.
\r
1221 * var dialogName = dialogObj.getName();
\r
1223 getName : function()
\r
1225 return this._.name;
\r
1229 * Gets a dialog UI element object from a dialog page.
\r
1230 * @param {String} pageId id of dialog page.
\r
1231 * @param {String} elementId id of UI element.
\r
1233 * dialogObj.getContentElement( 'tabId', 'elementId' ).setValue( 'Example' );
\r
1234 * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.
\r
1236 getContentElement : function( pageId, elementId )
\r
1238 var page = this._.contents[ pageId ];
\r
1239 return page && page[ elementId ];
\r
1243 * Gets the value of a dialog UI element.
\r
1244 * @param {String} pageId id of dialog page.
\r
1245 * @param {String} elementId id of UI element.
\r
1247 * alert( dialogObj.getValueOf( 'tabId', 'elementId' ) );
\r
1248 * @returns {Object} The value of the UI element.
\r
1250 getValueOf : function( pageId, elementId )
\r
1252 return this.getContentElement( pageId, elementId ).getValue();
\r
1256 * Sets the value of a dialog UI element.
\r
1257 * @param {String} pageId id of the dialog page.
\r
1258 * @param {String} elementId id of the UI element.
\r
1259 * @param {Object} value The new value of the UI element.
\r
1261 * dialogObj.setValueOf( 'tabId', 'elementId', 'Example' );
\r
1263 setValueOf : function( pageId, elementId, value )
\r
1265 return this.getContentElement( pageId, elementId ).setValue( value );
\r
1269 * Gets the UI element of a button in the dialog's button row.
\r
1270 * @param {String} id The id of the button.
\r
1272 * @returns {CKEDITOR.ui.dialog.button} The button object.
\r
1274 getButton : function( id )
\r
1276 return this._.buttons[ id ];
\r
1280 * Simulates a click to a dialog button in the dialog's button row.
\r
1281 * @param {String} id The id of the button.
\r
1283 * @returns The return value of the dialog's "click" event.
\r
1285 click : function( id )
\r
1287 return this._.buttons[ id ].click();
\r
1291 * Disables a dialog button.
\r
1292 * @param {String} id The id of the button.
\r
1295 disableButton : function( id )
\r
1297 return this._.buttons[ id ].disable();
\r
1301 * Enables a dialog button.
\r
1302 * @param {String} id The id of the button.
\r
1305 enableButton : function( id )
\r
1307 return this._.buttons[ id ].enable();
\r
1311 * Gets the number of pages in the dialog.
\r
1312 * @returns {Number} Page count.
\r
1314 getPageCount : function()
\r
1316 return this._.pageCount;
\r
1320 * Gets the editor instance which opened this dialog.
\r
1321 * @returns {CKEDITOR.editor} Parent editor instances.
\r
1323 getParentEditor : function()
\r
1325 return this._.editor;
\r
1329 * Gets the element that was selected when opening the dialog, if any.
\r
1330 * @returns {CKEDITOR.dom.element} The element that was selected, or null.
\r
1332 getSelectedElement : function()
\r
1334 return this.getParentEditor().getSelection().getSelectedElement();
\r
1338 * Adds element to dialog's focusable list.
\r
1340 * @param {CKEDITOR.dom.element} element
\r
1341 * @param {Number} [index]
\r
1343 addFocusable: function( element, index ) {
\r
1344 if ( typeof index == 'undefined' )
\r
1346 index = this._.focusList.length;
\r
1347 this._.focusList.push( new Focusable( this, element, index ) );
\r
1351 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );
\r
1352 for ( var i = index + 1 ; i < this._.focusList.length ; i++ )
\r
1353 this._.focusList[ i ].focusIndex++;
\r
1358 CKEDITOR.tools.extend( CKEDITOR.dialog,
\r
1360 * @lends CKEDITOR.dialog
\r
1364 * Registers a dialog.
\r
1365 * @param {String} name The dialog's name.
\r
1366 * @param {Function|String} dialogDefinition
\r
1367 * A function returning the dialog's definition, or the URL to the .js file holding the function.
\r
1368 * The function should accept an argument "editor" which is the current editor instance, and
\r
1369 * return an object conforming to {@link CKEDITOR.dialog.definition}.
\r
1370 * @see CKEDITOR.dialog.definition
\r
1372 * // Full sample plugin, which does not only register a dialog window but also adds an item to the context menu.
\r
1373 * // To open the dialog window, choose "Open dialog" in the context menu.
\r
1374 * CKEDITOR.plugins.add( 'myplugin',
\r
1376 * init: function( editor )
\r
1378 * editor.addCommand( 'mydialog',new CKEDITOR.dialogCommand( 'mydialog' ) );
\r
1380 * if ( editor.contextMenu )
\r
1382 * editor.addMenuGroup( 'mygroup', 10 );
\r
1383 * editor.addMenuItem( 'My Dialog',
\r
1385 * label : 'Open dialog',
\r
1386 * command : 'mydialog',
\r
1387 * group : 'mygroup'
\r
1389 * editor.contextMenu.addListener( function( element )
\r
1391 * return { 'My Dialog' : CKEDITOR.TRISTATE_OFF };
\r
1395 * <strong>CKEDITOR.dialog.add</strong>( 'mydialog', function( api )
\r
1397 * // CKEDITOR.dialog.definition
\r
1398 * var <strong>dialogDefinition</strong> =
\r
1400 * title : 'Sample dialog',
\r
1402 * minHeight : 130,
\r
1406 * label : 'Label',
\r
1407 * title : 'Title',
\r
1414 * html : '<p>This is some sample HTML content.</p>'
\r
1417 * type : 'textarea',
\r
1418 * id : 'textareaId',
\r
1425 * buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ],
\r
1426 * onOk : function() {
\r
1427 * // "this" is now a CKEDITOR.dialog object.
\r
1428 * // Accessing dialog elements:
\r
1429 * var textareaObj = this.<strong>getContentElement</strong>( 'tab1', 'textareaId' );
\r
1430 * alert( "You have entered: " + textareaObj.getValue() );
\r
1434 * return dialogDefinition;
\r
1439 * CKEDITOR.replace( 'editor1', { extraPlugins : 'myplugin' } );
\r
1441 add : function( name, dialogDefinition )
\r
1443 // Avoid path registration from multiple instances override definition.
\r
1444 if ( !this._.dialogDefinitions[name]
\r
1445 || typeof dialogDefinition == 'function' )
\r
1446 this._.dialogDefinitions[name] = dialogDefinition;
\r
1449 exists : function( name )
\r
1451 return !!this._.dialogDefinitions[ name ];
\r
1454 getCurrent : function()
\r
1456 return CKEDITOR.dialog._.currentTop;
\r
1460 * The default OK button for dialogs. Fires the "ok" event and closes the dialog if the event succeeds.
\r
1466 okButton : (function()
\r
1468 var retval = function( editor, override )
\r
1470 override = override || {};
\r
1471 return CKEDITOR.tools.extend( {
\r
1474 label : editor.lang.common.ok,
\r
1475 'class' : 'cke_dialog_ui_button_ok',
\r
1476 onClick : function( evt )
\r
1478 var dialog = evt.data.dialog;
\r
1479 if ( dialog.fire( 'ok', { hide : true } ).hide !== false )
\r
1482 }, override, true );
\r
1484 retval.type = 'button';
\r
1485 retval.override = function( override )
\r
1487 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1488 { type : 'button' }, true );
\r
1494 * The default cancel button for dialogs. Fires the "cancel" event and closes the dialog if no UI element value changed.
\r
1500 cancelButton : (function()
\r
1502 var retval = function( editor, override )
\r
1504 override = override || {};
\r
1505 return CKEDITOR.tools.extend( {
\r
1508 label : editor.lang.common.cancel,
\r
1509 'class' : 'cke_dialog_ui_button_cancel',
\r
1510 onClick : function( evt )
\r
1512 var dialog = evt.data.dialog;
\r
1513 if ( dialog.fire( 'cancel', { hide : true } ).hide !== false )
\r
1516 }, override, true );
\r
1518 retval.type = 'button';
\r
1519 retval.override = function( override )
\r
1521 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1522 { type : 'button' }, true );
\r
1528 * Registers a dialog UI element.
\r
1529 * @param {String} typeName The name of the UI element.
\r
1530 * @param {Function} builder The function to build the UI element.
\r
1533 addUIElement : function( typeName, builder )
\r
1535 this._.uiElementBuilders[ typeName ] = builder;
\r
1539 CKEDITOR.dialog._ =
\r
1541 uiElementBuilders : {},
\r
1543 dialogDefinitions : {},
\r
1545 currentTop : null,
\r
1547 currentZIndex : null
\r
1550 // "Inherit" (copy actually) from CKEDITOR.event.
\r
1551 CKEDITOR.event.implementOn( CKEDITOR.dialog );
\r
1552 CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype, true );
\r
1554 var defaultDialogDefinition =
\r
1556 resizable : CKEDITOR.DIALOG_RESIZE_BOTH,
\r
1559 buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
\r
1562 // Tool function used to return an item from an array based on its id
\r
1564 var getById = function( array, id, recurse )
\r
1566 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1568 if ( item.id == id )
\r
1570 if ( recurse && item[ recurse ] )
\r
1572 var retval = getById( item[ recurse ], id, recurse ) ;
\r
1580 // Tool function used to add an item into an array.
\r
1581 var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound )
\r
1583 if ( nextSiblingId )
\r
1585 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1587 if ( item.id == nextSiblingId )
\r
1589 array.splice( i, 0, newItem );
\r
1593 if ( recurse && item[ recurse ] )
\r
1595 var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
\r
1601 if ( nullIfNotFound )
\r
1605 array.push( newItem );
\r
1609 // Tool function used to remove an item from an array based on its id.
\r
1610 var removeById = function( array, id, recurse )
\r
1612 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1614 if ( item.id == id )
\r
1615 return array.splice( i, 1 );
\r
1616 if ( recurse && item[ recurse ] )
\r
1618 var retval = removeById( item[ recurse ], id, recurse );
\r
1627 * This class is not really part of the API. It is the "definition" property value
\r
1628 * passed to "dialogDefinition" event handlers.
\r
1630 * @name CKEDITOR.dialog.definitionObject
\r
1631 * @extends CKEDITOR.dialog.definition
\r
1633 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1635 * var definition = evt.data.definition;
\r
1636 * var content = definition.getContents( 'page1' );
\r
1640 var definitionObject = function( dialog, dialogDefinition )
\r
1642 // TODO : Check if needed.
\r
1643 this.dialog = dialog;
\r
1645 // Transform the contents entries in contentObjects.
\r
1646 var contents = dialogDefinition.contents;
\r
1647 for ( var i = 0, content ; ( content = contents[i] ) ; i++ )
\r
1648 contents[ i ] = content && new contentObject( dialog, content );
\r
1650 CKEDITOR.tools.extend( this, dialogDefinition );
\r
1653 definitionObject.prototype =
\r
1654 /** @lends CKEDITOR.dialog.definitionObject.prototype */
\r
1657 * Gets a content definition.
\r
1658 * @param {String} id The id of the content definition.
\r
1659 * @returns {CKEDITOR.dialog.definition.content} The content definition
\r
1662 getContents : function( id )
\r
1664 return getById( this.contents, id );
\r
1668 * Gets a button definition.
\r
1669 * @param {String} id The id of the button definition.
\r
1670 * @returns {CKEDITOR.dialog.definition.button} The button definition
\r
1673 getButton : function( id )
\r
1675 return getById( this.buttons, id );
\r
1679 * Adds a content definition object under this dialog definition.
\r
1680 * @param {CKEDITOR.dialog.definition.content} contentDefinition The
\r
1681 * content definition.
\r
1682 * @param {String} [nextSiblingId] The id of an existing content
\r
1683 * definition which the new content definition will be inserted
\r
1684 * before. Omit if the new content definition is to be inserted as
\r
1686 * @returns {CKEDITOR.dialog.definition.content} The inserted content
\r
1689 addContents : function( contentDefinition, nextSiblingId )
\r
1691 return addById( this.contents, contentDefinition, nextSiblingId );
\r
1695 * Adds a button definition object under this dialog definition.
\r
1696 * @param {CKEDITOR.dialog.definition.button} buttonDefinition The
\r
1697 * button definition.
\r
1698 * @param {String} [nextSiblingId] The id of an existing button
\r
1699 * definition which the new button definition will be inserted
\r
1700 * before. Omit if the new button definition is to be inserted as
\r
1702 * @returns {CKEDITOR.dialog.definition.button} The inserted button
\r
1705 addButton : function( buttonDefinition, nextSiblingId )
\r
1707 return addById( this.buttons, buttonDefinition, nextSiblingId );
\r
1711 * Removes a content definition from this dialog definition.
\r
1712 * @param {String} id The id of the content definition to be removed.
\r
1713 * @returns {CKEDITOR.dialog.definition.content} The removed content
\r
1716 removeContents : function( id )
\r
1718 removeById( this.contents, id );
\r
1722 * Removes a button definition from the dialog definition.
\r
1723 * @param {String} id The id of the button definition to be removed.
\r
1724 * @returns {CKEDITOR.dialog.definition.button} The removed button
\r
1727 removeButton : function( id )
\r
1729 removeById( this.buttons, id );
\r
1734 * This class is not really part of the API. It is the template of the
\r
1735 * objects representing content pages inside the
\r
1736 * CKEDITOR.dialog.definitionObject.
\r
1738 * @name CKEDITOR.dialog.definition.contentObject
\r
1740 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1742 * var definition = evt.data.definition;
\r
1743 * var content = definition.getContents( 'page1' );
\r
1744 * content.remove( 'textInput1' );
\r
1748 function contentObject( dialog, contentDefinition )
\r
1755 CKEDITOR.tools.extend( this, contentDefinition );
\r
1758 contentObject.prototype =
\r
1759 /** @lends CKEDITOR.dialog.definition.contentObject.prototype */
\r
1762 * Gets a UI element definition under the content definition.
\r
1763 * @param {String} id The id of the UI element definition.
\r
1764 * @returns {CKEDITOR.dialog.definition.uiElement}
\r
1766 get : function( id )
\r
1768 return getById( this.elements, id, 'children' );
\r
1772 * Adds a UI element definition to the content definition.
\r
1773 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition The
\r
1774 * UI elemnet definition to be added.
\r
1775 * @param {String} nextSiblingId The id of an existing UI element
\r
1776 * definition which the new UI element definition will be inserted
\r
1777 * before. Omit if the new button definition is to be inserted as
\r
1779 * @returns {CKEDITOR.dialog.definition.uiElement} The element
\r
1780 * definition inserted.
\r
1782 add : function( elementDefinition, nextSiblingId )
\r
1784 return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
\r
1788 * Removes a UI element definition from the content definition.
\r
1789 * @param {String} id The id of the UI element definition to be
\r
1791 * @returns {CKEDITOR.dialog.definition.uiElement} The element
\r
1792 * definition removed.
\r
1795 remove : function( id )
\r
1797 removeById( this.elements, id, 'children' );
\r
1801 function initDragAndDrop( dialog )
\r
1803 var lastCoords = null,
\r
1804 abstractDialogCoords = null,
\r
1805 element = dialog.getElement().getFirst(),
\r
1806 editor = dialog.getParentEditor(),
\r
1807 magnetDistance = editor.config.dialog_magnetDistance,
\r
1808 margins = editor.skin.margins || [ 0, 0, 0, 0 ];
\r
1810 if ( typeof magnetDistance == 'undefined' )
\r
1811 magnetDistance = 20;
\r
1813 function mouseMoveHandler( evt )
\r
1815 var dialogSize = dialog.getSize(),
\r
1816 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
1817 x = evt.data.$.screenX,
\r
1818 y = evt.data.$.screenY,
\r
1819 dx = x - lastCoords.x,
\r
1820 dy = y - lastCoords.y,
\r
1823 lastCoords = { x : x, y : y };
\r
1824 abstractDialogCoords.x += dx;
\r
1825 abstractDialogCoords.y += dy;
\r
1827 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
\r
1828 realX = - margins[3];
\r
1829 else if ( abstractDialogCoords.x - margins[1] > viewPaneSize.width - dialogSize.width - magnetDistance )
\r
1830 realX = viewPaneSize.width - dialogSize.width + ( editor.lang.dir == 'rtl' ? 0 : margins[1] );
\r
1832 realX = abstractDialogCoords.x;
\r
1834 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
\r
1835 realY = - margins[0];
\r
1836 else if ( abstractDialogCoords.y - margins[2] > viewPaneSize.height - dialogSize.height - magnetDistance )
\r
1837 realY = viewPaneSize.height - dialogSize.height + margins[2];
\r
1839 realY = abstractDialogCoords.y;
\r
1841 dialog.move( realX, realY, 1 );
\r
1843 evt.data.preventDefault();
\r
1846 function mouseUpHandler( evt )
\r
1848 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1849 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1851 if ( CKEDITOR.env.ie6Compat )
\r
1853 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1854 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1855 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1859 dialog.parts.title.on( 'mousedown', function( evt )
\r
1861 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
\r
1863 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
\r
1864 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
\r
1865 abstractDialogCoords = dialog.getPosition();
\r
1867 if ( CKEDITOR.env.ie6Compat )
\r
1869 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1870 coverDoc.on( 'mousemove', mouseMoveHandler );
\r
1871 coverDoc.on( 'mouseup', mouseUpHandler );
\r
1874 evt.data.preventDefault();
\r
1878 function initResizeHandles( dialog )
\r
1880 var def = dialog.definition,
\r
1881 resizable = def.resizable;
\r
1883 if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE )
\r
1886 var editor = dialog.getParentEditor();
\r
1887 var wrapperWidth, wrapperHeight,
\r
1888 viewSize, origin, startSize,
\r
1891 var mouseDownFn = CKEDITOR.tools.addFunction( function( $event )
\r
1893 startSize = dialog.getSize();
\r
1895 var content = dialog.parts.contents,
\r
1896 iframeDialog = content.$.getElementsByTagName( 'iframe' ).length;
\r
1898 // Shim to help capturing "mousemove" over iframe.
\r
1899 if ( iframeDialog )
\r
1901 dialogCover = CKEDITOR.dom.element.createFromHtml( '<div class="cke_dialog_resize_cover" style="height: 100%; position: absolute; width: 100%;"></div>' );
\r
1902 content.append( dialogCover );
\r
1905 // Calculate the offset between content and chrome size.
\r
1906 wrapperHeight = startSize.height - dialog.parts.contents.getSize( 'height', ! ( CKEDITOR.env.gecko || CKEDITOR.env.opera || CKEDITOR.env.ie && CKEDITOR.env.quirks ) );
\r
1907 wrapperWidth = startSize.width - dialog.parts.contents.getSize( 'width', 1 );
\r
1909 origin = { x : $event.screenX, y : $event.screenY };
\r
1911 viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
\r
1913 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
\r
1914 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
\r
1916 if ( CKEDITOR.env.ie6Compat )
\r
1918 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1919 coverDoc.on( 'mousemove', mouseMoveHandler );
\r
1920 coverDoc.on( 'mouseup', mouseUpHandler );
\r
1923 $event.preventDefault && $event.preventDefault();
\r
1926 // Prepend the grip to the dialog.
\r
1927 dialog.on( 'load', function()
\r
1929 var direction = '';
\r
1930 if ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH )
\r
1931 direction = ' cke_resizer_horizontal';
\r
1932 else if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT )
\r
1933 direction = ' cke_resizer_vertical';
\r
1934 var resizer = CKEDITOR.dom.element.createFromHtml( '<div' +
\r
1935 ' class="cke_resizer' + direction + ' cke_resizer_' + editor.lang.dir + '"' +
\r
1936 ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.resize ) + '"' +
\r
1937 ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event )"></div>' );
\r
1938 dialog.parts.footer.append( resizer, 1 );
\r
1940 editor.on( 'destroy', function() { CKEDITOR.tools.removeFunction( mouseDownFn ); } );
\r
1942 function mouseMoveHandler( evt )
\r
1944 var rtl = editor.lang.dir == 'rtl',
\r
1945 dx = ( evt.data.$.screenX - origin.x ) * ( rtl ? -1 : 1 ),
\r
1946 dy = evt.data.$.screenY - origin.y,
\r
1947 width = startSize.width,
\r
1948 height = startSize.height,
\r
1949 internalWidth = width + dx * ( dialog._.moved ? 1 : 2 ),
\r
1950 internalHeight = height + dy * ( dialog._.moved ? 1 : 2 ),
\r
1951 element = dialog._.element.getFirst(),
\r
1952 right = rtl && element.getComputedStyle( 'right' ),
\r
1953 position = dialog.getPosition();
\r
1955 if ( position.y + internalHeight > viewSize.height )
\r
1956 internalHeight = viewSize.height - position.y;
\r
1958 if ( ( rtl ? right : position.x ) + internalWidth > viewSize.width )
\r
1959 internalWidth = viewSize.width - ( rtl ? right : position.x );
\r
1961 // Make sure the dialog will not be resized to the wrong side when it's in the leftmost position for RTL.
\r
1962 if ( ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH || resizable == CKEDITOR.DIALOG_RESIZE_BOTH ) )
\r
1963 width = Math.max( def.minWidth || 0, internalWidth - wrapperWidth );
\r
1965 if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT || resizable == CKEDITOR.DIALOG_RESIZE_BOTH )
\r
1966 height = Math.max( def.minHeight || 0, internalHeight - wrapperHeight );
\r
1968 dialog.resize( width, height );
\r
1970 if ( !dialog._.moved )
\r
1973 evt.data.preventDefault();
\r
1976 function mouseUpHandler()
\r
1978 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1979 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1981 if ( dialogCover )
\r
1983 dialogCover.remove();
\r
1984 dialogCover = null;
\r
1987 if ( CKEDITOR.env.ie6Compat )
\r
1989 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1990 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1991 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1997 // Caching resuable covers and allowing only one cover
\r
2002 function cancelEvent( ev )
\r
2004 ev.data.preventDefault(1);
\r
2007 function showCover( editor )
\r
2009 var win = CKEDITOR.document.getWindow();
\r
2010 var config = editor.config,
\r
2011 backgroundColorStyle = config.dialog_backgroundCoverColor || 'white',
\r
2012 backgroundCoverOpacity = config.dialog_backgroundCoverOpacity,
\r
2013 baseFloatZIndex = config.baseFloatZIndex,
\r
2014 coverKey = CKEDITOR.tools.genKey(
\r
2015 backgroundColorStyle,
\r
2016 backgroundCoverOpacity,
\r
2017 baseFloatZIndex ),
\r
2018 coverElement = covers[ coverKey ];
\r
2020 if ( !coverElement )
\r
2023 '<div tabIndex="-1" style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),
\r
2024 '; z-index: ', baseFloatZIndex,
\r
2025 '; top: 0px; left: 0px; ',
\r
2026 ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),
\r
2027 '" class="cke_dialog_background_cover">'
\r
2030 if ( CKEDITOR.env.ie6Compat )
\r
2032 // Support for custom document.domain in IE.
\r
2033 var isCustomDomain = CKEDITOR.env.isCustomDomain(),
\r
2034 iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
\r
2038 ' hidefocus="true"' +
\r
2039 ' frameborder="0"' +
\r
2040 ' id="cke_dialog_background_iframe"' +
\r
2041 ' src="javascript:' );
\r
2043 html.push( 'void((function(){' +
\r
2044 'document.open();' +
\r
2045 ( isCustomDomain ? 'document.domain=\'' + document.domain + '\';' : '' ) +
\r
2046 'document.write( \'' + iframeHtml + '\' );' +
\r
2047 'document.close();' +
\r
2053 'position:absolute;' +
\r
2058 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
\r
2062 html.push( '</div>' );
\r
2064 coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
\r
2065 coverElement.setOpacity( backgroundCoverOpacity != undefined ? backgroundCoverOpacity : 0.5 );
\r
2067 coverElement.on( 'keydown', cancelEvent );
\r
2068 coverElement.on( 'keypress', cancelEvent );
\r
2069 coverElement.on( 'keyup', cancelEvent );
\r
2071 coverElement.appendTo( CKEDITOR.document.getBody() );
\r
2072 covers[ coverKey ] = coverElement;
\r
2075 coverElement. show();
\r
2077 currentCover = coverElement;
\r
2078 var resizeFunc = function()
\r
2080 var size = win.getViewPaneSize();
\r
2081 coverElement.setStyles(
\r
2083 width : size.width + 'px',
\r
2084 height : size.height + 'px'
\r
2088 var scrollFunc = function()
\r
2090 var pos = win.getScrollPosition(),
\r
2091 cursor = CKEDITOR.dialog._.currentTop;
\r
2092 coverElement.setStyles(
\r
2094 left : pos.x + 'px',
\r
2095 top : pos.y + 'px'
\r
2102 var dialogPos = cursor.getPosition();
\r
2103 cursor.move( dialogPos.x, dialogPos.y );
\r
2104 } while ( ( cursor = cursor._.parentDialog ) );
\r
2108 resizeCover = resizeFunc;
\r
2109 win.on( 'resize', resizeFunc );
\r
2111 // Using Safari/Mac, focus must be kept where it is (#7027)
\r
2112 if ( !( CKEDITOR.env.mac && CKEDITOR.env.webkit ) )
\r
2113 coverElement.focus();
\r
2115 if ( CKEDITOR.env.ie6Compat )
\r
2117 // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
\r
2118 // So we need to invent a really funny way to make it work.
\r
2119 var myScrollHandler = function()
\r
2122 arguments.callee.prevScrollHandler.apply( this, arguments );
\r
2124 win.$.setTimeout( function()
\r
2126 myScrollHandler.prevScrollHandler = window.onscroll || function(){};
\r
2127 window.onscroll = myScrollHandler;
\r
2133 function hideCover()
\r
2135 if ( !currentCover )
\r
2138 var win = CKEDITOR.document.getWindow();
\r
2139 currentCover.hide();
\r
2140 win.removeListener( 'resize', resizeCover );
\r
2142 if ( CKEDITOR.env.ie6Compat )
\r
2144 win.$.setTimeout( function()
\r
2146 var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
\r
2147 window.onscroll = prevScrollHandler || null;
\r
2150 resizeCover = null;
\r
2153 function removeCovers()
\r
2155 for ( var coverId in covers )
\r
2156 covers[ coverId ].remove();
\r
2160 var accessKeyProcessors = {};
\r
2162 var accessKeyDownHandler = function( evt )
\r
2164 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
2165 alt = evt.data.$.altKey,
\r
2166 shift = evt.data.$.shiftKey,
\r
2167 key = String.fromCharCode( evt.data.$.keyCode ),
\r
2168 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
2170 if ( !keyProcessor || !keyProcessor.length )
\r
2173 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
2174 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
2175 evt.data.preventDefault();
\r
2178 var accessKeyUpHandler = function( evt )
\r
2180 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
2181 alt = evt.data.$.altKey,
\r
2182 shift = evt.data.$.shiftKey,
\r
2183 key = String.fromCharCode( evt.data.$.keyCode ),
\r
2184 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
2186 if ( !keyProcessor || !keyProcessor.length )
\r
2189 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
2190 if ( keyProcessor.keyup )
\r
2192 keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
2193 evt.data.preventDefault();
\r
2197 var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc )
\r
2199 var procList = accessKeyProcessors[key] || ( accessKeyProcessors[key] = [] );
\r
2201 uiElement : uiElement,
\r
2204 keyup : upFunc || uiElement.accessKeyUp,
\r
2205 keydown : downFunc || uiElement.accessKeyDown
\r
2209 var unregisterAccessKey = function( obj )
\r
2211 for ( var i in accessKeyProcessors )
\r
2213 var list = accessKeyProcessors[i];
\r
2214 for ( var j = list.length - 1 ; j >= 0 ; j-- )
\r
2216 if ( list[j].dialog == obj || list[j].uiElement == obj )
\r
2217 list.splice( j, 1 );
\r
2219 if ( list.length === 0 )
\r
2220 delete accessKeyProcessors[i];
\r
2224 var tabAccessKeyUp = function( dialog, key )
\r
2226 if ( dialog._.accessKeyMap[key] )
\r
2227 dialog.selectPage( dialog._.accessKeyMap[key] );
\r
2230 var tabAccessKeyDown = function( dialog, key )
\r
2236 CKEDITOR.ui.dialog =
\r
2239 * The base class of all dialog UI elements.
\r
2241 * @param {CKEDITOR.dialog} dialog Parent dialog object.
\r
2242 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition Element
\r
2243 * definition. Accepted fields:
\r
2245 * <li><strong>id</strong> (Required) The id of the UI element. See {@link
\r
2246 * CKEDITOR.dialog#getContentElement}</li>
\r
2247 * <li><strong>type</strong> (Required) The type of the UI element. The
\r
2248 * value to this field specifies which UI element class will be used to
\r
2249 * generate the final widget.</li>
\r
2250 * <li><strong>title</strong> (Optional) The popup tooltip for the UI
\r
2252 * <li><strong>hidden</strong> (Optional) A flag that tells if the element
\r
2253 * should be initially visible.</li>
\r
2254 * <li><strong>className</strong> (Optional) Additional CSS class names
\r
2255 * to add to the UI element. Separated by space.</li>
\r
2256 * <li><strong>style</strong> (Optional) Additional CSS inline styles
\r
2257 * to add to the UI element. A semicolon (;) is required after the last
\r
2258 * style declaration.</li>
\r
2259 * <li><strong>accessKey</strong> (Optional) The alphanumeric access key
\r
2260 * for this element. Access keys are automatically prefixed by CTRL.</li>
\r
2261 * <li><strong>on*</strong> (Optional) Any UI element definition field that
\r
2262 * starts with <em>on</em> followed immediately by a capital letter and
\r
2263 * probably more letters is an event handler. Event handlers may be further
\r
2264 * divided into registered event handlers and DOM event handlers. Please
\r
2265 * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and
\r
2266 * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more
\r
2267 * information.</li>
\r
2269 * @param {Array} htmlList
\r
2270 * List of HTML code to be added to the dialog's content area.
\r
2271 * @param {Function|String} nodeNameArg
\r
2272 * A function returning a string, or a simple string for the node name for
\r
2273 * the root DOM node. Default is 'div'.
\r
2274 * @param {Function|Object} stylesArg
\r
2275 * A function returning an object, or a simple object for CSS styles applied
\r
2276 * to the DOM node. Default is empty object.
\r
2277 * @param {Function|Object} attributesArg
\r
2278 * A fucntion returning an object, or a simple object for attributes applied
\r
2279 * to the DOM node. Default is empty object.
\r
2280 * @param {Function|String} contentsArg
\r
2281 * A function returning a string, or a simple string for the HTML code inside
\r
2282 * the root DOM node. Default is empty string.
\r
2285 uiElement : function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg )
\r
2287 if ( arguments.length < 4 )
\r
2290 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',
\r
2291 html = [ '<', nodeName, ' ' ],
\r
2292 styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},
\r
2293 attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},
\r
2294 innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',
\r
2295 domId = this.domId = attributes.id || CKEDITOR.tools.getNextId() + '_uiElement',
\r
2296 id = this.id = elementDefinition.id,
\r
2299 // Set the id, a unique id is required for getElement() to work.
\r
2300 attributes.id = domId;
\r
2302 // Set the type and definition CSS class names.
\r
2304 if ( elementDefinition.type )
\r
2305 classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;
\r
2306 if ( elementDefinition.className )
\r
2307 classes[ elementDefinition.className ] = 1;
\r
2308 if ( elementDefinition.disabled )
\r
2309 classes[ 'cke_disabled' ] = 1;
\r
2311 var attributeClasses = ( attributes['class'] && attributes['class'].split ) ? attributes['class'].split( ' ' ) : [];
\r
2312 for ( i = 0 ; i < attributeClasses.length ; i++ )
\r
2314 if ( attributeClasses[i] )
\r
2315 classes[ attributeClasses[i] ] = 1;
\r
2317 var finalClasses = [];
\r
2318 for ( i in classes )
\r
2319 finalClasses.push( i );
\r
2320 attributes['class'] = finalClasses.join( ' ' );
\r
2322 // Set the popup tooltop.
\r
2323 if ( elementDefinition.title )
\r
2324 attributes.title = elementDefinition.title;
\r
2326 // Write the inline CSS styles.
\r
2327 var styleStr = ( elementDefinition.style || '' ).split( ';' );
\r
2329 // Element alignment support.
\r
2330 if ( elementDefinition.align )
\r
2332 var align = elementDefinition.align;
\r
2333 styles[ 'margin-left' ] = align == 'left' ? 0 : 'auto';
\r
2334 styles[ 'margin-right' ] = align == 'right' ? 0 : 'auto';
\r
2337 for ( i in styles )
\r
2338 styleStr.push( i + ':' + styles[i] );
\r
2339 if ( elementDefinition.hidden )
\r
2340 styleStr.push( 'display:none' );
\r
2341 for ( i = styleStr.length - 1 ; i >= 0 ; i-- )
\r
2343 if ( styleStr[i] === '' )
\r
2344 styleStr.splice( i, 1 );
\r
2346 if ( styleStr.length > 0 )
\r
2347 attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
\r
2349 // Write the attributes.
\r
2350 for ( i in attributes )
\r
2351 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '" ');
\r
2353 // Write the content HTML.
\r
2354 html.push( '>', innerHTML, '</', nodeName, '>' );
\r
2356 // Add contents to the parent HTML array.
\r
2357 htmlList.push( html.join( '' ) );
\r
2359 ( this._ || ( this._ = {} ) ).dialog = dialog;
\r
2361 // Override isChanged if it is defined in element definition.
\r
2362 if ( typeof( elementDefinition.isChanged ) == 'boolean' )
\r
2363 this.isChanged = function(){ return elementDefinition.isChanged; };
\r
2364 if ( typeof( elementDefinition.isChanged ) == 'function' )
\r
2365 this.isChanged = elementDefinition.isChanged;
\r
2367 // Overload 'get(set)Value' on definition.
\r
2368 if ( typeof( elementDefinition.setValue ) == 'function' )
\r
2370 this.setValue = CKEDITOR.tools.override( this.setValue, function( org )
\r
2372 return function( val ){ org.call( this, elementDefinition.setValue.call( this, val ) ); };
\r
2376 if ( typeof( elementDefinition.getValue ) == 'function' )
\r
2378 this.getValue = CKEDITOR.tools.override( this.getValue, function( org )
\r
2380 return function(){ return elementDefinition.getValue.call( this, org.call( this ) ); };
\r
2385 CKEDITOR.event.implementOn( this );
\r
2387 this.registerEvents( elementDefinition );
\r
2388 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
\r
2389 registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
\r
2392 dialog.on( 'load', function()
\r
2394 var input = me.getInputElement();
\r
2397 var focusClass = me.type in { 'checkbox' : 1, 'ratio' : 1 } && CKEDITOR.env.ie && CKEDITOR.env.version < 8 ? 'cke_dialog_ui_focused' : '';
\r
2398 input.on( 'focus', function()
\r
2400 dialog._.tabBarMode = false;
\r
2401 dialog._.hasFocus = true;
\r
2402 me.fire( 'focus' );
\r
2403 focusClass && this.addClass( focusClass );
\r
2407 input.on( 'blur', function()
\r
2409 me.fire( 'blur' );
\r
2410 focusClass && this.removeClass( focusClass );
\r
2415 // Register the object as a tab focus if it can be included.
\r
2416 if ( this.keyboardFocusable )
\r
2418 this.tabIndex = elementDefinition.tabIndex || 0;
\r
2420 this.focusIndex = dialog._.focusList.push( this ) - 1;
\r
2421 this.on( 'focus', function()
\r
2423 dialog._.currentFocusIndex = me.focusIndex;
\r
2427 // Completes this object with everything we have in the
\r
2429 CKEDITOR.tools.extend( this, elementDefinition );
\r
2433 * Horizontal layout box for dialog UI elements, auto-expends to available width of container.
\r
2435 * @extends CKEDITOR.ui.dialog.uiElement
\r
2436 * @param {CKEDITOR.dialog} dialog
\r
2437 * Parent dialog object.
\r
2438 * @param {Array} childObjList
\r
2439 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2441 * @param {Array} childHtmlList
\r
2442 * Array of HTML code that correspond to the HTML output of all the
\r
2443 * objects in childObjList.
\r
2444 * @param {Array} htmlList
\r
2445 * Array of HTML code that this element will output to.
\r
2446 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
\r
2447 * The element definition. Accepted fields:
\r
2449 * <li><strong>widths</strong> (Optional) The widths of child cells.</li>
\r
2450 * <li><strong>height</strong> (Optional) The height of the layout.</li>
\r
2451 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2453 * <li><strong>align</strong> (Optional) The alignment of the whole layout
\r
2458 hbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2460 if ( arguments.length < 4 )
\r
2463 this._ || ( this._ = {} );
\r
2465 var children = this._.children = childObjList,
\r
2466 widths = elementDefinition && elementDefinition.widths || null,
\r
2467 height = elementDefinition && elementDefinition.height || null,
\r
2471 var innerHTML = function()
\r
2473 var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];
\r
2474 for ( i = 0 ; i < childHtmlList.length ; i++ )
\r
2476 var className = 'cke_dialog_ui_hbox_child',
\r
2479 className = 'cke_dialog_ui_hbox_first';
\r
2480 if ( i == childHtmlList.length - 1 )
\r
2481 className = 'cke_dialog_ui_hbox_last';
\r
2482 html.push( '<td class="', className, '" role="presentation" ' );
\r
2486 styles.push( 'width:' + cssLength( widths[i] ) );
\r
2489 styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2491 styles.push( 'height:' + cssLength( height ) );
\r
2492 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2493 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
\r
2494 // In IE Quirks alignment has to be done on table cells. (#7324)
\r
2495 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && children[ i ].align )
\r
2496 styles.push( 'text-align:' + children[ i ].align );
\r
2497 if ( styles.length > 0 )
\r
2498 html.push( 'style="' + styles.join('; ') + '" ' );
\r
2499 html.push( '>', childHtmlList[i], '</td>' );
\r
2501 html.push( '</tr></tbody>' );
\r
2502 return html.join( '' );
\r
2505 var attribs = { role : 'presentation' };
\r
2506 elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );
\r
2508 CKEDITOR.ui.dialog.uiElement.call(
\r
2511 elementDefinition || { type : 'hbox' },
\r
2520 * Vertical layout box for dialog UI elements.
\r
2522 * @extends CKEDITOR.ui.dialog.hbox
\r
2523 * @param {CKEDITOR.dialog} dialog
\r
2524 * Parent dialog object.
\r
2525 * @param {Array} childObjList
\r
2526 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2528 * @param {Array} childHtmlList
\r
2529 * Array of HTML code that correspond to the HTML output of all the
\r
2530 * objects in childObjList.
\r
2531 * @param {Array} htmlList
\r
2532 * Array of HTML code that this element will output to.
\r
2533 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
\r
2534 * The element definition. Accepted fields:
\r
2536 * <li><strong>width</strong> (Optional) The width of the layout.</li>
\r
2537 * <li><strong>heights</strong> (Optional) The heights of individual cells.
\r
2539 * <li><strong>align</strong> (Optional) The alignment of the layout.</li>
\r
2540 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2542 * <li><strong>expand</strong> (Optional) Whether the layout should expand
\r
2543 * vertically to fill its container.</li>
\r
2547 vbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2549 if ( arguments.length < 3 )
\r
2552 this._ || ( this._ = {} );
\r
2554 var children = this._.children = childObjList,
\r
2555 width = elementDefinition && elementDefinition.width || null,
\r
2556 heights = elementDefinition && elementDefinition.heights || null;
\r
2558 var innerHTML = function()
\r
2560 var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];
\r
2561 html.push( 'style="' );
\r
2562 if ( elementDefinition && elementDefinition.expand )
\r
2563 html.push( 'height:100%;' );
\r
2564 html.push( 'width:' + cssLength( width || '100%' ), ';' );
\r
2566 html.push( 'align="', CKEDITOR.tools.htmlEncode(
\r
2567 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
\r
2569 html.push( '><tbody>' );
\r
2570 for ( var i = 0 ; i < childHtmlList.length ; i++ )
\r
2573 html.push( '<tr><td role="presentation" ' );
\r
2575 styles.push( 'width:' + cssLength( width || '100%' ) );
\r
2577 styles.push( 'height:' + cssLength( heights[i] ) );
\r
2578 else if ( elementDefinition && elementDefinition.expand )
\r
2579 styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2580 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2581 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
\r
2582 // In IE Quirks alignment has to be done on table cells. (#7324)
\r
2583 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && children[ i ].align )
\r
2584 styles.push( 'text-align:' + children[ i ].align );
\r
2585 if ( styles.length > 0 )
\r
2586 html.push( 'style="', styles.join( '; ' ), '" ' );
\r
2587 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[i], '</td></tr>' );
\r
2589 html.push( '</tbody></table>' );
\r
2590 return html.join( '' );
\r
2592 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type : 'vbox' }, htmlList, 'div', null, { role : 'presentation' }, innerHTML );
\r
2597 CKEDITOR.ui.dialog.uiElement.prototype =
\r
2600 * Gets the root DOM element of this dialog UI object.
\r
2601 * @returns {CKEDITOR.dom.element} Root DOM element of UI object.
\r
2603 * uiElement.getElement().hide();
\r
2605 getElement : function()
\r
2607 return CKEDITOR.document.getById( this.domId );
\r
2611 * Gets the DOM element that the user inputs values.
\r
2612 * This function is used by setValue(), getValue() and focus(). It should
\r
2613 * be overrided in child classes where the input element isn't the root
\r
2615 * @returns {CKEDITOR.dom.element} The element where the user input values.
\r
2617 * var rawValue = textInput.getInputElement().$.value;
\r
2619 getInputElement : function()
\r
2621 return this.getElement();
\r
2625 * Gets the parent dialog object containing this UI element.
\r
2626 * @returns {CKEDITOR.dialog} Parent dialog object.
\r
2628 * var dialog = uiElement.getDialog();
\r
2630 getDialog : function()
\r
2632 return this._.dialog;
\r
2636 * Sets the value of this dialog UI object.
\r
2637 * @param {Object} value The new value.
\r
2638 * @param {Boolean} noChangeEvent Internal commit, to supress 'change' event on this element.
\r
2639 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2641 * uiElement.setValue( 'Dingo' );
\r
2643 setValue : function( value, noChangeEvent )
\r
2645 this.getInputElement().setValue( value );
\r
2646 !noChangeEvent && this.fire( 'change', { value : value } );
\r
2651 * Gets the current value of this dialog UI object.
\r
2652 * @returns {Object} The current value.
\r
2654 * var myValue = uiElement.getValue();
\r
2656 getValue : function()
\r
2658 return this.getInputElement().getValue();
\r
2662 * Tells whether the UI object's value has changed.
\r
2663 * @returns {Boolean} true if changed, false if not changed.
\r
2665 * if ( uiElement.isChanged() )
\r
2666 * confirm( 'Value changed! Continue?' );
\r
2668 isChanged : function()
\r
2670 // Override in input classes.
\r
2675 * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
\r
2676 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2678 * focus : function()
\r
2680 * this.selectParentTab();
\r
2681 * // do something else.
\r
2684 selectParentTab : function()
\r
2686 var element = this.getInputElement(),
\r
2689 while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 )
\r
2692 // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
\r
2696 tabId = cursor.getAttribute( 'name' );
\r
2697 // Avoid duplicate select.
\r
2698 if ( this._.dialog._.currentTabId != tabId )
\r
2699 this._.dialog.selectPage( tabId );
\r
2704 * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
\r
2705 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2707 * uiElement.focus();
\r
2709 focus : function()
\r
2711 this.selectParentTab().getInputElement().focus();
\r
2716 * Registers the on* event handlers defined in the element definition.
\r
2717 * The default behavior of this function is:
\r
2720 * If the on* event is defined in the class's eventProcesors list,
\r
2721 * then the registration is delegated to the corresponding function
\r
2722 * in the eventProcessors list.
\r
2725 * If the on* event is not defined in the eventProcessors list, then
\r
2726 * register the event handler under the corresponding DOM event of
\r
2727 * the UI element's input DOM element (as defined by the return value
\r
2728 * of {@link CKEDITOR.ui.dialog.uiElement#getInputElement}).
\r
2731 * This function is only called at UI element instantiation, but can
\r
2732 * be overridded in child classes if they require more flexibility.
\r
2733 * @param {CKEDITOR.dialog.definition.uiElement} definition The UI element
\r
2735 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2738 registerEvents : function( definition )
\r
2740 var regex = /^on([A-Z]\w+)/,
\r
2743 var registerDomEvent = function( uiElement, dialog, eventName, func )
\r
2745 dialog.on( 'load', function()
\r
2747 uiElement.getInputElement().on( eventName, func, uiElement );
\r
2751 for ( var i in definition )
\r
2753 if ( !( match = i.match( regex ) ) )
\r
2755 if ( this.eventProcessors[i] )
\r
2756 this.eventProcessors[i].call( this, this._.dialog, definition[i] );
\r
2758 registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
\r
2765 * The event processor list used by
\r
2766 * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element
\r
2767 * instantiation. The default list defines three on* events:
\r
2769 * <li>onLoad - Called when the element's parent dialog opens for the
\r
2771 * <li>onShow - Called whenever the element's parent dialog opens.</li>
\r
2772 * <li>onHide - Called whenever the element's parent dialog closes.</li>
\r
2777 * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick
\r
2778 * // handlers in the UI element's definitions.
\r
2779 * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},
\r
2780 * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
\r
2781 * { onClick : function( dialog, func ) { this.on( 'click', func ); } },
\r
2782 * true );
\r
2786 onLoad : function( dialog, func )
\r
2788 dialog.on( 'load', func, this );
\r
2791 onShow : function( dialog, func )
\r
2793 dialog.on( 'show', func, this );
\r
2796 onHide : function( dialog, func )
\r
2798 dialog.on( 'hide', func, this );
\r
2803 * The default handler for a UI element's access key down event, which
\r
2804 * tries to put focus to the UI element.<br />
\r
2805 * Can be overridded in child classes for more sophisticaed behavior.
\r
2806 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2807 * @param {String} key The key combination pressed. Since access keys
\r
2808 * are defined to always include the CTRL key, its value should always
\r
2809 * include a 'CTRL+' prefix.
\r
2812 accessKeyDown : function( dialog, key )
\r
2818 * The default handler for a UI element's access key up event, which
\r
2819 * does nothing.<br />
\r
2820 * Can be overridded in child classes for more sophisticated behavior.
\r
2821 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2822 * @param {String} key The key combination pressed. Since access keys
\r
2823 * are defined to always include the CTRL key, its value should always
\r
2824 * include a 'CTRL+' prefix.
\r
2827 accessKeyUp : function( dialog, key )
\r
2832 * Disables a UI element.
\r
2835 disable : function()
\r
2837 var element = this.getElement(),
\r
2838 input = this.getInputElement();
\r
2839 input.setAttribute( 'disabled', 'true' );
\r
2840 element.addClass( 'cke_disabled' );
\r
2844 * Enables a UI element.
\r
2847 enable : function()
\r
2849 var element = this.getElement(),
\r
2850 input = this.getInputElement();
\r
2851 input.removeAttribute( 'disabled' );
\r
2852 element.removeClass( 'cke_disabled' );
\r
2856 * Determines whether an UI element is enabled or not.
\r
2857 * @returns {Boolean} Whether the UI element is enabled.
\r
2860 isEnabled : function()
\r
2862 return !this.getElement().hasClass( 'cke_disabled' );
\r
2866 * Determines whether an UI element is visible or not.
\r
2867 * @returns {Boolean} Whether the UI element is visible.
\r
2870 isVisible : function()
\r
2872 return this.getInputElement().isVisible();
\r
2876 * Determines whether an UI element is focus-able or not.
\r
2877 * Focus-able is defined as being both visible and enabled.
\r
2878 * @returns {Boolean} Whether the UI element can be focused.
\r
2881 isFocusable : function()
\r
2883 if ( !this.isEnabled() || !this.isVisible() )
\r
2889 CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
\r
2891 * @lends CKEDITOR.ui.dialog.hbox.prototype
\r
2895 * Gets a child UI element inside this container.
\r
2896 * @param {Array|Number} indices An array or a single number to indicate the child's
\r
2897 * position in the container's descendant tree. Omit to get all the children in an array.
\r
2898 * @returns {Array|CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container
\r
2899 * if no argument given, or the specified UI element if indices is given.
\r
2901 * var checkbox = hbox.getChild( [0,1] );
\r
2902 * checkbox.setValue( true );
\r
2904 getChild : function( indices )
\r
2906 // If no arguments, return a clone of the children array.
\r
2907 if ( arguments.length < 1 )
\r
2908 return this._.children.concat();
\r
2910 // If indices isn't array, make it one.
\r
2911 if ( !indices.splice )
\r
2912 indices = [ indices ];
\r
2914 // Retrieve the child element according to tree position.
\r
2915 if ( indices.length < 2 )
\r
2916 return this._.children[ indices[0] ];
\r
2918 return ( this._.children[ indices[0] ] && this._.children[ indices[0] ].getChild ) ?
\r
2919 this._.children[ indices[0] ].getChild( indices.slice( 1, indices.length ) ) :
\r
2924 CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
\r
2930 var commonBuilder = {
\r
2931 build : function( dialog, elementDefinition, output )
\r
2933 var children = elementDefinition.children,
\r
2935 childHtmlList = [],
\r
2936 childObjList = [];
\r
2937 for ( var i = 0 ; ( i < children.length && ( child = children[i] ) ) ; i++ )
\r
2939 var childHtml = [];
\r
2940 childHtmlList.push( childHtml );
\r
2941 childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
\r
2943 return new CKEDITOR.ui.dialog[elementDefinition.type]( dialog, childObjList, childHtmlList, output, elementDefinition );
\r
2947 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
\r
2948 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
\r
2952 * Generic dialog command. It opens a specific dialog when executed.
\r
2954 * @augments CKEDITOR.commandDefinition
\r
2955 * @param {string} dialogName The name of the dialog to open when executing
\r
2958 * // Register the "link" command, which opens the "link" dialog.
\r
2959 * editor.addCommand( 'link', <b>new CKEDITOR.dialogCommand( 'link' )</b> );
\r
2961 CKEDITOR.dialogCommand = function( dialogName )
\r
2963 this.dialogName = dialogName;
\r
2966 CKEDITOR.dialogCommand.prototype =
\r
2969 exec : function( editor )
\r
2971 // Special treatment for Opera. (#8031)
\r
2972 CKEDITOR.env.opera ?
\r
2973 CKEDITOR.tools.setTimeout( function() { editor.openDialog( this.dialogName ); }, 0, this )
\r
2974 : editor.openDialog( this.dialogName );
\r
2977 // Dialog commands just open a dialog ui, thus require no undo logic,
\r
2978 // undo support should dedicate to specific dialog implementation.
\r
2981 editorFocus : CKEDITOR.env.ie || CKEDITOR.env.webkit
\r
2986 var notEmptyRegex = /^([a]|[^a])+$/,
\r
2987 integerRegex = /^\d*$/,
\r
2988 numberRegex = /^\d*(?:\.\d+)?$/,
\r
2989 htmlLengthRegex = /^(((\d*(\.\d+))|(\d*))(px|\%)?)?$/,
\r
2990 cssLengthRegex = /^(((\d*(\.\d+))|(\d*))(px|em|ex|in|cm|mm|pt|pc|\%)?)?$/i,
\r
2991 inlineStyleRegex = /^(\s*[\w-]+\s*:\s*[^:;]+(?:;|$))*$/;
\r
2993 CKEDITOR.VALIDATE_OR = 1;
\r
2994 CKEDITOR.VALIDATE_AND = 2;
\r
2996 CKEDITOR.dialog.validate =
\r
2998 functions : function()
\r
3000 var args = arguments;
\r
3004 * It's important for validate functions to be able to accept the value
\r
3005 * as argument in addition to this.getValue(), so that it is possible to
\r
3006 * combine validate functions together to make more sophisticated
\r
3009 var value = this && this.getValue ? this.getValue() : args[ 0 ];
\r
3011 var msg = undefined,
\r
3012 relation = CKEDITOR.VALIDATE_AND,
\r
3013 functions = [], i;
\r
3015 for ( i = 0 ; i < args.length ; i++ )
\r
3017 if ( typeof( args[i] ) == 'function' )
\r
3018 functions.push( args[i] );
\r
3023 if ( i < args.length && typeof( args[i] ) == 'string' )
\r
3029 if ( i < args.length && typeof( args[i]) == 'number' )
\r
3030 relation = args[i];
\r
3032 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );
\r
3033 for ( i = 0 ; i < functions.length ; i++ )
\r
3035 if ( relation == CKEDITOR.VALIDATE_AND )
\r
3036 passed = passed && functions[i]( value );
\r
3038 passed = passed || functions[i]( value );
\r
3041 return !passed ? msg : true;
\r
3045 regex : function( regex, msg )
\r
3048 * Can be greatly shortened by deriving from functions validator if code size
\r
3049 * turns out to be more important than performance.
\r
3053 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
3054 return !regex.test( value ) ? msg : true;
\r
3058 notEmpty : function( msg )
\r
3060 return this.regex( notEmptyRegex, msg );
\r
3063 integer : function( msg )
\r
3065 return this.regex( integerRegex, msg );
\r
3068 'number' : function( msg )
\r
3070 return this.regex( numberRegex, msg );
\r
3073 'cssLength' : function( msg )
\r
3075 return this.functions( function( val ){ return cssLengthRegex.test( CKEDITOR.tools.trim( val ) ); }, msg );
\r
3078 'htmlLength' : function( msg )
\r
3080 return this.functions( function( val ){ return htmlLengthRegex.test( CKEDITOR.tools.trim( val ) ); }, msg );
\r
3083 'inlineStyle' : function( msg )
\r
3085 return this.functions( function( val ){ return inlineStyleRegex.test( CKEDITOR.tools.trim( val ) ); }, msg );
\r
3088 equals : function( value, msg )
\r
3090 return this.functions( function( val ){ return val == value; }, msg );
\r
3093 notEqual : function( value, msg )
\r
3095 return this.functions( function( val ){ return val != value; }, msg );
\r
3099 CKEDITOR.on( 'instanceDestroyed', function( evt )
\r
3101 // Remove dialog cover on last instance destroy.
\r
3102 if ( CKEDITOR.tools.isEmpty( CKEDITOR.instances ) )
\r
3104 var currentTopDialog;
\r
3105 while ( ( currentTopDialog = CKEDITOR.dialog._.currentTop ) )
\r
3106 currentTopDialog.hide();
\r
3110 var dialogs = evt.editor._.storedDialogs;
\r
3111 for ( var name in dialogs )
\r
3112 dialogs[ name ].destroy();
\r
3118 // Extend the CKEDITOR.editor class with dialog specific functions.
\r
3119 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
\r
3120 /** @lends CKEDITOR.editor.prototype */
\r
3123 * Loads and opens a registered dialog.
\r
3124 * @param {String} dialogName The registered name of the dialog.
\r
3125 * @param {Function} callback The function to be invoked after dialog instance created.
\r
3126 * @see CKEDITOR.dialog.add
\r
3128 * CKEDITOR.instances.editor1.openDialog( 'smiley' );
\r
3129 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed. null if the dialog name is not registered.
\r
3131 openDialog : function( dialogName, callback )
\r
3133 if ( this.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
3135 var selection = this.getSelection();
\r
3136 selection && selection.lock();
\r
3139 var dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
3140 dialogSkin = this.skin.dialog;
\r
3142 if ( CKEDITOR.dialog._.currentTop === null )
\r
3143 showCover( this );
\r
3145 // If the dialogDefinition is already loaded, open it immediately.
\r
3146 if ( typeof dialogDefinitions == 'function' && dialogSkin._isLoaded )
\r
3148 var storedDialogs = this._.storedDialogs ||
\r
3149 ( this._.storedDialogs = {} );
\r
3151 var dialog = storedDialogs[ dialogName ] ||
\r
3152 ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
\r
3154 callback && callback.call( dialog, dialog );
\r
3159 else if ( dialogDefinitions == 'failed' )
\r
3162 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
\r
3167 function onDialogFileLoaded( success )
\r
3169 var dialogDefinition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
3170 skin = me.skin.dialog;
\r
3172 // Check if both skin part and definition is loaded.
\r
3173 if ( !skin._isLoaded || loadDefinition && typeof success == 'undefined' )
\r
3176 // In case of plugin error, mark it as loading failed.
\r
3177 if ( typeof dialogDefinition != 'function' )
\r
3178 CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';
\r
3180 me.openDialog( dialogName, callback );
\r
3183 if ( typeof dialogDefinitions == 'string' )
\r
3185 var loadDefinition = 1;
\r
3186 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ), onDialogFileLoaded, null, 0, 1 );
\r
3189 CKEDITOR.skins.load( this, 'dialog', onDialogFileLoaded );
\r
3196 CKEDITOR.plugins.add( 'dialog',
\r
3198 requires : [ 'dialogui' ]
\r
3201 // Dialog related configurations.
\r
3204 * The color of the dialog background cover. It should be a valid CSS color
\r
3206 * @name CKEDITOR.config.dialog_backgroundCoverColor
\r
3208 * @default 'white'
\r
3210 * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
\r
3214 * The opacity of the dialog background cover. It should be a number within the
\r
3215 * range [0.0, 1.0].
\r
3216 * @name CKEDITOR.config.dialog_backgroundCoverOpacity
\r
3220 * config.dialog_backgroundCoverOpacity = 0.7;
\r
3224 * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.
\r
3225 * @name CKEDITOR.config.dialog_startupFocusTab
\r
3229 * config.dialog_startupFocusTab = true;
\r
3233 * The distance of magnetic borders used in moving and resizing dialogs,
\r
3234 * measured in pixels.
\r
3235 * @name CKEDITOR.config.dialog_magnetDistance
\r
3239 * config.dialog_magnetDistance = 30;
\r
3243 * The guideline to follow when generating the dialog buttons. There are 3 possible options:
\r
3245 * <li>'OS' - the buttons will be displayed in the default order of the user's OS;</li>
\r
3246 * <li>'ltr' - for Left-To-Right order;</li>
\r
3247 * <li>'rtl' - for Right-To-Left order.</li>
\r
3249 * @name CKEDITOR.config.dialog_buttonsOrder
\r
3254 * config.dialog_buttonsOrder = 'rtl';
\r
3258 * The dialog contents to removed. It's a string composed by dialog name and tab name with a colon between them.
\r
3259 * Separate each pair with semicolon (see example).
\r
3260 * <b>Note: All names are case-sensitive.</b>
\r
3261 * <b>Note: Be cautious when specifying dialog tabs that are mandatory, like "info", dialog functionality might be broken because of this!</b>
\r
3262 * @name CKEDITOR.config.removeDialogTabs
\r
3267 * config.removeDialogTabs = 'flash:advanced;image:Link';
\r
3271 * Fired when a dialog definition is about to be used to create a dialog into
\r
3272 * an editor instance. This event makes it possible to customize the definition
\r
3273 * before creating it.
\r
3274 * <p>Note that this event is called only the first time a specific dialog is
\r
3275 * opened. Successive openings will use the cached dialog, and this event will
\r
3276 * not get fired.</p>
\r
3277 * @name CKEDITOR#dialogDefinition
\r
3279 * @param {CKEDITOR.dialog.definition} data The dialog defination that
\r
3280 * is being loaded.
\r
3281 * @param {CKEDITOR.editor} editor The editor instance that will use the
\r
3286 * Fired when a tab is going to be selected in a dialog
\r
3287 * @name CKEDITOR.dialog#selectPage
\r
3289 * @param {String} page The id of the page that it's gonna be selected.
\r
3290 * @param {String} currentPage The id of the current page.
\r
3294 * Fired when the user tries to dismiss a dialog
\r
3295 * @name CKEDITOR.dialog#cancel
\r
3297 * @param {Boolean} hide Whether the event should proceed or not.
\r
3301 * Fired when the user tries to confirm a dialog
\r
3302 * @name CKEDITOR.dialog#ok
\r
3304 * @param {Boolean} hide Whether the event should proceed or not.
\r
3308 * Fired when a dialog is shown
\r
3309 * @name CKEDITOR.dialog#show
\r
3314 * Fired when a dialog is shown
\r
3315 * @name CKEDITOR.editor#dialogShow
\r
3320 * Fired when a dialog is hidden
\r
3321 * @name CKEDITOR.dialog#hide
\r
3326 * Fired when a dialog is hidden
\r
3327 * @name CKEDITOR.editor#dialogHide
\r
3332 * Fired when a dialog is being resized. The event is fired on
\r
3333 * both the 'CKEDITOR.dialog' object and the dialog instance
\r
3334 * since 3.5.3, previously it's available only in the global object.
\r
3335 * @name CKEDITOR.dialog#resize
\r
3338 * @param {CKEDITOR.dialog} dialog The dialog being resized (if
\r
3339 * it's fired on the dialog itself, this parameter isn't sent).
\r
3340 * @param {String} skin The skin name.
\r
3341 * @param {Number} width The new width.
\r
3342 * @param {Number} height The new height.
\r