X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fdialog%2Fplugin.js;h=ce287993adac365a2a90fbc64d0e7a273cf81640;hp=68494616cb9bb2f7cc2d7282ff62845dc6b6fc90;hb=4e90e78dc97789709ee7404359a5517540c27553;hpb=8f6c203fdaa543c3bca40baea6ae4ddcdf1a77f5 diff --git a/_source/plugins/dialog/plugin.js b/_source/plugins/dialog/plugin.js index 6849461..ce28799 100644 --- a/_source/plugins/dialog/plugin.js +++ b/_source/plugins/dialog/plugin.js @@ -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 ); }; @@ -731,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(); @@ -935,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. @@ -1249,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 ) { @@ -1442,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 ) * { @@ -1466,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 ) @@ -1482,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 ) @@ -1492,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 ) @@ -1508,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 ) @@ -1525,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 ) @@ -1536,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 ) @@ -1548,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 ) * { @@ -1571,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 ) { @@ -1585,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 ) @@ -1603,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 */ @@ -1703,19 +1794,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; viewSize, origin, startSize, dialogCover; - 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 mouseDownFn = CKEDITOR.tools.addFunction( function( $event ) { startSize = dialog.getSize(); @@ -1759,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 ); @@ -1779,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; @@ -1790,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(); } @@ -1820,24 +1896,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; 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 ); - } } } @@ -2086,7 +2144,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; * The base class of all dialog UI elements. * @constructor * @param {CKEDITOR.dialog} dialog Parent dialog object. - * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition Element + * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition Element * definition. Accepted fields: *