X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fdialog%2Fplugin.js;h=b0b125cdce3bc45d7aec32a364f6d061f81f0a01;hb=1056598c95187351dc58f4991d331e2258d038b5;hp=68494616cb9bb2f7cc2d7282ff62845dc6b6fc90;hpb=48b1db88210b4160dce439c6e3e32e14af8c106b;p=ckeditor.git diff --git a/_source/plugins/dialog/plugin.js b/_source/plugins/dialog/plugin.js index 6849461..b0b125c 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(); @@ -836,6 +859,16 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; return function(){ this.foreach( fn ); return this; }; })(), + + /** + * Calls the {@link CKEDITOR.dialog.definition.uiElement#setup} method of each of the UI elements, with the arguments passed through it. + * It is usually being called when the dialog is opened, to put the initial value inside the field. + * @example + * dialogObj.setupContent(); + * @example + * var timestamp = ( new Date() ).valueOf(); + * dialogObj.setupContent( timestamp ); + */ setupContent : function() { var args = arguments; @@ -846,6 +879,15 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; }); }, + /** + * Calls the {@link CKEDITOR.dialog.definition.uiElement#commit} method of each of the UI elements, with the arguments passed through it. + * It is usually being called when the user confirms the dialog, to process the values. + * @example + * dialogObj.commitContent(); + * @example + * var timestamp = ( new Date() ).valueOf(); + * dialogObj.commitContent( timestamp ); + */ commitContent : function() { var args = arguments; @@ -935,7 +977,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. @@ -1116,6 +1158,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; * @param {String} pageId id of dialog page. * @param {String} elementId id of UI element. * @example + * dialogObj.getContentElement( 'tabId', 'elementId' ).setValue( 'Example' ); * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element. */ getContentElement : function( pageId, elementId ) @@ -1129,6 +1172,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; * @param {String} pageId id of dialog page. * @param {String} elementId id of UI element. * @example + * alert( dialogObj.getValueOf( 'tabId', 'elementId' ) ); * @returns {Object} The value of the UI element. */ getValueOf : function( pageId, elementId ) @@ -1142,6 +1186,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; * @param {String} elementId id of the UI element. * @param {Object} value The new value of the UI element. * @example + * dialogObj.setValueOf( 'tabId', 'elementId', 'Example' ); */ setValueOf : function( pageId, elementId, value ) { @@ -1249,9 +1294,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 +1555,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 +1579,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 +1595,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 +1605,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 +1621,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 +1638,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 +1649,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 +1661,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 +1684,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 +1698,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 +1716,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 +1816,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 +1859,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 +1880,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 +1887,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 +1918,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 ); - } } } @@ -1847,6 +1927,11 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; var covers = {}, currentCover; + function cancelEvent( ev ) + { + ev.data.preventDefault(1); + } + function showCover( editor ) { var win = CKEDITOR.document.getWindow(); @@ -1907,6 +1992,10 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) ); coverElement.setOpacity( backgroundCoverOpacity != undefined ? backgroundCoverOpacity : 0.5 ); + coverElement.on( 'keydown', cancelEvent ); + coverElement.on( 'keypress', cancelEvent ); + coverElement.on( 'keyup', cancelEvent ); + coverElement.appendTo( CKEDITOR.document.getBody() ); covers[ coverKey ] = coverElement; } @@ -2086,7 +2175,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: *