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