X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fdialog%2Fplugin.js;h=e21f5d1afd5ae5e3b628d4eea959853d7b335717;hp=db371c4d95f873dbeab160349fc358390acf7478;hb=fb481ba0a7d298e3e7b9034fcb9f2afdc6e8e796;hpb=6e682412d5cc0dfaedb376482e585bf2989c6863 diff --git a/_source/plugins/dialog/plugin.js b/_source/plugins/dialog/plugin.js index db371c4..e21f5d1 100644 --- a/_source/plugins/dialog/plugin.js +++ b/_source/plugins/dialog/plugin.js @@ -457,7 +457,7 @@ CKEDITOR.DIALOG_RESIZE_BOTH = 3; { // Don't do that for a target that handles ENTER. var target = evt.data.getTarget(); - if ( !target.is( 'a', 'button', 'select' ) && ( !target.is( 'input' ) || target.$.type != 'button' ) ) + 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 ); @@ -665,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() @@ -733,49 +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(), - rtl = this._.editor.lang.dir == 'rtl'; + // 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 === undefined ) - isFixed = element.getComputedStyle( 'position' ) == 'fixed'; + var isFixed = element.getComputedStyle( 'position' ) == 'fixed'; - if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y ) - return; + if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y ) + return; - // Save the current position. - this._.position = { x : x, y : y }; + // Save the current position. + this._.position = { x : x, y : y }; - // If not fixed positioned, add scroll position to the coordinates. - if ( !isFixed ) - { - var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition(); - x += scrollPosition.x; - y += scrollPosition.y; - } + // If not fixed positioned, add scroll position to the coordinates. + if ( !isFixed ) + { + var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition(); + x += scrollPosition.x; + y += scrollPosition.y; + } - // Translate coordinate for RTL. - if ( rtl ) - { - var dialogSize = this.getSize(), - viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(); - x = viewPaneSize.width - dialogSize.width - x; - } + // 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'; + var styles = { 'top' : ( y > 0 ? y : 0 ) + 'px' }; + styles[ rtl ? 'right' : 'left' ] = ( x > 0 ? x : 0 ) + 'px'; - element.setStyles( styles ); + element.setStyles( styles ); - save && ( this._.moved = 1 ); - }; - })(), + save && ( this._.moved = 1 ); + }, /** * Gets the dialog's position in the window. @@ -852,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. @@ -874,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 ); }, /**