Ticket #8888: 8888.patch

File 8888.patch, 4.5 KB (added by Garry Yao, 12 years ago)
  • _source/plugins/dialog/plugin.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    665665                        } );
    666666        }
    667667
     668        // Re-layout the dialog on window resize.
     669        function resizeWithWindow( dialog )
     670        {
     671                var win = CKEDITOR.document.getWindow();
     672                function resizeHandler() { dialog.layout(); }
     673                win.on( 'resize', resizeHandler );
     674                dialog.on( 'hide', function() { win.removeListener( 'resize', resizeHandler ); } );
     675        }
     676
    668677        CKEDITOR.dialog.prototype =
    669678        {
    670679                destroy : function()
     
    733742                 * @example
    734743                 * dialogObj.move( 10, 40 );
    735744                 */
    736                 move : (function()
     745                move : function( x, y, save )
    737746                {
    738                         var isFixed;
    739                         return function( x, y, save )
    740                         {
    741                                 // The dialog may be fixed positioned or absolute positioned. Ask the
    742                                 // browser what is the current situation first.
    743                                 var element = this._.element.getFirst(),
    744                                         rtl = this._.editor.lang.dir == 'rtl';
     747                        // The dialog may be fixed positioned or absolute positioned. Ask the
     748                        // browser what is the current situation first.
     749                        var element = this._.element.getFirst(),
     750                                rtl = this._.editor.lang.dir == 'rtl';
    745751
    746                                 if ( isFixed === undefined )
    747                                         isFixed = element.getComputedStyle( 'position' ) == 'fixed';
     752                        var isFixed = element.getComputedStyle( 'position' ) == 'fixed';
    748753
    749                                 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
    750                                         return;
     754                        if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
     755                                return;
    751756
    752                                 // Save the current position.
    753                                 this._.position = { x : x, y : y };
     757                        // Save the current position.
     758                        this._.position = { x : x, y : y };
    754759
    755                                 // If not fixed positioned, add scroll position to the coordinates.
    756                                 if ( !isFixed )
    757                                 {
    758                                         var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
    759                                         x += scrollPosition.x;
    760                                         y += scrollPosition.y;
    761                                 }
     760                        // If not fixed positioned, add scroll position to the coordinates.
     761                        if ( !isFixed )
     762                        {
     763                                var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
     764                                x += scrollPosition.x;
     765                                y += scrollPosition.y;
     766                        }
    762767
    763                                 // Translate coordinate for RTL.
    764                                 if ( rtl )
    765                                 {
    766                                         var dialogSize = this.getSize(),
    767                                                 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize();
    768                                         x = viewPaneSize.width - dialogSize.width - x;
    769                                 }
     768                        // Translate coordinate for RTL.
     769                        if ( rtl )
     770                        {
     771                                var dialogSize = this.getSize(),
     772                                        viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize();
     773                                x = viewPaneSize.width - dialogSize.width - x;
     774                        }
    770775
    771                                 var styles = { 'top'    : ( y > 0 ? y : 0 ) + 'px' };
    772                                 styles[ rtl ? 'right' : 'left' ] = ( x > 0 ? x : 0 ) + 'px';
     776                        var styles = { 'top'    : ( y > 0 ? y : 0 ) + 'px' };
     777                        styles[ rtl ? 'right' : 'left' ] = ( x > 0 ? x : 0 ) + 'px';
    773778
    774                                 element.setStyles( styles );
     779                        element.setStyles( styles );
    775780
    776                                 save && ( this._.moved = 1 );
    777                         };
    778                 })(),
     781                        save && ( this._.moved = 1 );
     782                },
    779783
    780784                /**
    781785                 * Gets the dialog's position in the window.
     
    852856                        CKEDITOR.tools.setTimeout( function()
    853857                                {
    854858                                        this.layout();
     859                                        resizeWithWindow( this );
     860
    855861                                        this.parts.dialog.setStyle( 'visibility', '' );
    856862
    857863                                        // Execute onLoad for the first show.
     
    874880                 */
    875881                layout : function()
    876882                {
    877                         var viewSize = CKEDITOR.document.getWindow().getViewPaneSize(),
    878                                         dialogSize = this.getSize();
     883                        var el = this.parts.dialog;
     884                        var dialogSize = this.getSize();
     885                        var win = CKEDITOR.document.getWindow(),
     886                                        viewSize = win.getViewPaneSize();
    879887
    880                         this.move( this._.moved ? this._.position.x : ( viewSize.width - dialogSize.width ) / 2,
    881                                         this._.moved ? this._.position.y : ( viewSize.height - dialogSize.height ) / 2 );
     888                        var posX = ( viewSize.width - dialogSize.width ) / 2,
     889                                posY = ( viewSize.height - dialogSize.height ) / 2;
     890
     891                        // Switch to absolute position when viewport is smaller than dialog size.
     892                        if ( !CKEDITOR.env.ie6Compat )
     893                        {
     894                                if ( dialogSize.height + ( posY > 0 ? posY : 0 ) > viewSize.height ||
     895                                                 dialogSize.width + ( posX > 0 ? posX : 0 ) > viewSize.width )
     896                                        el.setStyle( 'position', 'absolute' );
     897                                else
     898                                        el.setStyle( 'position', 'fixed' );
     899                        }
     900
     901                        this.move( this._.moved ? this._.position.x : posX,
     902                                        this._.moved ? this._.position.y : posY );
    882903                },
    883904
    884905                /**
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy