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

Note that this event is called only the first time a specific dialog is + * opened. Successive openings will use the cached dialog, and this event will + * not get fired.

+ * @name CKEDITOR#dialogDefinition + * @event + * @param {CKEDITOR.dialog.dialogDefinition} data The dialog defination that + * is being loaded. + * @param {CKEDITOR.editor} editor The editor instance that will use the + * dialog. + */