X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fdialog%2Fplugin.js;h=e21f5d1afd5ae5e3b628d4eea959853d7b335717;hb=fb481ba0a7d298e3e7b9034fcb9f2afdc6e8e796;hp=b5aab8182c2060c5e27b7863ba76f6b848dce35b;hpb=9afde8772159bd3436f1f5b7862960307710ae5a;p=ckeditor.git diff --git a/_source/plugins/dialog/plugin.js b/_source/plugins/dialog/plugin.js index b5aab81..e21f5d1 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-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -93,6 +93,36 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; } } + // Handle dialog element validation state UI changes. + function handleFieldValidated( isValid, msg ) + { + var input = this.getInputElement(); + if ( input ) + { + isValid ? input.removeAttribute( 'aria-invalid' ) + : input.setAttribute( 'aria-invalid', true ); + } + + if ( !isValid ) + { + if ( this.select ) + this.select(); + else + this.focus(); + } + + msg && alert( msg ); + + this.fire( 'validated', { valid : isValid, msg : msg } ); + } + + function resetField() + { + var input = this.getInputElement(); + input && input.removeAttribute( 'aria-invalid' ); + } + + /** * This is the base class for runtime dialog objects. An instance of this * class represents a single named dialog for a single editor instance. @@ -108,7 +138,10 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ], defaultDefinition = CKEDITOR.tools.clone( defaultDialogDefinition ), buttonsOrder = editor.config.dialog_buttonsOrder || 'OS', - dir = editor.lang.dir; + dir = editor.lang.dir, + tabsToRemove = {}, + i, + processed, stopPropagation; if ( ( buttonsOrder == 'OS' && CKEDITOR.env.mac ) || // The buttons in MacOS Apps are in reverse order (#4750) ( buttonsOrder == 'rtl' && dir == 'ltr' ) || @@ -167,13 +200,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 ); @@ -187,7 +222,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; } , editor ).definition; - var tabsToRemove = {}; // Cache tabs that should be removed. if ( !( 'removeDialogTabs' in editor._ ) && editor.config.removeDialogTabs ) { @@ -271,25 +305,17 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; { if ( item.validate ) { - var isValid = item.validate( this ); - - if ( typeof isValid == 'string' ) - { - alert( isValid ); - isValid = false; - } + var retval = item.validate( this ), + invalid = typeof ( retval ) == 'string' || retval === false; - if ( isValid === false ) + if ( invalid ) { - if ( item.select ) - item.select(); - else - item.focus(); - evt.data.hide = false; evt.stop(); - return true; } + + handleFieldValidated.call( item, !invalid, typeof retval == 'string' ? retval : undefined ); + return invalid; } }); }, this, null, 0 ); @@ -334,10 +360,11 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; focusList[ i ].focusIndex = i; } - function changeFocus( forward ) + function changeFocus( offset ) { - var focusList = me._.focusList, - offset = forward ? 1 : -1; + var focusList = me._.focusList; + offset = offset || 0; + if ( focusList.length < 1 ) return; @@ -353,12 +380,13 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; var startIndex = ( current + offset + focusList.length ) % focusList.length, currentIndex = startIndex; - while ( !focusList[ currentIndex ].isFocusable() ) + while ( offset && !focusList[ currentIndex ].isFocusable() ) { currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length; if ( currentIndex == startIndex ) break; } + focusList[ currentIndex ].focus(); // Select whole field content. @@ -368,18 +396,19 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; this.changeFocus = changeFocus; - var processed; - function focusKeydownHandler( evt ) + function keydownHandler( evt ) { // If I'm not the top dialog, ignore. if ( me != CKEDITOR.dialog._.currentTop ) return; var keystroke = evt.data.getKeystroke(), - rtl = editor.lang.dir == 'rtl'; + rtl = editor.lang.dir == 'rtl', + button; + + processed = stopPropagation = 0; - processed = 0; if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 ) { var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 ); @@ -395,7 +424,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; else { // Change the focus of inputs. - changeFocus( !shiftPressed ); + changeFocus( shiftPressed ? -1 : 1 ); } processed = 1; @@ -420,43 +449,75 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; this.selectPage( this._.currentTabId ); this._.tabBarMode = false; this._.currentFocusIndex = -1; - changeFocus( true ); + changeFocus( 1 ); processed = 1; } - - if ( processed ) + // If user presses enter key in a text box, it implies clicking OK for the dialog. + else if ( keystroke == 13 /*ENTER*/ ) { - evt.stop(); - evt.data.preventDefault(); + // Don't do that for a target that handles ENTER. + var target = evt.data.getTarget(); + if ( !target.is( 'a', 'button', 'select', 'textarea' ) && ( !target.is( 'input' ) || target.$.type != 'button' ) ) + { + button = this.getButton( 'ok' ); + button && CKEDITOR.tools.setTimeout( button.click, 0, button ); + processed = 1; + } + stopPropagation = 1; // Always block the propagation (#4269) + } + else if ( keystroke == 27 /*ESC*/ ) + { + button = this.getButton( 'cancel' ); + + // If there's a Cancel button, click it, else just fire the cancel event and hide the dialog. + if ( button ) + CKEDITOR.tools.setTimeout( button.click, 0, button ); + else + { + if ( this.fire( 'cancel', { hide : true } ).hide !== false ) + this.hide(); + } + stopPropagation = 1; // Always block the propagation (#4269) } + else + return; + + keypressHandler( evt ); } - function focusKeyPressHandler( evt ) + function keypressHandler( evt ) { - processed && evt.data.preventDefault(); + if ( processed ) + evt.data.preventDefault(1); + else if ( stopPropagation ) + evt.data.stopPropagation(); } var dialogElement = this._.element; // Add the dialog keyboard handlers. this.on( 'show', function() { - dialogElement.on( 'keydown', focusKeydownHandler, this, null, 0 ); + dialogElement.on( 'keydown', keydownHandler, this ); + // Some browsers instead, don't cancel key events in the keydown, but in the - // keypress. So we must do a longer trip in those cases. (#4531) - if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) ) - dialogElement.on( 'keypress', focusKeyPressHandler, this ); + // keypress. So we must do a longer trip in those cases. (#4531,#8985) + if ( CKEDITOR.env.opera || CKEDITOR.env.gecko ) + dialogElement.on( 'keypress', keypressHandler, this ); } ); this.on( 'hide', function() { - dialogElement.removeListener( 'keydown', focusKeydownHandler ); - if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) ) - dialogElement.removeListener( 'keypress', focusKeyPressHandler ); + dialogElement.removeListener( 'keydown', keydownHandler ); + if ( CKEDITOR.env.opera || CKEDITOR.env.gecko ) + dialogElement.removeListener( 'keypress', keypressHandler ); + + // Reset fields state when closing dialog. + iterContents( function( item ) { resetField.apply( item ); } ); } ); this.on( 'iframeAdded', function( evt ) { var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document ); - doc.on( 'keydown', focusKeydownHandler, this, null, 0 ); + doc.on( 'keydown', keydownHandler, this, null, 0 ); } ); // Auto-focus logic in dialog. @@ -485,7 +546,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; } // Focus the first field in layout order. else - changeFocus( true ); + changeFocus( 1 ); /* * IE BUG: If the initial focus went into a non-text element (e.g. button), @@ -531,7 +592,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title ); // Insert the tabs and contents. - for ( var i = 0 ; i < definition.contents.length ; i++ ) + for ( i = 0 ; i < definition.contents.length ; i++ ) { var page = definition.contents[i]; page && this.addPage( page ); @@ -551,7 +612,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; { this._.tabBarMode = false; this._.currentFocusIndex = -1; - changeFocus( true ); + changeFocus( 1 ); } evt.data.preventDefault(); } @@ -604,6 +665,15 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; } ); } + // Re-layout the dialog on window resize. + function resizeWithWindow( dialog ) + { + var win = CKEDITOR.document.getWindow(); + function resizeHandler() { dialog.layout(); } + win.on( 'resize', resizeHandler ); + dialog.on( 'hide', function() { win.removeListener( 'resize', resizeHandler ); } ); + } + CKEDITOR.dialog.prototype = { destroy : function() @@ -635,6 +705,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 }; }; })(), @@ -660,40 +742,44 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; * @example * dialogObj.move( 10, 40 ); */ - move : (function() + move : function( x, y, save ) { - var isFixed; - return function( x, y, save ) - { - // The dialog may be fixed positioned or absolute positioned. Ask the - // browser what is the current situation first. - var element = this._.element.getFirst(); - if ( isFixed === undefined ) - isFixed = element.getComputedStyle( 'position' ) == 'fixed'; + // The dialog may be fixed positioned or absolute positioned. Ask the + // browser what is the current situation first. + var element = this._.element.getFirst(), + rtl = this._.editor.lang.dir == 'rtl'; - if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y ) - return; + var isFixed = element.getComputedStyle( 'position' ) == 'fixed'; - // Save the current position. - this._.position = { x : x, y : y }; + if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y ) + return; - // If not fixed positioned, add scroll position to the coordinates. - if ( !isFixed ) - { - var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition(); - x += scrollPosition.x; - y += scrollPosition.y; - } + // Save the current position. + this._.position = { x : x, y : y }; - element.setStyles( - { - 'left' : ( x > 0 ? x : 0 ) + 'px', - 'top' : ( y > 0 ? y : 0 ) + 'px' - }); + // If not fixed positioned, add scroll position to the coordinates. + if ( !isFixed ) + { + var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition(); + x += scrollPosition.x; + y += scrollPosition.y; + } - save && ( this._.moved = 1 ); - }; - })(), + // 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 ); + }, /** * Gets the dialog's position in the window. @@ -710,13 +796,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 +817,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(); @@ -753,19 +832,12 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 ); // Maintain the dialog ordering and dialog cover. - // Also register key handlers if first dialog. if ( CKEDITOR.dialog._.currentTop === null ) { CKEDITOR.dialog._.currentTop = this; this._.parentDialog = null; showCover( this._.editor ); - element.on( 'keydown', accessKeyDownHandler ); - element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler ); - - // Prevent some keys from bubbling up. (#4269) - for ( var event in { keyup :1, keydown :1, keypress :1 } ) - element.on( event, preventKeyBubbling ); } else { @@ -775,11 +847,8 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; CKEDITOR.dialog._.currentTop = this; } - // Register the Esc hotkeys. - registerAccessKey( this, this, '\x1b', null, function() - { - this.getButton( 'cancel' ) && this.getButton( 'cancel' ).click(); - } ); + element.on( 'keydown', accessKeyDownHandler ); + element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler ); // Reset the hasFocus state. this._.hasFocus = false; @@ -787,6 +856,8 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; CKEDITOR.tools.setTimeout( function() { this.layout(); + resizeWithWindow( this ); + this.parts.dialog.setStyle( 'visibility', '' ); // Execute onLoad for the first show. @@ -809,11 +880,26 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; */ layout : function() { - var viewSize = CKEDITOR.document.getWindow().getViewPaneSize(), - dialogSize = this.getSize(); + var el = this.parts.dialog; + var dialogSize = this.getSize(); + var win = CKEDITOR.document.getWindow(), + viewSize = win.getViewPaneSize(); + + var posX = ( viewSize.width - dialogSize.width ) / 2, + posY = ( viewSize.height - dialogSize.height ) / 2; + + // Switch to absolute position when viewport is smaller than dialog size. + if ( !CKEDITOR.env.ie6Compat ) + { + if ( dialogSize.height + ( posY > 0 ? posY : 0 ) > viewSize.height || + dialogSize.width + ( posX > 0 ? posX : 0 ) > viewSize.width ) + el.setStyle( 'position', 'absolute' ); + else + el.setStyle( 'position', 'fixed' ); + } - this.move( this._.moved ? this._.position.x : ( viewSize.width - dialogSize.width ) / 2, - this._.moved ? this._.position.y : ( viewSize.height - dialogSize.height ) / 2 ); + this.move( this._.moved ? this._.position.x : posX, + this._.moved ? this._.position.y : posY ); }, /** @@ -826,7 +912,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; for ( var i in this._.contents ) { for ( var j in this._.contents[i] ) - fn( this._.contents[i][j] ); + fn.call( this, this._.contents[i][j] ); } return this; }, @@ -843,6 +929,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; @@ -853,11 +949,24 @@ 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; this.foreach( function( widget ) { + // Make sure IE triggers "change" event on last focused input before closing the dialog. (#7915) + if ( CKEDITOR.env.ie && this._.currentFocusIndex == widget.focusIndex ) + widget.getInputElement().$.blur(); + if ( widget.commit ) widget.commit.apply( widget, args ); }); @@ -875,6 +984,8 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; this.fire( 'hide', {} ); this._.editor.fire( 'dialogHide', this ); + // Reset the tab page. + this.selectPage( this._.tabIdList[ 0 ] ); var element = this._.element; element.setStyle( 'display', 'none' ); this.parts.dialog.setStyle( 'visibility', 'hidden' ); @@ -904,10 +1015,6 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; element.removeListener( 'keydown', accessKeyDownHandler ); element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler ); - // Remove bubbling-prevention handler. (#4269) - for ( var event in { keyup :1, keydown :1, keypress :1 } ) - element.removeListener( event, preventKeyBubbling ); - var editor = this._.editor; editor.focus(); @@ -942,7 +1049,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. @@ -1123,6 +1230,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 ) @@ -1136,6 +1244,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 ) @@ -1149,6 +1258,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 ) { @@ -1256,9 +1366,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 +1627,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 +1651,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 +1667,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 +1677,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 +1693,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 +1710,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 +1721,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 +1733,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 +1756,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 +1770,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 +1788,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 +1884,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 +1931,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 +1952,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 +1959,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 +1978,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 ); - } } } @@ -1836,6 +1999,11 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; var covers = {}, currentCover; + function cancelEvent( ev ) + { + ev.data.preventDefault(1); + } + function showCover( editor ) { var win = CKEDITOR.document.getWindow(); @@ -1852,7 +2020,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; if ( !coverElement ) { var html = [ - '
', childHtmlList[i], '' ); @@ -2317,7 +2530,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; * objects in childObjList. * @param {Array} htmlList * Array of HTML code that this element will output to. - * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition + * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition * The element definition. Accepted fields: *