JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
13f632719684082337990ceab0de6d28c1aa0105
[ckeditor.git] / _source / plugins / dialog / plugin.js
1 /*\r
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 /**\r
7  * @fileOverview The floating dialog plugin.\r
8  */\r
9 \r
10 /**\r
11  * No resize for this dialog.\r
12  * @constant\r
13  */\r
14 CKEDITOR.DIALOG_RESIZE_NONE = 0;\r
15 \r
16 /**\r
17  * Only allow horizontal resizing for this dialog, disable vertical resizing.\r
18  * @constant\r
19  */\r
20 CKEDITOR.DIALOG_RESIZE_WIDTH = 1;\r
21 \r
22 /**\r
23  * Only allow vertical resizing for this dialog, disable horizontal resizing.\r
24  * @constant\r
25  */\r
26 CKEDITOR.DIALOG_RESIZE_HEIGHT = 2;\r
27 \r
28 /*\r
29  * Allow the dialog to be resized in both directions.\r
30  * @constant\r
31  */\r
32 CKEDITOR.DIALOG_RESIZE_BOTH = 3;\r
33 \r
34 (function()\r
35 {\r
36         var cssLength = CKEDITOR.tools.cssLength;\r
37         function isTabVisible( tabId )\r
38         {\r
39                 return !!this._.tabs[ tabId ][ 0 ].$.offsetHeight;\r
40         }\r
41 \r
42         function getPreviousVisibleTab()\r
43         {\r
44                 var tabId = this._.currentTabId,\r
45                         length = this._.tabIdList.length,\r
46                         tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId ) + length;\r
47 \r
48                 for ( var i = tabIndex - 1 ; i > tabIndex - length ; i-- )\r
49                 {\r
50                         if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )\r
51                                 return this._.tabIdList[ i % length ];\r
52                 }\r
53 \r
54                 return null;\r
55         }\r
56 \r
57         function getNextVisibleTab()\r
58         {\r
59                 var tabId = this._.currentTabId,\r
60                         length = this._.tabIdList.length,\r
61                         tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId );\r
62 \r
63                 for ( var i = tabIndex + 1 ; i < tabIndex + length ; i++ )\r
64                 {\r
65                         if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )\r
66                                 return this._.tabIdList[ i % length ];\r
67                 }\r
68 \r
69                 return null;\r
70         }\r
71 \r
72 \r
73         function clearOrRecoverTextInputValue( container, isRecover )\r
74         {\r
75                 var inputs = container.$.getElementsByTagName( 'input' );\r
76                 for ( var i = 0, length = inputs.length; i < length ; i++ )\r
77                 {\r
78                         var item = new CKEDITOR.dom.element( inputs[ i ] );\r
79 \r
80                         if ( item.getAttribute( 'type' ).toLowerCase() == 'text' )\r
81                         {\r
82                                 if ( isRecover )\r
83                                 {\r
84                                         item.setAttribute( 'value', item.getCustomData( 'fake_value' ) || '' );\r
85                                         item.removeCustomData( 'fake_value' );\r
86                                 }\r
87                                 else\r
88                                 {\r
89                                         item.setCustomData( 'fake_value', item.getAttribute( 'value' ) );\r
90                                         item.setAttribute( 'value', '' );\r
91                                 }\r
92                         }\r
93                 }\r
94         }\r
95 \r
96         /**\r
97          * This is the base class for runtime dialog objects. An instance of this\r
98          * class represents a single named dialog for a single editor instance.\r
99          * @param {Object} editor The editor which created the dialog.\r
100          * @param {String} dialogName The dialog's registered name.\r
101          * @constructor\r
102          * @example\r
103          * var dialogObj = new CKEDITOR.dialog( editor, 'smiley' );\r
104          */\r
105         CKEDITOR.dialog = function( editor, dialogName )\r
106         {\r
107                 // Load the dialog definition.\r
108                 var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];\r
109 \r
110                 // Completes the definition with the default values.\r
111                 definition = CKEDITOR.tools.extend( definition( editor ), defaultDialogDefinition );\r
112 \r
113                 // Clone a functionally independent copy for this dialog.\r
114                 definition = CKEDITOR.tools.clone( definition );\r
115 \r
116                 // Create a complex definition object, extending it with the API\r
117                 // functions.\r
118                 definition = new definitionObject( this, definition );\r
119 \r
120 \r
121                 var doc = CKEDITOR.document;\r
122 \r
123                 var themeBuilt = editor.theme.buildDialog( editor );\r
124 \r
125                 // Initialize some basic parameters.\r
126                 this._ =\r
127                 {\r
128                         editor : editor,\r
129                         element : themeBuilt.element,\r
130                         name : dialogName,\r
131                         contentSize : { width : 0, height : 0 },\r
132                         size : { width : 0, height : 0 },\r
133                         updateSize : false,\r
134                         contents : {},\r
135                         buttons : {},\r
136                         accessKeyMap : {},\r
137 \r
138                         // Initialize the tab and page map.\r
139                         tabs : {},\r
140                         tabIdList : [],\r
141                         currentTabId : null,\r
142                         currentTabIndex : null,\r
143                         pageCount : 0,\r
144                         lastTab : null,\r
145                         tabBarMode : false,\r
146 \r
147                         // Initialize the tab order array for input widgets.\r
148                         focusList : [],\r
149                         currentFocusIndex : 0,\r
150                         hasFocus : false\r
151                 };\r
152 \r
153                 this.parts = themeBuilt.parts;\r
154 \r
155                 CKEDITOR.tools.setTimeout( function()\r
156                         {\r
157                                 editor.fire( 'ariaWidget', this.parts.contents );\r
158                         },\r
159                         0, this );\r
160 \r
161                 // Set the startup styles for the dialog, avoiding it enlarging the\r
162                 // page size on the dialog creation.\r
163                 this.parts.dialog.setStyles(\r
164                         {\r
165                                 position : CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed',\r
166                                 top : 0,\r
167                                 left: 0,\r
168                                 visibility : 'hidden'\r
169                         });\r
170 \r
171                 // Call the CKEDITOR.event constructor to initialize this instance.\r
172                 CKEDITOR.event.call( this );\r
173 \r
174                 // Fire the "dialogDefinition" event, making it possible to customize\r
175                 // the dialog definition.\r
176                 this.definition = definition = CKEDITOR.fire( 'dialogDefinition',\r
177                         {\r
178                                 name : dialogName,\r
179                                 definition : definition\r
180                         }\r
181                         , editor ).definition;\r
182                 // Initialize load, show, hide, ok and cancel events.\r
183                 if ( definition.onLoad )\r
184                         this.on( 'load', definition.onLoad );\r
185 \r
186                 if ( definition.onShow )\r
187                         this.on( 'show', definition.onShow );\r
188 \r
189                 if ( definition.onHide )\r
190                         this.on( 'hide', definition.onHide );\r
191 \r
192                 if ( definition.onOk )\r
193                 {\r
194                         this.on( 'ok', function( evt )\r
195                                 {\r
196                                         // Dialog confirm might probably introduce content changes (#5415).\r
197                                         editor.fire( 'saveSnapshot' );\r
198                                         setTimeout( function () { editor.fire( 'saveSnapshot' ); }, 0 );\r
199                                         if ( definition.onOk.call( this, evt ) === false )\r
200                                                 evt.data.hide = false;\r
201                                 });\r
202                 }\r
203 \r
204                 if ( definition.onCancel )\r
205                 {\r
206                         this.on( 'cancel', function( evt )\r
207                                 {\r
208                                         if ( definition.onCancel.call( this, evt ) === false )\r
209                                                 evt.data.hide = false;\r
210                                 });\r
211                 }\r
212 \r
213                 var me = this;\r
214 \r
215                 // Iterates over all items inside all content in the dialog, calling a\r
216                 // function for each of them.\r
217                 var iterContents = function( func )\r
218                 {\r
219                         var contents = me._.contents,\r
220                                 stop = false;\r
221 \r
222                         for ( var i in contents )\r
223                         {\r
224                                 for ( var j in contents[i] )\r
225                                 {\r
226                                         stop = func.call( this, contents[i][j] );\r
227                                         if ( stop )\r
228                                                 return;\r
229                                 }\r
230                         }\r
231                 };\r
232 \r
233                 this.on( 'ok', function( evt )\r
234                         {\r
235                                 iterContents( function( item )\r
236                                         {\r
237                                                 if ( item.validate )\r
238                                                 {\r
239                                                         var isValid = item.validate( this );\r
240 \r
241                                                         if ( typeof isValid == 'string' )\r
242                                                         {\r
243                                                                 alert( isValid );\r
244                                                                 isValid = false;\r
245                                                         }\r
246 \r
247                                                         if ( isValid === false )\r
248                                                         {\r
249                                                                 if ( item.select )\r
250                                                                         item.select();\r
251                                                                 else\r
252                                                                         item.focus();\r
253 \r
254                                                                 evt.data.hide = false;\r
255                                                                 evt.stop();\r
256                                                                 return true;\r
257                                                         }\r
258                                                 }\r
259                                         });\r
260                         }, this, null, 0 );\r
261 \r
262                 this.on( 'cancel', function( evt )\r
263                         {\r
264                                 iterContents( function( item )\r
265                                         {\r
266                                                 if ( item.isChanged() )\r
267                                                 {\r
268                                                         if ( !confirm( editor.lang.common.confirmCancel ) )\r
269                                                                 evt.data.hide = false;\r
270                                                         return true;\r
271                                                 }\r
272                                         });\r
273                         }, this, null, 0 );\r
274 \r
275                 this.parts.close.on( 'click', function( evt )\r
276                                 {\r
277                                         if ( this.fire( 'cancel', { hide : true } ).hide !== false )\r
278                                                 this.hide();\r
279                                         evt.data.preventDefault();\r
280                                 }, this );\r
281 \r
282                 // Sort focus list according to tab order definitions.\r
283                 function setupFocus()\r
284                 {\r
285                         var focusList = me._.focusList;\r
286                         focusList.sort( function( a, b )\r
287                                 {\r
288                                         // Mimics browser tab order logics;\r
289                                         if ( a.tabIndex != b.tabIndex )\r
290                                                 return b.tabIndex - a.tabIndex;\r
291                                         //  Sort is not stable in some browsers,\r
292                                         // fall-back the comparator to 'focusIndex';\r
293                                         else\r
294                                                 return a.focusIndex - b.focusIndex;\r
295                                 });\r
296 \r
297                         var size = focusList.length;\r
298                         for ( var i = 0; i < size; i++ )\r
299                                 focusList[ i ].focusIndex = i;\r
300                 }\r
301 \r
302                 function changeFocus( forward )\r
303                 {\r
304                         var focusList = me._.focusList,\r
305                                 offset = forward ? 1 : -1;\r
306                         if ( focusList.length < 1 )\r
307                                 return;\r
308 \r
309                         var current = me._.currentFocusIndex;\r
310 \r
311                         // Trigger the 'blur' event of  any input element before anything,\r
312                         // since certain UI updates may depend on it.\r
313                         try\r
314                         {\r
315                                 focusList[ current ].getInputElement().$.blur();\r
316                         }\r
317                         catch( e ){}\r
318 \r
319                         var startIndex = ( current + offset + focusList.length ) % focusList.length,\r
320                                 currentIndex = startIndex;\r
321                         while ( !focusList[ currentIndex ].isFocusable() )\r
322                         {\r
323                                 currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length;\r
324                                 if ( currentIndex == startIndex )\r
325                                         break;\r
326                         }\r
327                         focusList[ currentIndex ].focus();\r
328 \r
329                         // Select whole field content.\r
330                         if ( focusList[ currentIndex ].type == 'text' )\r
331                                 focusList[ currentIndex ].select();\r
332                 }\r
333 \r
334                 this.changeFocus = changeFocus;\r
335 \r
336                 var processed;\r
337 \r
338                 function focusKeydownHandler( evt )\r
339                 {\r
340                         // If I'm not the top dialog, ignore.\r
341                         if ( me != CKEDITOR.dialog._.currentTop )\r
342                                 return;\r
343 \r
344                         var keystroke = evt.data.getKeystroke(),\r
345                                 rtl = editor.lang.dir == 'rtl';\r
346 \r
347                         processed = 0;\r
348                         if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )\r
349                         {\r
350                                 var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );\r
351 \r
352                                 // Handling Tab and Shift-Tab.\r
353                                 if ( me._.tabBarMode )\r
354                                 {\r
355                                         // Change tabs.\r
356                                         var nextId = shiftPressed ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );\r
357                                         me.selectPage( nextId );\r
358                                         me._.tabs[ nextId ][ 0 ].focus();\r
359                                 }\r
360                                 else\r
361                                 {\r
362                                         // Change the focus of inputs.\r
363                                         changeFocus( !shiftPressed );\r
364                                 }\r
365 \r
366                                 processed = 1;\r
367                         }\r
368                         else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode && me.getPageCount() > 1 )\r
369                         {\r
370                                 // Alt-F10 puts focus into the current tab item in the tab bar.\r
371                                 me._.tabBarMode = true;\r
372                                 me._.tabs[ me._.currentTabId ][ 0 ].focus();\r
373                                 processed = 1;\r
374                         }\r
375                         else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode )\r
376                         {\r
377                                 // Arrow keys - used for changing tabs.\r
378                                 nextId = ( keystroke == ( rtl ? 39 : 37 ) ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) );\r
379                                 me.selectPage( nextId );\r
380                                 me._.tabs[ nextId ][ 0 ].focus();\r
381                                 processed = 1;\r
382                         }\r
383                         else if ( ( keystroke == 13 || keystroke == 32 ) && me._.tabBarMode )\r
384                         {\r
385                                 this.selectPage( this._.currentTabId );\r
386                                 this._.tabBarMode = false;\r
387                                 this._.currentFocusIndex = -1;\r
388                                 changeFocus( true );\r
389                                 processed = 1;\r
390                         }\r
391 \r
392                         if ( processed )\r
393                         {\r
394                                 evt.stop();\r
395                                 evt.data.preventDefault();\r
396                         }\r
397                 }\r
398 \r
399                 function focusKeyPressHandler( evt )\r
400                 {\r
401                         processed && evt.data.preventDefault();\r
402                 }\r
403 \r
404                 var dialogElement = this._.element;\r
405                 // Add the dialog keyboard handlers.\r
406                 this.on( 'show', function()\r
407                         {\r
408                                 dialogElement.on( 'keydown', focusKeydownHandler, this, null, 0 );\r
409                                 // Some browsers instead, don't cancel key events in the keydown, but in the\r
410                                 // keypress. So we must do a longer trip in those cases. (#4531)\r
411                                 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )\r
412                                         dialogElement.on( 'keypress', focusKeyPressHandler, this );\r
413 \r
414                         } );\r
415                 this.on( 'hide', function()\r
416                         {\r
417                                 dialogElement.removeListener( 'keydown', focusKeydownHandler );\r
418                                 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )\r
419                                         dialogElement.removeListener( 'keypress', focusKeyPressHandler );\r
420                         } );\r
421                 this.on( 'iframeAdded', function( evt )\r
422                         {\r
423                                 var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );\r
424                                 doc.on( 'keydown', focusKeydownHandler, this, null, 0 );\r
425                         } );\r
426 \r
427                 // Auto-focus logic in dialog.\r
428                 this.on( 'show', function()\r
429                         {\r
430                                 // Setup tabIndex on showing the dialog instead of on loading\r
431                                 // to allow dynamic tab order happen in dialog definition.\r
432                                 setupFocus();\r
433 \r
434                                 if ( editor.config.dialog_startupFocusTab\r
435                                         && me._.pageCount > 1 )\r
436                                 {\r
437                                         me._.tabBarMode = true;\r
438                                         me._.tabs[ me._.currentTabId ][ 0 ].focus();\r
439                                 }\r
440                                 else if ( !this._.hasFocus )\r
441                                 {\r
442                                         this._.currentFocusIndex = -1;\r
443 \r
444                                         // Decide where to put the initial focus.\r
445                                         if ( definition.onFocus )\r
446                                         {\r
447                                                 var initialFocus = definition.onFocus.call( this );\r
448                                                 // Focus the field that the user specified.\r
449                                                 initialFocus && initialFocus.focus();\r
450                                         }\r
451                                         // Focus the first field in layout order.\r
452                                         else\r
453                                                 changeFocus( true );\r
454 \r
455                                         /*\r
456                                          * IE BUG: If the initial focus went into a non-text element (e.g. button),\r
457                                          * then IE would still leave the caret inside the editing area.\r
458                                          */\r
459                                         if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie )\r
460                                         {\r
461                                                 var $selection = editor.document.$.selection,\r
462                                                         $range = $selection.createRange();\r
463 \r
464                                                 if ( $range )\r
465                                                 {\r
466                                                         if ( $range.parentElement && $range.parentElement().ownerDocument == editor.document.$\r
467                                                           || $range.item && $range.item( 0 ).ownerDocument == editor.document.$ )\r
468                                                         {\r
469                                                                 var $myRange = document.body.createTextRange();\r
470                                                                 $myRange.moveToElementText( this.getElement().getFirst().$ );\r
471                                                                 $myRange.collapse( true );\r
472                                                                 $myRange.select();\r
473                                                         }\r
474                                                 }\r
475                                         }\r
476                                 }\r
477                         }, this, null, 0xffffffff );\r
478 \r
479                 // IE6 BUG: Text fields and text areas are only half-rendered the first time the dialog appears in IE6 (#2661).\r
480                 // This is still needed after [2708] and [2709] because text fields in hidden TR tags are still broken.\r
481                 if ( CKEDITOR.env.ie6Compat )\r
482                 {\r
483                         this.on( 'load', function( evt )\r
484                                         {\r
485                                                 var outer = this.getElement(),\r
486                                                         inner = outer.getFirst();\r
487                                                 inner.remove();\r
488                                                 inner.appendTo( outer );\r
489                                         }, this );\r
490                 }\r
491 \r
492                 initDragAndDrop( this );\r
493                 initResizeHandles( this );\r
494 \r
495                 // Insert the title.\r
496                 ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );\r
497 \r
498                 // Insert the tabs and contents.\r
499                 for ( var i = 0 ; i < definition.contents.length ; i++ )\r
500                 {\r
501                         var page = definition.contents[i];\r
502                         page && this.addPage( page );\r
503                 }\r
504 \r
505                 this.parts[ 'tabs' ].on( 'click', function( evt )\r
506                                 {\r
507                                         var target = evt.data.getTarget();\r
508                                         // If we aren't inside a tab, bail out.\r
509                                         if ( target.hasClass( 'cke_dialog_tab' ) )\r
510                                         {\r
511                                                 // Get the ID of the tab, without the 'cke_' prefix and the unique number suffix.\r
512                                                 var id = target.$.id;\r
513                                                 this.selectPage( id.substring( 4, id.lastIndexOf( '_' ) ) );\r
514 \r
515                                                 if ( this._.tabBarMode )\r
516                                                 {\r
517                                                         this._.tabBarMode = false;\r
518                                                         this._.currentFocusIndex = -1;\r
519                                                         changeFocus( true );\r
520                                                 }\r
521                                                 evt.data.preventDefault();\r
522                                         }\r
523                                 }, this );\r
524 \r
525                 // Insert buttons.\r
526                 var buttonsHtml = [],\r
527                         buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this,\r
528                                 {\r
529                                         type : 'hbox',\r
530                                         className : 'cke_dialog_footer_buttons',\r
531                                         widths : [],\r
532                                         children : definition.buttons\r
533                                 }, buttonsHtml ).getChild();\r
534                 this.parts.footer.setHtml( buttonsHtml.join( '' ) );\r
535 \r
536                 for ( i = 0 ; i < buttons.length ; i++ )\r
537                         this._.buttons[ buttons[i].id ] = buttons[i];\r
538         };\r
539 \r
540         // Focusable interface. Use it via dialog.addFocusable.\r
541         function Focusable( dialog, element, index )\r
542         {\r
543                 this.element = element;\r
544                 this.focusIndex = index;\r
545                 // TODO: support tabIndex for focusables.\r
546                 this.tabIndex = 0;\r
547                 this.isFocusable = function()\r
548                 {\r
549                         return !element.getAttribute( 'disabled' ) && element.isVisible();\r
550                 };\r
551                 this.focus = function()\r
552                 {\r
553                         dialog._.currentFocusIndex = this.focusIndex;\r
554                         this.element.focus();\r
555                 };\r
556                 // Bind events\r
557                 element.on( 'keydown', function( e )\r
558                         {\r
559                                 if ( e.data.getKeystroke() in { 32:1, 13:1 }  )\r
560                                         this.fire( 'click' );\r
561                         } );\r
562                 element.on( 'focus', function()\r
563                         {\r
564                                 this.fire( 'mouseover' );\r
565                         } );\r
566                 element.on( 'blur', function()\r
567                         {\r
568                                 this.fire( 'mouseout' );\r
569                         } );\r
570         }\r
571 \r
572         CKEDITOR.dialog.prototype =\r
573         {\r
574                 destroy : function()\r
575                 {\r
576                         this.hide();\r
577                         this._.element.remove();\r
578                 },\r
579 \r
580                 /**\r
581                  * Resizes the dialog.\r
582                  * @param {Number} width The width of the dialog in pixels.\r
583                  * @param {Number} height The height of the dialog in pixels.\r
584                  * @function\r
585                  * @example\r
586                  * dialogObj.resize( 800, 640 );\r
587                  */\r
588                 resize : (function()\r
589                 {\r
590                         return function( width, height )\r
591                         {\r
592                                 if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )\r
593                                         return;\r
594 \r
595                                 CKEDITOR.dialog.fire( 'resize',\r
596                                         {\r
597                                                 dialog : this,\r
598                                                 skin : this._.editor.skinName,\r
599                                                 width : width,\r
600                                                 height : height\r
601                                         }, this._.editor );\r
602 \r
603                                 this._.contentSize = { width : width, height : height };\r
604                                 this._.updateSize = true;\r
605                         };\r
606                 })(),\r
607 \r
608                 /**\r
609                  * Gets the current size of the dialog in pixels.\r
610                  * @returns {Object} An object with "width" and "height" properties.\r
611                  * @example\r
612                  * var width = dialogObj.getSize().width;\r
613                  */\r
614                 getSize : function()\r
615                 {\r
616                         if ( !this._.updateSize )\r
617                                 return this._.size;\r
618                         var element = this._.element.getFirst();\r
619                         var size = this._.size = { width : element.$.offsetWidth || 0, height : element.$.offsetHeight || 0};\r
620 \r
621                         // If either the offsetWidth or offsetHeight is 0, the element isn't visible.\r
622                         this._.updateSize = !size.width || !size.height;\r
623 \r
624                         return size;\r
625                 },\r
626 \r
627                 /**\r
628                  * Moves the dialog to an (x, y) coordinate relative to the window.\r
629                  * @function\r
630                  * @param {Number} x The target x-coordinate.\r
631                  * @param {Number} y The target y-coordinate.\r
632                  * @example\r
633                  * dialogObj.move( 10, 40 );\r
634                  */\r
635                 move : (function()\r
636                 {\r
637                         var isFixed;\r
638                         return function( x, y )\r
639                         {\r
640                                 // The dialog may be fixed positioned or absolute positioned. Ask the\r
641                                 // browser what is the current situation first.\r
642                                 var element = this._.element.getFirst();\r
643                                 if ( isFixed === undefined )\r
644                                         isFixed = element.getComputedStyle( 'position' ) == 'fixed';\r
645 \r
646                                 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )\r
647                                         return;\r
648 \r
649                                 // Save the current position.\r
650                                 this._.position = { x : x, y : y };\r
651 \r
652                                 // If not fixed positioned, add scroll position to the coordinates.\r
653                                 if ( !isFixed )\r
654                                 {\r
655                                         var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();\r
656                                         x += scrollPosition.x;\r
657                                         y += scrollPosition.y;\r
658                                 }\r
659 \r
660                                 element.setStyles(\r
661                                                 {\r
662                                                         'left'  : ( x > 0 ? x : 0 ) + 'px',\r
663                                                         'top'   : ( y > 0 ? y : 0 ) + 'px'\r
664                                                 });\r
665                         };\r
666                 })(),\r
667 \r
668                 /**\r
669                  * Gets the dialog's position in the window.\r
670                  * @returns {Object} An object with "x" and "y" properties.\r
671                  * @example\r
672                  * var dialogX = dialogObj.getPosition().x;\r
673                  */\r
674                 getPosition : function(){ return CKEDITOR.tools.extend( {}, this._.position ); },\r
675 \r
676                 /**\r
677                  * Shows the dialog box.\r
678                  * @example\r
679                  * dialogObj.show();\r
680                  */\r
681                 show : function()\r
682                 {\r
683                         var editor = this._.editor;\r
684                         if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )\r
685                         {\r
686                                 var selection = editor.getSelection();\r
687                                 selection && selection.lock();\r
688                         }\r
689 \r
690                         // Insert the dialog's element to the root document.\r
691                         var element = this._.element;\r
692                         var definition = this.definition;\r
693                         if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )\r
694                                 element.appendTo( CKEDITOR.document.getBody() );\r
695                         else\r
696                                 element.setStyle( 'display', 'block' );\r
697 \r
698                         // FIREFOX BUG: Fix vanishing caret for Firefox 2 or Gecko 1.8.\r
699                         if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )\r
700                         {\r
701                                 var dialogElement = this.parts.dialog;\r
702                                 dialogElement.setStyle( 'position', 'absolute' );\r
703                                 setTimeout( function()\r
704                                         {\r
705                                                 dialogElement.setStyle( 'position', 'fixed' );\r
706                                         }, 0 );\r
707                         }\r
708 \r
709 \r
710                         // First, set the dialog to an appropriate size.\r
711                         this.resize( definition.minWidth, definition.minHeight );\r
712 \r
713                         // Reset all inputs back to their default value.\r
714                         this.reset();\r
715 \r
716                         // Select the first tab by default.\r
717                         this.selectPage( this.definition.contents[0].id );\r
718 \r
719                         // Set z-index.\r
720                         if ( CKEDITOR.dialog._.currentZIndex === null )\r
721                                 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;\r
722                         this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );\r
723 \r
724                         // Maintain the dialog ordering and dialog cover.\r
725                         // Also register key handlers if first dialog.\r
726                         if ( CKEDITOR.dialog._.currentTop === null )\r
727                         {\r
728                                 CKEDITOR.dialog._.currentTop = this;\r
729                                 this._.parentDialog = null;\r
730                                 showCover( this._.editor );\r
731 \r
732                                 element.on( 'keydown', accessKeyDownHandler );\r
733                                 element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );\r
734 \r
735                                 // Prevent some keys from bubbling up. (#4269)\r
736                                 for ( var event in { keyup :1, keydown :1, keypress :1 } )\r
737                                         element.on( event, preventKeyBubbling );\r
738                         }\r
739                         else\r
740                         {\r
741                                 this._.parentDialog = CKEDITOR.dialog._.currentTop;\r
742                                 var parentElement = this._.parentDialog.getElement().getFirst();\r
743                                 parentElement.$.style.zIndex  -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );\r
744                                 CKEDITOR.dialog._.currentTop = this;\r
745                         }\r
746 \r
747                         // Register the Esc hotkeys.\r
748                         registerAccessKey( this, this, '\x1b', null, function()\r
749                                         {\r
750                                                 this.getButton( 'cancel' ) && this.getButton( 'cancel' ).click();\r
751                                         } );\r
752 \r
753                         // Reset the hasFocus state.\r
754                         this._.hasFocus = false;\r
755 \r
756                         // Rearrange the dialog to the middle of the window.\r
757                         CKEDITOR.tools.setTimeout( function()\r
758                                 {\r
759                                         var viewSize = CKEDITOR.document.getWindow().getViewPaneSize();\r
760                                         var dialogSize = this.getSize();\r
761 \r
762                                         // We're using definition size for initial position because of\r
763                                         // offten corrupted data in offsetWidth at this point. (#4084)\r
764                                         this.move( ( viewSize.width - definition.minWidth ) / 2, ( viewSize.height - dialogSize.height ) / 2 );\r
765 \r
766                                         this.parts.dialog.setStyle( 'visibility', '' );\r
767 \r
768                                         // Execute onLoad for the first show.\r
769                                         this.fireOnce( 'load', {} );\r
770                                         this.fire( 'show', {} );\r
771                                         this._.editor.fire( 'dialogShow', this );\r
772 \r
773                                         // Save the initial values of the dialog.\r
774                                         this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } );\r
775 \r
776                                 },\r
777                                 100, this );\r
778                 },\r
779 \r
780                 /**\r
781                  * Executes a function for each UI element.\r
782                  * @param {Function} fn Function to execute for each UI element.\r
783                  * @returns {CKEDITOR.dialog} The current dialog object.\r
784                  */\r
785                 foreach : function( fn )\r
786                 {\r
787                         for ( var i in this._.contents )\r
788                         {\r
789                                 for ( var j in this._.contents[i] )\r
790                                         fn( this._.contents[i][j] );\r
791                         }\r
792                         return this;\r
793                 },\r
794 \r
795                 /**\r
796                  * Resets all input values in the dialog.\r
797                  * @example\r
798                  * dialogObj.reset();\r
799                  * @returns {CKEDITOR.dialog} The current dialog object.\r
800                  */\r
801                 reset : (function()\r
802                 {\r
803                         var fn = function( widget ){ if ( widget.reset ) widget.reset( 1 ); };\r
804                         return function(){ this.foreach( fn ); return this; };\r
805                 })(),\r
806 \r
807                 setupContent : function()\r
808                 {\r
809                         var args = arguments;\r
810                         this.foreach( function( widget )\r
811                                 {\r
812                                         if ( widget.setup )\r
813                                                 widget.setup.apply( widget, args );\r
814                                 });\r
815                 },\r
816 \r
817                 commitContent : function()\r
818                 {\r
819                         var args = arguments;\r
820                         this.foreach( function( widget )\r
821                                 {\r
822                                         if ( widget.commit )\r
823                                                 widget.commit.apply( widget, args );\r
824                                 });\r
825                 },\r
826 \r
827                 /**\r
828                  * Hides the dialog box.\r
829                  * @example\r
830                  * dialogObj.hide();\r
831                  */\r
832                 hide : function()\r
833                 {\r
834                         if ( !this.parts.dialog.isVisible() )\r
835                                 return;\r
836 \r
837                         this.fire( 'hide', {} );\r
838                         this._.editor.fire( 'dialogHide', this );\r
839                         var element = this._.element;\r
840                         element.setStyle( 'display', 'none' );\r
841                         this.parts.dialog.setStyle( 'visibility', 'hidden' );\r
842                         // Unregister all access keys associated with this dialog.\r
843                         unregisterAccessKey( this );\r
844 \r
845                         // Close any child(top) dialogs first.\r
846                         while( CKEDITOR.dialog._.currentTop != this )\r
847                                 CKEDITOR.dialog._.currentTop.hide();\r
848 \r
849                         // Maintain dialog ordering and remove cover if needed.\r
850                         if ( !this._.parentDialog )\r
851                                 hideCover();\r
852                         else\r
853                         {\r
854                                 var parentElement = this._.parentDialog.getElement().getFirst();\r
855                                 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );\r
856                         }\r
857                         CKEDITOR.dialog._.currentTop = this._.parentDialog;\r
858 \r
859                         // Deduct or clear the z-index.\r
860                         if ( !this._.parentDialog )\r
861                         {\r
862                                 CKEDITOR.dialog._.currentZIndex = null;\r
863 \r
864                                 // Remove access key handlers.\r
865                                 element.removeListener( 'keydown', accessKeyDownHandler );\r
866                                 element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );\r
867 \r
868                                 // Remove bubbling-prevention handler. (#4269)\r
869                                 for ( var event in { keyup :1, keydown :1, keypress :1 } )\r
870                                         element.removeListener( event, preventKeyBubbling );\r
871 \r
872                                 var editor = this._.editor;\r
873                                 editor.focus();\r
874 \r
875                                 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )\r
876                                 {\r
877                                         var selection = editor.getSelection();\r
878                                         selection && selection.unlock( true );\r
879                                 }\r
880                         }\r
881                         else\r
882                                 CKEDITOR.dialog._.currentZIndex -= 10;\r
883 \r
884                         delete this._.parentDialog;\r
885                         // Reset the initial values of the dialog.\r
886                         this.foreach( function( contentObj ) { contentObj.resetInitValue && contentObj.resetInitValue(); } );\r
887                 },\r
888 \r
889                 /**\r
890                  * Adds a tabbed page into the dialog.\r
891                  * @param {Object} contents Content definition.\r
892                  * @example\r
893                  */\r
894                 addPage : function( contents )\r
895                 {\r
896                         var pageHtml = [],\r
897                                 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',\r
898                                 elements = contents.elements,\r
899                                 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this,\r
900                                                 {\r
901                                                         type : 'vbox',\r
902                                                         className : 'cke_dialog_page_contents',\r
903                                                         children : contents.elements,\r
904                                                         expand : !!contents.expand,\r
905                                                         padding : contents.padding,\r
906                                                         style : contents.style || 'width: 100%; height: 100%;'\r
907                                                 }, pageHtml );\r
908 \r
909                         // Create the HTML for the tab and the content block.\r
910                         var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );\r
911                         page.setAttribute( 'role', 'tabpanel' );\r
912 \r
913                         var env = CKEDITOR.env;\r
914                         var tabId = 'cke_' + contents.id + '_' + CKEDITOR.tools.getNextNumber(),\r
915                                  tab = CKEDITOR.dom.element.createFromHtml( [\r
916                                         '<a class="cke_dialog_tab"',\r
917                                                 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),\r
918                                                 titleHtml,\r
919                                                 ( !!contents.hidden ? ' style="display:none"' : '' ),\r
920                                                 ' id="', tabId, '"',\r
921                                                 env.gecko && env.version >= 10900 && !env.hc ? '' : ' href="javascript:void(0)"',\r
922                                                 ' tabIndex="-1"',\r
923                                                 ' hidefocus="true"',\r
924                                                 ' role="tab">',\r
925                                                         contents.label,\r
926                                         '</a>'\r
927                                 ].join( '' ) );\r
928 \r
929                         page.setAttribute( 'aria-labelledby', tabId );\r
930 \r
931                         // Take records for the tabs and elements created.\r
932                         this._.tabs[ contents.id ] = [ tab, page ];\r
933                         this._.tabIdList.push( contents.id );\r
934                         !contents.hidden && this._.pageCount++;\r
935                         this._.lastTab = tab;\r
936                         this.updateStyle();\r
937 \r
938                         var contentMap = this._.contents[ contents.id ] = {},\r
939                                 cursor,\r
940                                 children = vbox.getChild();\r
941 \r
942                         while ( ( cursor = children.shift() ) )\r
943                         {\r
944                                 contentMap[ cursor.id ] = cursor;\r
945                                 if ( typeof( cursor.getChild ) == 'function' )\r
946                                         children.push.apply( children, cursor.getChild() );\r
947                         }\r
948 \r
949                         // Attach the DOM nodes.\r
950 \r
951                         page.setAttribute( 'name', contents.id );\r
952                         page.appendTo( this.parts.contents );\r
953 \r
954                         tab.unselectable();\r
955                         this.parts.tabs.append( tab );\r
956 \r
957                         // Add access key handlers if access key is defined.\r
958                         if ( contents.accessKey )\r
959                         {\r
960                                 registerAccessKey( this, this, 'CTRL+' + contents.accessKey,\r
961                                         tabAccessKeyDown, tabAccessKeyUp );\r
962                                 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;\r
963                         }\r
964                 },\r
965 \r
966                 /**\r
967                  * Activates a tab page in the dialog by its id.\r
968                  * @param {String} id The id of the dialog tab to be activated.\r
969                  * @example\r
970                  * dialogObj.selectPage( 'tab_1' );\r
971                  */\r
972                 selectPage : function( id )\r
973                 {\r
974                         if ( this._.currentTabId == id )\r
975                                 return;\r
976 \r
977                         // Returning true means that the event has been canceled\r
978                         if ( this.fire( 'selectPage', { page : id, currentPage : this._.currentTabId } ) === true )\r
979                                 return;\r
980 \r
981                         // Hide the non-selected tabs and pages.\r
982                         for ( var i in this._.tabs )\r
983                         {\r
984                                 var tab = this._.tabs[i][0],\r
985                                         page = this._.tabs[i][1];\r
986                                 if ( i != id )\r
987                                 {\r
988                                         tab.removeClass( 'cke_dialog_tab_selected' );\r
989                                         page.hide();\r
990                                 }\r
991                                 page.setAttribute( 'aria-hidden', i != id );\r
992                         }\r
993 \r
994                         var selected = this._.tabs[ id ];\r
995                         selected[ 0 ].addClass( 'cke_dialog_tab_selected' );\r
996 \r
997                         // [IE] an invisible input[type='text'] will enlarge it's width\r
998                         // if it's value is long when it shows, so we clear it's value\r
999                         // before it shows and then recover it (#5649)\r
1000                         if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat )\r
1001                         {\r
1002                                 clearOrRecoverTextInputValue( selected[ 1 ] );\r
1003                                 selected[ 1 ].show();\r
1004                                 setTimeout( function()\r
1005                                 {\r
1006                                         clearOrRecoverTextInputValue( selected[ 1 ], 1 );\r
1007                                 }, 0 );\r
1008                         }\r
1009                         else\r
1010                                 selected[ 1 ].show();\r
1011 \r
1012                         this._.currentTabId = id;\r
1013                         this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );\r
1014                 },\r
1015 \r
1016                 // Dialog state-specific style updates.\r
1017                 updateStyle : function()\r
1018                 {\r
1019                         // If only a single page shown, a different style is used in the central pane.\r
1020                         this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );\r
1021                 },\r
1022 \r
1023                 /**\r
1024                  * Hides a page's tab away from the dialog.\r
1025                  * @param {String} id The page's Id.\r
1026                  * @example\r
1027                  * dialog.hidePage( 'tab_3' );\r
1028                  */\r
1029                 hidePage : function( id )\r
1030                 {\r
1031                         var tab = this._.tabs[id] && this._.tabs[id][0];\r
1032                         if ( !tab || this._.pageCount == 1 )\r
1033                                 return;\r
1034                         // Switch to other tab first when we're hiding the active tab.\r
1035                         else if ( id == this._.currentTabId )\r
1036                                 this.selectPage( getPreviousVisibleTab.call( this ) );\r
1037 \r
1038                         tab.hide();\r
1039                         this._.pageCount--;\r
1040                         this.updateStyle();\r
1041                 },\r
1042 \r
1043                 /**\r
1044                  * Unhides a page's tab.\r
1045                  * @param {String} id The page's Id.\r
1046                  * @example\r
1047                  * dialog.showPage( 'tab_2' );\r
1048                  */\r
1049                 showPage : function( id )\r
1050                 {\r
1051                         var tab = this._.tabs[id] && this._.tabs[id][0];\r
1052                         if ( !tab )\r
1053                                 return;\r
1054                         tab.show();\r
1055                         this._.pageCount++;\r
1056                         this.updateStyle();\r
1057                 },\r
1058 \r
1059                 /**\r
1060                  * Gets the root DOM element of the dialog.\r
1061                  * @returns {CKEDITOR.dom.element} The &lt;span&gt; element containing this dialog.\r
1062                  * @example\r
1063                  * var dialogElement = dialogObj.getElement().getFirst();\r
1064                  * dialogElement.setStyle( 'padding', '5px' );\r
1065                  */\r
1066                 getElement : function()\r
1067                 {\r
1068                         return this._.element;\r
1069                 },\r
1070 \r
1071                 /**\r
1072                  * Gets the name of the dialog.\r
1073                  * @returns {String} The name of this dialog.\r
1074                  * @example\r
1075                  * var dialogName = dialogObj.getName();\r
1076                  */\r
1077                 getName : function()\r
1078                 {\r
1079                         return this._.name;\r
1080                 },\r
1081 \r
1082                 /**\r
1083                  * Gets a dialog UI element object from a dialog page.\r
1084                  * @param {String} pageId id of dialog page.\r
1085                  * @param {String} elementId id of UI element.\r
1086                  * @example\r
1087                  * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.\r
1088                  */\r
1089                 getContentElement : function( pageId, elementId )\r
1090                 {\r
1091                         var page = this._.contents[ pageId ];\r
1092                         return page && page[ elementId ];\r
1093                 },\r
1094 \r
1095                 /**\r
1096                  * Gets the value of a dialog UI element.\r
1097                  * @param {String} pageId id of dialog page.\r
1098                  * @param {String} elementId id of UI element.\r
1099                  * @example\r
1100                  * @returns {Object} The value of the UI element.\r
1101                  */\r
1102                 getValueOf : function( pageId, elementId )\r
1103                 {\r
1104                         return this.getContentElement( pageId, elementId ).getValue();\r
1105                 },\r
1106 \r
1107                 /**\r
1108                  * Sets the value of a dialog UI element.\r
1109                  * @param {String} pageId id of the dialog page.\r
1110                  * @param {String} elementId id of the UI element.\r
1111                  * @param {Object} value The new value of the UI element.\r
1112                  * @example\r
1113                  */\r
1114                 setValueOf : function( pageId, elementId, value )\r
1115                 {\r
1116                         return this.getContentElement( pageId, elementId ).setValue( value );\r
1117                 },\r
1118 \r
1119                 /**\r
1120                  * Gets the UI element of a button in the dialog's button row.\r
1121                  * @param {String} id The id of the button.\r
1122                  * @example\r
1123                  * @returns {CKEDITOR.ui.dialog.button} The button object.\r
1124                  */\r
1125                 getButton : function( id )\r
1126                 {\r
1127                         return this._.buttons[ id ];\r
1128                 },\r
1129 \r
1130                 /**\r
1131                  * Simulates a click to a dialog button in the dialog's button row.\r
1132                  * @param {String} id The id of the button.\r
1133                  * @example\r
1134                  * @returns The return value of the dialog's "click" event.\r
1135                  */\r
1136                 click : function( id )\r
1137                 {\r
1138                         return this._.buttons[ id ].click();\r
1139                 },\r
1140 \r
1141                 /**\r
1142                  * Disables a dialog button.\r
1143                  * @param {String} id The id of the button.\r
1144                  * @example\r
1145                  */\r
1146                 disableButton : function( id )\r
1147                 {\r
1148                         return this._.buttons[ id ].disable();\r
1149                 },\r
1150 \r
1151                 /**\r
1152                  * Enables a dialog button.\r
1153                  * @param {String} id The id of the button.\r
1154                  * @example\r
1155                  */\r
1156                 enableButton : function( id )\r
1157                 {\r
1158                         return this._.buttons[ id ].enable();\r
1159                 },\r
1160 \r
1161                 /**\r
1162                  * Gets the number of pages in the dialog.\r
1163                  * @returns {Number} Page count.\r
1164                  */\r
1165                 getPageCount : function()\r
1166                 {\r
1167                         return this._.pageCount;\r
1168                 },\r
1169 \r
1170                 /**\r
1171                  * Gets the editor instance which opened this dialog.\r
1172                  * @returns {CKEDITOR.editor} Parent editor instances.\r
1173                  */\r
1174                 getParentEditor : function()\r
1175                 {\r
1176                         return this._.editor;\r
1177                 },\r
1178 \r
1179                 /**\r
1180                  * Gets the element that was selected when opening the dialog, if any.\r
1181                  * @returns {CKEDITOR.dom.element} The element that was selected, or null.\r
1182                  */\r
1183                 getSelectedElement : function()\r
1184                 {\r
1185                         return this.getParentEditor().getSelection().getSelectedElement();\r
1186                 },\r
1187 \r
1188                 /**\r
1189                  * Adds element to dialog's focusable list.\r
1190                  *\r
1191                  * @param {CKEDITOR.dom.element} element\r
1192                  * @param {Number} [index]\r
1193                  */\r
1194                 addFocusable: function( element, index ) {\r
1195                         if ( typeof index == 'undefined' )\r
1196                         {\r
1197                                 index = this._.focusList.length;\r
1198                                 this._.focusList.push( new Focusable( this, element, index ) );\r
1199                         }\r
1200                         else\r
1201                         {\r
1202                                 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );\r
1203                                 for ( var i = index + 1 ; i < this._.focusList.length ; i++ )\r
1204                                         this._.focusList[ i ].focusIndex++;\r
1205                         }\r
1206                 }\r
1207         };\r
1208 \r
1209         CKEDITOR.tools.extend( CKEDITOR.dialog,\r
1210                 /**\r
1211                  * @lends CKEDITOR.dialog\r
1212                  */\r
1213                 {\r
1214                         /**\r
1215                          * Registers a dialog.\r
1216                          * @param {String} name The dialog's name.\r
1217                          * @param {Function|String} dialogDefinition\r
1218                          * A function returning the dialog's definition, or the URL to the .js file holding the function.\r
1219                          * The function should accept an argument "editor" which is the current editor instance, and\r
1220                          * return an object conforming to {@link CKEDITOR.dialog.dialogDefinition}.\r
1221                          * @example\r
1222                          * @see CKEDITOR.dialog.dialogDefinition\r
1223                          */\r
1224                         add : function( name, dialogDefinition )\r
1225                         {\r
1226                                 // Avoid path registration from multiple instances override definition.\r
1227                                 if ( !this._.dialogDefinitions[name]\r
1228                                         || typeof  dialogDefinition == 'function' )\r
1229                                         this._.dialogDefinitions[name] = dialogDefinition;\r
1230                         },\r
1231 \r
1232                         exists : function( name )\r
1233                         {\r
1234                                 return !!this._.dialogDefinitions[ name ];\r
1235                         },\r
1236 \r
1237                         getCurrent : function()\r
1238                         {\r
1239                                 return CKEDITOR.dialog._.currentTop;\r
1240                         },\r
1241 \r
1242                         /**\r
1243                          * The default OK button for dialogs. Fires the "ok" event and closes the dialog if the event succeeds.\r
1244                          * @static\r
1245                          * @field\r
1246                          * @example\r
1247                          * @type Function\r
1248                          */\r
1249                         okButton : (function()\r
1250                         {\r
1251                                 var retval = function( editor, override )\r
1252                                 {\r
1253                                         override = override || {};\r
1254                                         return CKEDITOR.tools.extend( {\r
1255                                                 id : 'ok',\r
1256                                                 type : 'button',\r
1257                                                 label : editor.lang.common.ok,\r
1258                                                 'class' : 'cke_dialog_ui_button_ok',\r
1259                                                 onClick : function( evt )\r
1260                                                 {\r
1261                                                         var dialog = evt.data.dialog;\r
1262                                                         if ( dialog.fire( 'ok', { hide : true } ).hide !== false )\r
1263                                                                 dialog.hide();\r
1264                                                 }\r
1265                                         }, override, true );\r
1266                                 };\r
1267                                 retval.type = 'button';\r
1268                                 retval.override = function( override )\r
1269                                 {\r
1270                                         return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },\r
1271                                                         { type : 'button' }, true );\r
1272                                 };\r
1273                                 return retval;\r
1274                         })(),\r
1275 \r
1276                         /**\r
1277                          * The default cancel button for dialogs. Fires the "cancel" event and closes the dialog if no UI element value changed.\r
1278                          * @static\r
1279                          * @field\r
1280                          * @example\r
1281                          * @type Function\r
1282                          */\r
1283                         cancelButton : (function()\r
1284                         {\r
1285                                 var retval = function( editor, override )\r
1286                                 {\r
1287                                         override = override || {};\r
1288                                         return CKEDITOR.tools.extend( {\r
1289                                                 id : 'cancel',\r
1290                                                 type : 'button',\r
1291                                                 label : editor.lang.common.cancel,\r
1292                                                 'class' : 'cke_dialog_ui_button_cancel',\r
1293                                                 onClick : function( evt )\r
1294                                                 {\r
1295                                                         var dialog = evt.data.dialog;\r
1296                                                         if ( dialog.fire( 'cancel', { hide : true } ).hide !== false )\r
1297                                                                 dialog.hide();\r
1298                                                 }\r
1299                                         }, override, true );\r
1300                                 };\r
1301                                 retval.type = 'button';\r
1302                                 retval.override = function( override )\r
1303                                 {\r
1304                                         return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },\r
1305                                                         { type : 'button' }, true );\r
1306                                 };\r
1307                                 return retval;\r
1308                         })(),\r
1309 \r
1310                         /**\r
1311                          * Registers a dialog UI element.\r
1312                          * @param {String} typeName The name of the UI element.\r
1313                          * @param {Function} builder The function to build the UI element.\r
1314                          * @example\r
1315                          */\r
1316                         addUIElement : function( typeName, builder )\r
1317                         {\r
1318                                 this._.uiElementBuilders[ typeName ] = builder;\r
1319                         }\r
1320                 });\r
1321 \r
1322         CKEDITOR.dialog._ =\r
1323         {\r
1324                 uiElementBuilders : {},\r
1325 \r
1326                 dialogDefinitions : {},\r
1327 \r
1328                 currentTop : null,\r
1329 \r
1330                 currentZIndex : null\r
1331         };\r
1332 \r
1333         // "Inherit" (copy actually) from CKEDITOR.event.\r
1334         CKEDITOR.event.implementOn( CKEDITOR.dialog );\r
1335         CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype, true );\r
1336 \r
1337         var defaultDialogDefinition =\r
1338         {\r
1339                 resizable : CKEDITOR.DIALOG_RESIZE_BOTH,\r
1340                 minWidth : 600,\r
1341                 minHeight : 400,\r
1342                 buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]\r
1343         };\r
1344 \r
1345         // The buttons in MacOS Apps are in reverse order #4750\r
1346         CKEDITOR.env.mac && defaultDialogDefinition.buttons.reverse();\r
1347 \r
1348         // Tool function used to return an item from an array based on its id\r
1349         // property.\r
1350         var getById = function( array, id, recurse )\r
1351         {\r
1352                 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )\r
1353                 {\r
1354                         if ( item.id == id )\r
1355                                 return item;\r
1356                         if ( recurse && item[ recurse ] )\r
1357                         {\r
1358                                 var retval = getById( item[ recurse ], id, recurse ) ;\r
1359                                 if ( retval )\r
1360                                         return retval;\r
1361                         }\r
1362                 }\r
1363                 return null;\r
1364         };\r
1365 \r
1366         // Tool function used to add an item into an array.\r
1367         var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound )\r
1368         {\r
1369                 if ( nextSiblingId )\r
1370                 {\r
1371                         for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )\r
1372                         {\r
1373                                 if ( item.id == nextSiblingId )\r
1374                                 {\r
1375                                         array.splice( i, 0, newItem );\r
1376                                         return newItem;\r
1377                                 }\r
1378 \r
1379                                 if ( recurse && item[ recurse ] )\r
1380                                 {\r
1381                                         var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );\r
1382                                         if ( retval )\r
1383                                                 return retval;\r
1384                                 }\r
1385                         }\r
1386 \r
1387                         if ( nullIfNotFound )\r
1388                                 return null;\r
1389                 }\r
1390 \r
1391                 array.push( newItem );\r
1392                 return newItem;\r
1393         };\r
1394 \r
1395         // Tool function used to remove an item from an array based on its id.\r
1396         var removeById = function( array, id, recurse )\r
1397         {\r
1398                 for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )\r
1399                 {\r
1400                         if ( item.id == id )\r
1401                                 return array.splice( i, 1 );\r
1402                         if ( recurse && item[ recurse ] )\r
1403                         {\r
1404                                 var retval = removeById( item[ recurse ], id, recurse );\r
1405                                 if ( retval )\r
1406                                         return retval;\r
1407                         }\r
1408                 }\r
1409                 return null;\r
1410         };\r
1411 \r
1412         /**\r
1413          * This class is not really part of the API. It is the "definition" property value\r
1414          * passed to "dialogDefinition" event handlers.\r
1415          * @constructor\r
1416          * @name CKEDITOR.dialog.dialogDefinitionObject\r
1417          * @extends CKEDITOR.dialog.dialogDefinition\r
1418          * @example\r
1419          * CKEDITOR.on( 'dialogDefinition', function( evt )\r
1420          *      {\r
1421          *              var definition = evt.data.definition;\r
1422          *              var content = definition.getContents( 'page1' );\r
1423          *              ...\r
1424          *      } );\r
1425          */\r
1426         var definitionObject = function( dialog, dialogDefinition )\r
1427         {\r
1428                 // TODO : Check if needed.\r
1429                 this.dialog = dialog;\r
1430 \r
1431                 // Transform the contents entries in contentObjects.\r
1432                 var contents = dialogDefinition.contents;\r
1433                 for ( var i = 0, content ; ( content = contents[i] ) ; i++ )\r
1434                         contents[ i ] = content && new contentObject( dialog, content );\r
1435 \r
1436                 CKEDITOR.tools.extend( this, dialogDefinition );\r
1437         };\r
1438 \r
1439         definitionObject.prototype =\r
1440         /** @lends CKEDITOR.dialog.dialogDefinitionObject.prototype */\r
1441         {\r
1442                 /**\r
1443                  * Gets a content definition.\r
1444                  * @param {String} id The id of the content definition.\r
1445                  * @returns {CKEDITOR.dialog.contentDefinition} The content definition\r
1446                  *              matching id.\r
1447                  */\r
1448                 getContents : function( id )\r
1449                 {\r
1450                         return getById( this.contents, id );\r
1451                 },\r
1452 \r
1453                 /**\r
1454                  * Gets a button definition.\r
1455                  * @param {String} id The id of the button definition.\r
1456                  * @returns {CKEDITOR.dialog.buttonDefinition} The button definition\r
1457                  *              matching id.\r
1458                  */\r
1459                 getButton : function( id )\r
1460                 {\r
1461                         return getById( this.buttons, id );\r
1462                 },\r
1463 \r
1464                 /**\r
1465                  * Adds a content definition object under this dialog definition.\r
1466                  * @param {CKEDITOR.dialog.contentDefinition} contentDefinition The\r
1467                  *              content definition.\r
1468                  * @param {String} [nextSiblingId] The id of an existing content\r
1469                  *              definition which the new content definition will be inserted\r
1470                  *              before. Omit if the new content definition is to be inserted as\r
1471                  *              the last item.\r
1472                  * @returns {CKEDITOR.dialog.contentDefinition} The inserted content\r
1473                  *              definition.\r
1474                  */\r
1475                 addContents : function( contentDefinition, nextSiblingId )\r
1476                 {\r
1477                         return addById( this.contents, contentDefinition, nextSiblingId );\r
1478                 },\r
1479 \r
1480                 /**\r
1481                  * Adds a button definition object under this dialog definition.\r
1482                  * @param {CKEDITOR.dialog.buttonDefinition} buttonDefinition The\r
1483                  *              button definition.\r
1484                  * @param {String} [nextSiblingId] The id of an existing button\r
1485                  *              definition which the new button definition will be inserted\r
1486                  *              before. Omit if the new button definition is to be inserted as\r
1487                  *              the last item.\r
1488                  * @returns {CKEDITOR.dialog.buttonDefinition} The inserted button\r
1489                  *              definition.\r
1490                  */\r
1491                 addButton : function( buttonDefinition, nextSiblingId )\r
1492                 {\r
1493                         return addById( this.buttons, buttonDefinition, nextSiblingId );\r
1494                 },\r
1495 \r
1496                 /**\r
1497                  * Removes a content definition from this dialog definition.\r
1498                  * @param {String} id The id of the content definition to be removed.\r
1499                  * @returns {CKEDITOR.dialog.contentDefinition} The removed content\r
1500                  *              definition.\r
1501                  */\r
1502                 removeContents : function( id )\r
1503                 {\r
1504                         removeById( this.contents, id );\r
1505                 },\r
1506 \r
1507                 /**\r
1508                  * Removes a button definition from the dialog definition.\r
1509                  * @param {String} id The id of the button definition to be removed.\r
1510                  * @returns {CKEDITOR.dialog.buttonDefinition} The removed button\r
1511                  *              definition.\r
1512                  */\r
1513                 removeButton : function( id )\r
1514                 {\r
1515                         removeById( this.buttons, id );\r
1516                 }\r
1517         };\r
1518 \r
1519         /**\r
1520          * This class is not really part of the API. It is the template of the\r
1521          * objects representing content pages inside the\r
1522          * CKEDITOR.dialog.dialogDefinitionObject.\r
1523          * @constructor\r
1524          * @name CKEDITOR.dialog.contentDefinitionObject\r
1525          * @example\r
1526          * CKEDITOR.on( 'dialogDefinition', function( evt )\r
1527          *      {\r
1528          *              var definition = evt.data.definition;\r
1529          *              var content = definition.getContents( 'page1' );\r
1530          *              content.remove( 'textInput1' );\r
1531          *              ...\r
1532          *      } );\r
1533          */\r
1534         function contentObject( dialog, contentDefinition )\r
1535         {\r
1536                 this._ =\r
1537                 {\r
1538                         dialog : dialog\r
1539                 };\r
1540 \r
1541                 CKEDITOR.tools.extend( this, contentDefinition );\r
1542         }\r
1543 \r
1544         contentObject.prototype =\r
1545         /** @lends CKEDITOR.dialog.contentDefinitionObject.prototype */\r
1546         {\r
1547                 /**\r
1548                  * Gets a UI element definition under the content definition.\r
1549                  * @param {String} id The id of the UI element definition.\r
1550                  * @returns {CKEDITOR.dialog.uiElementDefinition}\r
1551                  */\r
1552                 get : function( id )\r
1553                 {\r
1554                         return getById( this.elements, id, 'children' );\r
1555                 },\r
1556 \r
1557                 /**\r
1558                  * Adds a UI element definition to the content definition.\r
1559                  * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition The\r
1560                  *              UI elemnet definition to be added.\r
1561                  * @param {String} nextSiblingId The id of an existing UI element\r
1562                  *              definition which the new UI element definition will be inserted\r
1563                  *              before. Omit if the new button definition is to be inserted as\r
1564                  *              the last item.\r
1565                  * @returns {CKEDITOR.dialog.uiElementDefinition} The element\r
1566                  *              definition inserted.\r
1567                  */\r
1568                 add : function( elementDefinition, nextSiblingId )\r
1569                 {\r
1570                         return addById( this.elements, elementDefinition, nextSiblingId, 'children' );\r
1571                 },\r
1572 \r
1573                 /**\r
1574                  * Removes a UI element definition from the content definition.\r
1575                  * @param {String} id The id of the UI element definition to be\r
1576                  *              removed.\r
1577                  * @returns {CKEDITOR.dialog.uiElementDefinition} The element\r
1578                  *              definition removed.\r
1579                  * @example\r
1580                  */\r
1581                 remove : function( id )\r
1582                 {\r
1583                         removeById( this.elements, id, 'children' );\r
1584                 }\r
1585         };\r
1586 \r
1587         function initDragAndDrop( dialog )\r
1588         {\r
1589                 var lastCoords = null,\r
1590                         abstractDialogCoords = null,\r
1591                         element = dialog.getElement().getFirst(),\r
1592                         editor = dialog.getParentEditor(),\r
1593                         magnetDistance = editor.config.dialog_magnetDistance,\r
1594                         margins = editor.skin.margins || [ 0, 0, 0, 0 ];\r
1595 \r
1596                 if ( typeof magnetDistance == 'undefined' )\r
1597                         magnetDistance = 20;\r
1598 \r
1599                 function mouseMoveHandler( evt )\r
1600                 {\r
1601                         var dialogSize = dialog.getSize(),\r
1602                                 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),\r
1603                                 x = evt.data.$.screenX,\r
1604                                 y = evt.data.$.screenY,\r
1605                                 dx = x - lastCoords.x,\r
1606                                 dy = y - lastCoords.y,\r
1607                                 realX, realY;\r
1608 \r
1609                         lastCoords = { x : x, y : y };\r
1610                         abstractDialogCoords.x += dx;\r
1611                         abstractDialogCoords.y += dy;\r
1612 \r
1613                         if ( abstractDialogCoords.x + margins[3] < magnetDistance )\r
1614                                 realX = - margins[3];\r
1615                         else if ( abstractDialogCoords.x - margins[1] > viewPaneSize.width - dialogSize.width - magnetDistance )\r
1616                                 realX = viewPaneSize.width - dialogSize.width + margins[1];\r
1617                         else\r
1618                                 realX = abstractDialogCoords.x;\r
1619 \r
1620                         if ( abstractDialogCoords.y + margins[0] < magnetDistance )\r
1621                                 realY = - margins[0];\r
1622                         else if ( abstractDialogCoords.y - margins[2] > viewPaneSize.height - dialogSize.height - magnetDistance )\r
1623                                 realY = viewPaneSize.height - dialogSize.height + margins[2];\r
1624                         else\r
1625                                 realY = abstractDialogCoords.y;\r
1626 \r
1627                         dialog.move( realX, realY );\r
1628 \r
1629                         evt.data.preventDefault();\r
1630                 }\r
1631 \r
1632                 function mouseUpHandler( evt )\r
1633                 {\r
1634                         CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );\r
1635                         CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );\r
1636 \r
1637                         if ( CKEDITOR.env.ie6Compat )\r
1638                         {\r
1639                                 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();\r
1640                                 coverDoc.removeListener( 'mousemove', mouseMoveHandler );\r
1641                                 coverDoc.removeListener( 'mouseup', mouseUpHandler );\r
1642                         }\r
1643                 }\r
1644 \r
1645                 dialog.parts.title.on( 'mousedown', function( evt )\r
1646                         {\r
1647                                 dialog._.updateSize = true;\r
1648 \r
1649                                 lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };\r
1650 \r
1651                                 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );\r
1652                                 CKEDITOR.document.on( 'mouseup', mouseUpHandler );\r
1653                                 abstractDialogCoords = dialog.getPosition();\r
1654 \r
1655                                 if ( CKEDITOR.env.ie6Compat )\r
1656                                 {\r
1657                                         var coverDoc = currentCover.getChild( 0 ).getFrameDocument();\r
1658                                         coverDoc.on( 'mousemove', mouseMoveHandler );\r
1659                                         coverDoc.on( 'mouseup', mouseUpHandler );\r
1660                                 }\r
1661 \r
1662                                 evt.data.preventDefault();\r
1663                         }, dialog );\r
1664         }\r
1665 \r
1666         function initResizeHandles( dialog )\r
1667         {\r
1668                 var definition = dialog.definition,\r
1669                         minWidth = definition.minWidth || 0,\r
1670                         minHeight = definition.minHeight || 0,\r
1671                         resizable = definition.resizable,\r
1672                         margins = dialog.getParentEditor().skin.margins || [ 0, 0, 0, 0 ];\r
1673 \r
1674                 function topSizer( coords, dy )\r
1675                 {\r
1676                         coords.y += dy;\r
1677                 }\r
1678 \r
1679                 function rightSizer( coords, dx )\r
1680                 {\r
1681                         coords.x2 += dx;\r
1682                 }\r
1683 \r
1684                 function bottomSizer( coords, dy )\r
1685                 {\r
1686                         coords.y2 += dy;\r
1687                 }\r
1688 \r
1689                 function leftSizer( coords, dx )\r
1690                 {\r
1691                         coords.x += dx;\r
1692                 }\r
1693 \r
1694                 var lastCoords = null,\r
1695                         abstractDialogCoords = null,\r
1696                         magnetDistance = dialog._.editor.config.magnetDistance,\r
1697                         parts = [ 'tl', 't', 'tr', 'l', 'r', 'bl', 'b', 'br' ];\r
1698 \r
1699                 function mouseDownHandler( evt )\r
1700                 {\r
1701                         var partName = evt.listenerData.part, size = dialog.getSize();\r
1702                         abstractDialogCoords = dialog.getPosition();\r
1703                         CKEDITOR.tools.extend( abstractDialogCoords,\r
1704                                 {\r
1705                                         x2 : abstractDialogCoords.x + size.width,\r
1706                                         y2 : abstractDialogCoords.y + size.height\r
1707                                 } );\r
1708                         lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };\r
1709 \r
1710                         CKEDITOR.document.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } );\r
1711                         CKEDITOR.document.on( 'mouseup', mouseUpHandler, dialog, { part : partName } );\r
1712 \r
1713                         if ( CKEDITOR.env.ie6Compat )\r
1714                         {\r
1715                                 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();\r
1716                                 coverDoc.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } );\r
1717                                 coverDoc.on( 'mouseup', mouseUpHandler, dialog, { part : partName } );\r
1718                         }\r
1719 \r
1720                         evt.data.preventDefault();\r
1721                 }\r
1722 \r
1723                 function mouseMoveHandler( evt )\r
1724                 {\r
1725                         var x = evt.data.$.screenX,\r
1726                                 y = evt.data.$.screenY,\r
1727                                 dx = x - lastCoords.x,\r
1728                                 dy = y - lastCoords.y,\r
1729                                 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),\r
1730                                 partName = evt.listenerData.part;\r
1731 \r
1732                         if ( partName.search( 't' ) != -1 )\r
1733                                 topSizer( abstractDialogCoords, dy );\r
1734                         if ( partName.search( 'l' ) != -1 )\r
1735                                 leftSizer( abstractDialogCoords, dx );\r
1736                         if ( partName.search( 'b' ) != -1 )\r
1737                                 bottomSizer( abstractDialogCoords, dy );\r
1738                         if ( partName.search( 'r' ) != -1 )\r
1739                                 rightSizer( abstractDialogCoords, dx );\r
1740 \r
1741                         lastCoords = { x : x, y : y };\r
1742 \r
1743                         var realX, realY, realX2, realY2;\r
1744 \r
1745                         if ( abstractDialogCoords.x + margins[3] < magnetDistance )\r
1746                                 realX = - margins[3];\r
1747                         else if ( partName.search( 'l' ) != -1 && abstractDialogCoords.x2 - abstractDialogCoords.x < minWidth + magnetDistance )\r
1748                                 realX = abstractDialogCoords.x2 - minWidth;\r
1749                         else\r
1750                                 realX = abstractDialogCoords.x;\r
1751 \r
1752                         if ( abstractDialogCoords.y + margins[0] < magnetDistance )\r
1753                                 realY = - margins[0];\r
1754                         else if ( partName.search( 't' ) != -1 && abstractDialogCoords.y2 - abstractDialogCoords.y < minHeight + magnetDistance )\r
1755                                 realY = abstractDialogCoords.y2 - minHeight;\r
1756                         else\r
1757                                 realY = abstractDialogCoords.y;\r
1758 \r
1759                         if ( abstractDialogCoords.x2 - margins[1] > viewPaneSize.width - magnetDistance )\r
1760                                 realX2 = viewPaneSize.width + margins[1] ;\r
1761                         else if ( partName.search( 'r' ) != -1 && abstractDialogCoords.x2 - abstractDialogCoords.x < minWidth + magnetDistance )\r
1762                                 realX2 = abstractDialogCoords.x + minWidth;\r
1763                         else\r
1764                                 realX2 = abstractDialogCoords.x2;\r
1765 \r
1766                         if ( abstractDialogCoords.y2 - margins[2] > viewPaneSize.height - magnetDistance )\r
1767                                 realY2= viewPaneSize.height + margins[2] ;\r
1768                         else if ( partName.search( 'b' ) != -1 && abstractDialogCoords.y2 - abstractDialogCoords.y < minHeight + magnetDistance )\r
1769                                 realY2 = abstractDialogCoords.y + minHeight;\r
1770                         else\r
1771                                 realY2 = abstractDialogCoords.y2 ;\r
1772 \r
1773                         dialog.move( realX, realY );\r
1774                         dialog.resize( realX2 - realX, realY2 - realY );\r
1775 \r
1776                         evt.data.preventDefault();\r
1777                 }\r
1778 \r
1779                 function mouseUpHandler( evt )\r
1780                 {\r
1781                         CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );\r
1782                         CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );\r
1783 \r
1784                         if ( CKEDITOR.env.ie6Compat )\r
1785                         {\r
1786                                 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();\r
1787                                 coverDoc.removeListener( 'mouseup', mouseUpHandler );\r
1788                                 coverDoc.removeListener( 'mousemove', mouseMoveHandler );\r
1789                         }\r
1790                 }\r
1791 \r
1792 // TODO : Simplify the resize logic, having just a single resize grip <div>.\r
1793 //              var widthTest = /[lr]/,\r
1794 //                      heightTest = /[tb]/;\r
1795 //              for ( var i = 0 ; i < parts.length ; i++ )\r
1796 //              {\r
1797 //                      var element = dialog.parts[ parts[i] + '_resize' ];\r
1798 //                      if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE ||\r
1799 //                                      resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT && widthTest.test( parts[i] ) ||\r
1800 //                                      resizable == CKEDITOR.DIALOG_RESIZE_WIDTH && heightTest.test( parts[i] ) )\r
1801 //                      {\r
1802 //                              element.hide();\r
1803 //                              continue;\r
1804 //                      }\r
1805 //                      element.on( 'mousedown', mouseDownHandler, dialog, { part : parts[i] } );\r
1806 //              }\r
1807         }\r
1808 \r
1809         var resizeCover;\r
1810         // Caching resuable covers and allowing only one cover\r
1811         // on screen.\r
1812         var covers = {},\r
1813                 currentCover;\r
1814 \r
1815         function showCover( editor )\r
1816         {\r
1817                 var win = CKEDITOR.document.getWindow();\r
1818                 var config = editor.config,\r
1819                         backgroundColorStyle = config.dialog_backgroundCoverColor || 'white',\r
1820                         backgroundCoverOpacity = config.dialog_backgroundCoverOpacity,\r
1821                         baseFloatZIndex = config.baseFloatZIndex,\r
1822                         coverKey = CKEDITOR.tools.genKey(\r
1823                                         backgroundColorStyle,\r
1824                                         backgroundCoverOpacity,\r
1825                                         baseFloatZIndex ),\r
1826                         coverElement = covers[ coverKey ];\r
1827 \r
1828                 if ( !coverElement )\r
1829                 {\r
1830                         var html = [\r
1831                                         '<div style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),\r
1832                                         '; z-index: ', baseFloatZIndex,\r
1833                                         '; top: 0px; left: 0px; ',\r
1834                                         ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),\r
1835                                         '" class="cke_dialog_background_cover">'\r
1836                                 ];\r
1837 \r
1838                         if ( CKEDITOR.env.ie6Compat )\r
1839                         {\r
1840                                 // Support for custom document.domain in IE.\r
1841                                 var isCustomDomain = CKEDITOR.env.isCustomDomain(),\r
1842                                         iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';\r
1843 \r
1844                                 html.push(\r
1845                                         '<iframe' +\r
1846                                                 ' hidefocus="true"' +\r
1847                                                 ' frameborder="0"' +\r
1848                                                 ' id="cke_dialog_background_iframe"' +\r
1849                                                 ' src="javascript:' );\r
1850 \r
1851                                 html.push( 'void((function(){' +\r
1852                                                                 'document.open();' +\r
1853                                                                 ( isCustomDomain ? 'document.domain=\'' + document.domain + '\';' : '' ) +\r
1854                                                                 'document.write( \'' + iframeHtml + '\' );' +\r
1855                                                                 'document.close();' +\r
1856                                                         '})())' );\r
1857 \r
1858                                 html.push(\r
1859                                                 '"' +\r
1860                                                 ' style="' +\r
1861                                                         'position:absolute;' +\r
1862                                                         'left:0;' +\r
1863                                                         'top:0;' +\r
1864                                                         'width:100%;' +\r
1865                                                         'height: 100%;' +\r
1866                                                         'progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +\r
1867                                         '</iframe>' );\r
1868                         }\r
1869 \r
1870                         html.push( '</div>' );\r
1871 \r
1872                         coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );\r
1873                         coverElement.setOpacity( backgroundCoverOpacity != undefined ? backgroundCoverOpacity : 0.5 );\r
1874 \r
1875                         coverElement.appendTo( CKEDITOR.document.getBody() );\r
1876                         covers[ coverKey ] = coverElement;\r
1877                 }\r
1878                 else\r
1879                         coverElement.   show();\r
1880 \r
1881                 currentCover = coverElement;\r
1882                 var resizeFunc = function()\r
1883                 {\r
1884                         var size = win.getViewPaneSize();\r
1885                         coverElement.setStyles(\r
1886                                 {\r
1887                                         width : size.width + 'px',\r
1888                                         height : size.height + 'px'\r
1889                                 } );\r
1890                 };\r
1891 \r
1892                 var scrollFunc = function()\r
1893                 {\r
1894                         var pos = win.getScrollPosition(),\r
1895                                 cursor = CKEDITOR.dialog._.currentTop;\r
1896                         coverElement.setStyles(\r
1897                                         {\r
1898                                                 left : pos.x + 'px',\r
1899                                                 top : pos.y + 'px'\r
1900                                         });\r
1901 \r
1902                         do\r
1903                         {\r
1904                                 var dialogPos = cursor.getPosition();\r
1905                                 cursor.move( dialogPos.x, dialogPos.y );\r
1906                         } while ( ( cursor = cursor._.parentDialog ) );\r
1907                 };\r
1908 \r
1909                 resizeCover = resizeFunc;\r
1910                 win.on( 'resize', resizeFunc );\r
1911                 resizeFunc();\r
1912                 if ( CKEDITOR.env.ie6Compat )\r
1913                 {\r
1914                         // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.\r
1915                         // So we need to invent a really funny way to make it work.\r
1916                         var myScrollHandler = function()\r
1917                                 {\r
1918                                         scrollFunc();\r
1919                                         arguments.callee.prevScrollHandler.apply( this, arguments );\r
1920                                 };\r
1921                         win.$.setTimeout( function()\r
1922                                 {\r
1923                                         myScrollHandler.prevScrollHandler = window.onscroll || function(){};\r
1924                                         window.onscroll = myScrollHandler;\r
1925                                 }, 0 );\r
1926                         scrollFunc();\r
1927                 }\r
1928         }\r
1929 \r
1930         function hideCover()\r
1931         {\r
1932                 if ( !currentCover )\r
1933                         return;\r
1934 \r
1935                 var win = CKEDITOR.document.getWindow();\r
1936                 currentCover.hide();\r
1937                 win.removeListener( 'resize', resizeCover );\r
1938 \r
1939                 if ( CKEDITOR.env.ie6Compat )\r
1940                 {\r
1941                         win.$.setTimeout( function()\r
1942                                 {\r
1943                                         var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;\r
1944                                         window.onscroll = prevScrollHandler || null;\r
1945                                 }, 0 );\r
1946                 }\r
1947                 resizeCover = null;\r
1948         }\r
1949 \r
1950         function removeCovers()\r
1951         {\r
1952                 for ( var coverId in covers )\r
1953                         covers[ coverId ].remove();\r
1954                 covers = {};\r
1955         }\r
1956 \r
1957         var accessKeyProcessors = {};\r
1958 \r
1959         var accessKeyDownHandler = function( evt )\r
1960         {\r
1961                 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,\r
1962                         alt = evt.data.$.altKey,\r
1963                         shift = evt.data.$.shiftKey,\r
1964                         key = String.fromCharCode( evt.data.$.keyCode ),\r
1965                         keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];\r
1966 \r
1967                 if ( !keyProcessor || !keyProcessor.length )\r
1968                         return;\r
1969 \r
1970                 keyProcessor = keyProcessor[keyProcessor.length - 1];\r
1971                 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );\r
1972                 evt.data.preventDefault();\r
1973         };\r
1974 \r
1975         var accessKeyUpHandler = function( evt )\r
1976         {\r
1977                 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,\r
1978                         alt = evt.data.$.altKey,\r
1979                         shift = evt.data.$.shiftKey,\r
1980                         key = String.fromCharCode( evt.data.$.keyCode ),\r
1981                         keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];\r
1982 \r
1983                 if ( !keyProcessor || !keyProcessor.length )\r
1984                         return;\r
1985 \r
1986                 keyProcessor = keyProcessor[keyProcessor.length - 1];\r
1987                 if ( keyProcessor.keyup )\r
1988                 {\r
1989                         keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );\r
1990                         evt.data.preventDefault();\r
1991                 }\r
1992         };\r
1993 \r
1994         var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc )\r
1995         {\r
1996                 var procList = accessKeyProcessors[key] || ( accessKeyProcessors[key] = [] );\r
1997                 procList.push( {\r
1998                                 uiElement : uiElement,\r
1999                                 dialog : dialog,\r
2000                                 key : key,\r
2001                                 keyup : upFunc || uiElement.accessKeyUp,\r
2002                                 keydown : downFunc || uiElement.accessKeyDown\r
2003                         } );\r
2004         };\r
2005 \r
2006         var unregisterAccessKey = function( obj )\r
2007         {\r
2008                 for ( var i in accessKeyProcessors )\r
2009                 {\r
2010                         var list = accessKeyProcessors[i];\r
2011                         for ( var j = list.length - 1 ; j >= 0 ; j-- )\r
2012                         {\r
2013                                 if ( list[j].dialog == obj || list[j].uiElement == obj )\r
2014                                         list.splice( j, 1 );\r
2015                         }\r
2016                         if ( list.length === 0 )\r
2017                                 delete accessKeyProcessors[i];\r
2018                 }\r
2019         };\r
2020 \r
2021         var tabAccessKeyUp = function( dialog, key )\r
2022         {\r
2023                 if ( dialog._.accessKeyMap[key] )\r
2024                         dialog.selectPage( dialog._.accessKeyMap[key] );\r
2025         };\r
2026 \r
2027         var tabAccessKeyDown = function( dialog, key )\r
2028         {\r
2029         };\r
2030 \r
2031         // ESC, ENTER\r
2032         var preventKeyBubblingKeys = { 27 :1, 13 :1 };\r
2033         var preventKeyBubbling = function( e )\r
2034         {\r
2035                 if ( e.data.getKeystroke() in preventKeyBubblingKeys )\r
2036                         e.data.stopPropagation();\r
2037         };\r
2038 \r
2039         (function()\r
2040         {\r
2041                 CKEDITOR.ui.dialog =\r
2042                 {\r
2043                         /**\r
2044                          * The base class of all dialog UI elements.\r
2045                          * @constructor\r
2046                          * @param {CKEDITOR.dialog} dialog Parent dialog object.\r
2047                          * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition Element\r
2048                          * definition. Accepted fields:\r
2049                          * <ul>\r
2050                          *      <li><strong>id</strong> (Required) The id of the UI element. See {@link\r
2051                          *      CKEDITOR.dialog#getContentElement}</li>\r
2052                          *      <li><strong>type</strong> (Required) The type of the UI element. The\r
2053                          *      value to this field specifies which UI element class will be used to\r
2054                          *      generate the final widget.</li>\r
2055                          *      <li><strong>title</strong> (Optional) The popup tooltip for the UI\r
2056                          *      element.</li>\r
2057                          *      <li><strong>hidden</strong> (Optional) A flag that tells if the element\r
2058                          *      should be initially visible.</li>\r
2059                          *      <li><strong>className</strong> (Optional) Additional CSS class names\r
2060                          *      to add to the UI element. Separated by space.</li>\r
2061                          *      <li><strong>style</strong> (Optional) Additional CSS inline styles\r
2062                          *      to add to the UI element. A semicolon (;) is required after the last\r
2063                          *      style declaration.</li>\r
2064                          *      <li><strong>accessKey</strong> (Optional) The alphanumeric access key\r
2065                          *      for this element. Access keys are automatically prefixed by CTRL.</li>\r
2066                          *      <li><strong>on*</strong> (Optional) Any UI element definition field that\r
2067                          *      starts with <em>on</em> followed immediately by a capital letter and\r
2068                          *      probably more letters is an event handler. Event handlers may be further\r
2069                          *      divided into registered event handlers and DOM event handlers. Please\r
2070                          *      refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and\r
2071                          *      {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more\r
2072                          *      information.</li>\r
2073                          * </ul>\r
2074                          * @param {Array} htmlList\r
2075                          * List of HTML code to be added to the dialog's content area.\r
2076                          * @param {Function|String} nodeNameArg\r
2077                          * A function returning a string, or a simple string for the node name for\r
2078                          * the root DOM node. Default is 'div'.\r
2079                          * @param {Function|Object} stylesArg\r
2080                          * A function returning an object, or a simple object for CSS styles applied\r
2081                          * to the DOM node. Default is empty object.\r
2082                          * @param {Function|Object} attributesArg\r
2083                          * A fucntion returning an object, or a simple object for attributes applied\r
2084                          * to the DOM node. Default is empty object.\r
2085                          * @param {Function|String} contentsArg\r
2086                          * A function returning a string, or a simple string for the HTML code inside\r
2087                          * the root DOM node. Default is empty string.\r
2088                          * @example\r
2089                          */\r
2090                         uiElement : function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg )\r
2091                         {\r
2092                                 if ( arguments.length < 4 )\r
2093                                         return;\r
2094 \r
2095                                 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',\r
2096                                         html = [ '<', nodeName, ' ' ],\r
2097                                         styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},\r
2098                                         attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},\r
2099                                         innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',\r
2100                                         domId = this.domId = attributes.id || CKEDITOR.tools.getNextId() + '_uiElement',\r
2101                                         id = this.id = elementDefinition.id,\r
2102                                         i;\r
2103 \r
2104                                 // Set the id, a unique id is required for getElement() to work.\r
2105                                 attributes.id = domId;\r
2106 \r
2107                                 // Set the type and definition CSS class names.\r
2108                                 var classes = {};\r
2109                                 if ( elementDefinition.type )\r
2110                                         classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;\r
2111                                 if ( elementDefinition.className )\r
2112                                         classes[ elementDefinition.className ] = 1;\r
2113                                 var attributeClasses = ( attributes['class'] && attributes['class'].split ) ? attributes['class'].split( ' ' ) : [];\r
2114                                 for ( i = 0 ; i < attributeClasses.length ; i++ )\r
2115                                 {\r
2116                                         if ( attributeClasses[i] )\r
2117                                                 classes[ attributeClasses[i] ] = 1;\r
2118                                 }\r
2119                                 var finalClasses = [];\r
2120                                 for ( i in classes )\r
2121                                         finalClasses.push( i );\r
2122                                 attributes['class'] = finalClasses.join( ' ' );\r
2123 \r
2124                                 // Set the popup tooltop.\r
2125                                 if ( elementDefinition.title )\r
2126                                         attributes.title = elementDefinition.title;\r
2127 \r
2128                                 // Write the inline CSS styles.\r
2129                                 var styleStr = ( elementDefinition.style || '' ).split( ';' );\r
2130                                 for ( i in styles )\r
2131                                         styleStr.push( i + ':' + styles[i] );\r
2132                                 if ( elementDefinition.hidden )\r
2133                                         styleStr.push( 'display:none' );\r
2134                                 for ( i = styleStr.length - 1 ; i >= 0 ; i-- )\r
2135                                 {\r
2136                                         if ( styleStr[i] === '' )\r
2137                                                 styleStr.splice( i, 1 );\r
2138                                 }\r
2139                                 if ( styleStr.length > 0 )\r
2140                                         attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );\r
2141 \r
2142                                 // Write the attributes.\r
2143                                 for ( i in attributes )\r
2144                                         html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '" ');\r
2145 \r
2146                                 // Write the content HTML.\r
2147                                 html.push( '>', innerHTML, '</', nodeName, '>' );\r
2148 \r
2149                                 // Add contents to the parent HTML array.\r
2150                                 htmlList.push( html.join( '' ) );\r
2151 \r
2152                                 ( this._ || ( this._ = {} ) ).dialog = dialog;\r
2153 \r
2154                                 // Override isChanged if it is defined in element definition.\r
2155                                 if ( typeof( elementDefinition.isChanged ) == 'boolean' )\r
2156                                         this.isChanged = function(){ return elementDefinition.isChanged; };\r
2157                                 if ( typeof( elementDefinition.isChanged ) == 'function' )\r
2158                                         this.isChanged = elementDefinition.isChanged;\r
2159 \r
2160                                 // Add events.\r
2161                                 CKEDITOR.event.implementOn( this );\r
2162 \r
2163                                 this.registerEvents( elementDefinition );\r
2164                                 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )\r
2165                                         registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );\r
2166 \r
2167                                 var me = this;\r
2168                                 dialog.on( 'load', function()\r
2169                                         {\r
2170                                                 if ( me.getInputElement() )\r
2171                                                 {\r
2172                                                         me.getInputElement().on( 'focus', function()\r
2173                                                                 {\r
2174                                                                         dialog._.tabBarMode = false;\r
2175                                                                         dialog._.hasFocus = true;\r
2176                                                                         me.fire( 'focus' );\r
2177                                                                 }, me );\r
2178                                                 }\r
2179                                         } );\r
2180 \r
2181                                 // Register the object as a tab focus if it can be included.\r
2182                                 if ( this.keyboardFocusable )\r
2183                                 {\r
2184                                         this.tabIndex = elementDefinition.tabIndex || 0;\r
2185 \r
2186                                         this.focusIndex = dialog._.focusList.push( this ) - 1;\r
2187                                         this.on( 'focus', function()\r
2188                                                 {\r
2189                                                         dialog._.currentFocusIndex = me.focusIndex;\r
2190                                                 } );\r
2191                                 }\r
2192 \r
2193                                 // Completes this object with everything we have in the\r
2194                                 // definition.\r
2195                                 CKEDITOR.tools.extend( this, elementDefinition );\r
2196                         },\r
2197 \r
2198                         /**\r
2199                          * Horizontal layout box for dialog UI elements, auto-expends to available width of container.\r
2200                          * @constructor\r
2201                          * @extends CKEDITOR.ui.dialog.uiElement\r
2202                          * @param {CKEDITOR.dialog} dialog\r
2203                          * Parent dialog object.\r
2204                          * @param {Array} childObjList\r
2205                          * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this\r
2206                          * container.\r
2207                          * @param {Array} childHtmlList\r
2208                          * Array of HTML code that correspond to the HTML output of all the\r
2209                          * objects in childObjList.\r
2210                          * @param {Array} htmlList\r
2211                          * Array of HTML code that this element will output to.\r
2212                          * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition\r
2213                          * The element definition. Accepted fields:\r
2214                          * <ul>\r
2215                          *      <li><strong>widths</strong> (Optional) The widths of child cells.</li>\r
2216                          *      <li><strong>height</strong> (Optional) The height of the layout.</li>\r
2217                          *      <li><strong>padding</strong> (Optional) The padding width inside child\r
2218                          *       cells.</li>\r
2219                          *      <li><strong>align</strong> (Optional) The alignment of the whole layout\r
2220                          *      </li>\r
2221                          * </ul>\r
2222                          * @example\r
2223                          */\r
2224                         hbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )\r
2225                         {\r
2226                                 if ( arguments.length < 4 )\r
2227                                         return;\r
2228 \r
2229                                 this._ || ( this._ = {} );\r
2230 \r
2231                                 var children = this._.children = childObjList,\r
2232                                         widths = elementDefinition && elementDefinition.widths || null,\r
2233                                         height = elementDefinition && elementDefinition.height || null,\r
2234                                         styles = {},\r
2235                                         i;\r
2236                                 /** @ignore */\r
2237                                 var innerHTML = function()\r
2238                                 {\r
2239                                         var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];\r
2240                                         for ( i = 0 ; i < childHtmlList.length ; i++ )\r
2241                                         {\r
2242                                                 var className = 'cke_dialog_ui_hbox_child',\r
2243                                                         styles = [];\r
2244                                                 if ( i === 0 )\r
2245                                                         className = 'cke_dialog_ui_hbox_first';\r
2246                                                 if ( i == childHtmlList.length - 1 )\r
2247                                                         className = 'cke_dialog_ui_hbox_last';\r
2248                                                 html.push( '<td class="', className, '" role="presentation" ' );\r
2249                                                 if ( widths )\r
2250                                                 {\r
2251                                                         if ( widths[i] )\r
2252                                                                 styles.push( 'width:' + cssLength( widths[i] ) );\r
2253                                                 }\r
2254                                                 else\r
2255                                                         styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );\r
2256                                                 if ( height )\r
2257                                                         styles.push( 'height:' + cssLength( height ) );\r
2258                                                 if ( elementDefinition && elementDefinition.padding != undefined )\r
2259                                                         styles.push( 'padding:' + cssLength( elementDefinition.padding ) );\r
2260                                                 if ( styles.length > 0 )\r
2261                                                         html.push( 'style="' + styles.join('; ') + '" ' );\r
2262                                                 html.push( '>', childHtmlList[i], '</td>' );\r
2263                                         }\r
2264                                         html.push( '</tr></tbody>' );\r
2265                                         return html.join( '' );\r
2266                                 };\r
2267 \r
2268                                 var attribs = { role : 'presentation' };\r
2269                                 elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );\r
2270 \r
2271                                 CKEDITOR.ui.dialog.uiElement.call(\r
2272                                         this,\r
2273                                         dialog,\r
2274                                         elementDefinition || { type : 'hbox' },\r
2275                                         htmlList,\r
2276                                         'table',\r
2277                                         styles,\r
2278                                         attribs,\r
2279                                         innerHTML );\r
2280                         },\r
2281 \r
2282                         /**\r
2283                          * Vertical layout box for dialog UI elements.\r
2284                          * @constructor\r
2285                          * @extends CKEDITOR.ui.dialog.hbox\r
2286                          * @param {CKEDITOR.dialog} dialog\r
2287                          * Parent dialog object.\r
2288                          * @param {Array} childObjList\r
2289                          * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this\r
2290                          * container.\r
2291                          * @param {Array} childHtmlList\r
2292                          * Array of HTML code that correspond to the HTML output of all the\r
2293                          * objects in childObjList.\r
2294                          * @param {Array} htmlList\r
2295                          * Array of HTML code that this element will output to.\r
2296                          * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition\r
2297                          * The element definition. Accepted fields:\r
2298                          * <ul>\r
2299                          *      <li><strong>width</strong> (Optional) The width of the layout.</li>\r
2300                          *      <li><strong>heights</strong> (Optional) The heights of individual cells.\r
2301                          *      </li>\r
2302                          *      <li><strong>align</strong> (Optional) The alignment of the layout.</li>\r
2303                          *      <li><strong>padding</strong> (Optional) The padding width inside child\r
2304                          *      cells.</li>\r
2305                          *      <li><strong>expand</strong> (Optional) Whether the layout should expand\r
2306                          *      vertically to fill its container.</li>\r
2307                          * </ul>\r
2308                          * @example\r
2309                          */\r
2310                         vbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )\r
2311                         {\r
2312                                 if ( arguments.length < 3 )\r
2313                                         return;\r
2314 \r
2315                                 this._ || ( this._ = {} );\r
2316 \r
2317                                 var children = this._.children = childObjList,\r
2318                                         width = elementDefinition && elementDefinition.width || null,\r
2319                                         heights = elementDefinition && elementDefinition.heights || null;\r
2320                                 /** @ignore */\r
2321                                 var innerHTML = function()\r
2322                                 {\r
2323                                         var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];\r
2324                                         html.push( 'style="' );\r
2325                                         if ( elementDefinition && elementDefinition.expand )\r
2326                                                 html.push( 'height:100%;' );\r
2327                                         html.push( 'width:' + cssLength( width || '100%' ), ';' );\r
2328                                         html.push( '"' );\r
2329                                         html.push( 'align="', CKEDITOR.tools.htmlEncode(\r
2330                                                 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );\r
2331 \r
2332                                         html.push( '><tbody>' );\r
2333                                         for ( var i = 0 ; i < childHtmlList.length ; i++ )\r
2334                                         {\r
2335                                                 var styles = [];\r
2336                                                 html.push( '<tr><td role="presentation" ' );\r
2337                                                 if ( width )\r
2338                                                         styles.push( 'width:' + cssLength( width || '100%' ) );\r
2339                                                 if ( heights )\r
2340                                                         styles.push( 'height:' + cssLength( heights[i] ) );\r
2341                                                 else if ( elementDefinition && elementDefinition.expand )\r
2342                                                         styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );\r
2343                                                 if ( elementDefinition && elementDefinition.padding != undefined )\r
2344                                                         styles.push( 'padding:' + cssLength( elementDefinition.padding ) );\r
2345                                                 if ( styles.length > 0 )\r
2346                                                         html.push( 'style="', styles.join( '; ' ), '" ' );\r
2347                                                 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[i], '</td></tr>' );\r
2348                                         }\r
2349                                         html.push( '</tbody></table>' );\r
2350                                         return html.join( '' );\r
2351                                 };\r
2352                                 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type : 'vbox' }, htmlList, 'div', null, { role : 'presentation' }, innerHTML );\r
2353                         }\r
2354                 };\r
2355         })();\r
2356 \r
2357         CKEDITOR.ui.dialog.uiElement.prototype =\r
2358         {\r
2359                 /**\r
2360                  * Gets the root DOM element of this dialog UI object.\r
2361                  * @returns {CKEDITOR.dom.element} Root DOM element of UI object.\r
2362                  * @example\r
2363                  * uiElement.getElement().hide();\r
2364                  */\r
2365                 getElement : function()\r
2366                 {\r
2367                         return CKEDITOR.document.getById( this.domId );\r
2368                 },\r
2369 \r
2370                 /**\r
2371                  * Gets the DOM element that the user inputs values.\r
2372                  * This function is used by setValue(), getValue() and focus(). It should\r
2373                  * be overrided in child classes where the input element isn't the root\r
2374                  * element.\r
2375                  * @returns {CKEDITOR.dom.element} The element where the user input values.\r
2376                  * @example\r
2377                  * var rawValue = textInput.getInputElement().$.value;\r
2378                  */\r
2379                 getInputElement : function()\r
2380                 {\r
2381                         return this.getElement();\r
2382                 },\r
2383 \r
2384                 /**\r
2385                  * Gets the parent dialog object containing this UI element.\r
2386                  * @returns {CKEDITOR.dialog} Parent dialog object.\r
2387                  * @example\r
2388                  * var dialog = uiElement.getDialog();\r
2389                  */\r
2390                 getDialog : function()\r
2391                 {\r
2392                         return this._.dialog;\r
2393                 },\r
2394 \r
2395                 /**\r
2396                  * Sets the value of this dialog UI object.\r
2397                  * @param {Object} value The new value.\r
2398                  * @param {Boolean} noChangeEvent Internal commit, to supress 'change' event on this element.\r
2399                  * @returns {CKEDITOR.dialog.uiElement} The current UI element.\r
2400                  * @example\r
2401                  * uiElement.setValue( 'Dingo' );\r
2402                  */\r
2403                 setValue : function( value, noChangeEvent )\r
2404                 {\r
2405                         this.getInputElement().setValue( value );\r
2406                         !noChangeEvent && this.fire( 'change', { value : value } );\r
2407                         return this;\r
2408                 },\r
2409 \r
2410                 /**\r
2411                  * Gets the current value of this dialog UI object.\r
2412                  * @returns {Object} The current value.\r
2413                  * @example\r
2414                  * var myValue = uiElement.getValue();\r
2415                  */\r
2416                 getValue : function()\r
2417                 {\r
2418                         return this.getInputElement().getValue();\r
2419                 },\r
2420 \r
2421                 /**\r
2422                  * Tells whether the UI object's value has changed.\r
2423                  * @returns {Boolean} true if changed, false if not changed.\r
2424                  * @example\r
2425                  * if ( uiElement.isChanged() )\r
2426                  * &nbsp;&nbsp;confirm( 'Value changed! Continue?' );\r
2427                  */\r
2428                 isChanged : function()\r
2429                 {\r
2430                         // Override in input classes.\r
2431                         return false;\r
2432                 },\r
2433 \r
2434                 /**\r
2435                  * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.\r
2436                  * @returns {CKEDITOR.dialog.uiElement} The current UI element.\r
2437                  * @example\r
2438                  * focus : function()\r
2439                  * {\r
2440                  *              this.selectParentTab();\r
2441                  *              // do something else.\r
2442                  * }\r
2443                  */\r
2444                 selectParentTab : function()\r
2445                 {\r
2446                         var element = this.getInputElement(),\r
2447                                 cursor = element,\r
2448                                 tabId;\r
2449                         while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 )\r
2450                         { /*jsl:pass*/ }\r
2451 \r
2452                         // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).\r
2453                         if ( !cursor )\r
2454                                 return this;\r
2455 \r
2456                         tabId = cursor.getAttribute( 'name' );\r
2457                         // Avoid duplicate select.\r
2458                         if ( this._.dialog._.currentTabId != tabId )\r
2459                                 this._.dialog.selectPage( tabId );\r
2460                         return this;\r
2461                 },\r
2462 \r
2463                 /**\r
2464                  * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.\r
2465                  * @returns {CKEDITOR.dialog.uiElement} The current UI element.\r
2466                  * @example\r
2467                  * uiElement.focus();\r
2468                  */\r
2469                 focus : function()\r
2470                 {\r
2471                         this.selectParentTab().getInputElement().focus();\r
2472                         return this;\r
2473                 },\r
2474 \r
2475                 /**\r
2476                  * Registers the on* event handlers defined in the element definition.\r
2477                  * The default behavior of this function is:\r
2478                  * <ol>\r
2479                  *  <li>\r
2480                  *      If the on* event is defined in the class's eventProcesors list,\r
2481                  *      then the registration is delegated to the corresponding function\r
2482                  *      in the eventProcessors list.\r
2483                  *  </li>\r
2484                  *  <li>\r
2485                  *      If the on* event is not defined in the eventProcessors list, then\r
2486                  *      register the event handler under the corresponding DOM event of\r
2487                  *      the UI element's input DOM element (as defined by the return value\r
2488                  *      of {@link CKEDITOR.ui.dialog.uiElement#getInputElement}).\r
2489                  *  </li>\r
2490                  * </ol>\r
2491                  * This function is only called at UI element instantiation, but can\r
2492                  * be overridded in child classes if they require more flexibility.\r
2493                  * @param {CKEDITOR.dialog.uiElementDefinition} definition The UI element\r
2494                  * definition.\r
2495                  * @returns {CKEDITOR.dialog.uiElement} The current UI element.\r
2496                  * @example\r
2497                  */\r
2498                 registerEvents : function( definition )\r
2499                 {\r
2500                         var regex = /^on([A-Z]\w+)/,\r
2501                                 match;\r
2502 \r
2503                         var registerDomEvent = function( uiElement, dialog, eventName, func )\r
2504                         {\r
2505                                 dialog.on( 'load', function()\r
2506                                 {\r
2507                                         uiElement.getInputElement().on( eventName, func, uiElement );\r
2508                                 });\r
2509                         };\r
2510 \r
2511                         for ( var i in definition )\r
2512                         {\r
2513                                 if ( !( match = i.match( regex ) ) )\r
2514                                         continue;\r
2515                                 if ( this.eventProcessors[i] )\r
2516                                         this.eventProcessors[i].call( this, this._.dialog, definition[i] );\r
2517                                 else\r
2518                                         registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );\r
2519                         }\r
2520 \r
2521                         return this;\r
2522                 },\r
2523 \r
2524                 /**\r
2525                  * The event processor list used by\r
2526                  * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element\r
2527                  * instantiation. The default list defines three on* events:\r
2528                  * <ol>\r
2529                  *  <li>onLoad - Called when the element's parent dialog opens for the\r
2530                  *  first time</li>\r
2531                  *  <li>onShow - Called whenever the element's parent dialog opens.</li>\r
2532                  *  <li>onHide - Called whenever the element's parent dialog closes.</li>\r
2533                  * </ol>\r
2534                  * @field\r
2535                  * @type Object\r
2536                  * @example\r
2537                  * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick\r
2538                  * // handlers in the UI element's definitions.\r
2539                  * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},\r
2540                  * &nbsp;&nbsp;CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,\r
2541                  * &nbsp;&nbsp;{ onClick : function( dialog, func ) { this.on( 'click', func ); } },\r
2542                  * &nbsp;&nbsp;true );\r
2543                  */\r
2544                 eventProcessors :\r
2545                 {\r
2546                         onLoad : function( dialog, func )\r
2547                         {\r
2548                                 dialog.on( 'load', func, this );\r
2549                         },\r
2550 \r
2551                         onShow : function( dialog, func )\r
2552                         {\r
2553                                 dialog.on( 'show', func, this );\r
2554                         },\r
2555 \r
2556                         onHide : function( dialog, func )\r
2557                         {\r
2558                                 dialog.on( 'hide', func, this );\r
2559                         }\r
2560                 },\r
2561 \r
2562                 /**\r
2563                  * The default handler for a UI element's access key down event, which\r
2564                  * tries to put focus to the UI element.<br />\r
2565                  * Can be overridded in child classes for more sophisticaed behavior.\r
2566                  * @param {CKEDITOR.dialog} dialog The parent dialog object.\r
2567                  * @param {String} key The key combination pressed. Since access keys\r
2568                  * are defined to always include the CTRL key, its value should always\r
2569                  * include a 'CTRL+' prefix.\r
2570                  * @example\r
2571                  */\r
2572                 accessKeyDown : function( dialog, key )\r
2573                 {\r
2574                         this.focus();\r
2575                 },\r
2576 \r
2577                 /**\r
2578                  * The default handler for a UI element's access key up event, which\r
2579                  * does nothing.<br />\r
2580                  * Can be overridded in child classes for more sophisticated behavior.\r
2581                  * @param {CKEDITOR.dialog} dialog The parent dialog object.\r
2582                  * @param {String} key The key combination pressed. Since access keys\r
2583                  * are defined to always include the CTRL key, its value should always\r
2584                  * include a 'CTRL+' prefix.\r
2585                  * @example\r
2586                  */\r
2587                 accessKeyUp : function( dialog, key )\r
2588                 {\r
2589                 },\r
2590 \r
2591                 /**\r
2592                  * Disables a UI element.\r
2593                  * @example\r
2594                  */\r
2595                 disable : function()\r
2596                 {\r
2597                         var element = this.getInputElement();\r
2598                         element.setAttribute( 'disabled', 'true' );\r
2599                         element.addClass( 'cke_disabled' );\r
2600                 },\r
2601 \r
2602                 /**\r
2603                  * Enables a UI element.\r
2604                  * @example\r
2605                  */\r
2606                 enable : function()\r
2607                 {\r
2608                         var element = this.getInputElement();\r
2609                         element.removeAttribute( 'disabled' );\r
2610                         element.removeClass( 'cke_disabled' );\r
2611                 },\r
2612 \r
2613                 /**\r
2614                  * Determines whether an UI element is enabled or not.\r
2615                  * @returns {Boolean} Whether the UI element is enabled.\r
2616                  * @example\r
2617                  */\r
2618                 isEnabled : function()\r
2619                 {\r
2620                         return !this.getInputElement().getAttribute( 'disabled' );\r
2621                 },\r
2622 \r
2623                 /**\r
2624                  * Determines whether an UI element is visible or not.\r
2625                  * @returns {Boolean} Whether the UI element is visible.\r
2626                  * @example\r
2627                  */\r
2628                 isVisible : function()\r
2629                 {\r
2630                         return this.getInputElement().isVisible();\r
2631                 },\r
2632 \r
2633                 /**\r
2634                  * Determines whether an UI element is focus-able or not.\r
2635                  * Focus-able is defined as being both visible and enabled.\r
2636                  * @returns {Boolean} Whether the UI element can be focused.\r
2637                  * @example\r
2638                  */\r
2639                 isFocusable : function()\r
2640                 {\r
2641                         if ( !this.isEnabled() || !this.isVisible() )\r
2642                                 return false;\r
2643                         return true;\r
2644                 }\r
2645         };\r
2646 \r
2647         CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,\r
2648                 /**\r
2649                  * @lends CKEDITOR.ui.dialog.hbox.prototype\r
2650                  */\r
2651                 {\r
2652                         /**\r
2653                          * Gets a child UI element inside this container.\r
2654                          * @param {Array|Number} indices An array or a single number to indicate the child's\r
2655                          * position in the container's descendant tree. Omit to get all the children in an array.\r
2656                          * @returns {Array|CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container\r
2657                          * if no argument given, or the specified UI element if indices is given.\r
2658                          * @example\r
2659                          * var checkbox = hbox.getChild( [0,1] );\r
2660                          * checkbox.setValue( true );\r
2661                          */\r
2662                         getChild : function( indices )\r
2663                         {\r
2664                                 // If no arguments, return a clone of the children array.\r
2665                                 if ( arguments.length < 1 )\r
2666                                         return this._.children.concat();\r
2667 \r
2668                                 // If indices isn't array, make it one.\r
2669                                 if ( !indices.splice )\r
2670                                         indices = [ indices ];\r
2671 \r
2672                                 // Retrieve the child element according to tree position.\r
2673                                 if ( indices.length < 2 )\r
2674                                         return this._.children[ indices[0] ];\r
2675                                 else\r
2676                                         return ( this._.children[ indices[0] ] && this._.children[ indices[0] ].getChild ) ?\r
2677                                                 this._.children[ indices[0] ].getChild( indices.slice( 1, indices.length ) ) :\r
2678                                                 null;\r
2679                         }\r
2680                 }, true );\r
2681 \r
2682         CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();\r
2683 \r
2684 \r
2685 \r
2686         (function()\r
2687         {\r
2688                 var commonBuilder = {\r
2689                         build : function( dialog, elementDefinition, output )\r
2690                         {\r
2691                                 var children = elementDefinition.children,\r
2692                                         child,\r
2693                                         childHtmlList = [],\r
2694                                         childObjList = [];\r
2695                                 for ( var i = 0 ; ( i < children.length && ( child = children[i] ) ) ; i++ )\r
2696                                 {\r
2697                                         var childHtml = [];\r
2698                                         childHtmlList.push( childHtml );\r
2699                                         childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );\r
2700                                 }\r
2701                                 return new CKEDITOR.ui.dialog[elementDefinition.type]( dialog, childObjList, childHtmlList, output, elementDefinition );\r
2702                         }\r
2703                 };\r
2704 \r
2705                 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );\r
2706                 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );\r
2707         })();\r
2708 \r
2709         /**\r
2710          * Generic dialog command. It opens a specific dialog when executed.\r
2711          * @constructor\r
2712          * @augments CKEDITOR.commandDefinition\r
2713          * @param {string} dialogName The name of the dialog to open when executing\r
2714          *              this command.\r
2715          * @example\r
2716          * // Register the "link" command, which opens the "link" dialog.\r
2717          * editor.addCommand( 'link', <b>new CKEDITOR.dialogCommand( 'link' )</b> );\r
2718          */\r
2719         CKEDITOR.dialogCommand = function( dialogName )\r
2720         {\r
2721                 this.dialogName = dialogName;\r
2722         };\r
2723 \r
2724         CKEDITOR.dialogCommand.prototype =\r
2725         {\r
2726                 /** @ignore */\r
2727                 exec : function( editor )\r
2728                 {\r
2729                         editor.openDialog( this.dialogName );\r
2730                 },\r
2731 \r
2732                 // Dialog commands just open a dialog ui, thus require no undo logic,\r
2733                 // undo support should dedicate to specific dialog implementation.\r
2734                 canUndo: false,\r
2735 \r
2736                 editorFocus : CKEDITOR.env.ie || CKEDITOR.env.webkit\r
2737         };\r
2738 \r
2739         (function()\r
2740         {\r
2741                 var notEmptyRegex = /^([a]|[^a])+$/,\r
2742                         integerRegex = /^\d*$/,\r
2743                         numberRegex = /^\d*(?:\.\d+)?$/;\r
2744 \r
2745                 CKEDITOR.VALIDATE_OR = 1;\r
2746                 CKEDITOR.VALIDATE_AND = 2;\r
2747 \r
2748                 CKEDITOR.dialog.validate =\r
2749                 {\r
2750                         functions : function()\r
2751                         {\r
2752                                 return function()\r
2753                                 {\r
2754                                         /**\r
2755                                          * It's important for validate functions to be able to accept the value\r
2756                                          * as argument in addition to this.getValue(), so that it is possible to\r
2757                                          * combine validate functions together to make more sophisticated\r
2758                                          * validators.\r
2759                                          */\r
2760                                         var value = this && this.getValue ? this.getValue() : arguments[0];\r
2761 \r
2762                                         var msg = undefined,\r
2763                                                 relation = CKEDITOR.VALIDATE_AND,\r
2764                                                 functions = [], i;\r
2765 \r
2766                                         for ( i = 0 ; i < arguments.length ; i++ )\r
2767                                         {\r
2768                                                 if ( typeof( arguments[i] ) == 'function' )\r
2769                                                         functions.push( arguments[i] );\r
2770                                                 else\r
2771                                                         break;\r
2772                                         }\r
2773 \r
2774                                         if ( i < arguments.length && typeof( arguments[i] ) == 'string' )\r
2775                                         {\r
2776                                                 msg = arguments[i];\r
2777                                                 i++;\r
2778                                         }\r
2779 \r
2780                                         if ( i < arguments.length && typeof( arguments[i]) == 'number' )\r
2781                                                 relation = arguments[i];\r
2782 \r
2783                                         var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );\r
2784                                         for ( i = 0 ; i < functions.length ; i++ )\r
2785                                         {\r
2786                                                 if ( relation == CKEDITOR.VALIDATE_AND )\r
2787                                                         passed = passed && functions[i]( value );\r
2788                                                 else\r
2789                                                         passed = passed || functions[i]( value );\r
2790                                         }\r
2791 \r
2792                                         if ( !passed )\r
2793                                         {\r
2794                                                 if ( msg !== undefined )\r
2795                                                         alert( msg );\r
2796                                                 if ( this && ( this.select || this.focus ) )\r
2797                                                         ( this.select || this.focus )();\r
2798                                                 return false;\r
2799                                         }\r
2800 \r
2801                                         return true;\r
2802                                 };\r
2803                         },\r
2804 \r
2805                         regex : function( regex, msg )\r
2806                         {\r
2807                                 /*\r
2808                                  * Can be greatly shortened by deriving from functions validator if code size\r
2809                                  * turns out to be more important than performance.\r
2810                                  */\r
2811                                 return function()\r
2812                                 {\r
2813                                         var value = this && this.getValue ? this.getValue() : arguments[0];\r
2814                                         if ( !regex.test( value ) )\r
2815                                         {\r
2816                                                 if ( msg !== undefined )\r
2817                                                         alert( msg );\r
2818                                                 if ( this && ( this.select || this.focus ) )\r
2819                                                 {\r
2820                                                         if ( this.select )\r
2821                                                                 this.select();\r
2822                                                         else\r
2823                                                                 this.focus();\r
2824                                                 }\r
2825                                                 return false;\r
2826                                         }\r
2827                                         return true;\r
2828                                 };\r
2829                         },\r
2830 \r
2831                         notEmpty : function( msg )\r
2832                         {\r
2833                                 return this.regex( notEmptyRegex, msg );\r
2834                         },\r
2835 \r
2836                         integer : function( msg )\r
2837                         {\r
2838                                 return this.regex( integerRegex, msg );\r
2839                         },\r
2840 \r
2841                         'number' : function( msg )\r
2842                         {\r
2843                                 return this.regex( numberRegex, msg );\r
2844                         },\r
2845 \r
2846                         equals : function( value, msg )\r
2847                         {\r
2848                                 return this.functions( function( val ){ return val == value; }, msg );\r
2849                         },\r
2850 \r
2851                         notEqual : function( value, msg )\r
2852                         {\r
2853                                 return this.functions( function( val ){ return val != value; }, msg );\r
2854                         }\r
2855                 };\r
2856 \r
2857         CKEDITOR.on( 'instanceDestroyed', function( evt )\r
2858         {\r
2859                 // Remove dialog cover on last instance destroy.\r
2860                 if ( CKEDITOR.tools.isEmpty( CKEDITOR.instances ) )\r
2861                 {\r
2862                         var currentTopDialog;\r
2863                         while ( ( currentTopDialog = CKEDITOR.dialog._.currentTop ) )\r
2864                                 currentTopDialog.hide();\r
2865                         removeCovers();\r
2866                 }\r
2867 \r
2868                 var dialogs = evt.editor._.storedDialogs;\r
2869                 for ( var name in dialogs )\r
2870                         dialogs[ name ].destroy();\r
2871 \r
2872         });\r
2873 \r
2874         })();\r
2875 })();\r
2876 \r
2877 // Extend the CKEDITOR.editor class with dialog specific functions.\r
2878 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,\r
2879         /** @lends CKEDITOR.editor.prototype */\r
2880         {\r
2881                 /**\r
2882                  * Loads and opens a registered dialog.\r
2883                  * @param {String} dialogName The registered name of the dialog.\r
2884                  * @param {Function} callback The function to be invoked after dialog instance created.\r
2885                  * @see CKEDITOR.dialog.add\r
2886                  * @example\r
2887                  * CKEDITOR.instances.editor1.openDialog( 'smiley' );\r
2888                  * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed. null if the dialog name is not registered.\r
2889                  */\r
2890                 openDialog : function( dialogName, callback )\r
2891                 {\r
2892                         var dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],\r
2893                                         dialogSkin = this.skin.dialog;\r
2894 \r
2895                         // If the dialogDefinition is already loaded, open it immediately.\r
2896                         if ( typeof dialogDefinitions == 'function' && dialogSkin._isLoaded )\r
2897                         {\r
2898                                 var storedDialogs = this._.storedDialogs ||\r
2899                                         ( this._.storedDialogs = {} );\r
2900 \r
2901                                 var dialog = storedDialogs[ dialogName ] ||\r
2902                                         ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );\r
2903 \r
2904                                 callback && callback.call( dialog, dialog );\r
2905                                 dialog.show();\r
2906 \r
2907                                 return dialog;\r
2908                         }\r
2909                         else if ( dialogDefinitions == 'failed' )\r
2910                                 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );\r
2911 \r
2912                         // Not loaded? Load the .js file first.\r
2913                         var body = CKEDITOR.document.getBody(),\r
2914                                 cursor = body.$.style.cursor,\r
2915                                 me = this;\r
2916 \r
2917                         body.setStyle( 'cursor', 'wait' );\r
2918 \r
2919                         function onDialogFileLoaded( success )\r
2920                         {\r
2921                                 var dialogDefinition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],\r
2922                                                 skin = me.skin.dialog;\r
2923 \r
2924                                 // Check if both skin part and definition is loaded.\r
2925                                 if ( !skin._isLoaded || loadDefinition && typeof success == 'undefined' )\r
2926                                         return;\r
2927 \r
2928                                 // In case of plugin error, mark it as loading failed.\r
2929                                 if ( typeof dialogDefinition != 'function' )\r
2930                                         CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';\r
2931 \r
2932                                 me.openDialog( dialogName, callback );\r
2933                                 body.setStyle( 'cursor', cursor );\r
2934                         }\r
2935 \r
2936                         if ( typeof dialogDefinitions == 'string' )\r
2937                         {\r
2938                                 var loadDefinition = 1;\r
2939                                 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ), onDialogFileLoaded );\r
2940                         }\r
2941 \r
2942                         CKEDITOR.skins.load( this, 'dialog', onDialogFileLoaded );\r
2943 \r
2944                         return null;\r
2945                 }\r
2946         });\r
2947 \r
2948 CKEDITOR.plugins.add( 'dialog',\r
2949         {\r
2950                 requires : [ 'dialogui' ]\r
2951         });\r
2952 \r
2953 // Dialog related configurations.\r
2954 \r
2955 /**\r
2956  * The color of the dialog background cover. It should be a valid CSS color\r
2957  * string.\r
2958  * @name CKEDITOR.config.dialog_backgroundCoverColor\r
2959  * @type String\r
2960  * @default 'white'\r
2961  * @example\r
2962  * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';\r
2963  */\r
2964 \r
2965 /**\r
2966  * The opacity of the dialog background cover. It should be a number within the\r
2967  * range [0.0, 1.0].\r
2968  * @name CKEDITOR.config.dialog_backgroundCoverOpacity\r
2969  * @type Number\r
2970  * @default 0.5\r
2971  * @example\r
2972  * config.dialog_backgroundCoverOpacity = 0.7;\r
2973  */\r
2974 \r
2975 /**\r
2976  * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.\r
2977  * @name CKEDITOR.config.dialog_startupFocusTab\r
2978  * @type Boolean\r
2979  * @default false\r
2980  * @example\r
2981  * config.dialog_startupFocusTab = true;\r
2982  */\r
2983 \r
2984 /**\r
2985  * The distance of magnetic borders used in moving and resizing dialogs,\r
2986  * measured in pixels.\r
2987  * @name CKEDITOR.config.dialog_magnetDistance\r
2988  * @type Number\r
2989  * @default 20\r
2990  * @example\r
2991  * config.dialog_magnetDistance = 30;\r
2992  */\r
2993 \r
2994 /**\r
2995  * Fired when a dialog definition is about to be used to create a dialog into\r
2996  * an editor instance. This event makes it possible to customize the definition\r
2997  * before creating it.\r
2998  * <p>Note that this event is called only the first time a specific dialog is\r
2999  * opened. Successive openings will use the cached dialog, and this event will\r
3000  * not get fired.</p>\r
3001  * @name CKEDITOR#dialogDefinition\r
3002  * @event\r
3003  * @param {CKEDITOR.dialog.dialogDefinition} data The dialog defination that\r
3004  *              is being loaded.\r
3005  * @param {CKEDITOR.editor} editor The editor instance that will use the\r
3006  *              dialog.\r
3007  */\r
3008 \r
3009 /**\r
3010  * Fired when a tab is going to be selected in a dialog\r
3011  * @name dialog#selectPage\r
3012  * @event\r
3013  * @param String page The id of the page that it's gonna be selected.\r
3014  * @param String currentPage The id of the current page.\r
3015  */\r