JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.3
[ckeditor.git] / _source / plugins / iframedialog / plugin.js
index dcde6fe..61ee605 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -12,7 +12,19 @@ CKEDITOR.plugins.add( 'iframedialog',
        requires : [ 'dialog' ],\r
        onLoad : function()\r
        {\r
-               CKEDITOR.dialog.addIframe = function( name, title, src, width, height, onContentLoad )\r
+               /**\r
+                * An iframe base dialog.\r
+                * @param {String} name Name of the dialog\r
+                * @param {String} title Title of the dialog\r
+                * @param {Number} minWidth Minimum width of the dialog\r
+                * @param {Number} minHeight Minimum height of the dialog\r
+                * @param {Function} [onContentLoad] Function called when the iframe has been loaded.\r
+                * If it isn't specified, the inner frame is notified of the dialog events ('load',\r
+                * 'resize', 'ok' and 'cancel') on a function called 'onDialogEvent'\r
+                * @param {Object} [userDefinition] Additional properties for the dialog definition\r
+                * @example\r
+                */\r
+               CKEDITOR.dialog.addIframe = function( name, title, src, minWidth, minHeight, onContentLoad, userDefinition )\r
                {\r
                        var element =\r
                        {\r
@@ -24,12 +36,49 @@ CKEDITOR.plugins.add( 'iframedialog',
 \r
                        if ( typeof( onContentLoad ) == 'function' )\r
                                element.onContentLoad = onContentLoad;\r
+                       else\r
+                               element.onContentLoad = function()\r
+                               {\r
+                                       var element = this.getElement(),\r
+                                               childWindow = element.$.contentWindow;\r
+\r
+                                       // If the inner frame has defined a "onDialogEvent" function, setup listeners\r
+                                       if ( childWindow.onDialogEvent )\r
+                                       {\r
+                                               var dialog = this.getDialog(),\r
+                                                       notifyEvent = function(e)\r
+                                                       {\r
+                                                               return childWindow.onDialogEvent(e);\r
+                                                       };\r
+\r
+                                               dialog.on( 'ok', notifyEvent );\r
+                                               dialog.on( 'cancel', notifyEvent );\r
+                                               dialog.on( 'resize', notifyEvent );\r
+\r
+                                               // Clear listeners\r
+                                               dialog.on( 'hide', function(e)\r
+                                                       {\r
+                                                               dialog.removeListener( 'ok', notifyEvent );\r
+                                                               dialog.removeListener( 'cancel', notifyEvent );\r
+                                                               dialog.removeListener( 'resize', notifyEvent );\r
+\r
+                                                               e.removeListener();\r
+                                                       } );\r
+\r
+                                               // Notify child iframe of load:\r
+                                               childWindow.onDialogEvent( {\r
+                                                               name : 'load',\r
+                                                               sender : this,\r
+                                                               editor : dialog._.editor\r
+                                                       } );\r
+                                       }\r
+                               };\r
 \r
                        var definition =\r
                        {\r
                                title : title,\r
-                               minWidth : width,\r
-                               minHeight : height,\r
+                               minWidth : minWidth,\r
+                               minHeight : minHeight,\r
                                contents :\r
                                [\r
                                        {\r
@@ -41,7 +90,10 @@ CKEDITOR.plugins.add( 'iframedialog',
                                ]\r
                        };\r
 \r
-                       return this.add( name, function(){ return definition; } );\r
+                       for ( var i in userDefinition )\r
+                               definition[i] = userDefinition[i];\r
+\r
+                       this.add( name, function(){ return definition; } );\r
                };\r
 \r
                (function()\r
@@ -53,7 +105,7 @@ CKEDITOR.plugins.add( 'iframedialog',
                         * @constructor\r
                         * @param {CKEDITOR.dialog} dialog\r
                         * Parent dialog object.\r
-                        * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition\r
+                        * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition\r
                         * The element definition. Accepted fields:\r
                         * <ul>\r
                         *      <li><strong>src</strong> (Required) The src field of the iframe. </li>\r
@@ -74,7 +126,7 @@ CKEDITOR.plugins.add( 'iframedialog',
                                        contentLoad = elementDefinition.onContentLoad && CKEDITOR.tools.bind( elementDefinition.onContentLoad, this ),\r
                                        cssWidth = CKEDITOR.tools.cssLength( elementDefinition.width ),\r
                                        cssHeight = CKEDITOR.tools.cssLength( elementDefinition.height );\r
-                               _.frameId = CKEDITOR.tools.getNextNumber() + '_iframe';\r
+                               _.frameId = CKEDITOR.tools.getNextId() + '_iframe';\r
 \r
                                // IE BUG: Parent container does not resize to contain the iframe automatically.\r
                                dialog.on( 'load', function()\r