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
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 focusKeydownHandler( 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 if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )
\r
412 var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
\r
414 // Handling Tab and Shift-Tab.
\r
415 if ( me._.tabBarMode )
\r
418 var nextId = shiftPressed ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );
\r
419 me.selectPage( nextId );
\r
420 me._.tabs[ nextId ][ 0 ].focus();
\r
424 // Change the focus of inputs.
\r
425 changeFocus( shiftPressed ? -1 : 1 );
\r
430 else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode && me.getPageCount() > 1 )
\r
432 // Alt-F10 puts focus into the current tab item in the tab bar.
\r
433 me._.tabBarMode = true;
\r
434 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
437 else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode )
\r
439 // Arrow keys - used for changing tabs.
\r
440 nextId = ( keystroke == ( rtl ? 39 : 37 ) ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) );
\r
441 me.selectPage( nextId );
\r
442 me._.tabs[ nextId ][ 0 ].focus();
\r
445 else if ( ( keystroke == 13 || keystroke == 32 ) && me._.tabBarMode )
\r
447 this.selectPage( this._.currentTabId );
\r
448 this._.tabBarMode = false;
\r
449 this._.currentFocusIndex = -1;
\r
457 evt.data.preventDefault();
\r
461 function focusKeyPressHandler( evt )
\r
463 processed && evt.data.preventDefault();
\r
466 var dialogElement = this._.element;
\r
467 // Add the dialog keyboard handlers.
\r
468 this.on( 'show', function()
\r
470 dialogElement.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
471 // Some browsers instead, don't cancel key events in the keydown, but in the
\r
472 // keypress. So we must do a longer trip in those cases. (#4531)
\r
473 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
474 dialogElement.on( 'keypress', focusKeyPressHandler, this );
\r
477 this.on( 'hide', function()
\r
479 dialogElement.removeListener( 'keydown', focusKeydownHandler );
\r
480 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
481 dialogElement.removeListener( 'keypress', focusKeyPressHandler );
\r
483 // Reset fields state when closing dialog.
\r
484 iterContents( function( item ) { resetField.apply( item ); } );
\r
486 this.on( 'iframeAdded', function( evt )
\r
488 var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );
\r
489 doc.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
492 // Auto-focus logic in dialog.
\r
493 this.on( 'show', function()
\r
495 // Setup tabIndex on showing the dialog instead of on loading
\r
496 // to allow dynamic tab order happen in dialog definition.
\r
499 if ( editor.config.dialog_startupFocusTab
\r
500 && me._.pageCount > 1 )
\r
502 me._.tabBarMode = true;
\r
503 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
505 else if ( !this._.hasFocus )
\r
507 this._.currentFocusIndex = -1;
\r
509 // Decide where to put the initial focus.
\r
510 if ( definition.onFocus )
\r
512 var initialFocus = definition.onFocus.call( this );
\r
513 // Focus the field that the user specified.
\r
514 initialFocus && initialFocus.focus();
\r
516 // Focus the first field in layout order.
\r
521 * IE BUG: If the initial focus went into a non-text element (e.g. button),
\r
522 * then IE would still leave the caret inside the editing area.
\r
524 if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
526 var $selection = editor.document.$.selection,
\r
527 $range = $selection.createRange();
\r
531 if ( $range.parentElement && $range.parentElement().ownerDocument == editor.document.$
\r
532 || $range.item && $range.item( 0 ).ownerDocument == editor.document.$ )
\r
534 var $myRange = document.body.createTextRange();
\r
535 $myRange.moveToElementText( this.getElement().getFirst().$ );
\r
536 $myRange.collapse( true );
\r
542 }, this, null, 0xffffffff );
\r
544 // IE6 BUG: Text fields and text areas are only half-rendered the first time the dialog appears in IE6 (#2661).
\r
545 // This is still needed after [2708] and [2709] because text fields in hidden TR tags are still broken.
\r
546 if ( CKEDITOR.env.ie6Compat )
\r
548 this.on( 'load', function( evt )
\r
550 var outer = this.getElement(),
\r
551 inner = outer.getFirst();
\r
553 inner.appendTo( outer );
\r
557 initDragAndDrop( this );
\r
558 initResizeHandles( this );
\r
560 // Insert the title.
\r
561 ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );
\r
563 // Insert the tabs and contents.
\r
564 for ( i = 0 ; i < definition.contents.length ; i++ )
\r
566 var page = definition.contents[i];
\r
567 page && this.addPage( page );
\r
570 this.parts[ 'tabs' ].on( 'click', function( evt )
\r
572 var target = evt.data.getTarget();
\r
573 // If we aren't inside a tab, bail out.
\r
574 if ( target.hasClass( 'cke_dialog_tab' ) )
\r
576 // Get the ID of the tab, without the 'cke_' prefix and the unique number suffix.
\r
577 var id = target.$.id;
\r
578 this.selectPage( id.substring( 4, id.lastIndexOf( '_' ) ) );
\r
580 if ( this._.tabBarMode )
\r
582 this._.tabBarMode = false;
\r
583 this._.currentFocusIndex = -1;
\r
586 evt.data.preventDefault();
\r
591 var buttonsHtml = [],
\r
592 buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this,
\r
595 className : 'cke_dialog_footer_buttons',
\r
597 children : definition.buttons
\r
598 }, buttonsHtml ).getChild();
\r
599 this.parts.footer.setHtml( buttonsHtml.join( '' ) );
\r
601 for ( i = 0 ; i < buttons.length ; i++ )
\r
602 this._.buttons[ buttons[i].id ] = buttons[i];
\r
605 // Focusable interface. Use it via dialog.addFocusable.
\r
606 function Focusable( dialog, element, index )
\r
608 this.element = element;
\r
609 this.focusIndex = index;
\r
610 // TODO: support tabIndex for focusables.
\r
612 this.isFocusable = function()
\r
614 return !element.getAttribute( 'disabled' ) && element.isVisible();
\r
616 this.focus = function()
\r
618 dialog._.currentFocusIndex = this.focusIndex;
\r
619 this.element.focus();
\r
622 element.on( 'keydown', function( e )
\r
624 if ( e.data.getKeystroke() in { 32:1, 13:1 } )
\r
625 this.fire( 'click' );
\r
627 element.on( 'focus', function()
\r
629 this.fire( 'mouseover' );
\r
631 element.on( 'blur', function()
\r
633 this.fire( 'mouseout' );
\r
637 CKEDITOR.dialog.prototype =
\r
639 destroy : function()
\r
642 this._.element.remove();
\r
646 * Resizes the dialog.
\r
647 * @param {Number} width The width of the dialog in pixels.
\r
648 * @param {Number} height The height of the dialog in pixels.
\r
651 * dialogObj.resize( 800, 640 );
\r
653 resize : (function()
\r
655 return function( width, height )
\r
657 if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )
\r
660 CKEDITOR.dialog.fire( 'resize',
\r
663 skin : this._.editor.skinName,
\r
666 }, this._.editor );
\r
668 this.fire( 'resize',
\r
670 skin : this._.editor.skinName,
\r
673 }, this._.editor );
\r
675 // Update dialog position when dimension get changed in RTL.
\r
676 if ( this._.editor.lang.dir == 'rtl' && this._.position )
\r
677 this._.position.x = CKEDITOR.document.getWindow().getViewPaneSize().width -
\r
678 this._.contentSize.width - parseInt( this._.element.getFirst().getStyle( 'right' ), 10 );
\r
680 this._.contentSize = { width : width, height : height };
\r
685 * Gets the current size of the dialog in pixels.
\r
686 * @returns {Object} An object with "width" and "height" properties.
\r
688 * var width = dialogObj.getSize().width;
\r
690 getSize : function()
\r
692 var element = this._.element.getFirst();
\r
693 return { width : element.$.offsetWidth || 0, height : element.$.offsetHeight || 0};
\r
697 * Moves the dialog to an (x, y) coordinate relative to the window.
\r
699 * @param {Number} x The target x-coordinate.
\r
700 * @param {Number} y The target y-coordinate.
\r
701 * @param {Boolean} save Flag indicate whether the dialog position should be remembered on next open up.
\r
703 * dialogObj.move( 10, 40 );
\r
708 return function( x, y, save )
\r
710 // The dialog may be fixed positioned or absolute positioned. Ask the
\r
711 // browser what is the current situation first.
\r
712 var element = this._.element.getFirst(),
\r
713 rtl = this._.editor.lang.dir == 'rtl';
\r
715 if ( isFixed === undefined )
\r
716 isFixed = element.getComputedStyle( 'position' ) == 'fixed';
\r
718 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
\r
721 // Save the current position.
\r
722 this._.position = { x : x, y : y };
\r
724 // If not fixed positioned, add scroll position to the coordinates.
\r
727 var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
\r
728 x += scrollPosition.x;
\r
729 y += scrollPosition.y;
\r
732 // Translate coordinate for RTL.
\r
735 var dialogSize = this.getSize(),
\r
736 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize();
\r
737 x = viewPaneSize.width - dialogSize.width - x;
\r
740 var styles = { 'top' : ( y > 0 ? y : 0 ) + 'px' };
\r
741 styles[ rtl ? 'right' : 'left' ] = ( x > 0 ? x : 0 ) + 'px';
\r
743 element.setStyles( styles );
\r
745 save && ( this._.moved = 1 );
\r
750 * Gets the dialog's position in the window.
\r
751 * @returns {Object} An object with "x" and "y" properties.
\r
753 * var dialogX = dialogObj.getPosition().x;
\r
755 getPosition : function(){ return CKEDITOR.tools.extend( {}, this._.position ); },
\r
758 * Shows the dialog box.
\r
760 * dialogObj.show();
\r
764 // Insert the dialog's element to the root document.
\r
765 var element = this._.element;
\r
766 var definition = this.definition;
\r
767 if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )
\r
768 element.appendTo( CKEDITOR.document.getBody() );
\r
770 element.setStyle( 'display', 'block' );
\r
772 // FIREFOX BUG: Fix vanishing caret for Firefox 2 or Gecko 1.8.
\r
773 if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
\r
775 var dialogElement = this.parts.dialog;
\r
776 dialogElement.setStyle( 'position', 'absolute' );
\r
777 setTimeout( function()
\r
779 dialogElement.setStyle( 'position', 'fixed' );
\r
784 // First, set the dialog to an appropriate size.
\r
785 this.resize( this._.contentSize && this._.contentSize.width || definition.width || definition.minWidth,
\r
786 this._.contentSize && this._.contentSize.height || definition.height || definition.minHeight );
\r
788 // Reset all inputs back to their default value.
\r
791 // Select the first tab by default.
\r
792 this.selectPage( this.definition.contents[0].id );
\r
795 if ( CKEDITOR.dialog._.currentZIndex === null )
\r
796 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;
\r
797 this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
\r
799 // Maintain the dialog ordering and dialog cover.
\r
800 if ( CKEDITOR.dialog._.currentTop === null )
\r
802 CKEDITOR.dialog._.currentTop = this;
\r
803 this._.parentDialog = null;
\r
804 showCover( this._.editor );
\r
809 this._.parentDialog = CKEDITOR.dialog._.currentTop;
\r
810 var parentElement = this._.parentDialog.getElement().getFirst();
\r
811 parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );
\r
812 CKEDITOR.dialog._.currentTop = this;
\r
815 element.on( 'keydown', accessKeyDownHandler );
\r
816 element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
818 // Prevent some keys from bubbling up. (#4269)
\r
819 for ( var event in { keyup :1, keydown :1, keypress :1 } )
\r
820 element.on( event, preventKeyBubbling );
\r
822 // Register the Esc hotkeys.
\r
823 registerAccessKey( this, this, '\x1b', null, function()
\r
825 var button = this.getButton( 'cancel' );
\r
826 // If there's a Cancel button, click it, else just fire the cancel event and hide the dialog
\r
831 if ( this.fire( 'cancel', { hide : true } ).hide !== false )
\r
836 // Reset the hasFocus state.
\r
837 this._.hasFocus = false;
\r
839 CKEDITOR.tools.setTimeout( function()
\r
842 this.parts.dialog.setStyle( 'visibility', '' );
\r
844 // Execute onLoad for the first show.
\r
845 this.fireOnce( 'load', {} );
\r
846 CKEDITOR.ui.fire( 'ready', this );
\r
848 this.fire( 'show', {} );
\r
849 this._.editor.fire( 'dialogShow', this );
\r
851 // Save the initial values of the dialog.
\r
852 this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } );
\r
859 * Rearrange the dialog to its previous position or the middle of the window.
\r
862 layout : function()
\r
864 var viewSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
865 dialogSize = this.getSize();
\r
867 this.move( this._.moved ? this._.position.x : ( viewSize.width - dialogSize.width ) / 2,
\r
868 this._.moved ? this._.position.y : ( viewSize.height - dialogSize.height ) / 2 );
\r
872 * Executes a function for each UI element.
\r
873 * @param {Function} fn Function to execute for each UI element.
\r
874 * @returns {CKEDITOR.dialog} The current dialog object.
\r
876 foreach : function( fn )
\r
878 for ( var i in this._.contents )
\r
880 for ( var j in this._.contents[i] )
\r
881 fn.call( this, this._.contents[i][j] );
\r
887 * Resets all input values in the dialog.
\r
889 * dialogObj.reset();
\r
890 * @returns {CKEDITOR.dialog} The current dialog object.
\r
892 reset : (function()
\r
894 var fn = function( widget ){ if ( widget.reset ) widget.reset( 1 ); };
\r
895 return function(){ this.foreach( fn ); return this; };
\r
900 * Calls the {@link CKEDITOR.dialog.definition.uiElement#setup} method of each of the UI elements, with the arguments passed through it.
\r
901 * It is usually being called when the dialog is opened, to put the initial value inside the field.
\r
903 * dialogObj.setupContent();
\r
905 * var timestamp = ( new Date() ).valueOf();
\r
906 * dialogObj.setupContent( timestamp );
\r
908 setupContent : function()
\r
910 var args = arguments;
\r
911 this.foreach( function( widget )
\r
913 if ( widget.setup )
\r
914 widget.setup.apply( widget, args );
\r
919 * Calls the {@link CKEDITOR.dialog.definition.uiElement#commit} method of each of the UI elements, with the arguments passed through it.
\r
920 * It is usually being called when the user confirms the dialog, to process the values.
\r
922 * dialogObj.commitContent();
\r
924 * var timestamp = ( new Date() ).valueOf();
\r
925 * dialogObj.commitContent( timestamp );
\r
927 commitContent : function()
\r
929 var args = arguments;
\r
930 this.foreach( function( widget )
\r
932 // Make sure IE triggers "change" event on last focused input before closing the dialog. (#7915)
\r
933 if ( CKEDITOR.env.ie && this._.currentFocusIndex == widget.focusIndex )
\r
934 widget.getInputElement().$.blur();
\r
936 if ( widget.commit )
\r
937 widget.commit.apply( widget, args );
\r
942 * Hides the dialog box.
\r
944 * dialogObj.hide();
\r
948 if ( !this.parts.dialog.isVisible() )
\r
951 this.fire( 'hide', {} );
\r
952 this._.editor.fire( 'dialogHide', this );
\r
953 var element = this._.element;
\r
954 element.setStyle( 'display', 'none' );
\r
955 this.parts.dialog.setStyle( 'visibility', 'hidden' );
\r
956 // Unregister all access keys associated with this dialog.
\r
957 unregisterAccessKey( this );
\r
959 // Close any child(top) dialogs first.
\r
960 while( CKEDITOR.dialog._.currentTop != this )
\r
961 CKEDITOR.dialog._.currentTop.hide();
\r
963 // Maintain dialog ordering and remove cover if needed.
\r
964 if ( !this._.parentDialog )
\r
968 var parentElement = this._.parentDialog.getElement().getFirst();
\r
969 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
\r
971 CKEDITOR.dialog._.currentTop = this._.parentDialog;
\r
973 // Deduct or clear the z-index.
\r
974 if ( !this._.parentDialog )
\r
976 CKEDITOR.dialog._.currentZIndex = null;
\r
978 // Remove access key handlers.
\r
979 element.removeListener( 'keydown', accessKeyDownHandler );
\r
980 element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
982 // Remove bubbling-prevention handler. (#4269)
\r
983 for ( var event in { keyup :1, keydown :1, keypress :1 } )
\r
984 element.removeListener( event, preventKeyBubbling );
\r
986 var editor = this._.editor;
\r
989 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
991 var selection = editor.getSelection();
\r
992 selection && selection.unlock( true );
\r
996 CKEDITOR.dialog._.currentZIndex -= 10;
\r
998 delete this._.parentDialog;
\r
999 // Reset the initial values of the dialog.
\r
1000 this.foreach( function( contentObj ) { contentObj.resetInitValue && contentObj.resetInitValue(); } );
\r
1004 * Adds a tabbed page into the dialog.
\r
1005 * @param {Object} contents Content definition.
\r
1008 addPage : function( contents )
\r
1010 var pageHtml = [],
\r
1011 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
\r
1012 elements = contents.elements,
\r
1013 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this,
\r
1016 className : 'cke_dialog_page_contents',
\r
1017 children : contents.elements,
\r
1018 expand : !!contents.expand,
\r
1019 padding : contents.padding,
\r
1020 style : contents.style || 'width: 100%;height:100%'
\r
1023 // Create the HTML for the tab and the content block.
\r
1024 var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
\r
1025 page.setAttribute( 'role', 'tabpanel' );
\r
1027 var env = CKEDITOR.env;
\r
1028 var tabId = 'cke_' + contents.id + '_' + CKEDITOR.tools.getNextNumber(),
\r
1029 tab = CKEDITOR.dom.element.createFromHtml( [
\r
1030 '<a class="cke_dialog_tab"',
\r
1031 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),
\r
1033 ( !!contents.hidden ? ' style="display:none"' : '' ),
\r
1034 ' id="', tabId, '"',
\r
1035 env.gecko && env.version >= 10900 && !env.hc ? '' : ' href="javascript:void(0)"',
\r
1037 ' hidefocus="true"',
\r
1043 page.setAttribute( 'aria-labelledby', tabId );
\r
1045 // Take records for the tabs and elements created.
\r
1046 this._.tabs[ contents.id ] = [ tab, page ];
\r
1047 this._.tabIdList.push( contents.id );
\r
1048 !contents.hidden && this._.pageCount++;
\r
1049 this._.lastTab = tab;
\r
1050 this.updateStyle();
\r
1052 var contentMap = this._.contents[ contents.id ] = {},
\r
1054 children = vbox.getChild();
\r
1056 while ( ( cursor = children.shift() ) )
\r
1058 contentMap[ cursor.id ] = cursor;
\r
1059 if ( typeof( cursor.getChild ) == 'function' )
\r
1060 children.push.apply( children, cursor.getChild() );
\r
1063 // Attach the DOM nodes.
\r
1065 page.setAttribute( 'name', contents.id );
\r
1066 page.appendTo( this.parts.contents );
\r
1068 tab.unselectable();
\r
1069 this.parts.tabs.append( tab );
\r
1071 // Add access key handlers if access key is defined.
\r
1072 if ( contents.accessKey )
\r
1074 registerAccessKey( this, this, 'CTRL+' + contents.accessKey,
\r
1075 tabAccessKeyDown, tabAccessKeyUp );
\r
1076 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;
\r
1081 * Activates a tab page in the dialog by its id.
\r
1082 * @param {String} id The id of the dialog tab to be activated.
\r
1084 * dialogObj.selectPage( 'tab_1' );
\r
1086 selectPage : function( id )
\r
1088 if ( this._.currentTabId == id )
\r
1091 // Returning true means that the event has been canceled
\r
1092 if ( this.fire( 'selectPage', { page : id, currentPage : this._.currentTabId } ) === true )
\r
1095 // Hide the non-selected tabs and pages.
\r
1096 for ( var i in this._.tabs )
\r
1098 var tab = this._.tabs[i][0],
\r
1099 page = this._.tabs[i][1];
\r
1102 tab.removeClass( 'cke_dialog_tab_selected' );
\r
1105 page.setAttribute( 'aria-hidden', i != id );
\r
1108 var selected = this._.tabs[ id ];
\r
1109 selected[ 0 ].addClass( 'cke_dialog_tab_selected' );
\r
1111 // [IE] an invisible input[type='text'] will enlarge it's width
\r
1112 // if it's value is long when it shows, so we clear it's value
\r
1113 // before it shows and then recover it (#5649)
\r
1114 if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat )
\r
1116 clearOrRecoverTextInputValue( selected[ 1 ] );
\r
1117 selected[ 1 ].show();
\r
1118 setTimeout( function()
\r
1120 clearOrRecoverTextInputValue( selected[ 1 ], 1 );
\r
1124 selected[ 1 ].show();
\r
1126 this._.currentTabId = id;
\r
1127 this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
\r
1130 // Dialog state-specific style updates.
\r
1131 updateStyle : function()
\r
1133 // If only a single page shown, a different style is used in the central pane.
\r
1134 this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );
\r
1138 * Hides a page's tab away from the dialog.
\r
1139 * @param {String} id The page's Id.
\r
1141 * dialog.hidePage( 'tab_3' );
\r
1143 hidePage : function( id )
\r
1145 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
1146 if ( !tab || this._.pageCount == 1 || !tab.isVisible() )
\r
1148 // Switch to other tab first when we're hiding the active tab.
\r
1149 else if ( id == this._.currentTabId )
\r
1150 this.selectPage( getPreviousVisibleTab.call( this ) );
\r
1153 this._.pageCount--;
\r
1154 this.updateStyle();
\r
1158 * Unhides a page's tab.
\r
1159 * @param {String} id The page's Id.
\r
1161 * dialog.showPage( 'tab_2' );
\r
1163 showPage : function( id )
\r
1165 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
1169 this._.pageCount++;
\r
1170 this.updateStyle();
\r
1174 * Gets the root DOM element of the dialog.
\r
1175 * @returns {CKEDITOR.dom.element} The <span> element containing this dialog.
\r
1177 * var dialogElement = dialogObj.getElement().getFirst();
\r
1178 * dialogElement.setStyle( 'padding', '5px' );
\r
1180 getElement : function()
\r
1182 return this._.element;
\r
1186 * Gets the name of the dialog.
\r
1187 * @returns {String} The name of this dialog.
\r
1189 * var dialogName = dialogObj.getName();
\r
1191 getName : function()
\r
1193 return this._.name;
\r
1197 * Gets a dialog UI element object from a dialog page.
\r
1198 * @param {String} pageId id of dialog page.
\r
1199 * @param {String} elementId id of UI element.
\r
1201 * dialogObj.getContentElement( 'tabId', 'elementId' ).setValue( 'Example' );
\r
1202 * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.
\r
1204 getContentElement : function( pageId, elementId )
\r
1206 var page = this._.contents[ pageId ];
\r
1207 return page && page[ elementId ];
\r
1211 * Gets the value of a dialog UI element.
\r
1212 * @param {String} pageId id of dialog page.
\r
1213 * @param {String} elementId id of UI element.
\r
1215 * alert( dialogObj.getValueOf( 'tabId', 'elementId' ) );
\r
1216 * @returns {Object} The value of the UI element.
\r
1218 getValueOf : function( pageId, elementId )
\r
1220 return this.getContentElement( pageId, elementId ).getValue();
\r
1224 * Sets the value of a dialog UI element.
\r
1225 * @param {String} pageId id of the dialog page.
\r
1226 * @param {String} elementId id of the UI element.
\r
1227 * @param {Object} value The new value of the UI element.
\r
1229 * dialogObj.setValueOf( 'tabId', 'elementId', 'Example' );
\r
1231 setValueOf : function( pageId, elementId, value )
\r
1233 return this.getContentElement( pageId, elementId ).setValue( value );
\r
1237 * Gets the UI element of a button in the dialog's button row.
\r
1238 * @param {String} id The id of the button.
\r
1240 * @returns {CKEDITOR.ui.dialog.button} The button object.
\r
1242 getButton : function( id )
\r
1244 return this._.buttons[ id ];
\r
1248 * Simulates a click to a dialog button in the dialog's button row.
\r
1249 * @param {String} id The id of the button.
\r
1251 * @returns The return value of the dialog's "click" event.
\r
1253 click : function( id )
\r
1255 return this._.buttons[ id ].click();
\r
1259 * Disables a dialog button.
\r
1260 * @param {String} id The id of the button.
\r
1263 disableButton : function( id )
\r
1265 return this._.buttons[ id ].disable();
\r
1269 * Enables a dialog button.
\r
1270 * @param {String} id The id of the button.
\r
1273 enableButton : function( id )
\r
1275 return this._.buttons[ id ].enable();
\r
1279 * Gets the number of pages in the dialog.
\r
1280 * @returns {Number} Page count.
\r
1282 getPageCount : function()
\r
1284 return this._.pageCount;
\r
1288 * Gets the editor instance which opened this dialog.
\r
1289 * @returns {CKEDITOR.editor} Parent editor instances.
\r
1291 getParentEditor : function()
\r
1293 return this._.editor;
\r
1297 * Gets the element that was selected when opening the dialog, if any.
\r
1298 * @returns {CKEDITOR.dom.element} The element that was selected, or null.
\r
1300 getSelectedElement : function()
\r
1302 return this.getParentEditor().getSelection().getSelectedElement();
\r
1306 * Adds element to dialog's focusable list.
\r
1308 * @param {CKEDITOR.dom.element} element
\r
1309 * @param {Number} [index]
\r
1311 addFocusable: function( element, index ) {
\r
1312 if ( typeof index == 'undefined' )
\r
1314 index = this._.focusList.length;
\r
1315 this._.focusList.push( new Focusable( this, element, index ) );
\r
1319 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );
\r
1320 for ( var i = index + 1 ; i < this._.focusList.length ; i++ )
\r
1321 this._.focusList[ i ].focusIndex++;
\r
1326 CKEDITOR.tools.extend( CKEDITOR.dialog,
\r
1328 * @lends CKEDITOR.dialog
\r
1332 * Registers a dialog.
\r
1333 * @param {String} name The dialog's name.
\r
1334 * @param {Function|String} dialogDefinition
\r
1335 * A function returning the dialog's definition, or the URL to the .js file holding the function.
\r
1336 * The function should accept an argument "editor" which is the current editor instance, and
\r
1337 * return an object conforming to {@link CKEDITOR.dialog.definition}.
\r
1338 * @see CKEDITOR.dialog.definition
\r
1340 * // Full sample plugin, which does not only register a dialog window but also adds an item to the context menu.
\r
1341 * // To open the dialog window, choose "Open dialog" in the context menu.
\r
1342 * CKEDITOR.plugins.add( 'myplugin',
\r
1344 * init: function( editor )
\r
1346 * editor.addCommand( 'mydialog',new CKEDITOR.dialogCommand( 'mydialog' ) );
\r
1348 * if ( editor.contextMenu )
\r
1350 * editor.addMenuGroup( 'mygroup', 10 );
\r
1351 * editor.addMenuItem( 'My Dialog',
\r
1353 * label : 'Open dialog',
\r
1354 * command : 'mydialog',
\r
1355 * group : 'mygroup'
\r
1357 * editor.contextMenu.addListener( function( element )
\r
1359 * return { 'My Dialog' : CKEDITOR.TRISTATE_OFF };
\r
1363 * <strong>CKEDITOR.dialog.add</strong>( 'mydialog', function( api )
\r
1365 * // CKEDITOR.dialog.definition
\r
1366 * var <strong>dialogDefinition</strong> =
\r
1368 * title : 'Sample dialog',
\r
1370 * minHeight : 130,
\r
1374 * label : 'Label',
\r
1375 * title : 'Title',
\r
1382 * html : '<p>This is some sample HTML content.</p>'
\r
1385 * type : 'textarea',
\r
1386 * id : 'textareaId',
\r
1393 * buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ],
\r
1394 * onOk : function() {
\r
1395 * // "this" is now a CKEDITOR.dialog object.
\r
1396 * // Accessing dialog elements:
\r
1397 * var textareaObj = this.<strong>getContentElement</strong>( 'tab1', 'textareaId' );
\r
1398 * alert( "You have entered: " + textareaObj.getValue() );
\r
1402 * return dialogDefinition;
\r
1407 * CKEDITOR.replace( 'editor1', { extraPlugins : 'myplugin' } );
\r
1409 add : function( name, dialogDefinition )
\r
1411 // Avoid path registration from multiple instances override definition.
\r
1412 if ( !this._.dialogDefinitions[name]
\r
1413 || typeof dialogDefinition == 'function' )
\r
1414 this._.dialogDefinitions[name] = dialogDefinition;
\r
1417 exists : function( name )
\r
1419 return !!this._.dialogDefinitions[ name ];
\r
1422 getCurrent : function()
\r
1424 return CKEDITOR.dialog._.currentTop;
\r
1428 * The default OK button for dialogs. Fires the "ok" event and closes the dialog if the event succeeds.
\r
1434 okButton : (function()
\r
1436 var retval = function( editor, override )
\r
1438 override = override || {};
\r
1439 return CKEDITOR.tools.extend( {
\r
1442 label : editor.lang.common.ok,
\r
1443 'class' : 'cke_dialog_ui_button_ok',
\r
1444 onClick : function( evt )
\r
1446 var dialog = evt.data.dialog;
\r
1447 if ( dialog.fire( 'ok', { hide : true } ).hide !== false )
\r
1450 }, override, true );
\r
1452 retval.type = 'button';
\r
1453 retval.override = function( override )
\r
1455 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1456 { type : 'button' }, true );
\r
1462 * The default cancel button for dialogs. Fires the "cancel" event and closes the dialog if no UI element value changed.
\r
1468 cancelButton : (function()
\r
1470 var retval = function( editor, override )
\r
1472 override = override || {};
\r
1473 return CKEDITOR.tools.extend( {
\r
1476 label : editor.lang.common.cancel,
\r
1477 'class' : 'cke_dialog_ui_button_cancel',
\r
1478 onClick : function( evt )
\r
1480 var dialog = evt.data.dialog;
\r
1481 if ( dialog.fire( 'cancel', { hide : true } ).hide !== false )
\r
1484 }, override, true );
\r
1486 retval.type = 'button';
\r
1487 retval.override = function( override )
\r
1489 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1490 { type : 'button' }, true );
\r
1496 * Registers a dialog UI element.
\r
1497 * @param {String} typeName The name of the UI element.
\r
1498 * @param {Function} builder The function to build the UI element.
\r
1501 addUIElement : function( typeName, builder )
\r
1503 this._.uiElementBuilders[ typeName ] = builder;
\r
1507 CKEDITOR.dialog._ =
\r
1509 uiElementBuilders : {},
\r
1511 dialogDefinitions : {},
\r
1513 currentTop : null,
\r
1515 currentZIndex : null
\r
1518 // "Inherit" (copy actually) from CKEDITOR.event.
\r
1519 CKEDITOR.event.implementOn( CKEDITOR.dialog );
\r
1520 CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype, true );
\r
1522 var defaultDialogDefinition =
\r
1524 resizable : CKEDITOR.DIALOG_RESIZE_BOTH,
\r
1527 buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
\r
1530 // Tool function used to return an item from an array based on its id
\r
1532 var getById = function( array, id, recurse )
\r
1534 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1536 if ( item.id == id )
\r
1538 if ( recurse && item[ recurse ] )
\r
1540 var retval = getById( item[ recurse ], id, recurse ) ;
\r
1548 // Tool function used to add an item into an array.
\r
1549 var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound )
\r
1551 if ( nextSiblingId )
\r
1553 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1555 if ( item.id == nextSiblingId )
\r
1557 array.splice( i, 0, newItem );
\r
1561 if ( recurse && item[ recurse ] )
\r
1563 var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
\r
1569 if ( nullIfNotFound )
\r
1573 array.push( newItem );
\r
1577 // Tool function used to remove an item from an array based on its id.
\r
1578 var removeById = function( array, id, recurse )
\r
1580 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1582 if ( item.id == id )
\r
1583 return array.splice( i, 1 );
\r
1584 if ( recurse && item[ recurse ] )
\r
1586 var retval = removeById( item[ recurse ], id, recurse );
\r
1595 * This class is not really part of the API. It is the "definition" property value
\r
1596 * passed to "dialogDefinition" event handlers.
\r
1598 * @name CKEDITOR.dialog.definitionObject
\r
1599 * @extends CKEDITOR.dialog.definition
\r
1601 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1603 * var definition = evt.data.definition;
\r
1604 * var content = definition.getContents( 'page1' );
\r
1608 var definitionObject = function( dialog, dialogDefinition )
\r
1610 // TODO : Check if needed.
\r
1611 this.dialog = dialog;
\r
1613 // Transform the contents entries in contentObjects.
\r
1614 var contents = dialogDefinition.contents;
\r
1615 for ( var i = 0, content ; ( content = contents[i] ) ; i++ )
\r
1616 contents[ i ] = content && new contentObject( dialog, content );
\r
1618 CKEDITOR.tools.extend( this, dialogDefinition );
\r
1621 definitionObject.prototype =
\r
1622 /** @lends CKEDITOR.dialog.definitionObject.prototype */
\r
1625 * Gets a content definition.
\r
1626 * @param {String} id The id of the content definition.
\r
1627 * @returns {CKEDITOR.dialog.definition.content} The content definition
\r
1630 getContents : function( id )
\r
1632 return getById( this.contents, id );
\r
1636 * Gets a button definition.
\r
1637 * @param {String} id The id of the button definition.
\r
1638 * @returns {CKEDITOR.dialog.definition.button} The button definition
\r
1641 getButton : function( id )
\r
1643 return getById( this.buttons, id );
\r
1647 * Adds a content definition object under this dialog definition.
\r
1648 * @param {CKEDITOR.dialog.definition.content} contentDefinition The
\r
1649 * content definition.
\r
1650 * @param {String} [nextSiblingId] The id of an existing content
\r
1651 * definition which the new content definition will be inserted
\r
1652 * before. Omit if the new content definition is to be inserted as
\r
1654 * @returns {CKEDITOR.dialog.definition.content} The inserted content
\r
1657 addContents : function( contentDefinition, nextSiblingId )
\r
1659 return addById( this.contents, contentDefinition, nextSiblingId );
\r
1663 * Adds a button definition object under this dialog definition.
\r
1664 * @param {CKEDITOR.dialog.definition.button} buttonDefinition The
\r
1665 * button definition.
\r
1666 * @param {String} [nextSiblingId] The id of an existing button
\r
1667 * definition which the new button definition will be inserted
\r
1668 * before. Omit if the new button definition is to be inserted as
\r
1670 * @returns {CKEDITOR.dialog.definition.button} The inserted button
\r
1673 addButton : function( buttonDefinition, nextSiblingId )
\r
1675 return addById( this.buttons, buttonDefinition, nextSiblingId );
\r
1679 * Removes a content definition from this dialog definition.
\r
1680 * @param {String} id The id of the content definition to be removed.
\r
1681 * @returns {CKEDITOR.dialog.definition.content} The removed content
\r
1684 removeContents : function( id )
\r
1686 removeById( this.contents, id );
\r
1690 * Removes a button definition from the dialog definition.
\r
1691 * @param {String} id The id of the button definition to be removed.
\r
1692 * @returns {CKEDITOR.dialog.definition.button} The removed button
\r
1695 removeButton : function( id )
\r
1697 removeById( this.buttons, id );
\r
1702 * This class is not really part of the API. It is the template of the
\r
1703 * objects representing content pages inside the
\r
1704 * CKEDITOR.dialog.definitionObject.
\r
1706 * @name CKEDITOR.dialog.definition.contentObject
\r
1708 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1710 * var definition = evt.data.definition;
\r
1711 * var content = definition.getContents( 'page1' );
\r
1712 * content.remove( 'textInput1' );
\r
1716 function contentObject( dialog, contentDefinition )
\r
1723 CKEDITOR.tools.extend( this, contentDefinition );
\r
1726 contentObject.prototype =
\r
1727 /** @lends CKEDITOR.dialog.definition.contentObject.prototype */
\r
1730 * Gets a UI element definition under the content definition.
\r
1731 * @param {String} id The id of the UI element definition.
\r
1732 * @returns {CKEDITOR.dialog.definition.uiElement}
\r
1734 get : function( id )
\r
1736 return getById( this.elements, id, 'children' );
\r
1740 * Adds a UI element definition to the content definition.
\r
1741 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition The
\r
1742 * UI elemnet definition to be added.
\r
1743 * @param {String} nextSiblingId The id of an existing UI element
\r
1744 * definition which the new UI element definition will be inserted
\r
1745 * before. Omit if the new button definition is to be inserted as
\r
1747 * @returns {CKEDITOR.dialog.definition.uiElement} The element
\r
1748 * definition inserted.
\r
1750 add : function( elementDefinition, nextSiblingId )
\r
1752 return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
\r
1756 * Removes a UI element definition from the content definition.
\r
1757 * @param {String} id The id of the UI element definition to be
\r
1759 * @returns {CKEDITOR.dialog.definition.uiElement} The element
\r
1760 * definition removed.
\r
1763 remove : function( id )
\r
1765 removeById( this.elements, id, 'children' );
\r
1769 function initDragAndDrop( dialog )
\r
1771 var lastCoords = null,
\r
1772 abstractDialogCoords = null,
\r
1773 element = dialog.getElement().getFirst(),
\r
1774 editor = dialog.getParentEditor(),
\r
1775 magnetDistance = editor.config.dialog_magnetDistance,
\r
1776 margins = editor.skin.margins || [ 0, 0, 0, 0 ];
\r
1778 if ( typeof magnetDistance == 'undefined' )
\r
1779 magnetDistance = 20;
\r
1781 function mouseMoveHandler( evt )
\r
1783 var dialogSize = dialog.getSize(),
\r
1784 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
1785 x = evt.data.$.screenX,
\r
1786 y = evt.data.$.screenY,
\r
1787 dx = x - lastCoords.x,
\r
1788 dy = y - lastCoords.y,
\r
1791 lastCoords = { x : x, y : y };
\r
1792 abstractDialogCoords.x += dx;
\r
1793 abstractDialogCoords.y += dy;
\r
1795 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
\r
1796 realX = - margins[3];
\r
1797 else if ( abstractDialogCoords.x - margins[1] > viewPaneSize.width - dialogSize.width - magnetDistance )
\r
1798 realX = viewPaneSize.width - dialogSize.width + ( editor.lang.dir == 'rtl' ? 0 : margins[1] );
\r
1800 realX = abstractDialogCoords.x;
\r
1802 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
\r
1803 realY = - margins[0];
\r
1804 else if ( abstractDialogCoords.y - margins[2] > viewPaneSize.height - dialogSize.height - magnetDistance )
\r
1805 realY = viewPaneSize.height - dialogSize.height + margins[2];
\r
1807 realY = abstractDialogCoords.y;
\r
1809 dialog.move( realX, realY, 1 );
\r
1811 evt.data.preventDefault();
\r
1814 function mouseUpHandler( evt )
\r
1816 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1817 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1819 if ( CKEDITOR.env.ie6Compat )
\r
1821 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1822 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1823 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1827 dialog.parts.title.on( 'mousedown', function( evt )
\r
1829 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
\r
1831 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
\r
1832 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
\r
1833 abstractDialogCoords = dialog.getPosition();
\r
1835 if ( CKEDITOR.env.ie6Compat )
\r
1837 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1838 coverDoc.on( 'mousemove', mouseMoveHandler );
\r
1839 coverDoc.on( 'mouseup', mouseUpHandler );
\r
1842 evt.data.preventDefault();
\r
1846 function initResizeHandles( dialog )
\r
1848 var def = dialog.definition,
\r
1849 resizable = def.resizable;
\r
1851 if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE )
\r
1854 var editor = dialog.getParentEditor();
\r
1855 var wrapperWidth, wrapperHeight,
\r
1856 viewSize, origin, startSize,
\r
1859 var mouseDownFn = CKEDITOR.tools.addFunction( function( $event )
\r
1861 startSize = dialog.getSize();
\r
1863 var content = dialog.parts.contents,
\r
1864 iframeDialog = content.$.getElementsByTagName( 'iframe' ).length;
\r
1866 // Shim to help capturing "mousemove" over iframe.
\r
1867 if ( iframeDialog )
\r
1869 dialogCover = CKEDITOR.dom.element.createFromHtml( '<div class="cke_dialog_resize_cover" style="height: 100%; position: absolute; width: 100%;"></div>' );
\r
1870 content.append( dialogCover );
\r
1873 // Calculate the offset between content and chrome size.
\r
1874 wrapperHeight = startSize.height - dialog.parts.contents.getSize( 'height', ! ( CKEDITOR.env.gecko || CKEDITOR.env.opera || CKEDITOR.env.ie && CKEDITOR.env.quirks ) );
\r
1875 wrapperWidth = startSize.width - dialog.parts.contents.getSize( 'width', 1 );
\r
1877 origin = { x : $event.screenX, y : $event.screenY };
\r
1879 viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
\r
1881 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
\r
1882 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
\r
1884 if ( CKEDITOR.env.ie6Compat )
\r
1886 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1887 coverDoc.on( 'mousemove', mouseMoveHandler );
\r
1888 coverDoc.on( 'mouseup', mouseUpHandler );
\r
1891 $event.preventDefault && $event.preventDefault();
\r
1894 // Prepend the grip to the dialog.
\r
1895 dialog.on( 'load', function()
\r
1897 var direction = '';
\r
1898 if ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH )
\r
1899 direction = ' cke_resizer_horizontal';
\r
1900 else if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT )
\r
1901 direction = ' cke_resizer_vertical';
\r
1902 var resizer = CKEDITOR.dom.element.createFromHtml( '<div' +
\r
1903 ' class="cke_resizer' + direction + ' cke_resizer_' + editor.lang.dir + '"' +
\r
1904 ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.resize ) + '"' +
\r
1905 ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event )"></div>' );
\r
1906 dialog.parts.footer.append( resizer, 1 );
\r
1908 editor.on( 'destroy', function() { CKEDITOR.tools.removeFunction( mouseDownFn ); } );
\r
1910 function mouseMoveHandler( evt )
\r
1912 var rtl = editor.lang.dir == 'rtl',
\r
1913 dx = ( evt.data.$.screenX - origin.x ) * ( rtl ? -1 : 1 ),
\r
1914 dy = evt.data.$.screenY - origin.y,
\r
1915 width = startSize.width,
\r
1916 height = startSize.height,
\r
1917 internalWidth = width + dx * ( dialog._.moved ? 1 : 2 ),
\r
1918 internalHeight = height + dy * ( dialog._.moved ? 1 : 2 ),
\r
1919 element = dialog._.element.getFirst(),
\r
1920 right = rtl && element.getComputedStyle( 'right' ),
\r
1921 position = dialog.getPosition();
\r
1923 if ( position.y + internalHeight > viewSize.height )
\r
1924 internalHeight = viewSize.height - position.y;
\r
1926 if ( ( rtl ? right : position.x ) + internalWidth > viewSize.width )
\r
1927 internalWidth = viewSize.width - ( rtl ? right : position.x );
\r
1929 // Make sure the dialog will not be resized to the wrong side when it's in the leftmost position for RTL.
\r
1930 if ( ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH || resizable == CKEDITOR.DIALOG_RESIZE_BOTH ) )
\r
1931 width = Math.max( def.minWidth || 0, internalWidth - wrapperWidth );
\r
1933 if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT || resizable == CKEDITOR.DIALOG_RESIZE_BOTH )
\r
1934 height = Math.max( def.minHeight || 0, internalHeight - wrapperHeight );
\r
1936 dialog.resize( width, height );
\r
1938 if ( !dialog._.moved )
\r
1941 evt.data.preventDefault();
\r
1944 function mouseUpHandler()
\r
1946 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1947 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1949 if ( dialogCover )
\r
1951 dialogCover.remove();
\r
1952 dialogCover = null;
\r
1955 if ( CKEDITOR.env.ie6Compat )
\r
1957 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();
\r
1958 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1959 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1965 // Caching resuable covers and allowing only one cover
\r
1970 function cancelEvent( ev )
\r
1972 ev.data.preventDefault(1);
\r
1975 function showCover( editor )
\r
1977 var win = CKEDITOR.document.getWindow();
\r
1978 var config = editor.config,
\r
1979 backgroundColorStyle = config.dialog_backgroundCoverColor || 'white',
\r
1980 backgroundCoverOpacity = config.dialog_backgroundCoverOpacity,
\r
1981 baseFloatZIndex = config.baseFloatZIndex,
\r
1982 coverKey = CKEDITOR.tools.genKey(
\r
1983 backgroundColorStyle,
\r
1984 backgroundCoverOpacity,
\r
1985 baseFloatZIndex ),
\r
1986 coverElement = covers[ coverKey ];
\r
1988 if ( !coverElement )
\r
1991 '<div tabIndex="-1" style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),
\r
1992 '; z-index: ', baseFloatZIndex,
\r
1993 '; top: 0px; left: 0px; ',
\r
1994 ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),
\r
1995 '" class="cke_dialog_background_cover">'
\r
1998 if ( CKEDITOR.env.ie6Compat )
\r
2000 // Support for custom document.domain in IE.
\r
2001 var isCustomDomain = CKEDITOR.env.isCustomDomain(),
\r
2002 iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
\r
2006 ' hidefocus="true"' +
\r
2007 ' frameborder="0"' +
\r
2008 ' id="cke_dialog_background_iframe"' +
\r
2009 ' src="javascript:' );
\r
2011 html.push( 'void((function(){' +
\r
2012 'document.open();' +
\r
2013 ( isCustomDomain ? 'document.domain=\'' + document.domain + '\';' : '' ) +
\r
2014 'document.write( \'' + iframeHtml + '\' );' +
\r
2015 'document.close();' +
\r
2021 'position:absolute;' +
\r
2026 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
\r
2030 html.push( '</div>' );
\r
2032 coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
\r
2033 coverElement.setOpacity( backgroundCoverOpacity != undefined ? backgroundCoverOpacity : 0.5 );
\r
2035 coverElement.on( 'keydown', cancelEvent );
\r
2036 coverElement.on( 'keypress', cancelEvent );
\r
2037 coverElement.on( 'keyup', cancelEvent );
\r
2039 coverElement.appendTo( CKEDITOR.document.getBody() );
\r
2040 covers[ coverKey ] = coverElement;
\r
2043 coverElement. show();
\r
2045 currentCover = coverElement;
\r
2046 var resizeFunc = function()
\r
2048 var size = win.getViewPaneSize();
\r
2049 coverElement.setStyles(
\r
2051 width : size.width + 'px',
\r
2052 height : size.height + 'px'
\r
2056 var scrollFunc = function()
\r
2058 var pos = win.getScrollPosition(),
\r
2059 cursor = CKEDITOR.dialog._.currentTop;
\r
2060 coverElement.setStyles(
\r
2062 left : pos.x + 'px',
\r
2063 top : pos.y + 'px'
\r
2070 var dialogPos = cursor.getPosition();
\r
2071 cursor.move( dialogPos.x, dialogPos.y );
\r
2072 } while ( ( cursor = cursor._.parentDialog ) );
\r
2076 resizeCover = resizeFunc;
\r
2077 win.on( 'resize', resizeFunc );
\r
2079 // Using Safari/Mac, focus must be kept where it is (#7027)
\r
2080 if ( !( CKEDITOR.env.mac && CKEDITOR.env.webkit ) )
\r
2081 coverElement.focus();
\r
2083 if ( CKEDITOR.env.ie6Compat )
\r
2085 // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
\r
2086 // So we need to invent a really funny way to make it work.
\r
2087 var myScrollHandler = function()
\r
2090 arguments.callee.prevScrollHandler.apply( this, arguments );
\r
2092 win.$.setTimeout( function()
\r
2094 myScrollHandler.prevScrollHandler = window.onscroll || function(){};
\r
2095 window.onscroll = myScrollHandler;
\r
2101 function hideCover()
\r
2103 if ( !currentCover )
\r
2106 var win = CKEDITOR.document.getWindow();
\r
2107 currentCover.hide();
\r
2108 win.removeListener( 'resize', resizeCover );
\r
2110 if ( CKEDITOR.env.ie6Compat )
\r
2112 win.$.setTimeout( function()
\r
2114 var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
\r
2115 window.onscroll = prevScrollHandler || null;
\r
2118 resizeCover = null;
\r
2121 function removeCovers()
\r
2123 for ( var coverId in covers )
\r
2124 covers[ coverId ].remove();
\r
2128 var accessKeyProcessors = {};
\r
2130 var accessKeyDownHandler = function( evt )
\r
2132 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
2133 alt = evt.data.$.altKey,
\r
2134 shift = evt.data.$.shiftKey,
\r
2135 key = String.fromCharCode( evt.data.$.keyCode ),
\r
2136 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
2138 if ( !keyProcessor || !keyProcessor.length )
\r
2141 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
2142 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
2143 evt.data.preventDefault();
\r
2146 var accessKeyUpHandler = function( evt )
\r
2148 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
2149 alt = evt.data.$.altKey,
\r
2150 shift = evt.data.$.shiftKey,
\r
2151 key = String.fromCharCode( evt.data.$.keyCode ),
\r
2152 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
2154 if ( !keyProcessor || !keyProcessor.length )
\r
2157 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
2158 if ( keyProcessor.keyup )
\r
2160 keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
2161 evt.data.preventDefault();
\r
2165 var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc )
\r
2167 var procList = accessKeyProcessors[key] || ( accessKeyProcessors[key] = [] );
\r
2169 uiElement : uiElement,
\r
2172 keyup : upFunc || uiElement.accessKeyUp,
\r
2173 keydown : downFunc || uiElement.accessKeyDown
\r
2177 var unregisterAccessKey = function( obj )
\r
2179 for ( var i in accessKeyProcessors )
\r
2181 var list = accessKeyProcessors[i];
\r
2182 for ( var j = list.length - 1 ; j >= 0 ; j-- )
\r
2184 if ( list[j].dialog == obj || list[j].uiElement == obj )
\r
2185 list.splice( j, 1 );
\r
2187 if ( list.length === 0 )
\r
2188 delete accessKeyProcessors[i];
\r
2192 var tabAccessKeyUp = function( dialog, key )
\r
2194 if ( dialog._.accessKeyMap[key] )
\r
2195 dialog.selectPage( dialog._.accessKeyMap[key] );
\r
2198 var tabAccessKeyDown = function( dialog, key )
\r
2203 var preventKeyBubblingKeys = { 27 :1, 13 :1 };
\r
2204 var preventKeyBubbling = function( e )
\r
2206 if ( e.data.getKeystroke() in preventKeyBubblingKeys )
\r
2207 e.data.stopPropagation();
\r
2212 CKEDITOR.ui.dialog =
\r
2215 * The base class of all dialog UI elements.
\r
2217 * @param {CKEDITOR.dialog} dialog Parent dialog object.
\r
2218 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition Element
\r
2219 * definition. Accepted fields:
\r
2221 * <li><strong>id</strong> (Required) The id of the UI element. See {@link
\r
2222 * CKEDITOR.dialog#getContentElement}</li>
\r
2223 * <li><strong>type</strong> (Required) The type of the UI element. The
\r
2224 * value to this field specifies which UI element class will be used to
\r
2225 * generate the final widget.</li>
\r
2226 * <li><strong>title</strong> (Optional) The popup tooltip for the UI
\r
2228 * <li><strong>hidden</strong> (Optional) A flag that tells if the element
\r
2229 * should be initially visible.</li>
\r
2230 * <li><strong>className</strong> (Optional) Additional CSS class names
\r
2231 * to add to the UI element. Separated by space.</li>
\r
2232 * <li><strong>style</strong> (Optional) Additional CSS inline styles
\r
2233 * to add to the UI element. A semicolon (;) is required after the last
\r
2234 * style declaration.</li>
\r
2235 * <li><strong>accessKey</strong> (Optional) The alphanumeric access key
\r
2236 * for this element. Access keys are automatically prefixed by CTRL.</li>
\r
2237 * <li><strong>on*</strong> (Optional) Any UI element definition field that
\r
2238 * starts with <em>on</em> followed immediately by a capital letter and
\r
2239 * probably more letters is an event handler. Event handlers may be further
\r
2240 * divided into registered event handlers and DOM event handlers. Please
\r
2241 * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and
\r
2242 * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more
\r
2243 * information.</li>
\r
2245 * @param {Array} htmlList
\r
2246 * List of HTML code to be added to the dialog's content area.
\r
2247 * @param {Function|String} nodeNameArg
\r
2248 * A function returning a string, or a simple string for the node name for
\r
2249 * the root DOM node. Default is 'div'.
\r
2250 * @param {Function|Object} stylesArg
\r
2251 * A function returning an object, or a simple object for CSS styles applied
\r
2252 * to the DOM node. Default is empty object.
\r
2253 * @param {Function|Object} attributesArg
\r
2254 * A fucntion returning an object, or a simple object for attributes applied
\r
2255 * to the DOM node. Default is empty object.
\r
2256 * @param {Function|String} contentsArg
\r
2257 * A function returning a string, or a simple string for the HTML code inside
\r
2258 * the root DOM node. Default is empty string.
\r
2261 uiElement : function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg )
\r
2263 if ( arguments.length < 4 )
\r
2266 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',
\r
2267 html = [ '<', nodeName, ' ' ],
\r
2268 styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},
\r
2269 attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},
\r
2270 innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',
\r
2271 domId = this.domId = attributes.id || CKEDITOR.tools.getNextId() + '_uiElement',
\r
2272 id = this.id = elementDefinition.id,
\r
2275 // Set the id, a unique id is required for getElement() to work.
\r
2276 attributes.id = domId;
\r
2278 // Set the type and definition CSS class names.
\r
2280 if ( elementDefinition.type )
\r
2281 classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;
\r
2282 if ( elementDefinition.className )
\r
2283 classes[ elementDefinition.className ] = 1;
\r
2284 if ( elementDefinition.disabled )
\r
2285 classes[ 'cke_disabled' ] = 1;
\r
2287 var attributeClasses = ( attributes['class'] && attributes['class'].split ) ? attributes['class'].split( ' ' ) : [];
\r
2288 for ( i = 0 ; i < attributeClasses.length ; i++ )
\r
2290 if ( attributeClasses[i] )
\r
2291 classes[ attributeClasses[i] ] = 1;
\r
2293 var finalClasses = [];
\r
2294 for ( i in classes )
\r
2295 finalClasses.push( i );
\r
2296 attributes['class'] = finalClasses.join( ' ' );
\r
2298 // Set the popup tooltop.
\r
2299 if ( elementDefinition.title )
\r
2300 attributes.title = elementDefinition.title;
\r
2302 // Write the inline CSS styles.
\r
2303 var styleStr = ( elementDefinition.style || '' ).split( ';' );
\r
2305 // Element alignment support.
\r
2306 if ( elementDefinition.align )
\r
2308 var align = elementDefinition.align;
\r
2309 styles[ 'margin-left' ] = align == 'left' ? 0 : 'auto';
\r
2310 styles[ 'margin-right' ] = align == 'right' ? 0 : 'auto';
\r
2313 for ( i in styles )
\r
2314 styleStr.push( i + ':' + styles[i] );
\r
2315 if ( elementDefinition.hidden )
\r
2316 styleStr.push( 'display:none' );
\r
2317 for ( i = styleStr.length - 1 ; i >= 0 ; i-- )
\r
2319 if ( styleStr[i] === '' )
\r
2320 styleStr.splice( i, 1 );
\r
2322 if ( styleStr.length > 0 )
\r
2323 attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
\r
2325 // Write the attributes.
\r
2326 for ( i in attributes )
\r
2327 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '" ');
\r
2329 // Write the content HTML.
\r
2330 html.push( '>', innerHTML, '</', nodeName, '>' );
\r
2332 // Add contents to the parent HTML array.
\r
2333 htmlList.push( html.join( '' ) );
\r
2335 ( this._ || ( this._ = {} ) ).dialog = dialog;
\r
2337 // Override isChanged if it is defined in element definition.
\r
2338 if ( typeof( elementDefinition.isChanged ) == 'boolean' )
\r
2339 this.isChanged = function(){ return elementDefinition.isChanged; };
\r
2340 if ( typeof( elementDefinition.isChanged ) == 'function' )
\r
2341 this.isChanged = elementDefinition.isChanged;
\r
2343 // Overload 'get(set)Value' on definition.
\r
2344 if ( typeof( elementDefinition.setValue ) == 'function' )
\r
2346 this.setValue = CKEDITOR.tools.override( this.setValue, function( org )
\r
2348 return function( val ){ org.call( this, elementDefinition.setValue.call( this, val ) ); };
\r
2352 if ( typeof( elementDefinition.getValue ) == 'function' )
\r
2354 this.getValue = CKEDITOR.tools.override( this.getValue, function( org )
\r
2356 return function(){ return elementDefinition.getValue.call( this, org.call( this ) ); };
\r
2361 CKEDITOR.event.implementOn( this );
\r
2363 this.registerEvents( elementDefinition );
\r
2364 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
\r
2365 registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
\r
2368 dialog.on( 'load', function()
\r
2370 var input = me.getInputElement();
\r
2373 var focusClass = me.type in { 'checkbox' : 1, 'ratio' : 1 } && CKEDITOR.env.ie && CKEDITOR.env.version < 8 ? 'cke_dialog_ui_focused' : '';
\r
2374 input.on( 'focus', function()
\r
2376 dialog._.tabBarMode = false;
\r
2377 dialog._.hasFocus = true;
\r
2378 me.fire( 'focus' );
\r
2379 focusClass && this.addClass( focusClass );
\r
2383 input.on( 'blur', function()
\r
2385 me.fire( 'blur' );
\r
2386 focusClass && this.removeClass( focusClass );
\r
2391 // Register the object as a tab focus if it can be included.
\r
2392 if ( this.keyboardFocusable )
\r
2394 this.tabIndex = elementDefinition.tabIndex || 0;
\r
2396 this.focusIndex = dialog._.focusList.push( this ) - 1;
\r
2397 this.on( 'focus', function()
\r
2399 dialog._.currentFocusIndex = me.focusIndex;
\r
2403 // Completes this object with everything we have in the
\r
2405 CKEDITOR.tools.extend( this, elementDefinition );
\r
2409 * Horizontal layout box for dialog UI elements, auto-expends to available width of container.
\r
2411 * @extends CKEDITOR.ui.dialog.uiElement
\r
2412 * @param {CKEDITOR.dialog} dialog
\r
2413 * Parent dialog object.
\r
2414 * @param {Array} childObjList
\r
2415 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2417 * @param {Array} childHtmlList
\r
2418 * Array of HTML code that correspond to the HTML output of all the
\r
2419 * objects in childObjList.
\r
2420 * @param {Array} htmlList
\r
2421 * Array of HTML code that this element will output to.
\r
2422 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
\r
2423 * The element definition. Accepted fields:
\r
2425 * <li><strong>widths</strong> (Optional) The widths of child cells.</li>
\r
2426 * <li><strong>height</strong> (Optional) The height of the layout.</li>
\r
2427 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2429 * <li><strong>align</strong> (Optional) The alignment of the whole layout
\r
2434 hbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2436 if ( arguments.length < 4 )
\r
2439 this._ || ( this._ = {} );
\r
2441 var children = this._.children = childObjList,
\r
2442 widths = elementDefinition && elementDefinition.widths || null,
\r
2443 height = elementDefinition && elementDefinition.height || null,
\r
2447 var innerHTML = function()
\r
2449 var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];
\r
2450 for ( i = 0 ; i < childHtmlList.length ; i++ )
\r
2452 var className = 'cke_dialog_ui_hbox_child',
\r
2455 className = 'cke_dialog_ui_hbox_first';
\r
2456 if ( i == childHtmlList.length - 1 )
\r
2457 className = 'cke_dialog_ui_hbox_last';
\r
2458 html.push( '<td class="', className, '" role="presentation" ' );
\r
2462 styles.push( 'width:' + cssLength( widths[i] ) );
\r
2465 styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2467 styles.push( 'height:' + cssLength( height ) );
\r
2468 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2469 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
\r
2470 // In IE Quirks alignment has to be done on table cells. (#7324)
\r
2471 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && children[ i ].align )
\r
2472 styles.push( 'text-align:' + children[ i ].align );
\r
2473 if ( styles.length > 0 )
\r
2474 html.push( 'style="' + styles.join('; ') + '" ' );
\r
2475 html.push( '>', childHtmlList[i], '</td>' );
\r
2477 html.push( '</tr></tbody>' );
\r
2478 return html.join( '' );
\r
2481 var attribs = { role : 'presentation' };
\r
2482 elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );
\r
2484 CKEDITOR.ui.dialog.uiElement.call(
\r
2487 elementDefinition || { type : 'hbox' },
\r
2496 * Vertical layout box for dialog UI elements.
\r
2498 * @extends CKEDITOR.ui.dialog.hbox
\r
2499 * @param {CKEDITOR.dialog} dialog
\r
2500 * Parent dialog object.
\r
2501 * @param {Array} childObjList
\r
2502 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2504 * @param {Array} childHtmlList
\r
2505 * Array of HTML code that correspond to the HTML output of all the
\r
2506 * objects in childObjList.
\r
2507 * @param {Array} htmlList
\r
2508 * Array of HTML code that this element will output to.
\r
2509 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
\r
2510 * The element definition. Accepted fields:
\r
2512 * <li><strong>width</strong> (Optional) The width of the layout.</li>
\r
2513 * <li><strong>heights</strong> (Optional) The heights of individual cells.
\r
2515 * <li><strong>align</strong> (Optional) The alignment of the layout.</li>
\r
2516 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2518 * <li><strong>expand</strong> (Optional) Whether the layout should expand
\r
2519 * vertically to fill its container.</li>
\r
2523 vbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2525 if ( arguments.length < 3 )
\r
2528 this._ || ( this._ = {} );
\r
2530 var children = this._.children = childObjList,
\r
2531 width = elementDefinition && elementDefinition.width || null,
\r
2532 heights = elementDefinition && elementDefinition.heights || null;
\r
2534 var innerHTML = function()
\r
2536 var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];
\r
2537 html.push( 'style="' );
\r
2538 if ( elementDefinition && elementDefinition.expand )
\r
2539 html.push( 'height:100%;' );
\r
2540 html.push( 'width:' + cssLength( width || '100%' ), ';' );
\r
2542 html.push( 'align="', CKEDITOR.tools.htmlEncode(
\r
2543 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
\r
2545 html.push( '><tbody>' );
\r
2546 for ( var i = 0 ; i < childHtmlList.length ; i++ )
\r
2549 html.push( '<tr><td role="presentation" ' );
\r
2551 styles.push( 'width:' + cssLength( width || '100%' ) );
\r
2553 styles.push( 'height:' + cssLength( heights[i] ) );
\r
2554 else if ( elementDefinition && elementDefinition.expand )
\r
2555 styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2556 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2557 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );
\r
2558 // In IE Quirks alignment has to be done on table cells. (#7324)
\r
2559 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && children[ i ].align )
\r
2560 styles.push( 'text-align:' + children[ i ].align );
\r
2561 if ( styles.length > 0 )
\r
2562 html.push( 'style="', styles.join( '; ' ), '" ' );
\r
2563 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[i], '</td></tr>' );
\r
2565 html.push( '</tbody></table>' );
\r
2566 return html.join( '' );
\r
2568 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type : 'vbox' }, htmlList, 'div', null, { role : 'presentation' }, innerHTML );
\r
2573 CKEDITOR.ui.dialog.uiElement.prototype =
\r
2576 * Gets the root DOM element of this dialog UI object.
\r
2577 * @returns {CKEDITOR.dom.element} Root DOM element of UI object.
\r
2579 * uiElement.getElement().hide();
\r
2581 getElement : function()
\r
2583 return CKEDITOR.document.getById( this.domId );
\r
2587 * Gets the DOM element that the user inputs values.
\r
2588 * This function is used by setValue(), getValue() and focus(). It should
\r
2589 * be overrided in child classes where the input element isn't the root
\r
2591 * @returns {CKEDITOR.dom.element} The element where the user input values.
\r
2593 * var rawValue = textInput.getInputElement().$.value;
\r
2595 getInputElement : function()
\r
2597 return this.getElement();
\r
2601 * Gets the parent dialog object containing this UI element.
\r
2602 * @returns {CKEDITOR.dialog} Parent dialog object.
\r
2604 * var dialog = uiElement.getDialog();
\r
2606 getDialog : function()
\r
2608 return this._.dialog;
\r
2612 * Sets the value of this dialog UI object.
\r
2613 * @param {Object} value The new value.
\r
2614 * @param {Boolean} noChangeEvent Internal commit, to supress 'change' event on this element.
\r
2615 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2617 * uiElement.setValue( 'Dingo' );
\r
2619 setValue : function( value, noChangeEvent )
\r
2621 this.getInputElement().setValue( value );
\r
2622 !noChangeEvent && this.fire( 'change', { value : value } );
\r
2627 * Gets the current value of this dialog UI object.
\r
2628 * @returns {Object} The current value.
\r
2630 * var myValue = uiElement.getValue();
\r
2632 getValue : function()
\r
2634 return this.getInputElement().getValue();
\r
2638 * Tells whether the UI object's value has changed.
\r
2639 * @returns {Boolean} true if changed, false if not changed.
\r
2641 * if ( uiElement.isChanged() )
\r
2642 * confirm( 'Value changed! Continue?' );
\r
2644 isChanged : function()
\r
2646 // Override in input classes.
\r
2651 * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
\r
2652 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2654 * focus : function()
\r
2656 * this.selectParentTab();
\r
2657 * // do something else.
\r
2660 selectParentTab : function()
\r
2662 var element = this.getInputElement(),
\r
2665 while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 )
\r
2668 // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
\r
2672 tabId = cursor.getAttribute( 'name' );
\r
2673 // Avoid duplicate select.
\r
2674 if ( this._.dialog._.currentTabId != tabId )
\r
2675 this._.dialog.selectPage( tabId );
\r
2680 * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
\r
2681 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2683 * uiElement.focus();
\r
2685 focus : function()
\r
2687 this.selectParentTab().getInputElement().focus();
\r
2692 * Registers the on* event handlers defined in the element definition.
\r
2693 * The default behavior of this function is:
\r
2696 * If the on* event is defined in the class's eventProcesors list,
\r
2697 * then the registration is delegated to the corresponding function
\r
2698 * in the eventProcessors list.
\r
2701 * If the on* event is not defined in the eventProcessors list, then
\r
2702 * register the event handler under the corresponding DOM event of
\r
2703 * the UI element's input DOM element (as defined by the return value
\r
2704 * of {@link CKEDITOR.ui.dialog.uiElement#getInputElement}).
\r
2707 * This function is only called at UI element instantiation, but can
\r
2708 * be overridded in child classes if they require more flexibility.
\r
2709 * @param {CKEDITOR.dialog.definition.uiElement} definition The UI element
\r
2711 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2714 registerEvents : function( definition )
\r
2716 var regex = /^on([A-Z]\w+)/,
\r
2719 var registerDomEvent = function( uiElement, dialog, eventName, func )
\r
2721 dialog.on( 'load', function()
\r
2723 uiElement.getInputElement().on( eventName, func, uiElement );
\r
2727 for ( var i in definition )
\r
2729 if ( !( match = i.match( regex ) ) )
\r
2731 if ( this.eventProcessors[i] )
\r
2732 this.eventProcessors[i].call( this, this._.dialog, definition[i] );
\r
2734 registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
\r
2741 * The event processor list used by
\r
2742 * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element
\r
2743 * instantiation. The default list defines three on* events:
\r
2745 * <li>onLoad - Called when the element's parent dialog opens for the
\r
2747 * <li>onShow - Called whenever the element's parent dialog opens.</li>
\r
2748 * <li>onHide - Called whenever the element's parent dialog closes.</li>
\r
2753 * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick
\r
2754 * // handlers in the UI element's definitions.
\r
2755 * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},
\r
2756 * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
\r
2757 * { onClick : function( dialog, func ) { this.on( 'click', func ); } },
\r
2758 * true );
\r
2762 onLoad : function( dialog, func )
\r
2764 dialog.on( 'load', func, this );
\r
2767 onShow : function( dialog, func )
\r
2769 dialog.on( 'show', func, this );
\r
2772 onHide : function( dialog, func )
\r
2774 dialog.on( 'hide', func, this );
\r
2779 * The default handler for a UI element's access key down event, which
\r
2780 * tries to put focus to the UI element.<br />
\r
2781 * Can be overridded in child classes for more sophisticaed behavior.
\r
2782 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2783 * @param {String} key The key combination pressed. Since access keys
\r
2784 * are defined to always include the CTRL key, its value should always
\r
2785 * include a 'CTRL+' prefix.
\r
2788 accessKeyDown : function( dialog, key )
\r
2794 * The default handler for a UI element's access key up event, which
\r
2795 * does nothing.<br />
\r
2796 * Can be overridded in child classes for more sophisticated behavior.
\r
2797 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2798 * @param {String} key The key combination pressed. Since access keys
\r
2799 * are defined to always include the CTRL key, its value should always
\r
2800 * include a 'CTRL+' prefix.
\r
2803 accessKeyUp : function( dialog, key )
\r
2808 * Disables a UI element.
\r
2811 disable : function()
\r
2813 var element = this.getElement(),
\r
2814 input = this.getInputElement();
\r
2815 input.setAttribute( 'disabled', 'true' );
\r
2816 element.addClass( 'cke_disabled' );
\r
2820 * Enables a UI element.
\r
2823 enable : function()
\r
2825 var element = this.getElement(),
\r
2826 input = this.getInputElement();
\r
2827 input.removeAttribute( 'disabled' );
\r
2828 element.removeClass( 'cke_disabled' );
\r
2832 * Determines whether an UI element is enabled or not.
\r
2833 * @returns {Boolean} Whether the UI element is enabled.
\r
2836 isEnabled : function()
\r
2838 return !this.getElement().hasClass( 'cke_disabled' );
\r
2842 * Determines whether an UI element is visible or not.
\r
2843 * @returns {Boolean} Whether the UI element is visible.
\r
2846 isVisible : function()
\r
2848 return this.getInputElement().isVisible();
\r
2852 * Determines whether an UI element is focus-able or not.
\r
2853 * Focus-able is defined as being both visible and enabled.
\r
2854 * @returns {Boolean} Whether the UI element can be focused.
\r
2857 isFocusable : function()
\r
2859 if ( !this.isEnabled() || !this.isVisible() )
\r
2865 CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
\r
2867 * @lends CKEDITOR.ui.dialog.hbox.prototype
\r
2871 * Gets a child UI element inside this container.
\r
2872 * @param {Array|Number} indices An array or a single number to indicate the child's
\r
2873 * position in the container's descendant tree. Omit to get all the children in an array.
\r
2874 * @returns {Array|CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container
\r
2875 * if no argument given, or the specified UI element if indices is given.
\r
2877 * var checkbox = hbox.getChild( [0,1] );
\r
2878 * checkbox.setValue( true );
\r
2880 getChild : function( indices )
\r
2882 // If no arguments, return a clone of the children array.
\r
2883 if ( arguments.length < 1 )
\r
2884 return this._.children.concat();
\r
2886 // If indices isn't array, make it one.
\r
2887 if ( !indices.splice )
\r
2888 indices = [ indices ];
\r
2890 // Retrieve the child element according to tree position.
\r
2891 if ( indices.length < 2 )
\r
2892 return this._.children[ indices[0] ];
\r
2894 return ( this._.children[ indices[0] ] && this._.children[ indices[0] ].getChild ) ?
\r
2895 this._.children[ indices[0] ].getChild( indices.slice( 1, indices.length ) ) :
\r
2900 CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
\r
2906 var commonBuilder = {
\r
2907 build : function( dialog, elementDefinition, output )
\r
2909 var children = elementDefinition.children,
\r
2911 childHtmlList = [],
\r
2912 childObjList = [];
\r
2913 for ( var i = 0 ; ( i < children.length && ( child = children[i] ) ) ; i++ )
\r
2915 var childHtml = [];
\r
2916 childHtmlList.push( childHtml );
\r
2917 childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
\r
2919 return new CKEDITOR.ui.dialog[elementDefinition.type]( dialog, childObjList, childHtmlList, output, elementDefinition );
\r
2923 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
\r
2924 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
\r
2928 * Generic dialog command. It opens a specific dialog when executed.
\r
2930 * @augments CKEDITOR.commandDefinition
\r
2931 * @param {string} dialogName The name of the dialog to open when executing
\r
2934 * // Register the "link" command, which opens the "link" dialog.
\r
2935 * editor.addCommand( 'link', <b>new CKEDITOR.dialogCommand( 'link' )</b> );
\r
2937 CKEDITOR.dialogCommand = function( dialogName )
\r
2939 this.dialogName = dialogName;
\r
2942 CKEDITOR.dialogCommand.prototype =
\r
2945 exec : function( editor )
\r
2947 // Special treatment for Opera. (#8031)
\r
2948 CKEDITOR.env.opera ?
\r
2949 CKEDITOR.tools.setTimeout( function() { editor.openDialog( this.dialogName ); }, 0, this )
\r
2950 : editor.openDialog( this.dialogName );
\r
2953 // Dialog commands just open a dialog ui, thus require no undo logic,
\r
2954 // undo support should dedicate to specific dialog implementation.
\r
2957 editorFocus : CKEDITOR.env.ie || CKEDITOR.env.webkit
\r
2962 var notEmptyRegex = /^([a]|[^a])+$/,
\r
2963 integerRegex = /^\d*$/,
\r
2964 numberRegex = /^\d*(?:\.\d+)?$/,
\r
2965 htmlLengthRegex = /^(((\d*(\.\d+))|(\d*))(px|\%)?)?$/,
\r
2966 cssLengthRegex = /^(((\d*(\.\d+))|(\d*))(px|em|ex|in|cm|mm|pt|pc|\%)?)?$/i,
\r
2967 inlineStyleRegex = /^(\s*[\w-]+\s*:\s*[^:;]+(?:;|$))*$/;
\r
2969 CKEDITOR.VALIDATE_OR = 1;
\r
2970 CKEDITOR.VALIDATE_AND = 2;
\r
2972 CKEDITOR.dialog.validate =
\r
2974 functions : function()
\r
2976 var args = arguments;
\r
2980 * It's important for validate functions to be able to accept the value
\r
2981 * as argument in addition to this.getValue(), so that it is possible to
\r
2982 * combine validate functions together to make more sophisticated
\r
2985 var value = this && this.getValue ? this.getValue() : args[ 0 ];
\r
2987 var msg = undefined,
\r
2988 relation = CKEDITOR.VALIDATE_AND,
\r
2989 functions = [], i;
\r
2991 for ( i = 0 ; i < args.length ; i++ )
\r
2993 if ( typeof( args[i] ) == 'function' )
\r
2994 functions.push( args[i] );
\r
2999 if ( i < args.length && typeof( args[i] ) == 'string' )
\r
3005 if ( i < args.length && typeof( args[i]) == 'number' )
\r
3006 relation = args[i];
\r
3008 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );
\r
3009 for ( i = 0 ; i < functions.length ; i++ )
\r
3011 if ( relation == CKEDITOR.VALIDATE_AND )
\r
3012 passed = passed && functions[i]( value );
\r
3014 passed = passed || functions[i]( value );
\r
3017 return !passed ? msg : true;
\r
3021 regex : function( regex, msg )
\r
3024 * Can be greatly shortened by deriving from functions validator if code size
\r
3025 * turns out to be more important than performance.
\r
3029 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
3030 return !regex.test( value ) ? msg : true;
\r
3034 notEmpty : function( msg )
\r
3036 return this.regex( notEmptyRegex, msg );
\r
3039 integer : function( msg )
\r
3041 return this.regex( integerRegex, msg );
\r
3044 'number' : function( msg )
\r
3046 return this.regex( numberRegex, msg );
\r
3049 'cssLength' : function( msg )
\r
3051 return this.functions( function( val ){ return cssLengthRegex.test( CKEDITOR.tools.trim( val ) ); }, msg );
\r
3054 'htmlLength' : function( msg )
\r
3056 return this.functions( function( val ){ return htmlLengthRegex.test( CKEDITOR.tools.trim( val ) ); }, msg );
\r
3059 'inlineStyle' : function( msg )
\r
3061 return this.functions( function( val ){ return inlineStyleRegex.test( CKEDITOR.tools.trim( val ) ); }, msg );
\r
3064 equals : function( value, msg )
\r
3066 return this.functions( function( val ){ return val == value; }, msg );
\r
3069 notEqual : function( value, msg )
\r
3071 return this.functions( function( val ){ return val != value; }, msg );
\r
3075 CKEDITOR.on( 'instanceDestroyed', function( evt )
\r
3077 // Remove dialog cover on last instance destroy.
\r
3078 if ( CKEDITOR.tools.isEmpty( CKEDITOR.instances ) )
\r
3080 var currentTopDialog;
\r
3081 while ( ( currentTopDialog = CKEDITOR.dialog._.currentTop ) )
\r
3082 currentTopDialog.hide();
\r
3086 var dialogs = evt.editor._.storedDialogs;
\r
3087 for ( var name in dialogs )
\r
3088 dialogs[ name ].destroy();
\r
3094 // Extend the CKEDITOR.editor class with dialog specific functions.
\r
3095 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
\r
3096 /** @lends CKEDITOR.editor.prototype */
\r
3099 * Loads and opens a registered dialog.
\r
3100 * @param {String} dialogName The registered name of the dialog.
\r
3101 * @param {Function} callback The function to be invoked after dialog instance created.
\r
3102 * @see CKEDITOR.dialog.add
\r
3104 * CKEDITOR.instances.editor1.openDialog( 'smiley' );
\r
3105 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed. null if the dialog name is not registered.
\r
3107 openDialog : function( dialogName, callback )
\r
3109 if ( this.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
3111 var selection = this.getSelection();
\r
3112 selection && selection.lock();
\r
3115 var dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
3116 dialogSkin = this.skin.dialog;
\r
3118 if ( CKEDITOR.dialog._.currentTop === null )
\r
3119 showCover( this );
\r
3121 // If the dialogDefinition is already loaded, open it immediately.
\r
3122 if ( typeof dialogDefinitions == 'function' && dialogSkin._isLoaded )
\r
3124 var storedDialogs = this._.storedDialogs ||
\r
3125 ( this._.storedDialogs = {} );
\r
3127 var dialog = storedDialogs[ dialogName ] ||
\r
3128 ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
\r
3130 callback && callback.call( dialog, dialog );
\r
3135 else if ( dialogDefinitions == 'failed' )
\r
3138 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
\r
3143 function onDialogFileLoaded( success )
\r
3145 var dialogDefinition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
\r
3146 skin = me.skin.dialog;
\r
3148 // Check if both skin part and definition is loaded.
\r
3149 if ( !skin._isLoaded || loadDefinition && typeof success == 'undefined' )
\r
3152 // In case of plugin error, mark it as loading failed.
\r
3153 if ( typeof dialogDefinition != 'function' )
\r
3154 CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';
\r
3156 me.openDialog( dialogName, callback );
\r
3159 if ( typeof dialogDefinitions == 'string' )
\r
3161 var loadDefinition = 1;
\r
3162 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ), onDialogFileLoaded, null, 0, 1 );
\r
3165 CKEDITOR.skins.load( this, 'dialog', onDialogFileLoaded );
\r
3172 CKEDITOR.plugins.add( 'dialog',
\r
3174 requires : [ 'dialogui' ]
\r
3177 // Dialog related configurations.
\r
3180 * The color of the dialog background cover. It should be a valid CSS color
\r
3182 * @name CKEDITOR.config.dialog_backgroundCoverColor
\r
3184 * @default 'white'
\r
3186 * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
\r
3190 * The opacity of the dialog background cover. It should be a number within the
\r
3191 * range [0.0, 1.0].
\r
3192 * @name CKEDITOR.config.dialog_backgroundCoverOpacity
\r
3196 * config.dialog_backgroundCoverOpacity = 0.7;
\r
3200 * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.
\r
3201 * @name CKEDITOR.config.dialog_startupFocusTab
\r
3205 * config.dialog_startupFocusTab = true;
\r
3209 * The distance of magnetic borders used in moving and resizing dialogs,
\r
3210 * measured in pixels.
\r
3211 * @name CKEDITOR.config.dialog_magnetDistance
\r
3215 * config.dialog_magnetDistance = 30;
\r
3219 * The guideline to follow when generating the dialog buttons. There are 3 possible options:
\r
3221 * <li>'OS' - the buttons will be displayed in the default order of the user's OS;</li>
\r
3222 * <li>'ltr' - for Left-To-Right order;</li>
\r
3223 * <li>'rtl' - for Right-To-Left order.</li>
\r
3225 * @name CKEDITOR.config.dialog_buttonsOrder
\r
3230 * config.dialog_buttonsOrder = 'rtl';
\r
3234 * The dialog contents to removed. It's a string composed by dialog name and tab name with a colon between them.
\r
3235 * Separate each pair with semicolon (see example).
\r
3236 * <b>Note: All names are case-sensitive.</b>
\r
3237 * <b>Note: Be cautious when specifying dialog tabs that are mandatory, like "info", dialog functionality might be broken because of this!</b>
\r
3238 * @name CKEDITOR.config.removeDialogTabs
\r
3243 * config.removeDialogTabs = 'flash:advanced;image:Link';
\r
3247 * Fired when a dialog definition is about to be used to create a dialog into
\r
3248 * an editor instance. This event makes it possible to customize the definition
\r
3249 * before creating it.
\r
3250 * <p>Note that this event is called only the first time a specific dialog is
\r
3251 * opened. Successive openings will use the cached dialog, and this event will
\r
3252 * not get fired.</p>
\r
3253 * @name CKEDITOR#dialogDefinition
\r
3255 * @param {CKEDITOR.dialog.definition} data The dialog defination that
\r
3256 * is being loaded.
\r
3257 * @param {CKEDITOR.editor} editor The editor instance that will use the
\r
3262 * Fired when a tab is going to be selected in a dialog
\r
3263 * @name CKEDITOR.dialog#selectPage
\r
3265 * @param {String} page The id of the page that it's gonna be selected.
\r
3266 * @param {String} currentPage The id of the current page.
\r
3270 * Fired when the user tries to dismiss a dialog
\r
3271 * @name CKEDITOR.dialog#cancel
\r
3273 * @param {Boolean} hide Whether the event should proceed or not.
\r
3277 * Fired when the user tries to confirm a dialog
\r
3278 * @name CKEDITOR.dialog#ok
\r
3280 * @param {Boolean} hide Whether the event should proceed or not.
\r
3284 * Fired when a dialog is shown
\r
3285 * @name CKEDITOR.dialog#show
\r
3290 * Fired when a dialog is shown
\r
3291 * @name CKEDITOR.editor#dialogShow
\r
3296 * Fired when a dialog is hidden
\r
3297 * @name CKEDITOR.dialog#hide
\r
3302 * Fired when a dialog is hidden
\r
3303 * @name CKEDITOR.editor#dialogHide
\r
3308 * Fired when a dialog is being resized. The event is fired on
\r
3309 * both the 'CKEDITOR.dialog' object and the dialog instance
\r
3310 * since 3.5.3, previously it's available only in the global object.
\r
3311 * @name CKEDITOR.dialog#resize
\r
3314 * @param {CKEDITOR.dialog} dialog The dialog being resized (if
\r
3315 * it's fired on the dialog itself, this parameter isn't sent).
\r
3316 * @param {String} skin The skin name.
\r
3317 * @param {Number} width The new width.
\r
3318 * @param {Number} height The new height.
\r