JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5.3
[ckeditor.git] / _source / plugins / image / dialogs / image.js
index 72a4c45..c604ebd 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -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
@@ -262,9 +263,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        previewImageId = numbering( 'previewImage' );\r
 \r
                return {\r
-                       title : ( dialogType == 'image' ) ? editor.lang.image.title : editor.lang.image.titleButton,\r
+                       title : editor.lang.image[ dialogType == 'image' ? 'title' : 'titleButton' ],\r
                        minWidth : 420,\r
-                       minHeight : 310,\r
+                       minHeight : 360,\r
                        onShow : function()\r
                        {\r
                                this.imageElement = false;\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
@@ -319,7 +321,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                this.setupContent( LINK, link );\r
                                }\r
 \r
-                               if ( element && element.getName() == 'img' && !element.getAttribute( '_cke_realelement' )\r
+                               if ( element && element.getName() == 'img' && !element.data( 'cke-realelement' )\r
                                        || element && element.getName() == 'input' && element.getAttribute( 'type' ) == 'image' )\r
                                {\r
                                        this.imageEditMode = element.getName();\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
@@ -533,7 +535,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                        {\r
                                                                                                if ( type == IMAGE )\r
                                                                                                {\r
-                                                                                                       var url = element.getAttribute( '_cke_saved_src' ) || element.getAttribute( 'src' );\r
+                                                                                                       var url = element.data( 'cke-saved-src' ) || element.getAttribute( 'src' );\r
                                                                                                        var field = this;\r
 \r
                                                                                                        this.getDialog().dontResetSize = true;\r
@@ -547,8 +549,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                        {\r
                                                                                                if ( type == IMAGE && ( this.getValue() || this.isChanged() ) )\r
                                                                                                {\r
-                                                                                                       element.setAttribute( '_cke_saved_src', decodeURI( this.getValue() ) );\r
-                                                                                                       element.setAttribute( 'src', decodeURI( this.getValue() ) );\r
+                                                                                                       element.data( 'cke-saved-src', this.getValue() );\r
+                                                                                                       element.setAttribute( 'src', this.getValue() );\r
                                                                                                }\r
                                                                                                else if ( type == CLEANUP )\r
                                                                                                {\r
@@ -607,17 +609,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                },\r
                                                {\r
                                                        type : 'hbox',\r
-                                                       widths : [ '140px', '240px' ],\r
                                                        children :\r
                                                        [\r
                                                                {\r
                                                                        type : 'vbox',\r
-                                                                       padding : 10,\r
                                                                        children :\r
                                                                        [\r
                                                                                {\r
                                                                                        type : 'hbox',\r
-                                                                                       widths : [ '70%', '30%' ],\r
+                                                                                       widths : [ '50%', '50%' ],\r
                                                                                        children :\r
                                                                                        [\r
                                                                                                {\r
@@ -629,8 +629,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                                                        type : 'text',\r
                                                                                                                        width: '40px',\r
                                                                                                                        id : 'txtWidth',\r
-                                                                                                                       labelLayout : 'horizontal',\r
-                                                                                                                       label : editor.lang.image.width,\r
+                                                                                                                       label : editor.lang.common.width,\r
                                                                                                                        onKeyUp : onSizeChange,\r
                                                                                                                        onChange : function()\r
                                                                                                                        {\r
@@ -638,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
-                                                                                                                                       alert( editor.lang.image.validateWidth );\r
-                                                                                                                               return !!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 isValid;\r
                                                                                                                        },\r
                                                                                                                        setup : setupDimension,\r
                                                                                                                        commit : function( type, element, internalCommit )\r
@@ -651,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
@@ -679,8 +679,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                                                        type : 'text',\r
                                                                                                                        id : 'txtHeight',\r
                                                                                                                        width: '40px',\r
-                                                                                                                       labelLayout : 'horizontal',\r
-                                                                                                                       label : editor.lang.image.height,\r
+                                                                                                                       label : editor.lang.common.height,\r
                                                                                                                        onKeyUp : onSizeChange,\r
                                                                                                                        onChange : function()\r
                                                                                                                        {\r
@@ -688,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
-                                                                                                                                       alert( editor.lang.image.validateHeight );\r
-                                                                                                                               return !!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 isValid;\r
                                                                                                                        },\r
                                                                                                                        setup : setupDimension,\r
                                                                                                                        commit : function( type, element, internalCommit )\r
@@ -701,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
@@ -730,7 +729,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                                },\r
                                                                                                {\r
                                                                                                        type : 'html',\r
-                                                                                                       style : 'margin-top:10px;width:40px;height:40px;',\r
+                                                                                                       style : 'margin-top:30px;width:40px;height:40px;',\r
                                                                                                        onLoad : function()\r
                                                                                                        {\r
                                                                                                                // Activate Reset button\r
@@ -738,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
@@ -800,7 +799,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                                        type : 'text',\r
                                                                                                        id : 'txtBorder',\r
                                                                                                        width: '60px',\r
-                                                                                                       labelLayout : 'horizontal',\r
                                                                                                        label : editor.lang.image.border,\r
                                                                                                        'default' : '',\r
                                                                                                        onKeyUp : function()\r
@@ -857,7 +855,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                                        type : 'text',\r
                                                                                                        id : 'txtHSpace',\r
                                                                                                        width: '60px',\r
-                                                                                                       labelLayout : 'horizontal',\r
                                                                                                        label : editor.lang.image.hSpace,\r
                                                                                                        'default' : '',\r
                                                                                                        onKeyUp : function()\r
@@ -921,7 +918,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                                        type : 'text',\r
                                                                                                        id : 'txtVSpace',\r
                                                                                                        width : '60px',\r
-                                                                                                       labelLayout : 'horizontal',\r
                                                                                                        label : editor.lang.image.vSpace,\r
                                                                                                        'default' : '',\r
                                                                                                        onKeyUp : function()\r
@@ -983,16 +979,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                                {\r
                                                                                                        id : 'cmbAlign',\r
                                                                                                        type : 'select',\r
-                                                                                                       labelLayout : 'horizontal',\r
                                                                                                        widths : [ '35%','65%' ],\r
                                                                                                        style : 'width:90px',\r
-                                                                                                       label : editor.lang.image.align,\r
+                                                                                                       label : editor.lang.common.align,\r
                                                                                                        'default' : '',\r
                                                                                                        items :\r
                                                                                                        [\r
                                                                                                                [ editor.lang.common.notSet , ''],\r
-                                                                                                               [ editor.lang.image.alignLeft , 'left'],\r
-                                                                                                               [ editor.lang.image.alignRight , 'right']\r
+                                                                                                               [ editor.lang.common.alignLeft , 'left'],\r
+                                                                                                               [ editor.lang.common.alignRight , 'right']\r
                                                                                                                // Backward compatible with v2 on setup when specified as attribute value,\r
                                                                                                                // while these values are no more available as select options.\r
                                                                                                                //      [ editor.lang.image.alignAbsBottom , 'absBottom'],\r
@@ -1098,7 +1093,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        {\r
                                                                if ( type == LINK )\r
                                                                {\r
-                                                                       var href = element.getAttribute( '_cke_saved_href' );\r
+                                                                       var href = element.data( 'cke-saved-href' );\r
                                                                        if ( !href )\r
                                                                                href = element.getAttribute( 'href' );\r
                                                                        this.setValue( href );\r
@@ -1110,9 +1105,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                {\r
                                                                        if ( this.getValue() || this.isChanged() )\r
                                                                        {\r
-                                                                               element.setAttribute( '_cke_saved_href', decodeURI( this.getValue() ) );\r
-                                                                               element.setAttribute( 'href', 'javascript:void(0)/*' +\r
-                                                                                       CKEDITOR.tools.getNextNumber() + '*/' );\r
+                                                                               var url = decodeURI( this.getValue() );\r
+                                                                               element.data( 'cke-saved-href', url );\r
+                                                                               element.setAttribute( 'href', url );\r
 \r
                                                                                if ( this.getValue() || !editor.config.image_removeLinkByEmptyURL )\r
                                                                                        this.getDialog().addLink = true;\r
@@ -1127,7 +1122,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        {\r
                                                                action : 'Browse',\r
                                                                target: 'Link:txtUrl',\r
-                                                               url: editor.config.filebrowserImageBrowseLinkUrl || editor.config.filebrowserBrowseUrl\r
+                                                               url: editor.config.filebrowserImageBrowseLinkUrl\r
                                                        },\r
                                                        style : 'float:right',\r
                                                        hidden : true,\r
@@ -1149,7 +1144,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        setup : function( type, element )\r
                                                        {\r
                                                                if ( type == LINK )\r
-                                                                       this.setValue( element.getAttribute( 'target' ) );\r
+                                                                       this.setValue( element.getAttribute( 'target' ) || '' );\r
                                                        },\r
                                                        commit : function( type, element )\r
                                                        {\r