2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @fileOverview The floating dialog plugin.
\r
11 * No resize for this dialog.
\r
14 CKEDITOR.DIALOG_RESIZE_NONE = 0;
\r
17 * Only allow horizontal resizing for this dialog, disable vertical resizing.
\r
20 CKEDITOR.DIALOG_RESIZE_WIDTH = 1;
\r
23 * Only allow vertical resizing for this dialog, disable horizontal resizing.
\r
26 CKEDITOR.DIALOG_RESIZE_HEIGHT = 2;
\r
29 * Allow the dialog to be resized in both directions.
\r
32 CKEDITOR.DIALOG_RESIZE_BOTH = 3;
\r
36 function isTabVisible( tabId )
\r
38 return !!this._.tabs[ tabId ][ 0 ].$.offsetHeight;
\r
41 function getPreviousVisibleTab()
\r
43 var tabId = this._.currentTabId,
\r
44 length = this._.tabIdList.length,
\r
45 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId ) + length;
\r
47 for ( var i = tabIndex - 1 ; i > tabIndex - length ; i-- )
\r
49 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
\r
50 return this._.tabIdList[ i % length ];
\r
56 function getNextVisibleTab()
\r
58 var tabId = this._.currentTabId,
\r
59 length = this._.tabIdList.length,
\r
60 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId );
\r
62 for ( var i = tabIndex + 1 ; i < tabIndex + length ; i++ )
\r
64 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
\r
65 return this._.tabIdList[ i % length ];
\r
72 * This is the base class for runtime dialog objects. An instance of this
\r
73 * class represents a single named dialog for a single editor instance.
\r
74 * @param {Object} editor The editor which created the dialog.
\r
75 * @param {String} dialogName The dialog's registered name.
\r
78 * var dialogObj = new CKEDITOR.dialog( editor, 'smiley' );
\r
80 CKEDITOR.dialog = function( editor, dialogName )
\r
82 // Load the dialog definition.
\r
83 var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];
\r
85 // Completes the definition with the default values.
\r
86 definition = CKEDITOR.tools.extend( definition( editor ), defaultDialogDefinition );
\r
88 // Clone a functionally independent copy for this dialog.
\r
89 definition = CKEDITOR.tools.clone( definition );
\r
91 // Create a complex definition object, extending it with the API
\r
93 definition = new definitionObject( this, definition );
\r
96 var doc = CKEDITOR.document;
\r
98 var themeBuilt = editor.theme.buildDialog( editor );
\r
100 // Initialize some basic parameters.
\r
104 element : themeBuilt.element,
\r
106 contentSize : { width : 0, height : 0 },
\r
107 size : { width : 0, height : 0 },
\r
108 updateSize : false,
\r
113 // Initialize the tab and page map.
\r
116 currentTabId : null,
\r
117 currentTabIndex : null,
\r
120 tabBarMode : false,
\r
122 // Initialize the tab order array for input widgets.
\r
124 currentFocusIndex : 0,
\r
128 this.parts = themeBuilt.parts;
\r
130 CKEDITOR.tools.setTimeout( function()
\r
132 editor.fire( 'ariaWidget', this.parts.contents );
\r
136 // Set the startup styles for the dialog, avoiding it enlarging the
\r
137 // page size on the dialog creation.
\r
138 this.parts.dialog.setStyles(
\r
140 position : CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed',
\r
143 visibility : 'hidden'
\r
146 // Call the CKEDITOR.event constructor to initialize this instance.
\r
147 CKEDITOR.event.call( this );
\r
149 // Fire the "dialogDefinition" event, making it possible to customize
\r
150 // the dialog definition.
\r
151 this.definition = definition = CKEDITOR.fire( 'dialogDefinition',
\r
154 definition : definition
\r
156 , editor ).definition;
\r
157 // Initialize load, show, hide, ok and cancel events.
\r
158 if ( definition.onLoad )
\r
159 this.on( 'load', definition.onLoad );
\r
161 if ( definition.onShow )
\r
162 this.on( 'show', definition.onShow );
\r
164 if ( definition.onHide )
\r
165 this.on( 'hide', definition.onHide );
\r
167 if ( definition.onOk )
\r
169 this.on( 'ok', function( evt )
\r
171 if ( definition.onOk.call( this, evt ) === false )
\r
172 evt.data.hide = false;
\r
176 if ( definition.onCancel )
\r
178 this.on( 'cancel', function( evt )
\r
180 if ( definition.onCancel.call( this, evt ) === false )
\r
181 evt.data.hide = false;
\r
187 // Iterates over all items inside all content in the dialog, calling a
\r
188 // function for each of them.
\r
189 var iterContents = function( func )
\r
191 var contents = me._.contents,
\r
194 for ( var i in contents )
\r
196 for ( var j in contents[i] )
\r
198 stop = func.call( this, contents[i][j] );
\r
205 this.on( 'ok', function( evt )
\r
207 iterContents( function( item )
\r
209 if ( item.validate )
\r
211 var isValid = item.validate( this );
\r
213 if ( typeof isValid == 'string' )
\r
219 if ( isValid === false )
\r
226 evt.data.hide = false;
\r
232 }, this, null, 0 );
\r
234 this.on( 'cancel', function( evt )
\r
236 iterContents( function( item )
\r
238 if ( item.isChanged() )
\r
240 if ( !confirm( editor.lang.common.confirmCancel ) )
\r
241 evt.data.hide = false;
\r
245 }, this, null, 0 );
\r
247 this.parts.close.on( 'click', function( evt )
\r
249 if ( this.fire( 'cancel', { hide : true } ).hide !== false )
\r
253 // Sort focus list according to tab order definitions.
\r
254 function setupFocus()
\r
256 var focusList = me._.focusList;
\r
257 focusList.sort( function( a, b )
\r
259 // Mimics browser tab order logics;
\r
260 if ( a.tabIndex != b.tabIndex )
\r
261 return b.tabIndex - a.tabIndex;
\r
262 // Sort is not stable in some browsers,
\r
263 // fall-back the comparator to 'focusIndex';
\r
265 return a.focusIndex - b.focusIndex;
\r
268 var size = focusList.length;
\r
269 for ( var i = 0; i < size; i++ )
\r
270 focusList[ i ].focusIndex = i;
\r
273 function changeFocus( forward )
\r
275 var focusList = me._.focusList,
\r
276 offset = forward ? 1 : -1;
\r
277 if ( focusList.length < 1 )
\r
280 var current = me._.currentFocusIndex;
\r
282 // Trigger the 'blur' event of any input element before anything,
\r
283 // since certain UI updates may depend on it.
\r
286 focusList[ current ].getInputElement().$.blur();
\r
290 var startIndex = ( current + offset + focusList.length ) % focusList.length,
\r
291 currentIndex = startIndex;
\r
292 while ( !focusList[ currentIndex ].isFocusable() )
\r
294 currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length;
\r
295 if ( currentIndex == startIndex )
\r
298 focusList[ currentIndex ].focus();
\r
300 // Select whole field content.
\r
301 if ( focusList[ currentIndex ].type == 'text' )
\r
302 focusList[ currentIndex ].select();
\r
305 this.changeFocus = changeFocus;
\r
309 function focusKeydownHandler( evt )
\r
311 // If I'm not the top dialog, ignore.
\r
312 if ( me != CKEDITOR.dialog._.currentTop )
\r
315 var keystroke = evt.data.getKeystroke();
\r
318 if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )
\r
320 var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
\r
322 // Handling Tab and Shift-Tab.
\r
323 if ( me._.tabBarMode )
\r
326 var nextId = shiftPressed ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );
\r
327 me.selectPage( nextId );
\r
328 me._.tabs[ nextId ][ 0 ].focus();
\r
332 // Change the focus of inputs.
\r
333 changeFocus( !shiftPressed );
\r
338 else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode )
\r
340 // Alt-F10 puts focus into the current tab item in the tab bar.
\r
341 me._.tabBarMode = true;
\r
342 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
345 else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode )
\r
347 // Arrow keys - used for changing tabs.
\r
348 nextId = ( keystroke == 37 ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) );
\r
349 me.selectPage( nextId );
\r
350 me._.tabs[ nextId ][ 0 ].focus();
\r
353 else if ( ( keystroke == 13 || keystroke == 32 ) && me._.tabBarMode )
\r
355 this.selectPage( this._.currentTabId );
\r
356 this._.tabBarMode = false;
\r
357 this._.currentFocusIndex = -1;
\r
358 changeFocus( true );
\r
365 evt.data.preventDefault();
\r
369 function focusKeyPressHandler( evt )
\r
371 processed && evt.data.preventDefault();
\r
374 var dialogElement = this._.element;
\r
375 // Add the dialog keyboard handlers.
\r
376 this.on( 'show', function()
\r
378 dialogElement.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
379 // Some browsers instead, don't cancel key events in the keydown, but in the
\r
380 // keypress. So we must do a longer trip in those cases. (#4531)
\r
381 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
382 dialogElement.on( 'keypress', focusKeyPressHandler, this );
\r
384 if ( CKEDITOR.env.ie6Compat )
\r
386 var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
\r
387 coverDoc.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
390 this.on( 'hide', function()
\r
392 dialogElement.removeListener( 'keydown', focusKeydownHandler );
\r
393 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
\r
394 dialogElement.removeListener( 'keypress', focusKeyPressHandler );
\r
396 this.on( 'iframeAdded', function( evt )
\r
398 var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );
\r
399 doc.on( 'keydown', focusKeydownHandler, this, null, 0 );
\r
402 // Auto-focus logic in dialog.
\r
403 this.on( 'show', function()
\r
405 // Setup tabIndex on showing the dialog instead of on loading
\r
406 // to allow dynamic tab order happen in dialog definition.
\r
409 if ( editor.config.dialog_startupFocusTab
\r
410 && me._.tabIdList.length > 1 )
\r
412 me._.tabBarMode = true;
\r
413 me._.tabs[ me._.currentTabId ][ 0 ].focus();
\r
415 else if ( !this._.hasFocus )
\r
417 this._.currentFocusIndex = -1;
\r
419 // Decide where to put the initial focus.
\r
420 if ( definition.onFocus )
\r
422 var initialFocus = definition.onFocus.call( this );
\r
423 // Focus the field that the user specified.
\r
424 initialFocus && initialFocus.focus();
\r
426 // Focus the first field in layout order.
\r
428 changeFocus( true );
\r
431 * IE BUG: If the initial focus went into a non-text element (e.g. button),
\r
432 * then IE would still leave the caret inside the editing area.
\r
434 if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
436 var $selection = editor.document.$.selection,
\r
437 $range = $selection.createRange();
\r
441 if ( $range.parentElement && $range.parentElement().ownerDocument == editor.document.$
\r
442 || $range.item && $range.item( 0 ).ownerDocument == editor.document.$ )
\r
444 var $myRange = document.body.createTextRange();
\r
445 $myRange.moveToElementText( this.getElement().getFirst().$ );
\r
446 $myRange.collapse( true );
\r
452 }, this, null, 0xffffffff );
\r
454 // IE6 BUG: Text fields and text areas are only half-rendered the first time the dialog appears in IE6 (#2661).
\r
455 // This is still needed after [2708] and [2709] because text fields in hidden TR tags are still broken.
\r
456 if ( CKEDITOR.env.ie6Compat )
\r
458 this.on( 'load', function( evt )
\r
460 var outer = this.getElement(),
\r
461 inner = outer.getFirst();
\r
463 inner.appendTo( outer );
\r
467 initDragAndDrop( this );
\r
468 initResizeHandles( this );
\r
470 // Insert the title.
\r
471 ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );
\r
473 // Insert the tabs and contents.
\r
474 for ( var i = 0 ; i < definition.contents.length ; i++ )
\r
475 this.addPage( definition.contents[i] );
\r
477 this.parts['tabs'].on( 'click', function( evt )
\r
479 var target = evt.data.getTarget();
\r
480 // If we aren't inside a tab, bail out.
\r
481 if ( target.hasClass( 'cke_dialog_tab' ) )
\r
483 var id = target.$.id;
\r
484 this.selectPage( id.substr( 0, id.lastIndexOf( '_' ) ) );
\r
485 if ( this._.tabBarMode )
\r
487 this._.tabBarMode = false;
\r
488 this._.currentFocusIndex = -1;
\r
489 changeFocus( true );
\r
491 evt.data.preventDefault();
\r
496 var buttonsHtml = [],
\r
497 buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this,
\r
500 className : 'cke_dialog_footer_buttons',
\r
502 children : definition.buttons
\r
503 }, buttonsHtml ).getChild();
\r
504 this.parts.footer.setHtml( buttonsHtml.join( '' ) );
\r
506 for ( i = 0 ; i < buttons.length ; i++ )
\r
507 this._.buttons[ buttons[i].id ] = buttons[i];
\r
509 CKEDITOR.skins.load( editor, 'dialog' );
\r
512 // Focusable interface. Use it via dialog.addFocusable.
\r
513 function Focusable( dialog, element, index )
\r
515 this.element = element;
\r
516 this.focusIndex = index;
\r
517 // TODO: support tabIndex for focusables.
\r
519 this.isFocusable = function()
\r
521 return !element.getAttribute( 'disabled' ) && element.isVisible();
\r
523 this.focus = function()
\r
525 dialog._.currentFocusIndex = this.focusIndex;
\r
526 this.element.focus();
\r
529 element.on( 'keydown', function( e )
\r
531 if ( e.data.getKeystroke() in { 32:1, 13:1 } )
\r
532 this.fire( 'click' );
\r
534 element.on( 'focus', function()
\r
536 this.fire( 'mouseover' );
\r
538 element.on( 'blur', function()
\r
540 this.fire( 'mouseout' );
\r
544 CKEDITOR.dialog.prototype =
\r
547 * Resizes the dialog.
\r
548 * @param {Number} width The width of the dialog in pixels.
\r
549 * @param {Number} height The height of the dialog in pixels.
\r
552 * dialogObj.resize( 800, 640 );
\r
554 resize : (function()
\r
556 return function( width, height )
\r
558 if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )
\r
561 CKEDITOR.dialog.fire( 'resize',
\r
564 skin : this._.editor.skinName,
\r
567 }, this._.editor );
\r
569 this._.contentSize = { width : width, height : height };
\r
570 this._.updateSize = true;
\r
575 * Gets the current size of the dialog in pixels.
\r
576 * @returns {Object} An object with "width" and "height" properties.
\r
578 * var width = dialogObj.getSize().width;
\r
580 getSize : function()
\r
582 if ( !this._.updateSize )
\r
583 return this._.size;
\r
584 var element = this._.element.getFirst();
\r
585 var size = this._.size = { width : element.$.offsetWidth || 0, height : element.$.offsetHeight || 0};
\r
587 // If either the offsetWidth or offsetHeight is 0, the element isn't visible.
\r
588 this._.updateSize = !size.width || !size.height;
\r
594 * Moves the dialog to an (x, y) coordinate relative to the window.
\r
596 * @param {Number} x The target x-coordinate.
\r
597 * @param {Number} y The target y-coordinate.
\r
599 * dialogObj.move( 10, 40 );
\r
604 return function( x, y )
\r
606 // The dialog may be fixed positioned or absolute positioned. Ask the
\r
607 // browser what is the current situation first.
\r
608 var element = this._.element.getFirst();
\r
609 if ( isFixed === undefined )
\r
610 isFixed = element.getComputedStyle( 'position' ) == 'fixed';
\r
612 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
\r
615 // Save the current position.
\r
616 this._.position = { x : x, y : y };
\r
618 // If not fixed positioned, add scroll position to the coordinates.
\r
621 var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
\r
622 x += scrollPosition.x;
\r
623 y += scrollPosition.y;
\r
628 'left' : ( x > 0 ? x : 0 ) + 'px',
\r
629 'top' : ( y > 0 ? y : 0 ) + 'px'
\r
635 * Gets the dialog's position in the window.
\r
636 * @returns {Object} An object with "x" and "y" properties.
\r
638 * var dialogX = dialogObj.getPosition().x;
\r
640 getPosition : function(){ return CKEDITOR.tools.extend( {}, this._.position ); },
\r
643 * Shows the dialog box.
\r
645 * dialogObj.show();
\r
649 var editor = this._.editor;
\r
650 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
652 var selection = editor.getSelection();
\r
653 selection && selection.lock();
\r
656 // Insert the dialog's element to the root document.
\r
657 var element = this._.element;
\r
658 var definition = this.definition;
\r
659 if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )
\r
660 element.appendTo( CKEDITOR.document.getBody() );
\r
664 // FIREFOX BUG: Fix vanishing caret for Firefox 2 or Gecko 1.8.
\r
665 if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
\r
667 var dialogElement = this.parts.dialog;
\r
668 dialogElement.setStyle( 'position', 'absolute' );
\r
669 setTimeout( function()
\r
671 dialogElement.setStyle( 'position', 'fixed' );
\r
676 // First, set the dialog to an appropriate size.
\r
677 this.resize( definition.minWidth, definition.minHeight );
\r
679 // Select the first tab by default.
\r
680 this.selectPage( this.definition.contents[0].id );
\r
682 // Reset all inputs back to their default value.
\r
686 if ( CKEDITOR.dialog._.currentZIndex === null )
\r
687 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;
\r
688 this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
\r
690 // Maintain the dialog ordering and dialog cover.
\r
691 // Also register key handlers if first dialog.
\r
692 if ( CKEDITOR.dialog._.currentTop === null )
\r
694 CKEDITOR.dialog._.currentTop = this;
\r
695 this._.parentDialog = null;
\r
696 addCover( this._.editor );
\r
698 element.on( 'keydown', accessKeyDownHandler );
\r
699 element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
701 // Prevent some keys from bubbling up. (#4269)
\r
702 for ( var event in { keyup :1, keydown :1, keypress :1 } )
\r
703 element.on( event, preventKeyBubbling );
\r
707 this._.parentDialog = CKEDITOR.dialog._.currentTop;
\r
708 var parentElement = this._.parentDialog.getElement().getFirst();
\r
709 parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );
\r
710 CKEDITOR.dialog._.currentTop = this;
\r
713 // Register the Esc hotkeys.
\r
714 registerAccessKey( this, this, '\x1b', null, function()
\r
716 this.getButton( 'cancel' ) && this.getButton( 'cancel' ).click();
\r
719 // Reset the hasFocus state.
\r
720 this._.hasFocus = false;
\r
722 // Rearrange the dialog to the middle of the window.
\r
723 CKEDITOR.tools.setTimeout( function()
\r
725 var viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
\r
726 var dialogSize = this.getSize();
\r
728 // We're using definition size for initial position because of
\r
729 // offten corrupted data in offsetWidth at this point. (#4084)
\r
730 this.move( ( viewSize.width - definition.minWidth ) / 2, ( viewSize.height - dialogSize.height ) / 2 );
\r
732 this.parts.dialog.setStyle( 'visibility', '' );
\r
734 // Execute onLoad for the first show.
\r
735 this.fireOnce( 'load', {} );
\r
736 this.fire( 'show', {} );
\r
737 this._.editor.fire( 'dialogShow', this );
\r
739 // Save the initial values of the dialog.
\r
740 this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } );
\r
747 * Executes a function for each UI element.
\r
748 * @param {Function} fn Function to execute for each UI element.
\r
749 * @returns {CKEDITOR.dialog} The current dialog object.
\r
751 foreach : function( fn )
\r
753 for ( var i in this._.contents )
\r
755 for ( var j in this._.contents[i] )
\r
756 fn( this._.contents[i][j]);
\r
762 * Resets all input values in the dialog.
\r
764 * dialogObj.reset();
\r
765 * @returns {CKEDITOR.dialog} The current dialog object.
\r
767 reset : (function()
\r
769 var fn = function( widget ){ if ( widget.reset ) widget.reset(); };
\r
770 return function(){ this.foreach( fn ); return this; };
\r
773 setupContent : function()
\r
775 var args = arguments;
\r
776 this.foreach( function( widget )
\r
778 if ( widget.setup )
\r
779 widget.setup.apply( widget, args );
\r
783 commitContent : function()
\r
785 var args = arguments;
\r
786 this.foreach( function( widget )
\r
788 if ( widget.commit )
\r
789 widget.commit.apply( widget, args );
\r
794 * Hides the dialog box.
\r
796 * dialogObj.hide();
\r
800 this.fire( 'hide', {} );
\r
801 this._.editor.fire( 'dialogHide', this );
\r
803 // Remove the dialog's element from the root document.
\r
804 var element = this._.element;
\r
805 if ( !element.getParent() )
\r
809 this.parts.dialog.setStyle( 'visibility', 'hidden' );
\r
811 // Unregister all access keys associated with this dialog.
\r
812 unregisterAccessKey( this );
\r
814 // Maintain dialog ordering and remove cover if needed.
\r
815 if ( !this._.parentDialog )
\r
819 var parentElement = this._.parentDialog.getElement().getFirst();
\r
820 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
\r
822 CKEDITOR.dialog._.currentTop = this._.parentDialog;
\r
824 // Deduct or clear the z-index.
\r
825 if ( !this._.parentDialog )
\r
827 CKEDITOR.dialog._.currentZIndex = null;
\r
829 // Remove access key handlers.
\r
830 element.removeListener( 'keydown', accessKeyDownHandler );
\r
831 element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
\r
833 // Remove bubbling-prevention handler. (#4269)
\r
834 for ( var event in { keyup :1, keydown :1, keypress :1 } )
\r
835 element.removeListener( event, preventKeyBubbling );
\r
837 var editor = this._.editor;
\r
840 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
\r
842 var selection = editor.getSelection();
\r
843 selection && selection.unlock( true );
\r
847 CKEDITOR.dialog._.currentZIndex -= 10;
\r
850 // Reset the initial values of the dialog.
\r
851 this.foreach( function( contentObj ) { contentObj.resetInitValue && contentObj.resetInitValue(); } );
\r
855 * Adds a tabbed page into the dialog.
\r
856 * @param {Object} contents Content definition.
\r
859 addPage : function( contents )
\r
862 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
\r
863 elements = contents.elements,
\r
864 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this,
\r
867 className : 'cke_dialog_page_contents',
\r
868 children : contents.elements,
\r
869 expand : !!contents.expand,
\r
870 padding : contents.padding,
\r
871 style : contents.style || 'width: 100%;' + ( CKEDITOR.env.ie6Compat ? '' : 'height: 100%;' )
\r
874 // Create the HTML for the tab and the content block.
\r
875 var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
\r
876 page.setAttribute( 'role', 'tabpanel' );
\r
878 var env = CKEDITOR.env;
\r
879 var tabId = contents.id + '_' + CKEDITOR.tools.getNextNumber(),
\r
880 tab = CKEDITOR.dom.element.createFromHtml( [
\r
881 '<a class="cke_dialog_tab"',
\r
882 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),
\r
884 ( !!contents.hidden ? ' style="display:none"' : '' ),
\r
885 ' id="', tabId, '"',
\r
886 env.gecko && env.version >= 10900 && !env.hc ? '' : ' href="javascript:void(0)"',
\r
888 ' hidefocus="true"',
\r
894 page.setAttribute( 'aria-labelledby', tabId );
\r
896 // If only a single page exist, a different style is used in the central pane.
\r
897 if ( this._.pageCount === 0 )
\r
898 this.parts.dialog.addClass( 'cke_single_page' );
\r
900 this.parts.dialog.removeClass( 'cke_single_page' );
\r
902 // Take records for the tabs and elements created.
\r
903 this._.tabs[ contents.id ] = [ tab, page ];
\r
904 this._.tabIdList.push( contents.id );
\r
905 this._.pageCount++;
\r
906 this._.lastTab = tab;
\r
908 var contentMap = this._.contents[ contents.id ] = {},
\r
910 children = vbox.getChild();
\r
912 while ( ( cursor = children.shift() ) )
\r
914 contentMap[ cursor.id ] = cursor;
\r
915 if ( typeof( cursor.getChild ) == 'function' )
\r
916 children.push.apply( children, cursor.getChild() );
\r
919 // Attach the DOM nodes.
\r
921 page.setAttribute( 'name', contents.id );
\r
922 page.appendTo( this.parts.contents );
\r
924 tab.unselectable();
\r
925 this.parts.tabs.append( tab );
\r
927 // Add access key handlers if access key is defined.
\r
928 if ( contents.accessKey )
\r
930 registerAccessKey( this, this, 'CTRL+' + contents.accessKey,
\r
931 tabAccessKeyDown, tabAccessKeyUp );
\r
932 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;
\r
937 * Activates a tab page in the dialog by its id.
\r
938 * @param {String} id The id of the dialog tab to be activated.
\r
940 * dialogObj.selectPage( 'tab_1' );
\r
942 selectPage : function( id )
\r
944 // Hide the non-selected tabs and pages.
\r
945 for ( var i in this._.tabs )
\r
947 var tab = this._.tabs[i][0],
\r
948 page = this._.tabs[i][1];
\r
951 tab.removeClass( 'cke_dialog_tab_selected' );
\r
954 page.setAttribute( 'aria-hidden', i != id );
\r
957 var selected = this._.tabs[id];
\r
958 selected[0].addClass( 'cke_dialog_tab_selected' );
\r
959 selected[1].show();
\r
960 this._.currentTabId = id;
\r
961 this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
\r
965 * Hides a page's tab away from the dialog.
\r
966 * @param {String} id The page's Id.
\r
968 * dialog.hidePage( 'tab_3' );
\r
970 hidePage : function( id )
\r
972 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
979 * Unhides a page's tab.
\r
980 * @param {String} id The page's Id.
\r
982 * dialog.showPage( 'tab_2' );
\r
984 showPage : function( id )
\r
986 var tab = this._.tabs[id] && this._.tabs[id][0];
\r
993 * Gets the root DOM element of the dialog.
\r
994 * @returns {CKEDITOR.dom.element} The <span> element containing this dialog.
\r
996 * var dialogElement = dialogObj.getElement().getFirst();
\r
997 * dialogElement.setStyle( 'padding', '5px' );
\r
999 getElement : function()
\r
1001 return this._.element;
\r
1005 * Gets the name of the dialog.
\r
1006 * @returns {String} The name of this dialog.
\r
1008 * var dialogName = dialogObj.getName();
\r
1010 getName : function()
\r
1012 return this._.name;
\r
1016 * Gets a dialog UI element object from a dialog page.
\r
1017 * @param {String} pageId id of dialog page.
\r
1018 * @param {String} elementId id of UI element.
\r
1020 * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.
\r
1022 getContentElement : function( pageId, elementId )
\r
1024 var page = this._.contents[ pageId ];
\r
1025 return page && page[ elementId ];
\r
1029 * Gets the value of a dialog UI element.
\r
1030 * @param {String} pageId id of dialog page.
\r
1031 * @param {String} elementId id of UI element.
\r
1033 * @returns {Object} The value of the UI element.
\r
1035 getValueOf : function( pageId, elementId )
\r
1037 return this.getContentElement( pageId, elementId ).getValue();
\r
1041 * Sets the value of a dialog UI element.
\r
1042 * @param {String} pageId id of the dialog page.
\r
1043 * @param {String} elementId id of the UI element.
\r
1044 * @param {Object} value The new value of the UI element.
\r
1047 setValueOf : function( pageId, elementId, value )
\r
1049 return this.getContentElement( pageId, elementId ).setValue( value );
\r
1053 * Gets the UI element of a button in the dialog's button row.
\r
1054 * @param {String} id The id of the button.
\r
1056 * @returns {CKEDITOR.ui.dialog.button} The button object.
\r
1058 getButton : function( id )
\r
1060 return this._.buttons[ id ];
\r
1064 * Simulates a click to a dialog button in the dialog's button row.
\r
1065 * @param {String} id The id of the button.
\r
1067 * @returns The return value of the dialog's "click" event.
\r
1069 click : function( id )
\r
1071 return this._.buttons[ id ].click();
\r
1075 * Disables a dialog button.
\r
1076 * @param {String} id The id of the button.
\r
1079 disableButton : function( id )
\r
1081 return this._.buttons[ id ].disable();
\r
1085 * Enables a dialog button.
\r
1086 * @param {String} id The id of the button.
\r
1089 enableButton : function( id )
\r
1091 return this._.buttons[ id ].enable();
\r
1095 * Gets the number of pages in the dialog.
\r
1096 * @returns {Number} Page count.
\r
1098 getPageCount : function()
\r
1100 return this._.pageCount;
\r
1104 * Gets the editor instance which opened this dialog.
\r
1105 * @returns {CKEDITOR.editor} Parent editor instances.
\r
1107 getParentEditor : function()
\r
1109 return this._.editor;
\r
1113 * Gets the element that was selected when opening the dialog, if any.
\r
1114 * @returns {CKEDITOR.dom.element} The element that was selected, or null.
\r
1116 getSelectedElement : function()
\r
1118 return this.getParentEditor().getSelection().getSelectedElement();
\r
1122 * Adds element to dialog's focusable list.
\r
1124 * @param {CKEDITOR.dom.element} element
\r
1125 * @param {Number} [index]
\r
1127 addFocusable: function( element, index ) {
\r
1128 if ( typeof index == 'undefined' )
\r
1130 index = this._.focusList.length;
\r
1131 this._.focusList.push( new Focusable( this, element, index ) );
\r
1135 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );
\r
1136 for ( var i = index + 1 ; i < this._.focusList.length ; i++ )
\r
1137 this._.focusList[ i ].focusIndex++;
\r
1142 CKEDITOR.tools.extend( CKEDITOR.dialog,
\r
1144 * @lends CKEDITOR.dialog
\r
1148 * Registers a dialog.
\r
1149 * @param {String} name The dialog's name.
\r
1150 * @param {Function|String} dialogDefinition
\r
1151 * A function returning the dialog's definition, or the URL to the .js file holding the function.
\r
1152 * The function should accept an argument "editor" which is the current editor instance, and
\r
1153 * return an object conforming to {@link CKEDITOR.dialog.dialogDefinition}.
\r
1155 * @see CKEDITOR.dialog.dialogDefinition
\r
1157 add : function( name, dialogDefinition )
\r
1159 // Avoid path registration from multiple instances override definition.
\r
1160 if ( !this._.dialogDefinitions[name]
\r
1161 || typeof dialogDefinition == 'function' )
\r
1162 this._.dialogDefinitions[name] = dialogDefinition;
\r
1165 exists : function( name )
\r
1167 return !!this._.dialogDefinitions[ name ];
\r
1170 getCurrent : function()
\r
1172 return CKEDITOR.dialog._.currentTop;
\r
1176 * The default OK button for dialogs. Fires the "ok" event and closes the dialog if the event succeeds.
\r
1182 okButton : (function()
\r
1184 var retval = function( editor, override )
\r
1186 override = override || {};
\r
1187 return CKEDITOR.tools.extend( {
\r
1190 label : editor.lang.common.ok,
\r
1191 'class' : 'cke_dialog_ui_button_ok',
\r
1192 onClick : function( evt )
\r
1194 var dialog = evt.data.dialog;
\r
1195 if ( dialog.fire( 'ok', { hide : true } ).hide !== false )
\r
1198 }, override, true );
\r
1200 retval.type = 'button';
\r
1201 retval.override = function( override )
\r
1203 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1204 { type : 'button' }, true );
\r
1210 * The default cancel button for dialogs. Fires the "cancel" event and closes the dialog if no UI element value changed.
\r
1216 cancelButton : (function()
\r
1218 var retval = function( editor, override )
\r
1220 override = override || {};
\r
1221 return CKEDITOR.tools.extend( {
\r
1224 label : editor.lang.common.cancel,
\r
1225 'class' : 'cke_dialog_ui_button_cancel',
\r
1226 onClick : function( evt )
\r
1228 var dialog = evt.data.dialog;
\r
1229 if ( dialog.fire( 'cancel', { hide : true } ).hide !== false )
\r
1232 }, override, true );
\r
1234 retval.type = 'button';
\r
1235 retval.override = function( override )
\r
1237 return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
\r
1238 { type : 'button' }, true );
\r
1244 * Registers a dialog UI element.
\r
1245 * @param {String} typeName The name of the UI element.
\r
1246 * @param {Function} builder The function to build the UI element.
\r
1249 addUIElement : function( typeName, builder )
\r
1251 this._.uiElementBuilders[ typeName ] = builder;
\r
1255 CKEDITOR.dialog._ =
\r
1257 uiElementBuilders : {},
\r
1259 dialogDefinitions : {},
\r
1261 currentTop : null,
\r
1263 currentZIndex : null
\r
1266 // "Inherit" (copy actually) from CKEDITOR.event.
\r
1267 CKEDITOR.event.implementOn( CKEDITOR.dialog );
\r
1268 CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype, true );
\r
1270 var defaultDialogDefinition =
\r
1272 resizable : CKEDITOR.DIALOG_RESIZE_NONE,
\r
1275 buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
\r
1278 // Tool function used to return an item from an array based on its id
\r
1280 var getById = function( array, id, recurse )
\r
1282 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1284 if ( item.id == id )
\r
1286 if ( recurse && item[ recurse ] )
\r
1288 var retval = getById( item[ recurse ], id, recurse ) ;
\r
1296 // Tool function used to add an item into an array.
\r
1297 var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound )
\r
1299 if ( nextSiblingId )
\r
1301 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1303 if ( item.id == nextSiblingId )
\r
1305 array.splice( i, 0, newItem );
\r
1309 if ( recurse && item[ recurse ] )
\r
1311 var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
\r
1317 if ( nullIfNotFound )
\r
1321 array.push( newItem );
\r
1325 // Tool function used to remove an item from an array based on its id.
\r
1326 var removeById = function( array, id, recurse )
\r
1328 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
\r
1330 if ( item.id == id )
\r
1331 return array.splice( i, 1 );
\r
1332 if ( recurse && item[ recurse ] )
\r
1334 var retval = removeById( item[ recurse ], id, recurse );
\r
1343 * This class is not really part of the API. It is the "definition" property value
\r
1344 * passed to "dialogDefinition" event handlers.
\r
1346 * @name CKEDITOR.dialog.dialogDefinitionObject
\r
1347 * @extends CKEDITOR.dialog.dialogDefinition
\r
1349 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1351 * var definition = evt.data.definition;
\r
1352 * var content = definition.getContents( 'page1' );
\r
1356 var definitionObject = function( dialog, dialogDefinition )
\r
1358 // TODO : Check if needed.
\r
1359 this.dialog = dialog;
\r
1361 // Transform the contents entries in contentObjects.
\r
1362 var contents = dialogDefinition.contents;
\r
1363 for ( var i = 0, content ; ( content = contents[i] ) ; i++ )
\r
1364 contents[ i ] = new contentObject( dialog, content );
\r
1366 CKEDITOR.tools.extend( this, dialogDefinition );
\r
1369 definitionObject.prototype =
\r
1370 /** @lends CKEDITOR.dialog.dialogDefinitionObject.prototype */
\r
1373 * Gets a content definition.
\r
1374 * @param {String} id The id of the content definition.
\r
1375 * @returns {CKEDITOR.dialog.contentDefinition} The content definition
\r
1378 getContents : function( id )
\r
1380 return getById( this.contents, id );
\r
1384 * Gets a button definition.
\r
1385 * @param {String} id The id of the button definition.
\r
1386 * @returns {CKEDITOR.dialog.buttonDefinition} The button definition
\r
1389 getButton : function( id )
\r
1391 return getById( this.buttons, id );
\r
1395 * Adds a content definition object under this dialog definition.
\r
1396 * @param {CKEDITOR.dialog.contentDefinition} contentDefinition The
\r
1397 * content definition.
\r
1398 * @param {String} [nextSiblingId] The id of an existing content
\r
1399 * definition which the new content definition will be inserted
\r
1400 * before. Omit if the new content definition is to be inserted as
\r
1402 * @returns {CKEDITOR.dialog.contentDefinition} The inserted content
\r
1405 addContents : function( contentDefinition, nextSiblingId )
\r
1407 return addById( this.contents, contentDefinition, nextSiblingId );
\r
1411 * Adds a button definition object under this dialog definition.
\r
1412 * @param {CKEDITOR.dialog.buttonDefinition} buttonDefinition The
\r
1413 * button definition.
\r
1414 * @param {String} [nextSiblingId] The id of an existing button
\r
1415 * definition which the new button definition will be inserted
\r
1416 * before. Omit if the new button definition is to be inserted as
\r
1418 * @returns {CKEDITOR.dialog.buttonDefinition} The inserted button
\r
1421 addButton : function( buttonDefinition, nextSiblingId )
\r
1423 return addById( this.buttons, buttonDefinition, nextSiblingId );
\r
1427 * Removes a content definition from this dialog definition.
\r
1428 * @param {String} id The id of the content definition to be removed.
\r
1429 * @returns {CKEDITOR.dialog.contentDefinition} The removed content
\r
1432 removeContents : function( id )
\r
1434 removeById( this.contents, id );
\r
1438 * Removes a button definition from the dialog definition.
\r
1439 * @param {String} id The id of the button definition to be removed.
\r
1440 * @returns {CKEDITOR.dialog.buttonDefinition} The removed button
\r
1443 removeButton : function( id )
\r
1445 removeById( this.buttons, id );
\r
1450 * This class is not really part of the API. It is the template of the
\r
1451 * objects representing content pages inside the
\r
1452 * CKEDITOR.dialog.dialogDefinitionObject.
\r
1454 * @name CKEDITOR.dialog.contentDefinitionObject
\r
1456 * CKEDITOR.on( 'dialogDefinition', function( evt )
\r
1458 * var definition = evt.data.definition;
\r
1459 * var content = definition.getContents( 'page1' );
\r
1460 * content.remove( 'textInput1' );
\r
1464 function contentObject( dialog, contentDefinition )
\r
1471 CKEDITOR.tools.extend( this, contentDefinition );
\r
1474 contentObject.prototype =
\r
1475 /** @lends CKEDITOR.dialog.contentDefinitionObject.prototype */
\r
1478 * Gets a UI element definition under the content definition.
\r
1479 * @param {String} id The id of the UI element definition.
\r
1480 * @returns {CKEDITOR.dialog.uiElementDefinition}
\r
1482 get : function( id )
\r
1484 return getById( this.elements, id, 'children' );
\r
1488 * Adds a UI element definition to the content definition.
\r
1489 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition The
\r
1490 * UI elemnet definition to be added.
\r
1491 * @param {String} nextSiblingId The id of an existing UI element
\r
1492 * definition which the new UI element definition will be inserted
\r
1493 * before. Omit if the new button definition is to be inserted as
\r
1495 * @returns {CKEDITOR.dialog.uiElementDefinition} The element
\r
1496 * definition inserted.
\r
1498 add : function( elementDefinition, nextSiblingId )
\r
1500 return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
\r
1504 * Removes a UI element definition from the content definition.
\r
1505 * @param {String} id The id of the UI element definition to be
\r
1507 * @returns {CKEDITOR.dialog.uiElementDefinition} The element
\r
1508 * definition removed.
\r
1511 remove : function( id )
\r
1513 removeById( this.elements, id, 'children' );
\r
1517 function initDragAndDrop( dialog )
\r
1519 var lastCoords = null,
\r
1520 abstractDialogCoords = null,
\r
1521 element = dialog.getElement().getFirst(),
\r
1522 editor = dialog.getParentEditor(),
\r
1523 magnetDistance = editor.config.dialog_magnetDistance,
\r
1524 margins = editor.skin.margins || [ 0, 0, 0, 0 ];
\r
1526 if ( typeof magnetDistance == 'undefined' )
\r
1527 magnetDistance = 20;
\r
1529 function mouseMoveHandler( evt )
\r
1531 var dialogSize = dialog.getSize(),
\r
1532 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
1533 x = evt.data.$.screenX,
\r
1534 y = evt.data.$.screenY,
\r
1535 dx = x - lastCoords.x,
\r
1536 dy = y - lastCoords.y,
\r
1539 lastCoords = { x : x, y : y };
\r
1540 abstractDialogCoords.x += dx;
\r
1541 abstractDialogCoords.y += dy;
\r
1543 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
\r
1544 realX = - margins[3];
\r
1545 else if ( abstractDialogCoords.x - margins[1] > viewPaneSize.width - dialogSize.width - magnetDistance )
\r
1546 realX = viewPaneSize.width - dialogSize.width + margins[1];
\r
1548 realX = abstractDialogCoords.x;
\r
1550 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
\r
1551 realY = - margins[0];
\r
1552 else if ( abstractDialogCoords.y - margins[2] > viewPaneSize.height - dialogSize.height - magnetDistance )
\r
1553 realY = viewPaneSize.height - dialogSize.height + margins[2];
\r
1555 realY = abstractDialogCoords.y;
\r
1557 dialog.move( realX, realY );
\r
1559 evt.data.preventDefault();
\r
1562 function mouseUpHandler( evt )
\r
1564 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1565 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1567 if ( CKEDITOR.env.ie6Compat )
\r
1569 var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
\r
1570 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1571 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1575 dialog.parts.title.on( 'mousedown', function( evt )
\r
1577 dialog._.updateSize = true;
\r
1579 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
\r
1581 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
\r
1582 CKEDITOR.document.on( 'mouseup', mouseUpHandler );
\r
1583 abstractDialogCoords = dialog.getPosition();
\r
1585 if ( CKEDITOR.env.ie6Compat )
\r
1587 var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
\r
1588 coverDoc.on( 'mousemove', mouseMoveHandler );
\r
1589 coverDoc.on( 'mouseup', mouseUpHandler );
\r
1592 evt.data.preventDefault();
\r
1596 function initResizeHandles( dialog )
\r
1598 var definition = dialog.definition,
\r
1599 minWidth = definition.minWidth || 0,
\r
1600 minHeight = definition.minHeight || 0,
\r
1601 resizable = definition.resizable,
\r
1602 margins = dialog.getParentEditor().skin.margins || [ 0, 0, 0, 0 ];
\r
1604 function topSizer( coords, dy )
\r
1609 function rightSizer( coords, dx )
\r
1614 function bottomSizer( coords, dy )
\r
1619 function leftSizer( coords, dx )
\r
1624 var lastCoords = null,
\r
1625 abstractDialogCoords = null,
\r
1626 magnetDistance = dialog._.editor.config.magnetDistance,
\r
1627 parts = [ 'tl', 't', 'tr', 'l', 'r', 'bl', 'b', 'br' ];
\r
1629 function mouseDownHandler( evt )
\r
1631 var partName = evt.listenerData.part, size = dialog.getSize();
\r
1632 abstractDialogCoords = dialog.getPosition();
\r
1633 CKEDITOR.tools.extend( abstractDialogCoords,
\r
1635 x2 : abstractDialogCoords.x + size.width,
\r
1636 y2 : abstractDialogCoords.y + size.height
\r
1638 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
\r
1640 CKEDITOR.document.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } );
\r
1641 CKEDITOR.document.on( 'mouseup', mouseUpHandler, dialog, { part : partName } );
\r
1643 if ( CKEDITOR.env.ie6Compat )
\r
1645 var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
\r
1646 coverDoc.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } );
\r
1647 coverDoc.on( 'mouseup', mouseUpHandler, dialog, { part : partName } );
\r
1650 evt.data.preventDefault();
\r
1653 function mouseMoveHandler( evt )
\r
1655 var x = evt.data.$.screenX,
\r
1656 y = evt.data.$.screenY,
\r
1657 dx = x - lastCoords.x,
\r
1658 dy = y - lastCoords.y,
\r
1659 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
\r
1660 partName = evt.listenerData.part;
\r
1662 if ( partName.search( 't' ) != -1 )
\r
1663 topSizer( abstractDialogCoords, dy );
\r
1664 if ( partName.search( 'l' ) != -1 )
\r
1665 leftSizer( abstractDialogCoords, dx );
\r
1666 if ( partName.search( 'b' ) != -1 )
\r
1667 bottomSizer( abstractDialogCoords, dy );
\r
1668 if ( partName.search( 'r' ) != -1 )
\r
1669 rightSizer( abstractDialogCoords, dx );
\r
1671 lastCoords = { x : x, y : y };
\r
1673 var realX, realY, realX2, realY2;
\r
1675 if ( abstractDialogCoords.x + margins[3] < magnetDistance )
\r
1676 realX = - margins[3];
\r
1677 else if ( partName.search( 'l' ) != -1 && abstractDialogCoords.x2 - abstractDialogCoords.x < minWidth + magnetDistance )
\r
1678 realX = abstractDialogCoords.x2 - minWidth;
\r
1680 realX = abstractDialogCoords.x;
\r
1682 if ( abstractDialogCoords.y + margins[0] < magnetDistance )
\r
1683 realY = - margins[0];
\r
1684 else if ( partName.search( 't' ) != -1 && abstractDialogCoords.y2 - abstractDialogCoords.y < minHeight + magnetDistance )
\r
1685 realY = abstractDialogCoords.y2 - minHeight;
\r
1687 realY = abstractDialogCoords.y;
\r
1689 if ( abstractDialogCoords.x2 - margins[1] > viewPaneSize.width - magnetDistance )
\r
1690 realX2 = viewPaneSize.width + margins[1] ;
\r
1691 else if ( partName.search( 'r' ) != -1 && abstractDialogCoords.x2 - abstractDialogCoords.x < minWidth + magnetDistance )
\r
1692 realX2 = abstractDialogCoords.x + minWidth;
\r
1694 realX2 = abstractDialogCoords.x2;
\r
1696 if ( abstractDialogCoords.y2 - margins[2] > viewPaneSize.height - magnetDistance )
\r
1697 realY2= viewPaneSize.height + margins[2] ;
\r
1698 else if ( partName.search( 'b' ) != -1 && abstractDialogCoords.y2 - abstractDialogCoords.y < minHeight + magnetDistance )
\r
1699 realY2 = abstractDialogCoords.y + minHeight;
\r
1701 realY2 = abstractDialogCoords.y2 ;
\r
1703 dialog.move( realX, realY );
\r
1704 dialog.resize( realX2 - realX, realY2 - realY );
\r
1706 evt.data.preventDefault();
\r
1709 function mouseUpHandler( evt )
\r
1711 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
\r
1712 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
\r
1714 if ( CKEDITOR.env.ie6Compat )
\r
1716 var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
\r
1717 coverDoc.removeListener( 'mouseup', mouseUpHandler );
\r
1718 coverDoc.removeListener( 'mousemove', mouseMoveHandler );
\r
1722 // TODO : Simplify the resize logic, having just a single resize grip <div>.
\r
1723 // var widthTest = /[lr]/,
\r
1724 // heightTest = /[tb]/;
\r
1725 // for ( var i = 0 ; i < parts.length ; i++ )
\r
1727 // var element = dialog.parts[ parts[i] + '_resize' ];
\r
1728 // if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE ||
\r
1729 // resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT && widthTest.test( parts[i] ) ||
\r
1730 // resizable == CKEDITOR.DIALOG_RESIZE_WIDTH && heightTest.test( parts[i] ) )
\r
1732 // element.hide();
\r
1735 // element.on( 'mousedown', mouseDownHandler, dialog, { part : parts[i] } );
\r
1742 var addCover = function( editor )
\r
1744 var win = CKEDITOR.document.getWindow();
\r
1746 if ( !coverElement )
\r
1748 var backgroundColorStyle = editor.config.dialog_backgroundCoverColor || 'white';
\r
1751 '<div style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),
\r
1752 '; z-index: ', editor.config.baseFloatZIndex,
\r
1753 '; top: 0px; left: 0px; ',
\r
1754 ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),
\r
1755 '" id="cke_dialog_background_cover">'
\r
1759 if ( CKEDITOR.env.ie6Compat )
\r
1761 // Support for custom document.domain in IE.
\r
1762 var isCustomDomain = CKEDITOR.env.isCustomDomain(),
\r
1763 iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
\r
1767 ' hidefocus="true"' +
\r
1768 ' frameborder="0"' +
\r
1769 ' id="cke_dialog_background_iframe"' +
\r
1770 ' src="javascript:' );
\r
1772 html.push( 'void((function(){' +
\r
1773 'document.open();' +
\r
1774 ( isCustomDomain ? 'document.domain=\'' + document.domain + '\';' : '' ) +
\r
1775 'document.write( \'' + iframeHtml + '\' );' +
\r
1776 'document.close();' +
\r
1782 'position:absolute;' +
\r
1787 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
\r
1791 html.push( '</div>' );
\r
1793 coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
\r
1796 var element = coverElement;
\r
1798 var resizeFunc = function()
\r
1800 var size = win.getViewPaneSize();
\r
1801 element.setStyles(
\r
1803 width : size.width + 'px',
\r
1804 height : size.height + 'px'
\r
1808 var scrollFunc = function()
\r
1810 var pos = win.getScrollPosition(),
\r
1811 cursor = CKEDITOR.dialog._.currentTop;
\r
1812 element.setStyles(
\r
1814 left : pos.x + 'px',
\r
1815 top : pos.y + 'px'
\r
1820 var dialogPos = cursor.getPosition();
\r
1821 cursor.move( dialogPos.x, dialogPos.y );
\r
1822 } while ( ( cursor = cursor._.parentDialog ) );
\r
1825 resizeCover = resizeFunc;
\r
1826 win.on( 'resize', resizeFunc );
\r
1828 if ( CKEDITOR.env.ie6Compat )
\r
1830 // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
\r
1831 // So we need to invent a really funny way to make it work.
\r
1832 var myScrollHandler = function()
\r
1835 arguments.callee.prevScrollHandler.apply( this, arguments );
\r
1837 win.$.setTimeout( function()
\r
1839 myScrollHandler.prevScrollHandler = window.onscroll || function(){};
\r
1840 window.onscroll = myScrollHandler;
\r
1845 var opacity = editor.config.dialog_backgroundCoverOpacity;
\r
1846 element.setOpacity( typeof opacity != 'undefined' ? opacity : 0.5 );
\r
1848 element.appendTo( CKEDITOR.document.getBody() );
\r
1851 var removeCover = function()
\r
1853 if ( !coverElement )
\r
1856 var win = CKEDITOR.document.getWindow();
\r
1857 coverElement.remove();
\r
1858 win.removeListener( 'resize', resizeCover );
\r
1860 if ( CKEDITOR.env.ie6Compat )
\r
1862 win.$.setTimeout( function()
\r
1864 var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
\r
1865 window.onscroll = prevScrollHandler || null;
\r
1868 resizeCover = null;
\r
1871 var accessKeyProcessors = {};
\r
1873 var accessKeyDownHandler = function( evt )
\r
1875 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
1876 alt = evt.data.$.altKey,
\r
1877 shift = evt.data.$.shiftKey,
\r
1878 key = String.fromCharCode( evt.data.$.keyCode ),
\r
1879 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
1881 if ( !keyProcessor || !keyProcessor.length )
\r
1884 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
1885 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
1886 evt.data.preventDefault();
\r
1889 var accessKeyUpHandler = function( evt )
\r
1891 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
\r
1892 alt = evt.data.$.altKey,
\r
1893 shift = evt.data.$.shiftKey,
\r
1894 key = String.fromCharCode( evt.data.$.keyCode ),
\r
1895 keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
\r
1897 if ( !keyProcessor || !keyProcessor.length )
\r
1900 keyProcessor = keyProcessor[keyProcessor.length - 1];
\r
1901 if ( keyProcessor.keyup )
\r
1903 keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
\r
1904 evt.data.preventDefault();
\r
1908 var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc )
\r
1910 var procList = accessKeyProcessors[key] || ( accessKeyProcessors[key] = [] );
\r
1912 uiElement : uiElement,
\r
1915 keyup : upFunc || uiElement.accessKeyUp,
\r
1916 keydown : downFunc || uiElement.accessKeyDown
\r
1920 var unregisterAccessKey = function( obj )
\r
1922 for ( var i in accessKeyProcessors )
\r
1924 var list = accessKeyProcessors[i];
\r
1925 for ( var j = list.length - 1 ; j >= 0 ; j-- )
\r
1927 if ( list[j].dialog == obj || list[j].uiElement == obj )
\r
1928 list.splice( j, 1 );
\r
1930 if ( list.length === 0 )
\r
1931 delete accessKeyProcessors[i];
\r
1935 var tabAccessKeyUp = function( dialog, key )
\r
1937 if ( dialog._.accessKeyMap[key] )
\r
1938 dialog.selectPage( dialog._.accessKeyMap[key] );
\r
1941 var tabAccessKeyDown = function( dialog, key )
\r
1946 var preventKeyBubblingKeys = { 27 :1, 13 :1 };
\r
1947 var preventKeyBubbling = function( e )
\r
1949 if ( e.data.getKeystroke() in preventKeyBubblingKeys )
\r
1950 e.data.stopPropagation();
\r
1955 CKEDITOR.ui.dialog =
\r
1958 * The base class of all dialog UI elements.
\r
1960 * @param {CKEDITOR.dialog} dialog Parent dialog object.
\r
1961 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition Element
\r
1962 * definition. Accepted fields:
\r
1964 * <li><strong>id</strong> (Required) The id of the UI element. See {@link
\r
1965 * CKEDITOR.dialog#getContentElement}</li>
\r
1966 * <li><strong>type</strong> (Required) The type of the UI element. The
\r
1967 * value to this field specifies which UI element class will be used to
\r
1968 * generate the final widget.</li>
\r
1969 * <li><strong>title</strong> (Optional) The popup tooltip for the UI
\r
1971 * <li><strong>hidden</strong> (Optional) A flag that tells if the element
\r
1972 * should be initially visible.</li>
\r
1973 * <li><strong>className</strong> (Optional) Additional CSS class names
\r
1974 * to add to the UI element. Separated by space.</li>
\r
1975 * <li><strong>style</strong> (Optional) Additional CSS inline styles
\r
1976 * to add to the UI element. A semicolon (;) is required after the last
\r
1977 * style declaration.</li>
\r
1978 * <li><strong>accessKey</strong> (Optional) The alphanumeric access key
\r
1979 * for this element. Access keys are automatically prefixed by CTRL.</li>
\r
1980 * <li><strong>on*</strong> (Optional) Any UI element definition field that
\r
1981 * starts with <em>on</em> followed immediately by a capital letter and
\r
1982 * probably more letters is an event handler. Event handlers may be further
\r
1983 * divided into registered event handlers and DOM event handlers. Please
\r
1984 * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and
\r
1985 * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more
\r
1986 * information.</li>
\r
1988 * @param {Array} htmlList
\r
1989 * List of HTML code to be added to the dialog's content area.
\r
1990 * @param {Function|String} nodeNameArg
\r
1991 * A function returning a string, or a simple string for the node name for
\r
1992 * the root DOM node. Default is 'div'.
\r
1993 * @param {Function|Object} stylesArg
\r
1994 * A function returning an object, or a simple object for CSS styles applied
\r
1995 * to the DOM node. Default is empty object.
\r
1996 * @param {Function|Object} attributesArg
\r
1997 * A fucntion returning an object, or a simple object for attributes applied
\r
1998 * to the DOM node. Default is empty object.
\r
1999 * @param {Function|String} contentsArg
\r
2000 * A function returning a string, or a simple string for the HTML code inside
\r
2001 * the root DOM node. Default is empty string.
\r
2004 uiElement : function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg )
\r
2006 if ( arguments.length < 4 )
\r
2009 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',
\r
2010 html = [ '<', nodeName, ' ' ],
\r
2011 styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},
\r
2012 attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},
\r
2013 innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',
\r
2014 domId = this.domId = attributes.id || CKEDITOR.tools.getNextNumber() + '_uiElement',
\r
2015 id = this.id = elementDefinition.id,
\r
2018 // Set the id, a unique id is required for getElement() to work.
\r
2019 attributes.id = domId;
\r
2021 // Set the type and definition CSS class names.
\r
2023 if ( elementDefinition.type )
\r
2024 classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;
\r
2025 if ( elementDefinition.className )
\r
2026 classes[ elementDefinition.className ] = 1;
\r
2027 var attributeClasses = ( attributes['class'] && attributes['class'].split ) ? attributes['class'].split( ' ' ) : [];
\r
2028 for ( i = 0 ; i < attributeClasses.length ; i++ )
\r
2030 if ( attributeClasses[i] )
\r
2031 classes[ attributeClasses[i] ] = 1;
\r
2033 var finalClasses = [];
\r
2034 for ( i in classes )
\r
2035 finalClasses.push( i );
\r
2036 attributes['class'] = finalClasses.join( ' ' );
\r
2038 // Set the popup tooltop.
\r
2039 if ( elementDefinition.title )
\r
2040 attributes.title = elementDefinition.title;
\r
2042 // Write the inline CSS styles.
\r
2043 var styleStr = ( elementDefinition.style || '' ).split( ';' );
\r
2044 for ( i in styles )
\r
2045 styleStr.push( i + ':' + styles[i] );
\r
2046 if ( elementDefinition.hidden )
\r
2047 styleStr.push( 'display:none' );
\r
2048 for ( i = styleStr.length - 1 ; i >= 0 ; i-- )
\r
2050 if ( styleStr[i] === '' )
\r
2051 styleStr.splice( i, 1 );
\r
2053 if ( styleStr.length > 0 )
\r
2054 attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
\r
2056 // Write the attributes.
\r
2057 for ( i in attributes )
\r
2058 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '" ');
\r
2060 // Write the content HTML.
\r
2061 html.push( '>', innerHTML, '</', nodeName, '>' );
\r
2063 // Add contents to the parent HTML array.
\r
2064 htmlList.push( html.join( '' ) );
\r
2066 ( this._ || ( this._ = {} ) ).dialog = dialog;
\r
2068 // Override isChanged if it is defined in element definition.
\r
2069 if ( typeof( elementDefinition.isChanged ) == 'boolean' )
\r
2070 this.isChanged = function(){ return elementDefinition.isChanged; };
\r
2071 if ( typeof( elementDefinition.isChanged ) == 'function' )
\r
2072 this.isChanged = elementDefinition.isChanged;
\r
2075 CKEDITOR.event.implementOn( this );
\r
2077 this.registerEvents( elementDefinition );
\r
2078 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
\r
2079 registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
\r
2082 dialog.on( 'load', function()
\r
2084 if ( me.getInputElement() )
\r
2086 me.getInputElement().on( 'focus', function()
\r
2088 dialog._.tabBarMode = false;
\r
2089 dialog._.hasFocus = true;
\r
2090 me.fire( 'focus' );
\r
2095 // Register the object as a tab focus if it can be included.
\r
2096 if ( this.keyboardFocusable )
\r
2098 this.tabIndex = elementDefinition.tabIndex || 0;
\r
2100 this.focusIndex = dialog._.focusList.push( this ) - 1;
\r
2101 this.on( 'focus', function()
\r
2103 dialog._.currentFocusIndex = me.focusIndex;
\r
2107 // Completes this object with everything we have in the
\r
2109 CKEDITOR.tools.extend( this, elementDefinition );
\r
2113 * Horizontal layout box for dialog UI elements, auto-expends to available width of container.
\r
2115 * @extends CKEDITOR.ui.dialog.uiElement
\r
2116 * @param {CKEDITOR.dialog} dialog
\r
2117 * Parent dialog object.
\r
2118 * @param {Array} childObjList
\r
2119 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2121 * @param {Array} childHtmlList
\r
2122 * Array of HTML code that correspond to the HTML output of all the
\r
2123 * objects in childObjList.
\r
2124 * @param {Array} htmlList
\r
2125 * Array of HTML code that this element will output to.
\r
2126 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
2127 * The element definition. Accepted fields:
\r
2129 * <li><strong>widths</strong> (Optional) The widths of child cells.</li>
\r
2130 * <li><strong>height</strong> (Optional) The height of the layout.</li>
\r
2131 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2133 * <li><strong>align</strong> (Optional) The alignment of the whole layout
\r
2138 hbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2140 if ( arguments.length < 4 )
\r
2143 this._ || ( this._ = {} );
\r
2145 var children = this._.children = childObjList,
\r
2146 widths = elementDefinition && elementDefinition.widths || null,
\r
2147 height = elementDefinition && elementDefinition.height || null,
\r
2151 var innerHTML = function()
\r
2153 var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];
\r
2154 for ( i = 0 ; i < childHtmlList.length ; i++ )
\r
2156 var className = 'cke_dialog_ui_hbox_child',
\r
2159 className = 'cke_dialog_ui_hbox_first';
\r
2160 if ( i == childHtmlList.length - 1 )
\r
2161 className = 'cke_dialog_ui_hbox_last';
\r
2162 html.push( '<td class="', className, '" role="presentation" ' );
\r
2166 styles.push( 'width:' + CKEDITOR.tools.cssLength( widths[i] ) );
\r
2169 styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2171 styles.push( 'height:' + CKEDITOR.tools.cssLength( height ) );
\r
2172 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2173 styles.push( 'padding:' + CKEDITOR.tools.cssLength( elementDefinition.padding ) );
\r
2174 if ( styles.length > 0 )
\r
2175 html.push( 'style="' + styles.join('; ') + '" ' );
\r
2176 html.push( '>', childHtmlList[i], '</td>' );
\r
2178 html.push( '</tr></tbody>' );
\r
2179 return html.join( '' );
\r
2182 var attribs = { role : 'presentation' };
\r
2183 elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );
\r
2185 CKEDITOR.ui.dialog.uiElement.call(
\r
2188 elementDefinition || { type : 'hbox' },
\r
2197 * Vertical layout box for dialog UI elements.
\r
2199 * @extends CKEDITOR.ui.dialog.hbox
\r
2200 * @param {CKEDITOR.dialog} dialog
\r
2201 * Parent dialog object.
\r
2202 * @param {Array} childObjList
\r
2203 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
\r
2205 * @param {Array} childHtmlList
\r
2206 * Array of HTML code that correspond to the HTML output of all the
\r
2207 * objects in childObjList.
\r
2208 * @param {Array} htmlList
\r
2209 * Array of HTML code that this element will output to.
\r
2210 * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
\r
2211 * The element definition. Accepted fields:
\r
2213 * <li><strong>width</strong> (Optional) The width of the layout.</li>
\r
2214 * <li><strong>heights</strong> (Optional) The heights of individual cells.
\r
2216 * <li><strong>align</strong> (Optional) The alignment of the layout.</li>
\r
2217 * <li><strong>padding</strong> (Optional) The padding width inside child
\r
2219 * <li><strong>expand</strong> (Optional) Whether the layout should expand
\r
2220 * vertically to fill its container.</li>
\r
2224 vbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
\r
2226 if (arguments.length < 3 )
\r
2229 this._ || ( this._ = {} );
\r
2231 var children = this._.children = childObjList,
\r
2232 width = elementDefinition && elementDefinition.width || null,
\r
2233 heights = elementDefinition && elementDefinition.heights || null;
\r
2235 var innerHTML = function()
\r
2237 var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];
\r
2238 html.push( 'style="' );
\r
2239 if ( elementDefinition && elementDefinition.expand )
\r
2240 html.push( 'height:100%;' );
\r
2241 html.push( 'width:' + CKEDITOR.tools.cssLength( width || '100%' ), ';' );
\r
2243 html.push( 'align="', CKEDITOR.tools.htmlEncode(
\r
2244 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
\r
2246 html.push( '><tbody>' );
\r
2247 for ( var i = 0 ; i < childHtmlList.length ; i++ )
\r
2250 html.push( '<tr><td role="presentation" ' );
\r
2252 styles.push( 'width:' + CKEDITOR.tools.cssLength( width || '100%' ) );
\r
2254 styles.push( 'height:' + CKEDITOR.tools.cssLength( heights[i] ) );
\r
2255 else if ( elementDefinition && elementDefinition.expand )
\r
2256 styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
\r
2257 if ( elementDefinition && elementDefinition.padding != undefined )
\r
2258 styles.push( 'padding:' + CKEDITOR.tools.cssLength( elementDefinition.padding ) );
\r
2259 if ( styles.length > 0 )
\r
2260 html.push( 'style="', styles.join( '; ' ), '" ' );
\r
2261 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[i], '</td></tr>' );
\r
2263 html.push( '</tbody></table>' );
\r
2264 return html.join( '' );
\r
2266 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type : 'vbox' }, htmlList, 'div', null, { role : 'presentation' }, innerHTML );
\r
2271 CKEDITOR.ui.dialog.uiElement.prototype =
\r
2274 * Gets the root DOM element of this dialog UI object.
\r
2275 * @returns {CKEDITOR.dom.element} Root DOM element of UI object.
\r
2277 * uiElement.getElement().hide();
\r
2279 getElement : function()
\r
2281 return CKEDITOR.document.getById( this.domId );
\r
2285 * Gets the DOM element that the user inputs values.
\r
2286 * This function is used by setValue(), getValue() and focus(). It should
\r
2287 * be overrided in child classes where the input element isn't the root
\r
2289 * @returns {CKEDITOR.dom.element} The element where the user input values.
\r
2291 * var rawValue = textInput.getInputElement().$.value;
\r
2293 getInputElement : function()
\r
2295 return this.getElement();
\r
2299 * Gets the parent dialog object containing this UI element.
\r
2300 * @returns {CKEDITOR.dialog} Parent dialog object.
\r
2302 * var dialog = uiElement.getDialog();
\r
2304 getDialog : function()
\r
2306 return this._.dialog;
\r
2310 * Sets the value of this dialog UI object.
\r
2311 * @param {Object} value The new value.
\r
2312 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2314 * uiElement.setValue( 'Dingo' );
\r
2316 setValue : function( value )
\r
2318 this.getInputElement().setValue( value );
\r
2319 this.fire( 'change', { value : value } );
\r
2324 * Gets the current value of this dialog UI object.
\r
2325 * @returns {Object} The current value.
\r
2327 * var myValue = uiElement.getValue();
\r
2329 getValue : function()
\r
2331 return this.getInputElement().getValue();
\r
2335 * Tells whether the UI object's value has changed.
\r
2336 * @returns {Boolean} true if changed, false if not changed.
\r
2338 * if ( uiElement.isChanged() )
\r
2339 * confirm( 'Value changed! Continue?' );
\r
2341 isChanged : function()
\r
2343 // Override in input classes.
\r
2348 * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
\r
2349 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2351 * focus : function()
\r
2353 * this.selectParentTab();
\r
2354 * // do something else.
\r
2357 selectParentTab : function()
\r
2359 var element = this.getInputElement(),
\r
2362 while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 )
\r
2365 // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
\r
2369 tabId = cursor.getAttribute( 'name' );
\r
2370 // Avoid duplicate select.
\r
2371 if ( this._.dialog._.currentTabId != tabId )
\r
2372 this._.dialog.selectPage( tabId );
\r
2377 * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
\r
2378 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2380 * uiElement.focus();
\r
2382 focus : function()
\r
2384 this.selectParentTab().getInputElement().focus();
\r
2389 * Registers the on* event handlers defined in the element definition.
\r
2390 * The default behavior of this function is:
\r
2393 * If the on* event is defined in the class's eventProcesors list,
\r
2394 * then the registration is delegated to the corresponding function
\r
2395 * in the eventProcessors list.
\r
2398 * If the on* event is not defined in the eventProcessors list, then
\r
2399 * register the event handler under the corresponding DOM event of
\r
2400 * the UI element's input DOM element (as defined by the return value
\r
2401 * of {@link CKEDITOR.ui.dialog.uiElement#getInputElement}).
\r
2404 * This function is only called at UI element instantiation, but can
\r
2405 * be overridded in child classes if they require more flexibility.
\r
2406 * @param {CKEDITOR.dialog.uiElementDefinition} definition The UI element
\r
2408 * @returns {CKEDITOR.dialog.uiElement} The current UI element.
\r
2411 registerEvents : function( definition )
\r
2413 var regex = /^on([A-Z]\w+)/,
\r
2416 var registerDomEvent = function( uiElement, dialog, eventName, func )
\r
2418 dialog.on( 'load', function()
\r
2420 uiElement.getInputElement().on( eventName, func, uiElement );
\r
2424 for ( var i in definition )
\r
2426 if ( !( match = i.match( regex ) ) )
\r
2428 if ( this.eventProcessors[i] )
\r
2429 this.eventProcessors[i].call( this, this._.dialog, definition[i] );
\r
2431 registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
\r
2438 * The event processor list used by
\r
2439 * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element
\r
2440 * instantiation. The default list defines three on* events:
\r
2442 * <li>onLoad - Called when the element's parent dialog opens for the
\r
2444 * <li>onShow - Called whenever the element's parent dialog opens.</li>
\r
2445 * <li>onHide - Called whenever the element's parent dialog closes.</li>
\r
2450 * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick
\r
2451 * // handlers in the UI element's definitions.
\r
2452 * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},
\r
2453 * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
\r
2454 * { onClick : function( dialog, func ) { this.on( 'click', func ); } },
\r
2455 * true );
\r
2459 onLoad : function( dialog, func )
\r
2461 dialog.on( 'load', func, this );
\r
2464 onShow : function( dialog, func )
\r
2466 dialog.on( 'show', func, this );
\r
2469 onHide : function( dialog, func )
\r
2471 dialog.on( 'hide', func, this );
\r
2476 * The default handler for a UI element's access key down event, which
\r
2477 * tries to put focus to the UI element.<br />
\r
2478 * Can be overridded in child classes for more sophisticaed behavior.
\r
2479 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2480 * @param {String} key The key combination pressed. Since access keys
\r
2481 * are defined to always include the CTRL key, its value should always
\r
2482 * include a 'CTRL+' prefix.
\r
2485 accessKeyDown : function( dialog, key )
\r
2491 * The default handler for a UI element's access key up event, which
\r
2492 * does nothing.<br />
\r
2493 * Can be overridded in child classes for more sophisticated behavior.
\r
2494 * @param {CKEDITOR.dialog} dialog The parent dialog object.
\r
2495 * @param {String} key The key combination pressed. Since access keys
\r
2496 * are defined to always include the CTRL key, its value should always
\r
2497 * include a 'CTRL+' prefix.
\r
2500 accessKeyUp : function( dialog, key )
\r
2505 * Disables a UI element.
\r
2508 disable : function()
\r
2510 var element = this.getInputElement();
\r
2511 element.setAttribute( 'disabled', 'true' );
\r
2512 element.addClass( 'cke_disabled' );
\r
2516 * Enables a UI element.
\r
2519 enable : function()
\r
2521 var element = this.getInputElement();
\r
2522 element.removeAttribute( 'disabled' );
\r
2523 element.removeClass( 'cke_disabled' );
\r
2527 * Determines whether an UI element is enabled or not.
\r
2528 * @returns {Boolean} Whether the UI element is enabled.
\r
2531 isEnabled : function()
\r
2533 return !this.getInputElement().getAttribute( 'disabled' );
\r
2537 * Determines whether an UI element is visible or not.
\r
2538 * @returns {Boolean} Whether the UI element is visible.
\r
2541 isVisible : function()
\r
2543 return this.getInputElement().isVisible();
\r
2547 * Determines whether an UI element is focus-able or not.
\r
2548 * Focus-able is defined as being both visible and enabled.
\r
2549 * @returns {Boolean} Whether the UI element can be focused.
\r
2552 isFocusable : function()
\r
2554 if ( !this.isEnabled() || !this.isVisible() )
\r
2560 CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
\r
2562 * @lends CKEDITOR.ui.dialog.hbox.prototype
\r
2566 * Gets a child UI element inside this container.
\r
2567 * @param {Array|Number} indices An array or a single number to indicate the child's
\r
2568 * position in the container's descendant tree. Omit to get all the children in an array.
\r
2569 * @returns {Array|CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container
\r
2570 * if no argument given, or the specified UI element if indices is given.
\r
2572 * var checkbox = hbox.getChild( [0,1] );
\r
2573 * checkbox.setValue( true );
\r
2575 getChild : function( indices )
\r
2577 // If no arguments, return a clone of the children array.
\r
2578 if ( arguments.length < 1 )
\r
2579 return this._.children.concat();
\r
2581 // If indices isn't array, make it one.
\r
2582 if ( !indices.splice )
\r
2583 indices = [ indices ];
\r
2585 // Retrieve the child element according to tree position.
\r
2586 if ( indices.length < 2 )
\r
2587 return this._.children[ indices[0] ];
\r
2589 return ( this._.children[ indices[0] ] && this._.children[ indices[0] ].getChild ) ?
\r
2590 this._.children[ indices[0] ].getChild( indices.slice( 1, indices.length ) ) :
\r
2595 CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
\r
2601 var commonBuilder = {
\r
2602 build : function( dialog, elementDefinition, output )
\r
2604 var children = elementDefinition.children,
\r
2606 childHtmlList = [],
\r
2607 childObjList = [];
\r
2608 for ( var i = 0 ; ( i < children.length && ( child = children[i] ) ) ; i++ )
\r
2610 var childHtml = [];
\r
2611 childHtmlList.push( childHtml );
\r
2612 childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
\r
2614 return new CKEDITOR.ui.dialog[elementDefinition.type]( dialog, childObjList, childHtmlList, output, elementDefinition );
\r
2618 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
\r
2619 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
\r
2623 * Generic dialog command. It opens a specific dialog when executed.
\r
2625 * @augments CKEDITOR.commandDefinition
\r
2626 * @param {string} dialogName The name of the dialog to open when executing
\r
2629 * // Register the "link" command, which opens the "link" dialog.
\r
2630 * editor.addCommand( 'link', <b>new CKEDITOR.dialogCommand( 'link' )</b> );
\r
2632 CKEDITOR.dialogCommand = function( dialogName )
\r
2634 this.dialogName = dialogName;
\r
2637 CKEDITOR.dialogCommand.prototype =
\r
2640 exec : function( editor )
\r
2642 editor.openDialog( this.dialogName );
\r
2645 // Dialog commands just open a dialog ui, thus require no undo logic,
\r
2646 // undo support should dedicate to specific dialog implementation.
\r
2649 editorFocus : CKEDITOR.env.ie
\r
2654 var notEmptyRegex = /^([a]|[^a])+$/,
\r
2655 integerRegex = /^\d*$/,
\r
2656 numberRegex = /^\d*(?:\.\d+)?$/;
\r
2658 CKEDITOR.VALIDATE_OR = 1;
\r
2659 CKEDITOR.VALIDATE_AND = 2;
\r
2661 CKEDITOR.dialog.validate =
\r
2663 functions : function()
\r
2668 * It's important for validate functions to be able to accept the value
\r
2669 * as argument in addition to this.getValue(), so that it is possible to
\r
2670 * combine validate functions together to make more sophisticated
\r
2673 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
2675 var msg = undefined,
\r
2676 relation = CKEDITOR.VALIDATE_AND,
\r
2677 functions = [], i;
\r
2679 for ( i = 0 ; i < arguments.length ; i++ )
\r
2681 if ( typeof( arguments[i] ) == 'function' )
\r
2682 functions.push( arguments[i] );
\r
2687 if ( i < arguments.length && typeof( arguments[i] ) == 'string' )
\r
2689 msg = arguments[i];
\r
2693 if ( i < arguments.length && typeof( arguments[i]) == 'number' )
\r
2694 relation = arguments[i];
\r
2696 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );
\r
2697 for ( i = 0 ; i < functions.length ; i++ )
\r
2699 if ( relation == CKEDITOR.VALIDATE_AND )
\r
2700 passed = passed && functions[i]( value );
\r
2702 passed = passed || functions[i]( value );
\r
2707 if ( msg !== undefined )
\r
2709 if ( this && ( this.select || this.focus ) )
\r
2710 ( this.select || this.focus )();
\r
2718 regex : function( regex, msg )
\r
2721 * Can be greatly shortened by deriving from functions validator if code size
\r
2722 * turns out to be more important than performance.
\r
2726 var value = this && this.getValue ? this.getValue() : arguments[0];
\r
2727 if ( !regex.test( value ) )
\r
2729 if ( msg !== undefined )
\r
2731 if ( this && ( this.select || this.focus ) )
\r
2733 if ( this.select )
\r
2744 notEmpty : function( msg )
\r
2746 return this.regex( notEmptyRegex, msg );
\r
2749 integer : function( msg )
\r
2751 return this.regex( integerRegex, msg );
\r
2754 'number' : function( msg )
\r
2756 return this.regex( numberRegex, msg );
\r
2759 equals : function( value, msg )
\r
2761 return this.functions( function( val ){ return val == value; }, msg );
\r
2764 notEqual : function( value, msg )
\r
2766 return this.functions( function( val ){ return val != value; }, msg );
\r
2772 // Extend the CKEDITOR.editor class with dialog specific functions.
\r
2773 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
\r
2774 /** @lends CKEDITOR.editor.prototype */
\r
2777 * Loads and opens a registered dialog.
\r
2778 * @param {String} dialogName The registered name of the dialog.
\r
2779 * @param {Function} callback The function to be invoked after dialog instance created.
\r
2780 * @see CKEDITOR.dialog.add
\r
2782 * CKEDITOR.instances.editor1.openDialog( 'smiley' );
\r
2783 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed. null if the dialog name is not registered.
\r
2785 openDialog : function( dialogName, callback )
\r
2787 var dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];
\r
2789 // If the dialogDefinition is already loaded, open it immediately.
\r
2790 if ( typeof dialogDefinitions == 'function' )
\r
2792 var storedDialogs = this._.storedDialogs ||
\r
2793 ( this._.storedDialogs = {} );
\r
2795 var dialog = storedDialogs[ dialogName ] ||
\r
2796 ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
\r
2798 callback && callback.call( dialog, dialog );
\r
2803 else if ( dialogDefinitions == 'failed' )
\r
2804 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
\r
2806 // Not loaded? Load the .js file first.
\r
2807 var body = CKEDITOR.document.getBody(),
\r
2808 cursor = body.$.style.cursor,
\r
2811 body.setStyle( 'cursor', 'wait' );
\r
2812 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ), function()
\r
2814 // In case of plugin error, mark it as loading failed.
\r
2815 if ( typeof CKEDITOR.dialog._.dialogDefinitions[ dialogName ] != 'function' )
\r
2816 CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';
\r
2817 me.openDialog( dialogName, callback );
\r
2818 body.setStyle( 'cursor', cursor );
\r
2825 CKEDITOR.plugins.add( 'dialog',
\r
2827 requires : [ 'dialogui' ]
\r
2830 // Dialog related configurations.
\r
2833 * The color of the dialog background cover. It should be a valid CSS color
\r
2835 * @name CKEDITOR.config.dialog_backgroundCoverColor
\r
2837 * @default 'white'
\r
2839 * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
\r
2843 * The opacity of the dialog background cover. It should be a number within the
\r
2844 * range [0.0, 1.0].
\r
2845 * @name CKEDITOR.config.dialog_backgroundCoverOpacity
\r
2849 * config.dialog_backgroundCoverOpacity = 0.7;
\r
2853 * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.
\r
2854 * @name CKEDITOR.config.dialog_startupFocusTab
\r
2858 * config.dialog_startupFocusTab = true;
\r
2862 * The distance of magnetic borders used in moving and resizing dialogs,
\r
2863 * measured in pixels.
\r
2864 * @name CKEDITOR.config.dialog_magnetDistance
\r
2868 * config.dialog_magnetDistance = 30;
\r
2872 * Fired when a dialog definition is about to be used to create a dialog into
\r
2873 * an editor instance. This event makes it possible to customize the definition
\r
2874 * before creating it.
\r
2875 * <p>Note that this event is called only the first time a specific dialog is
\r
2876 * opened. Successive openings will use the cached dialog, and this event will
\r
2877 * not get fired.</p>
\r
2878 * @name CKEDITOR#dialogDefinition
\r
2880 * @param {CKEDITOR.dialog.dialogDefinition} data The dialog defination that
\r
2881 * is being loaded.
\r
2882 * @param {CKEDITOR.editor} editor The editor instance that will use the
\r