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