Ticket #2819: 2819.patch

File 2819.patch, 4.8 KB (added by Artur Formella, 15 years ago)
  • image.js

     
    4949                CKEDITOR.document.getById( 'ImagePreviewLoader' ).setStyle( 'display', 'none' );
    5050
    5151                // New image -> new domensions
    52                 if ( this.forceResetSize ){
     52                if ( this.forceResetSize )
    5353                        resetSize( this );
    54                 }
     54
     55                updatePreview( this );
     56                if ( this.firstLoad )
     57                        switchLockRatio( this, 'check' );
     58                this.firstLoad = false;
    5559        }
    5660        var onImgLoadError = function()
    5761        {
     
    146150        {
    147151                if ( !dialog.editObj[ 'imagePreview' ] )
    148152                        return 1;
    149 
    150                 var oImageOriginal = dialog.editObj[ 'imageOriginal' ];
    151                 if ( oImageOriginal && oImageOriginal.getCustomData( 'isReady' ) == 'true' && showPreview )
     153                if ( showPreview )
    152154                {
     155                        var imageOriginal = dialog.editObj[ 'imageOriginal' ];
    153156                        var width = dialog.getValueOf( 'info', 'txtWidth' );
    154157                        var height = dialog.getValueOf( 'info', 'txtHeight' );
    155158
    156                         if ( width == '' && oImageOriginal )
    157                                 width = oImageOriginal.$.width;
    158                         if ( height == '' && oImageOriginal )
    159                                 height = oImageOriginal.$.height;
     159                        if ( !!imageOriginal && dialog.editObj[ 'imageOriginal' ].getCustomData( 'isReady' ) == 'true' )
     160                        {
     161                                if ( width == '' )
     162                                        width = imageOriginal.$.width;
     163                                if ( height == '' )
     164                                        height = imageOriginal.$.height;
     165                        }
    160166
    161167                        dialog.editObj[ 'imagePreview' ].setStyle( 'width', width + 'px');
    162168                        dialog.editObj[ 'imagePreview' ].setStyle( 'height', height + 'px');
     
    228234                var oImageOriginal = dialog.editObj[ 'imageOriginal' ];
    229235                if ( oImageOriginal && oImageOriginal.getCustomData( 'isReady' ) == 'true' )
    230236                {
    231                         if ( value != undefined )
     237                        if ( value == 'check' )
     238                        {
     239                                dialog.imageLockRatio  = false;         // Default: unlock ratio
     240
     241                                var width = dialog.getValueOf( 'info', 'txtWidth' );
     242                                var height = dialog.getValueOf( 'info', 'txtHeight' );
     243                                var originalRatio = oImageOriginal.$.width * 1000 / oImageOriginal.$.height;
     244                                var thisRatio = width * 1000 / height;
     245
     246                                if ( width == 0 && height == 0 )
     247                                        dialog.imageLockRatio = true;
     248                                else if ( !isNaN( originalRatio ) && !isNaN( thisRatio ))
     249                                        if ( Math.round( originalRatio ) == Math.round( thisRatio ) )
     250                                                dialog.imageLockRatio = true;
     251                        }
     252                        else if ( value != undefined )
    232253                                dialog.imageLockRatio = value
    233254                        else
    234255                                dialog.imageLockRatio = !dialog.imageLockRatio;
    235256                }
    236                 else
     257                else if ( value != 'check' )
    237258                        dialog.imageLockRatio = false;
    238259
    239260                var ratioButton = CKEDITOR.document.getById( 'btnLockSizes' );
     
    255276                        dialog.setValueOf( 'info', 'txtHeight', oImageOriginal.$.height );
    256277                        dialog.allowOnChange = true;
    257278                }
    258                 updatePreview( dialog );
    259279        }
    260280        var readSize = function( dialog )
    261281        {
     
    385405                        if ( !this.editObj[ 'image' ] )
    386406                                this.editObj[ 'image' ] = element;
    387407
    388                         updateOriginal( this, true );
    389                         readSize( this );
    390 
    391408                        var imgObject = this.editObj[ 'image' ];
    392409
    393410                        // Fill out all fields.
     
    410427
    411428                        readAttribute.apply( this, [ 'advanced', 'class', 'txtGenClass', imgObject ] );
    412429                        readAttribute.apply( this, [ 'advanced', 'title', 'txtGenTitle', imgObject ] );
     430
     431                        updateOriginal( this, false );
     432                        readSize( this );
    413433                }
    414                 updatePreview( this );
    415434
    416435                return false;
    417436        };
     
    558577                        this.dimensionsInStyle[ 'width' ] = false;
    559578                        this.dimensionsInStyle[ 'height' ] = false;
    560579                        this.forceResetSize = false;
     580                        this.firstLoad = true;
    561581
    562582                        // IE BUG: Selection must be in the editor for getSelection() to work.
    563583                        this.restoreSelection();
     
    606626                                }
    607627                        }
    608628                        updateOriginal( this, false );
    609                         updatePreview( this );
    610629
    611630                        if ( !showPreview )
    612631                        {
     
    642661                                resetButton.on( 'click', function()
    643662                                        {
    644663                                                resetSize( this );
     664                                                updatePreview( this );
    645665                                        }, this );
    646666                                resetButton.on( 'mouseover', function()
    647667                                        {
     
    659679                        {
    660680                                ratioButton.on( 'click', function()
    661681                                        {
    662                                                 var btnLockSizes = CKEDITOR.document.getById( 'btnLockSizes' );
    663682                                                switchLockRatio( this );
    664683                                        }, this );
    665684                                ratioButton.on( 'mouseover', function()
     
    783802                                                                                                                id : 'txtWidth',
    784803                                                                                                                labelLayout : 'horizontal',
    785804                                                                                                                label : editor.lang.image.width,
    786                                                                                                                 onChange : function()
     805                                                                                                                onKeyUp : function()
    787806                                                                                                                {
    788807                                                                                                                        onSizeChange( this );
    789808                                                                                                                },
     
    808827                                                                                                                id : 'txtHeight',
    809828                                                                                                                labelLayout : 'horizontal',
    810829                                                                                                                label : editor.lang.image.height,
    811                                                                                                                 onChange : function()
     830                                                                                                                onKeyUp : function()
    812831                                                                                                                {
    813832                                                                                                                        onSizeChange( this );
    814833                                                                                                                },
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy