修改 fckeditor\editor\dialog\fck_image 路径下的 fck_image.js 文件
1、找到UpdateOriginal方法
function UpdateOriginal(resetSize ){ if ( !eImgPreview ) return ; if ( GetE('txtUrl').value.length == 0 ){ oImageOriginal = null ; return ; } oImageOriginal = document.createElement( 'IMG' ) ;// new Image() ;
//以上为添加代码 oImageOriginal.onload = function(){ if(GetE('txtWidth').value.length==0){ GetE('txtWidth').value=oImageOriginal.width; } if(GetE('txtWidth').value>800){ GetE('txtWidth').value =800; var imgHeight=800 * oImageOriginal.height / oImageOriginal.width; GetE('txtHeight').value =imgHeight; } }
//以上为添加代码
if ( resetSize ){ oImageOriginal.onload = function(){ this.onload = null ; ResetSizes(); } } oImageOriginal.src = eImgPreview.src ; }
2、找到OnSizeChanged方法
function OnSizeChanged( dimension, value )
{
// Verifies if the aspect ration has to be maintained
if ( oImageOriginal && bLockRatio )
{
var e = dimension == 'Width' ? GetE('txtHeight') : GetE('txtWidth') ;
if ( value.length == 0 || isNaN( value ) )
{
e.value = '' ;
return ;
}
if ( dimension == 'Width' )
value = value == 0 ? 0 : Math.round( oImageOriginal.height * ( value / oImageOriginal.width ) ) ;
else
value = value == 0 ? 0 : Math.round( oImageOriginal.width * ( value / oImageOriginal.height ) ) ;
if ( !isNaN( value ) )
e.value = value ;
if(GetE('txtWidth').value>800){
var imgWidth=800;
var imgHeight=800 * oImageOriginal.height / oImageOriginal.width;
GetE('txtWidth').value =imgWidth;
GetE('txtHeight').value =imgHeight;
}
}
UpdatePreview() ;
}
3、找到ResetSizes方法
function ResetSizes() { if ( ! oImageOriginal ) return ; if ( oEditor.FCKBrowserInfo.IsGecko && !oImageOriginal.complete ) { setTimeout( ResetSizes, 50 ) ; return ; } //GetE('txtWidth').value = oImageOriginal.width ; //GetE('txtHeight').value = oImageOriginal.height ; if ( oImageOriginal.width<800) { GetE('txtWidth').value=oImageOriginal.width ; GetE('txtHeight').value=oImageOriginal.height ; } else { GetE('txtWidth').value=800; GetE('txtHeight').value=800*oImageOriginal.height/oImageOriginal.width ; } UpdatePreview() ; }
以上红色的为添加的代码,蓝色的为删除的代码,修改后涮洗浏览器,就可以看到效果。