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