X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fimage%2Fdialogs%2Fimage.js;h=c604ebdfa3e6ba475c1a6d5cacfbfe9bd169011e;hp=b194a5d5fd65857bc815509eebaf352276520010;hb=4e90e78dc97789709ee7404359a5517540c27553;hpb=8f6c203fdaa543c3bca40baea6ae4ddcdf1a77f5 diff --git a/_source/plugins/image/dialogs/image.js b/_source/plugins/image/dialogs/image.js index b194a5d..c604ebd 100644 --- a/_source/plugins/image/dialogs/image.js +++ b/_source/plugins/image/dialogs/image.js @@ -121,11 +121,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if( !oImageOriginal ) return null; - var ratioButton = CKEDITOR.document.getById( btnLockSizesId ); - - if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' ) + // Check image ratio and original image ratio, but respecting user's preference. + if ( value == 'check' ) { - if ( value == 'check' ) // Check image ratio and original image ratio. + if ( !dialog.userlockRatio && oImageOriginal.getCustomData( 'isReady' ) == 'true' ) { var width = dialog.getValueOf( 'info', 'txtWidth' ), height = dialog.getValueOf( 'info', 'txtHeight' ), @@ -141,14 +140,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license dialog.lockRatio = true; } } - else if ( value != undefined ) - dialog.lockRatio = value; - else - dialog.lockRatio = !dialog.lockRatio; } - else if ( value != 'check' ) // I can't lock ratio if ratio is unknown. - dialog.lockRatio = false; + else if ( value != undefined ) + dialog.lockRatio = value; + else + { + dialog.userlockRatio = 1; + dialog.lockRatio = !dialog.lockRatio; + } + var ratioButton = CKEDITOR.document.getById( btnLockSizesId ); if ( dialog.lockRatio ) ratioButton.removeClass( 'cke_btn_unlocked' ); else @@ -196,7 +197,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var dialog = this.getDialog(), value = '', - dimension = (( this.id == 'txtWidth' )? 'width' : 'height' ), + dimension = this.id == 'txtWidth' ? 'width' : 'height', size = element.getAttribute( dimension ); if ( size ) @@ -275,6 +276,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license this.linkEditMode = false; this.lockRatio = true; + this.userlockRatio = 0; this.dontResetSize = false; this.firstLoad = true; this.addLink = false; @@ -335,13 +337,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Fill out all fields. this.setupContent( IMAGE, this.imageElement ); - - // Refresh LockRatio button - switchLockRatio ( this, true ); } else this.imageElement = editor.document.createElement( 'img' ); + // Refresh LockRatio button + switchLockRatio ( this, true ); + // Dont show preview if no URL given. if ( !CKEDITOR.tools.trim( this.getValueOf( 'info', 'txtUrl' ) ) ) { @@ -419,11 +421,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license //Insert a new Link. if ( !this.linkEditMode ) { - editor.insertElement(this.linkElement); - this.linkElement.append(this.imageElement, false); + editor.insertElement( this.linkElement ); + this.linkElement.append( this.imageElement, false ); } else //Link already exists, image not. - editor.insertElement(this.imageElement ); + editor.insertElement( this.imageElement ); } else editor.insertElement( this.imageElement ); @@ -635,10 +637,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }, validate : function() { - var aMatch = this.getValue().match( regexGetSizeOrEmpty ); - if ( !aMatch ) + var aMatch = this.getValue().match( regexGetSizeOrEmpty ), + isValid = !!( aMatch && parseInt( aMatch[1], 10 ) !== 0 ); + if ( !isValid ) alert( editor.lang.common.invalidWidth ); - return !!aMatch; + return isValid; }, setup : setupDimension, commit : function( type, element, internalCommit ) @@ -648,7 +651,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { if ( value ) element.setStyle( 'width', CKEDITOR.tools.cssLength( value ) ); - else if ( !value && this.isChanged( ) ) + else element.removeStyle( 'width' ); !internalCommit && element.removeAttribute( 'width' ); @@ -684,10 +687,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }, validate : function() { - var aMatch = this.getValue().match( regexGetSizeOrEmpty ); - if ( !aMatch ) + var aMatch = this.getValue().match( regexGetSizeOrEmpty ), + isValid = !!( aMatch && parseInt( aMatch[1], 10 ) !== 0 ); + if ( !isValid ) alert( editor.lang.common.invalidHeight ); - return !!aMatch; + return isValid; }, setup : setupDimension, commit : function( type, element, internalCommit ) @@ -697,11 +701,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { if ( value ) element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) ); - else if ( !value && this.isChanged( ) ) + else element.removeStyle( 'height' ); - if ( !internalCommit && type == IMAGE ) - element.removeAttribute( 'height' ); + !internalCommit && element.removeAttribute( 'height' ); } else if ( type == PREVIEW ) { @@ -734,10 +737,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license ratioButton = CKEDITOR.document.getById( btnLockSizesId ); if ( resetButton ) { - resetButton.on( 'click', function(evt) + resetButton.on( 'click', function( evt ) { resetSize( this ); - evt.data.preventDefault(); + evt.data && evt.data.preventDefault(); }, this.getDialog() ); resetButton.on( 'mouseover', function() {