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