Ticket #3601: 3601_2.patch

File 3601_2.patch, 4.3 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/resize/plugin.js

     
    77{
    88        init : function( editor )
    99        {
    10                 var config = editor.config;
     10                var config = editor.config,
     11                                useProxy = config.resize_proxy || CKEDITOR.env.webkit || CKEDITOR.env.ie6Compat && !CKEDITOR.env.ie8;
    1112
    1213                if ( config.resize_enabled )
    1314                {
    14                         var container = null,
     15                        var resizeable = null,
     16                                proxy,
     17                                pixel = CKEDITOR.tools.cssLength,
    1518                                origin,
    1619                                startSize,
     20                                width, height, adjustmentX, adjustmentY,
    1721                                resizeHorizontal = ( config.resize_dir == 'both' || config.resize_dir == 'horizontal' ) &&
    1822                                        ( config.resize_minWidth != config.resize_maxWidth ),
    1923                                resizeVertical = ( config.resize_dir == 'both' || config.resize_dir == 'vertical' ) &&
     
    2327                        {
    2428                                var dx = evt.data.$.screenX - origin.x,
    2529                                        dy = evt.data.$.screenY - origin.y,
    26                                         width = startSize.width,
    27                                         height = startSize.height,
    28                                         internalWidth = width + dx * ( editor.lang.dir == 'rtl' ? -1 : 1 ),
    29                                         internalHeight = height + dy;
     30                                        internalWidth = startSize.width + dx * ( editor.lang.dir == 'rtl' ? -1 : 1 ),
     31                                        internalHeight = startSize.height + dy;
    3032
    3133                                if ( resizeHorizontal )
    3234                                        width =  Math.max( config.resize_minWidth, Math.min( internalWidth, config.resize_maxWidth ) );
     
    3436                                if ( resizeVertical )
    3537                                        height =  Math.max( config.resize_minHeight, Math.min( internalHeight, config.resize_maxHeight ) );
    3638
    37                                 editor.resize( width, height );
     39                                if ( useProxy )
     40                                        proxy.setStyles( { width: pixel( width ), height: pixel( height ) } );
     41                                else
     42                                        editor.resize( width + adjustmentX, height + adjustmentY );
    3843                        }
    3944
    4045                        function dragEndHandler ( evt )
    4146                        {
     47                                useProxy && proxy.hide();
     48
     49                                editor.resize( width + adjustmentX, height + adjustmentY );
     50
    4251                                CKEDITOR.document.removeListener( 'mousemove', dragHandler );
    4352                                CKEDITOR.document.removeListener( 'mouseup', dragEndHandler );
    4453
     
    5160
    5261                        var mouseDownFn = CKEDITOR.tools.addFunction( function( $event )
    5362                                {
    54                                         if ( !container )
    55                                                 container = editor.getResizable();
     63                                        function showProxy()
     64                                        {
     65                                                if ( !( proxy = CKEDITOR.document.getById( 'cke_resize_proxy' ) ) )
     66                                                        proxy = CKEDITOR.document.getBody().append( CKEDITOR.dom.element.createFromHtml( '<div id="cke_resize_proxy" style="position:absolute;border:dotted 1px;"></div>' ) );
    5667
    57                                         startSize = { width : container.$.offsetWidth || 0, height : container.$.offsetHeight || 0 };
     68                                                var docPosition = editor.container.getDocumentPosition();
     69                                                proxy.setStyles( { left : pixel( docPosition.x ), top: pixel( docPosition.y ), width: pixel( startSize.width ), height: pixel( startSize.height )  } );
     70                                                proxy.show();
     71                                        }
     72
     73                                        if ( !resizeable )
     74                                                resizeable = editor.getResizable();
     75
     76                                        startSize = { width : resizeable.$.offsetWidth || 0, height : resizeable.$.offsetHeight || 0 };
    5877                                        origin = { x : $event.screenX, y : $event.screenY };
     78                                        adjustmentX = CKEDITOR.env.quirks ? editor.container.$.offsetHeight - resizeable.$.offsetHeight : 0;
     79                                        adjustmentY = editor.container.$.offsetHeight - resizeable.$.offsetHeight;
    5980
     81                                        useProxy && showProxy();
     82
    6083                                        CKEDITOR.document.on( 'mousemove', dragHandler );
    6184                                        CKEDITOR.document.on( 'mouseup', dragEndHandler );
    6285
     
    6790                                        }
    6891                                });
    6992
    70                         editor.on( 'destroy', function() { CKEDITOR.tools.removeFunction( mouseDownFn ); } );
     93                        editor.on( 'destroy', function()
     94                        {
     95                                CKEDITOR.tools.removeFunction( mouseDownFn );
     96                                proxy && proxy.remove();
     97                        } );
    7198
    7299                        editor.on( 'themeSpace', function( event )
    73100                                {
     
    143170 * config.resize_dir = 'vertical';
    144171 */
    145172
    146 CKEDITOR.config.resize_dir = 'both';
    147  No newline at end of file
     173/**
     174 * Whether use a proxy element to present the resizing rectangle
     175 * instead of live content resizing.
     176 * @name CKEDITOR.config.resize_proxy
     177 * @type String
     178 * @default "false" for all browsers except Safari and IE6.
     179 * @since 3.4
     180 * @example
     181 * config.resize_proxy = true;
     182 */
     183
     184CKEDITOR.config.resize_dir = 'both';
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy