2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @fileOverview Plugin for making iframe based dialogs.
10 CKEDITOR.plugins.add( 'iframedialog',
12 requires : [ 'dialog' ],
16 * An iframe base dialog.
17 * @param {String} name Name of the dialog
18 * @param {String} title Title of the dialog
19 * @param {Number} minWidth Minimum width of the dialog
20 * @param {Number} minHeight Minimum height of the dialog
21 * @param {Function} [onContentLoad] Function called when the iframe has been loaded.
22 * If it isn't specified, the inner frame is notified of the dialog events ('load',
23 * 'resize', 'ok' and 'cancel') on a function called 'onDialogEvent'
24 * @param {Object} [userDefinition] Additional properties for the dialog definition
27 CKEDITOR.dialog.addIframe = function( name, title, src, minWidth, minHeight, onContentLoad, userDefinition )
37 if ( typeof( onContentLoad ) == 'function' )
38 element.onContentLoad = onContentLoad;
40 element.onContentLoad = function()
42 var element = this.getElement(),
43 childWindow = element.$.contentWindow;
45 // If the inner frame has defined a "onDialogEvent" function, setup listeners
46 if ( childWindow.onDialogEvent )
48 var dialog = this.getDialog(),
49 notifyEvent = function(e)
51 return childWindow.onDialogEvent(e);
54 dialog.on( 'ok', notifyEvent );
55 dialog.on( 'cancel', notifyEvent );
56 dialog.on( 'resize', notifyEvent );
59 dialog.on( 'hide', function(e)
61 dialog.removeListener( 'ok', notifyEvent );
62 dialog.removeListener( 'cancel', notifyEvent );
63 dialog.removeListener( 'resize', notifyEvent );
68 // Notify child iframe of load:
69 childWindow.onDialogEvent( {
72 editor : dialog._.editor
81 minHeight : minHeight,
88 elements : [ element ]
93 for ( var i in userDefinition )
94 definition[i] = userDefinition[i];
96 this.add( name, function(){ return definition; } );
103 * @extends CKEDITOR.ui.dialog.uiElement
106 * @param {CKEDITOR.dialog} dialog
107 * Parent dialog object.
108 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition
109 * The element definition. Accepted fields:
111 * <li><strong>src</strong> (Required) The src field of the iframe. </li>
112 * <li><strong>width</strong> (Required) The iframe's width.</li>
113 * <li><strong>height</strong> (Required) The iframe's height.</li>
114 * <li><strong>onContentLoad</strong> (Optional) A function to be executed
115 * after the iframe's contents has finished loading.</li>
117 * @param {Array} htmlList
118 * List of HTML code to output to.
120 var iframeElement = function( dialog, elementDefinition, htmlList )
122 if ( arguments.length < 3 )
125 var _ = ( this._ || ( this._ = {} ) ),
126 contentLoad = elementDefinition.onContentLoad && CKEDITOR.tools.bind( elementDefinition.onContentLoad, this ),
127 cssWidth = CKEDITOR.tools.cssLength( elementDefinition.width ),
128 cssHeight = CKEDITOR.tools.cssLength( elementDefinition.height );
129 _.frameId = CKEDITOR.tools.getNextId() + '_iframe';
131 // IE BUG: Parent container does not resize to contain the iframe automatically.
132 dialog.on( 'load', function()
134 var iframe = CKEDITOR.document.getById( _.frameId ),
135 parentContainer = iframe.getParent();
137 parentContainer.setStyles(
149 allowtransparency : true
153 if ( typeof( elementDefinition.onContentLoad ) == 'function' )
154 attributes.onload = 'CKEDITOR.tools.callFunction(%1);';
156 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition, myHtml, 'iframe',
162 // Put a placeholder for the first time.
163 htmlList.push( '<div style="width:' + cssWidth + ';height:' + cssHeight + ';" id="' + this.domId + '"></div>' );
165 // Iframe elements should be refreshed whenever it is shown.
166 myHtml = myHtml.join( '' );
167 dialog.on( 'show', function()
169 var iframe = CKEDITOR.document.getById( _.frameId ),
170 parentContainer = iframe.getParent(),
171 callIndex = CKEDITOR.tools.addFunction( contentLoad ),
172 html = myHtml.replace( '%1', callIndex ).replace( '%2', CKEDITOR.tools.htmlEncode( elementDefinition.src ) );
173 parentContainer.setHtml( html );
177 iframeElement.prototype = new CKEDITOR.ui.dialog.uiElement;
179 CKEDITOR.dialog.addUIElement( 'iframe',
181 build : function( dialog, elementDefinition, output )
183 return new iframeElement( dialog, elementDefinition, output );