X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fdialog%2Fplugin.js;h=ce287993adac365a2a90fbc64d0e7a273cf81640;hb=4e90e78dc97789709ee7404359a5517540c27553;hp=b5aab8182c2060c5e27b7863ba76f6b848dce35b;hpb=9afde8772159bd3436f1f5b7862960307710ae5a;p=ckeditor.git diff --git a/_source/plugins/dialog/plugin.js b/_source/plugins/dialog/plugin.js index b5aab81..ce28799 100644 --- a/_source/plugins/dialog/plugin.js +++ b/_source/plugins/dialog/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -167,13 +167,15 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; // Set the startup styles for the dialog, avoiding it enlarging the // page size on the dialog creation. - this.parts.dialog.setStyles( - { + var startStyles = { position : CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed', top : 0, - left: 0, visibility : 'hidden' - }); + }; + + startStyles[ dir == 'rtl' ? 'right' : 'left' ] = 0; + this.parts.dialog.setStyles( startStyles ); + // Call the CKEDITOR.event constructor to initialize this instance. CKEDITOR.event.call( this ); @@ -635,6 +637,18 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; height : height }, this._.editor ); + this.fire( 'resize', + { + skin : this._.editor.skinName, + width : width, + height : height + }, this._.editor ); + + // Update dialog position when dimension get changed in RTL. + if ( this._.editor.lang.dir == 'rtl' && this._.position ) + this._.position.x = CKEDITOR.document.getWindow().getViewPaneSize().width - + this._.contentSize.width - parseInt( this._.element.getFirst().getStyle( 'right' ), 10 ); + this._.contentSize = { width : width, height : height }; }; })(), @@ -667,7 +681,9 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; { // The dialog may be fixed positioned or absolute positioned. Ask the // browser what is the current situation first. - var element = this._.element.getFirst(); + var element = this._.element.getFirst(), + rtl = this._.editor.lang.dir == 'rtl'; + if ( isFixed === undefined ) isFixed = element.getComputedStyle( 'position' ) == 'fixed'; @@ -685,11 +701,18 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; y += scrollPosition.y; } - element.setStyles( - { - 'left' : ( x > 0 ? x : 0 ) + 'px', - 'top' : ( y > 0 ? y : 0 ) + 'px' - }); + // Translate coordinate for RTL. + if ( rtl ) + { + var dialogSize = this.getSize(), + viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(); + x = viewPaneSize.width - dialogSize.width - x; + } + + var styles = { 'top' : ( y > 0 ? y : 0 ) + 'px' }; + styles[ rtl ? 'right' : 'left' ] = ( x > 0 ? x : 0 ) + 'px'; + + element.setStyles( styles ); save && ( this._.moved = 1 ); }; @@ -710,13 +733,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; */ show : function() { - var editor = this._.editor; - if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie ) - { - var selection = editor.getSelection(); - selection && selection.lock(); - } - // Insert the dialog's element to the root document. var element = this._.element; var definition = this.definition; @@ -738,8 +754,8 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; // First, set the dialog to an appropriate size. - this.resize( this._.contentSize && this._.contentSize.width || definition.minWidth, - this._.contentSize && this._.contentSize.height || definition.minHeight ); + this.resize( this._.contentSize && this._.contentSize.width || definition.width || definition.minWidth, + this._.contentSize && this._.contentSize.height || definition.height || definition.minHeight ); // Reset all inputs back to their default value. this.reset(); @@ -942,7 +958,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%;height:100%' }, pageHtml ); // Create the HTML for the tab and the content block. @@ -1256,9 +1272,77 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; * @param {Function|String} dialogDefinition * A function returning the dialog's definition, or the URL to the .js file holding the function. * The function should accept an argument "editor" which is the current editor instance, and - * return an object conforming to {@link CKEDITOR.dialog.dialogDefinition}. + * return an object conforming to {@link CKEDITOR.dialog.definition}. + * @see CKEDITOR.dialog.definition * @example - * @see CKEDITOR.dialog.dialogDefinition + * // Full sample plugin, which does not only register a dialog window but also adds an item to the context menu. + * // To open the dialog window, choose "Open dialog" in the context menu. + * CKEDITOR.plugins.add( 'myplugin', + * { + * init: function( editor ) + * { + * editor.addCommand( 'mydialog',new CKEDITOR.dialogCommand( 'mydialog' ) ); + * + * if ( editor.contextMenu ) + * { + * editor.addMenuGroup( 'mygroup', 10 ); + * editor.addMenuItem( 'My Dialog', + * { + * label : 'Open dialog', + * command : 'mydialog', + * group : 'mygroup' + * }); + * editor.contextMenu.addListener( function( element ) + * { + * return { 'My Dialog' : CKEDITOR.TRISTATE_OFF }; + * }); + * } + * + * CKEDITOR.dialog.add( 'mydialog', function( api ) + * { + * // CKEDITOR.dialog.definition + * var dialogDefinition = + * { + * title : 'Sample dialog', + * minWidth : 390, + * minHeight : 130, + * contents : [ + * { + * id : 'tab1', + * label : 'Label', + * title : 'Title', + * expand : true, + * padding : 0, + * elements : + * [ + * { + * type : 'html', + * html : '<p>This is some sample HTML content.</p>' + * }, + * { + * type : 'textarea', + * id : 'textareaId', + * rows : 4, + * cols : 40 + * } + * ] + * } + * ], + * buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ], + * onOk : function() { + * // "this" is now a CKEDITOR.dialog object. + * // Accessing dialog elements: + * var textareaObj = this.getContentElement( 'tab1', 'textareaId' ); + * alert( "You have entered: " + textareaObj.getValue() ); + * } + * }; + * + * return dialogDefinition; + * } ); + * } + * } ); + * + * CKEDITOR.replace( 'editor1', { extraPlugins : 'myplugin' } ); */ add : function( name, dialogDefinition ) { @@ -1449,8 +1533,8 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; * This class is not really part of the API. It is the "definition" property value * passed to "dialogDefinition" event handlers. * @constructor - * @name CKEDITOR.dialog.dialogDefinitionObject - * @extends CKEDITOR.dialog.dialogDefinition + * @name CKEDITOR.dialog.definitionObject + * @extends CKEDITOR.dialog.definition * @example * CKEDITOR.on( 'dialogDefinition', function( evt ) * { @@ -1473,12 +1557,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; }; definitionObject.prototype = - /** @lends CKEDITOR.dialog.dialogDefinitionObject.prototype */ + /** @lends CKEDITOR.dialog.definitionObject.prototype */ { /** * Gets a content definition. * @param {String} id The id of the content definition. - * @returns {CKEDITOR.dialog.contentDefinition} The content definition + * @returns {CKEDITOR.dialog.definition.content} The content definition * matching id. */ getContents : function( id ) @@ -1489,7 +1573,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; /** * Gets a button definition. * @param {String} id The id of the button definition. - * @returns {CKEDITOR.dialog.buttonDefinition} The button definition + * @returns {CKEDITOR.dialog.definition.button} The button definition * matching id. */ getButton : function( id ) @@ -1499,13 +1583,13 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; /** * Adds a content definition object under this dialog definition. - * @param {CKEDITOR.dialog.contentDefinition} contentDefinition The + * @param {CKEDITOR.dialog.definition.content} contentDefinition The * content definition. * @param {String} [nextSiblingId] The id of an existing content * definition which the new content definition will be inserted * before. Omit if the new content definition is to be inserted as * the last item. - * @returns {CKEDITOR.dialog.contentDefinition} The inserted content + * @returns {CKEDITOR.dialog.definition.content} The inserted content * definition. */ addContents : function( contentDefinition, nextSiblingId ) @@ -1515,13 +1599,13 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; /** * Adds a button definition object under this dialog definition. - * @param {CKEDITOR.dialog.buttonDefinition} buttonDefinition The + * @param {CKEDITOR.dialog.definition.button} buttonDefinition The * button definition. * @param {String} [nextSiblingId] The id of an existing button * definition which the new button definition will be inserted * before. Omit if the new button definition is to be inserted as * the last item. - * @returns {CKEDITOR.dialog.buttonDefinition} The inserted button + * @returns {CKEDITOR.dialog.definition.button} The inserted button * definition. */ addButton : function( buttonDefinition, nextSiblingId ) @@ -1532,7 +1616,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; /** * Removes a content definition from this dialog definition. * @param {String} id The id of the content definition to be removed. - * @returns {CKEDITOR.dialog.contentDefinition} The removed content + * @returns {CKEDITOR.dialog.definition.content} The removed content * definition. */ removeContents : function( id ) @@ -1543,7 +1627,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; /** * Removes a button definition from the dialog definition. * @param {String} id The id of the button definition to be removed. - * @returns {CKEDITOR.dialog.buttonDefinition} The removed button + * @returns {CKEDITOR.dialog.definition.button} The removed button * definition. */ removeButton : function( id ) @@ -1555,9 +1639,9 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; /** * This class is not really part of the API. It is the template of the * objects representing content pages inside the - * CKEDITOR.dialog.dialogDefinitionObject. + * CKEDITOR.dialog.definitionObject. * @constructor - * @name CKEDITOR.dialog.contentDefinitionObject + * @name CKEDITOR.dialog.definition.contentObject * @example * CKEDITOR.on( 'dialogDefinition', function( evt ) * { @@ -1578,12 +1662,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; } contentObject.prototype = - /** @lends CKEDITOR.dialog.contentDefinitionObject.prototype */ + /** @lends CKEDITOR.dialog.definition.contentObject.prototype */ { /** * Gets a UI element definition under the content definition. * @param {String} id The id of the UI element definition. - * @returns {CKEDITOR.dialog.uiElementDefinition} + * @returns {CKEDITOR.dialog.definition.uiElement} */ get : function( id ) { @@ -1592,13 +1676,13 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; /** * Adds a UI element definition to the content definition. - * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition The + * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition The * UI elemnet definition to be added. * @param {String} nextSiblingId The id of an existing UI element * definition which the new UI element definition will be inserted * before. Omit if the new button definition is to be inserted as * the last item. - * @returns {CKEDITOR.dialog.uiElementDefinition} The element + * @returns {CKEDITOR.dialog.definition.uiElement} The element * definition inserted. */ add : function( elementDefinition, nextSiblingId ) @@ -1610,7 +1694,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; * Removes a UI element definition from the content definition. * @param {String} id The id of the UI element definition to be * removed. - * @returns {CKEDITOR.dialog.uiElementDefinition} The element + * @returns {CKEDITOR.dialog.definition.uiElement} The element * definition removed. * @example */ @@ -1706,25 +1790,24 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; return; var editor = dialog.getParentEditor(); - var wrapperWidth, wrapperHeight, viewSize, origin, startSize; - - function positionDialog( right ) - { - // Maintain righthand sizing in RTL. - if ( dialog._.moved && editor.lang.dir == 'rtl' ) - { - var element = dialog._.element.getFirst(); - element.setStyle( 'right', right + "px" ); - element.removeStyle( 'left' ); - } - else if ( !dialog._.moved ) - dialog.layout(); - } + var wrapperWidth, wrapperHeight, + viewSize, origin, startSize, + dialogCover; var mouseDownFn = CKEDITOR.tools.addFunction( function( $event ) { startSize = dialog.getSize(); + var content = dialog.parts.contents, + iframeDialog = content.$.getElementsByTagName( 'iframe' ).length; + + // Shim to help capturing "mousemove" over iframe. + if ( iframeDialog ) + { + dialogCover = CKEDITOR.dom.element.createFromHtml( '
' ); + content.append( dialogCover ); + } + // Calculate the offset between content and chrome size. wrapperHeight = startSize.height - dialog.parts.contents.getSize( 'height', ! ( CKEDITOR.env.gecko || CKEDITOR.env.opera || CKEDITOR.env.ie && CKEDITOR.env.quirks ) ); wrapperWidth = startSize.width - dialog.parts.contents.getSize( 'width', 1 ); @@ -1754,7 +1837,8 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; direction = ' cke_resizer_horizontal'; else if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT ) direction = ' cke_resizer_vertical'; - var resizer = CKEDITOR.dom.element.createFromHtml( '
' ); dialog.parts.footer.append( resizer, 1 ); @@ -1774,10 +1858,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; right = rtl && element.getComputedStyle( 'right' ), position = dialog.getPosition(); - // IE might return "auto", we need exact position. - if ( right ) - right = right == 'auto' ? viewSize.width - ( position.x || 0 ) - element.getSize( 'width' ) : parseInt( right, 10 ); - if ( position.y + internalHeight > viewSize.height ) internalHeight = viewSize.height - position.y; @@ -1785,15 +1865,16 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; internalWidth = viewSize.width - ( rtl ? right : position.x ); // Make sure the dialog will not be resized to the wrong side when it's in the leftmost position for RTL. - if ( ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH || resizable == CKEDITOR.DIALOG_RESIZE_BOTH ) && !( rtl && dx > 0 && !position.x ) ) + if ( ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH || resizable == CKEDITOR.DIALOG_RESIZE_BOTH ) ) width = Math.max( def.minWidth || 0, internalWidth - wrapperWidth ); if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT || resizable == CKEDITOR.DIALOG_RESIZE_BOTH ) height = Math.max( def.minHeight || 0, internalHeight - wrapperHeight ); dialog.resize( width, height ); - // The right property might get broken during resizing, so computing it before the resizing. - positionDialog( right ); + + if ( !dialog._.moved ) + dialog.layout(); evt.data.preventDefault(); } @@ -1803,30 +1884,18 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler ); CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler ); + if ( dialogCover ) + { + dialogCover.remove(); + dialogCover = null; + } + if ( CKEDITOR.env.ie6Compat ) { var coverDoc = currentCover.getChild( 0 ).getFrameDocument(); coverDoc.removeListener( 'mouseup', mouseUpHandler ); coverDoc.removeListener( 'mousemove', mouseMoveHandler ); } - - // Switch back to use the left property, if RTL is used. - if ( editor.lang.dir == 'rtl' ) - { - var element = dialog._.element.getFirst(), - left = element.getComputedStyle( 'left' ); - - // IE might return "auto", we need exact position. - if ( left == 'auto' ) - left = viewSize.width - parseInt( element.getStyle( 'right' ), 10 ) - dialog.getSize().width; - else - left = parseInt( left, 10 ); - - element.removeStyle( 'right' ); - // Make sure the left property gets applied, even if it is the same as previously. - dialog._.position.x += 1; - dialog.move( left, dialog._.position.y ); - } } } @@ -1852,7 +1921,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; if ( !coverElement ) { var html = [ - '
*
  • 'OS' - the buttons will be displayed in the default order of the user's OS;
  • *
  • 'ltr' - for Left-To-Right order;
  • @@ -3034,7 +3116,7 @@ CKEDITOR.plugins.add( 'dialog', * The dialog contents to removed. It's a string composed by dialog name and tab name with a colon between them. * Separate each pair with semicolon (see example). * Note: All names are case-sensitive. - * Note: Be cautious when specifying dialog tabs that are mandatory, like "info", dialog functionality might be broken because of this! + * Note: Be cautious when specifying dialog tabs that are mandatory, like "info", dialog functionality might be broken because of this! * @name CKEDITOR.config.removeDialogTabs * @type String * @since 3.5 @@ -3052,7 +3134,7 @@ CKEDITOR.plugins.add( 'dialog', * not get fired.

    * @name CKEDITOR#dialogDefinition * @event - * @param {CKEDITOR.dialog.dialogDefinition} data The dialog defination that + * @param {CKEDITOR.dialog.definition} data The dialog defination that * is being loaded. * @param {CKEDITOR.editor} editor The editor instance that will use the * dialog. @@ -3060,8 +3142,60 @@ CKEDITOR.plugins.add( 'dialog', /** * Fired when a tab is going to be selected in a dialog - * @name dialog#selectPage + * @name CKEDITOR.dialog#selectPage + * @event + * @param {String} page The id of the page that it's gonna be selected. + * @param {String} currentPage The id of the current page. + */ + +/** + * Fired when the user tries to dismiss a dialog + * @name CKEDITOR.dialog#cancel + * @event + * @param {Boolean} hide Whether the event should proceed or not. + */ + +/** + * Fired when the user tries to confirm a dialog + * @name CKEDITOR.dialog#ok + * @event + * @param {Boolean} hide Whether the event should proceed or not. + */ + +/** + * Fired when a dialog is shown + * @name CKEDITOR.dialog#show + * @event + */ + +/** + * Fired when a dialog is shown + * @name CKEDITOR.editor#dialogShow + * @event + */ + +/** + * Fired when a dialog is hidden + * @name CKEDITOR.dialog#hide + * @event + */ + +/** + * Fired when a dialog is hidden + * @name CKEDITOR.editor#dialogHide + * @event + */ + +/** + * Fired when a dialog is being resized. The event is fired on + * both the 'CKEDITOR.dialog' object and the dialog instance + * since 3.5.3, previously it's available only in the global object. + * @name CKEDITOR.dialog#resize + * @since 3.5 * @event - * @param String page The id of the page that it's gonna be selected. - * @param String currentPage The id of the current page. + * @param {CKEDITOR.dialog} dialog The dialog being resized (if + * it's fired on the dialog itself, this parameter isn't sent). + * @param {String} skin The skin name. + * @param {Number} width The new width. + * @param {Number} height The new height. */