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