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