JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1.1
[ckeditor.git] / _source / plugins / dialog / plugin.js
index 75067d6..fa4cc99 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -7,11 +7,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
  * @fileOverview The floating dialog plugin.\r
  */\r
 \r
-CKEDITOR.plugins.add( 'dialog',\r
-       {\r
-               requires : [ 'dialogui' ]\r
-       });\r
-\r
 /**\r
  * No resize for this dialog.\r
  * @constant\r
@@ -73,9 +68,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                return null;\r
        }\r
 \r
-       // Stores dialog related data from skin definitions. e.g. margin sizes.\r
-       var skinData = {};\r
-\r
        /**\r
         * This is the base class for runtime dialog objects. An instance of this\r
         * class represents a single named dialog for a single editor instance.\r
@@ -100,14 +92,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                // functions.\r
                definition = new definitionObject( this, definition );\r
 \r
-               // Fire the "dialogDefinition" event, making it possible to customize\r
-               // the dialog definition.\r
-               this.definition = definition = CKEDITOR.fire( 'dialogDefinition',\r
-                       {\r
-                               name : dialogName,\r
-                               definition : definition\r
-                       }\r
-                       , editor ).definition;\r
 \r
                var doc = CKEDITOR.document;\r
 \r
@@ -156,6 +140,14 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                // Call the CKEDITOR.event constructor to initialize this instance.\r
                CKEDITOR.event.call( this );\r
 \r
+               // Fire the "dialogDefinition" event, making it possible to customize\r
+               // the dialog definition.\r
+               this.definition = definition = CKEDITOR.fire( 'dialogDefinition',\r
+                       {\r
+                               name : dialogName,\r
+                               definition : definition\r
+                       }\r
+                       , editor ).definition;\r
                // Initialize load, show, hide, ok and cancel events.\r
                if ( definition.onLoad )\r
                        this.on( 'load', definition.onLoad );\r
@@ -679,6 +671,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                        // Execute onLoad for the first show.\r
                                        this.fireOnce( 'load', {} );\r
                                        this.fire( 'show', {} );\r
+                                       this._.editor.fire( 'dialogShow', this );\r
 \r
                                        // Save the initial values of the dialog.\r
                                        this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } );\r
@@ -742,6 +735,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                hide : function()\r
                {\r
                        this.fire( 'hide', {} );\r
+                       this._.editor.fire( 'dialogHide', this );\r
 \r
                        // Remove the dialog's element from the root document.\r
                        var element = this._.element;\r
@@ -811,7 +805,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                                                        children : contents.elements,\r
                                                        expand : !!contents.expand,\r
                                                        padding : contents.padding,\r
-                                                       style : contents.style || 'width: 100%;'\r
+                                                       style : contents.style || 'width: 100%;' + ( CKEDITOR.env.ie6Compat ? '' : 'height: 100%;' )\r
                                                }, pageHtml );\r
 \r
                        // Create the HTML for the tab and the content block.\r
@@ -955,7 +949,8 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                 */\r
                getContentElement : function( pageId, elementId )\r
                {\r
-                       return this._.contents[pageId][elementId];\r
+                       var page = this._.contents[ pageId ];\r
+                       return page && page[ elementId ];\r
                },\r
 \r
                /**\r
@@ -1454,7 +1449,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        element = dialog.getElement().getFirst(),\r
                        editor = dialog.getParentEditor(),\r
                        magnetDistance = editor.config.dialog_magnetDistance,\r
-                       margins = skinData[ editor.skinName ].margins || [ 0, 0, 0, 0 ];\r
+                       margins = editor.skin.margins || [ 0, 0, 0, 0 ];\r
 \r
                if ( typeof magnetDistance == 'undefined' )\r
                        magnetDistance = 20;\r
@@ -1532,7 +1527,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        minWidth = definition.minWidth || 0,\r
                        minHeight = definition.minHeight || 0,\r
                        resizable = definition.resizable,\r
-                       margins = skinData[ dialog.getParentEditor().skinName ].margins || [ 0, 0, 0, 0 ];\r
+                       margins = dialog.getParentEditor().skin.margins || [ 0, 0, 0, 0 ];\r
 \r
                function topSizer( coords, dy )\r
                {\r
@@ -1752,7 +1747,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        {\r
                                var dialogPos = cursor.getPosition();\r
                                cursor.move( dialogPos.x, dialogPos.y );\r
-                       } while( ( cursor = cursor._.parentDialog ) );\r
+                       } while ( ( cursor = cursor._.parentDialog ) );\r
                };\r
 \r
                resizeCover = resizeFunc;\r
@@ -2692,17 +2687,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3;
                        }\r
                };\r
        })();\r
-\r
-       // Grab the margin data from skin definition and store it away.\r
-       CKEDITOR.skins.add = ( function()\r
-       {\r
-               var original = CKEDITOR.skins.add;\r
-               return function( skinName, skinDefinition )\r
-               {\r
-                       skinData[ skinName ] = { margins : skinDefinition.margins };\r
-                       return original.apply( this, arguments );\r
-               };\r
-       } )();\r
 })();\r
 \r
 // Extend the CKEDITOR.editor class with dialog specific functions.\r
@@ -2712,12 +2696,13 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                /**\r
                 * Loads and opens a registered dialog.\r
                 * @param {String} dialogName The registered name of the dialog.\r
+                * @param {Function} callback The function to be invoked after dialog instance created.\r
                 * @see CKEDITOR.dialog.add\r
                 * @example\r
                 * CKEDITOR.instances.editor1.openDialog( 'smiley' );\r
                 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed. null if the dialog name is not registered.\r
                 */\r
-               openDialog : function( dialogName )\r
+               openDialog : function( dialogName, callback )\r
                {\r
                        var dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];\r
 \r
@@ -2730,6 +2715,7 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                                var dialog = storedDialogs[ dialogName ] ||\r
                                        ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );\r
 \r
+                               callback && callback.call( dialog, dialog );\r
                                dialog.show();\r
 \r
                                return dialog;\r
@@ -2748,7 +2734,7 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                                        // In case of plugin error, mark it as loading failed.\r
                                        if ( typeof CKEDITOR.dialog._.dialogDefinitions[ dialogName ] != 'function' )\r
                                                        CKEDITOR.dialog._.dialogDefinitions[ dialogName ] =  'failed';\r
-                                       me.openDialog( dialogName );\r
+                                       me.openDialog( dialogName, callback );\r
                                        body.setStyle( 'cursor', cursor );\r
                                } );\r
 \r
@@ -2756,6 +2742,11 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
                }\r
        });\r
 \r
+CKEDITOR.plugins.add( 'dialog',\r
+       {\r
+               requires : [ 'dialogui' ]\r
+       });\r
+\r
 // Dialog related configurations.\r
 \r
 /**\r
@@ -2787,3 +2778,18 @@ CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
  * @example\r
  * config.dialog_magnetDistance = 30;\r
  */\r
+\r
+/**\r
+ * Fired when a dialog definition is about to be used to create a dialog into\r
+ * an editor instance. This event makes it possible to customize the definition\r
+ * before creating it.\r
+ * <p>Note that this event is called only the first time a specific dialog is\r
+ * opened. Successive openings will use the cached dialog, and this event will\r
+ * not get fired.</p>\r
+ * @name CKEDITOR#dialogDefinition\r
+ * @event\r
+ * @param {CKEDITOR.dialog.dialogDefinition} data The dialog defination that\r
+ *             is being loaded.\r
+ * @param {CKEDITOR.editor} editor The editor instance that will use the\r
+ *             dialog.\r
+ */\r