/*\r
-Copyright (c) 2003-2009, 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
(function()\r
{\r
- // Load image preview.\r
- var IMAGE = 1,\r
- LINK = 2,\r
- PREVIEW = 4,\r
- CLEANUP = 8,\r
- regexGetSize = /^\s*(\d+)((px)|\%)?\s*$/i,\r
- regexGetSizeOrEmpty = /(^\s*(\d+)((px)|\%)?\s*$)|^$/i,\r
- pxLengthRegex = /^\d+px$/;\r
-\r
- var onSizeChange = function()\r
+ var imageDialog = function( editor, dialogType )\r
{\r
- var value = this.getValue(), // This = input element.\r
- dialog = this.getDialog(),\r
- aMatch = value.match( regexGetSize ); // Check value\r
- if ( aMatch )\r
+ // Load image preview.\r
+ var IMAGE = 1,\r
+ LINK = 2,\r
+ PREVIEW = 4,\r
+ CLEANUP = 8,\r
+ regexGetSize = /^\s*(\d+)((px)|\%)?\s*$/i,\r
+ regexGetSizeOrEmpty = /(^\s*(\d+)((px)|\%)?\s*$)|^$/i,\r
+ pxLengthRegex = /^\d+px$/;\r
+\r
+ var onSizeChange = function()\r
{\r
- if ( aMatch[2] == '%' ) // % is allowed - > unlock ratio.\r
- switchLockRatio( dialog, false ); // Unlock.\r
- value = aMatch[1];\r
- }\r
+ var value = this.getValue(), // This = input element.\r
+ dialog = this.getDialog(),\r
+ aMatch = value.match( regexGetSize ); // Check value\r
+ if ( aMatch )\r
+ {\r
+ if ( aMatch[2] == '%' ) // % is allowed - > unlock ratio.\r
+ switchLockRatio( dialog, false ); // Unlock.\r
+ value = aMatch[1];\r
+ }\r
\r
- // Only if ratio is locked\r
- if ( dialog.lockRatio )\r
- {\r
- var oImageOriginal = dialog.originalElement;\r
- if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' )\r
+ // Only if ratio is locked\r
+ if ( dialog.lockRatio )\r
{\r
- if ( this.id == 'txtHeight' )\r
- {\r
- if ( value && value != '0' )\r
- value = Math.round( oImageOriginal.$.width * ( value / oImageOriginal.$.height ) );\r
- if ( !isNaN( value ) )\r
- dialog.setValueOf( 'info', 'txtWidth', value );\r
- }\r
- else //this.id = txtWidth.\r
+ var oImageOriginal = dialog.originalElement;\r
+ if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' )\r
{\r
- if ( value && value != '0' )\r
- value = Math.round( oImageOriginal.$.height * ( value / oImageOriginal.$.width ) );\r
- if ( !isNaN( value ) )\r
- dialog.setValueOf( 'info', 'txtHeight', value );\r
+ if ( this.id == 'txtHeight' )\r
+ {\r
+ if ( value && value != '0' )\r
+ value = Math.round( oImageOriginal.$.width * ( value / oImageOriginal.$.height ) );\r
+ if ( !isNaN( value ) )\r
+ dialog.setValueOf( 'info', 'txtWidth', value );\r
+ }\r
+ else //this.id = txtWidth.\r
+ {\r
+ if ( value && value != '0' )\r
+ value = Math.round( oImageOriginal.$.height * ( value / oImageOriginal.$.width ) );\r
+ if ( !isNaN( value ) )\r
+ dialog.setValueOf( 'info', 'txtHeight', value );\r
+ }\r
}\r
}\r
- }\r
- updatePreview( dialog );\r
- };\r
-\r
- var updatePreview = function( dialog )\r
- {\r
- //Don't load before onShow.\r
- if ( !dialog.originalElement || !dialog.preview )\r
- return 1;\r
+ updatePreview( dialog );\r
+ };\r
\r
- // Read attributes and update imagePreview;\r
- dialog.commitContent( PREVIEW, dialog.preview );\r
- return 0;\r
- };\r
+ var updatePreview = function( dialog )\r
+ {\r
+ //Don't load before onShow.\r
+ if ( !dialog.originalElement || !dialog.preview )\r
+ return 1;\r
\r
- // Custom commit dialog logic, where we're intended to give inline style\r
- // field (txtdlgGenStyle) higher priority to avoid overwriting styles contribute\r
- // by other fields.\r
- function commitContent()\r
- {\r
- var args = arguments;\r
- var inlineStyleField = this.getContentElement( 'advanced', 'txtdlgGenStyle' );\r
- inlineStyleField && inlineStyleField.commit.apply( inlineStyleField, args );\r
+ // Read attributes and update imagePreview;\r
+ dialog.commitContent( PREVIEW, dialog.preview );\r
+ return 0;\r
+ };\r
\r
- this.foreach( function( widget )\r
+ // Custom commit dialog logic, where we're intended to give inline style\r
+ // field (txtdlgGenStyle) higher priority to avoid overwriting styles contribute\r
+ // by other fields.\r
+ function commitContent()\r
{\r
- if ( widget.commit && widget.id != 'txtdlgGenStyle' )\r
- widget.commit.apply( widget, args );\r
- });\r
- }\r
-\r
- // Avoid recursions.\r
- var incommit;\r
+ var args = arguments;\r
+ var inlineStyleField = this.getContentElement( 'advanced', 'txtdlgGenStyle' );\r
+ inlineStyleField && inlineStyleField.commit.apply( inlineStyleField, args );\r
\r
- // Synchronous field values to other impacted fields is required, e.g. border\r
- // size change should alter inline-style text as well.\r
- function commitInternally( targetFields )\r
- {\r
- if( incommit )\r
- return;\r
+ this.foreach( function( widget )\r
+ {\r
+ if ( widget.commit && widget.id != 'txtdlgGenStyle' )\r
+ widget.commit.apply( widget, args );\r
+ });\r
+ }\r
\r
- incommit = 1;\r
+ // Avoid recursions.\r
+ var incommit;\r
\r
- var dialog = this.getDialog(),\r
- element = dialog.imageElement;\r
- if( element )\r
+ // Synchronous field values to other impacted fields is required, e.g. border\r
+ // size change should alter inline-style text as well.\r
+ function commitInternally( targetFields )\r
{\r
- // Commit this field and broadcast to target fields.\r
- this.commit( IMAGE, element );\r
+ if ( incommit )\r
+ return;\r
\r
- targetFields = [].concat( targetFields );\r
- var length = targetFields.length,\r
- field;\r
- for ( var i = 0; i < length; i++ )\r
+ incommit = 1;\r
+\r
+ var dialog = this.getDialog(),\r
+ element = dialog.imageElement;\r
+ if ( element )\r
{\r
- field = dialog.getContentElement.apply( dialog, targetFields[ i ].split( ':' ) );\r
- // May cause recursion.\r
- field && field.setup( IMAGE, element );\r
+ // Commit this field and broadcast to target fields.\r
+ this.commit( IMAGE, element );\r
+\r
+ targetFields = [].concat( targetFields );\r
+ var length = targetFields.length,\r
+ field;\r
+ for ( var i = 0; i < length; i++ )\r
+ {\r
+ field = dialog.getContentElement.apply( dialog, targetFields[ i ].split( ':' ) );\r
+ // May cause recursion.\r
+ field && field.setup( IMAGE, element );\r
+ }\r
}\r
+\r
+ incommit = 0;\r
}\r
\r
- incommit = 0;\r
- }\r
+ var switchLockRatio = function( dialog, value )\r
+ {\r
+ if ( !dialog.getContentElement( 'info', 'ratioLock' ) )\r
+ return null;\r
\r
- var switchLockRatio = function( dialog, value )\r
- {\r
- var oImageOriginal = dialog.originalElement,\r
- ratioButton = CKEDITOR.document.getById( 'btnLockSizes' );\r
+ var oImageOriginal = dialog.originalElement;\r
\r
- if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' )\r
- {\r
- if ( value == 'check' ) // Check image ratio and original image ratio.\r
+ // Dialog may already closed. (#5505)\r
+ if( !oImageOriginal )\r
+ return null;\r
+\r
+ // Check image ratio and original image ratio, but respecting user's preference.\r
+ if ( value == 'check' )\r
{\r
- var width = dialog.getValueOf( 'info', 'txtWidth' ),\r
- height = dialog.getValueOf( 'info', 'txtHeight' ),\r
- originalRatio = oImageOriginal.$.width * 1000 / oImageOriginal.$.height,\r
- thisRatio = width * 1000 / height;\r
- dialog.lockRatio = false; // Default: unlock ratio\r
-\r
- if ( !width && !height )\r
- dialog.lockRatio = true;\r
- else if ( !isNaN( originalRatio ) && !isNaN( thisRatio ) )\r
+ if ( !dialog.userlockRatio && oImageOriginal.getCustomData( 'isReady' ) == 'true' )\r
{\r
- if ( Math.round( originalRatio ) == Math.round( thisRatio ) )\r
+ var width = dialog.getValueOf( 'info', 'txtWidth' ),\r
+ height = dialog.getValueOf( 'info', 'txtHeight' ),\r
+ originalRatio = oImageOriginal.$.width * 1000 / oImageOriginal.$.height,\r
+ thisRatio = width * 1000 / height;\r
+ dialog.lockRatio = false; // Default: unlock ratio\r
+\r
+ if ( !width && !height )\r
dialog.lockRatio = true;\r
+ else if ( !isNaN( originalRatio ) && !isNaN( thisRatio ) )\r
+ {\r
+ if ( Math.round( originalRatio ) == Math.round( thisRatio ) )\r
+ dialog.lockRatio = true;\r
+ }\r
}\r
}\r
else if ( value != undefined )\r
dialog.lockRatio = value;\r
else\r
+ {\r
+ dialog.userlockRatio = 1;\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
+ }\r
\r
- if ( dialog.lockRatio )\r
- ratioButton.removeClass( 'cke_btn_unlocked' );\r
- else\r
- ratioButton.addClass( 'cke_btn_unlocked' );\r
+ var ratioButton = CKEDITOR.document.getById( btnLockSizesId );\r
+ if ( dialog.lockRatio )\r
+ ratioButton.removeClass( 'cke_btn_unlocked' );\r
+ else\r
+ ratioButton.addClass( 'cke_btn_unlocked' );\r
\r
- return dialog.lockRatio;\r
- };\r
+ var lang = dialog._.editor.lang.image,\r
+ label = lang[ dialog.lockRatio ? 'unlockRatio' : 'lockRatio' ];\r
\r
- var resetSize = function( dialog )\r
- {\r
- var oImageOriginal = dialog.originalElement;\r
- if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' )\r
- {\r
- dialog.setValueOf( 'info', 'txtWidth', oImageOriginal.$.width );\r
- dialog.setValueOf( 'info', 'txtHeight', oImageOriginal.$.height );\r
- }\r
- updatePreview( dialog );\r
- };\r
+ ratioButton.setAttribute( 'title', label );\r
+ ratioButton.getFirst().setText( label );\r
\r
- var setupDimension = function( type, element )\r
- {\r
- if ( type != IMAGE )\r
- return;\r
+ return dialog.lockRatio;\r
+ };\r
\r
- function checkDimension( size, defaultValue )\r
+ var resetSize = function( dialog )\r
{\r
- var aMatch = size.match( regexGetSize );\r
- if ( aMatch )\r
+ var oImageOriginal = dialog.originalElement;\r
+ if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' )\r
{\r
- if ( aMatch[2] == '%' ) // % is allowed.\r
+ var widthField = dialog.getContentElement( 'info', 'txtWidth' ),\r
+ heightField = dialog.getContentElement( 'info', 'txtHeight' );\r
+ widthField && widthField.setValue( oImageOriginal.$.width );\r
+ heightField && heightField.setValue( oImageOriginal.$.height );\r
+ }\r
+ updatePreview( dialog );\r
+ };\r
+\r
+ var setupDimension = function( type, element )\r
+ {\r
+ if ( type != IMAGE )\r
+ return;\r
+\r
+ function checkDimension( size, defaultValue )\r
+ {\r
+ var aMatch = size.match( regexGetSize );\r
+ if ( aMatch )\r
{\r
- aMatch[1] += '%';\r
- switchLockRatio( dialog, false ); // Unlock ratio\r
+ if ( aMatch[2] == '%' ) // % is allowed.\r
+ {\r
+ aMatch[1] += '%';\r
+ switchLockRatio( dialog, false ); // Unlock ratio\r
+ }\r
+ return aMatch[1];\r
}\r
- return aMatch[1];\r
+ return defaultValue;\r
}\r
- return defaultValue;\r
- }\r
\r
- var dialog = this.getDialog(),\r
- value = '',\r
- dimension = (( this.id == 'txtWidth' )? 'width' : 'height' ),\r
- size = element.getAttribute( dimension );\r
+ var dialog = this.getDialog(),\r
+ value = '',\r
+ dimension = this.id == 'txtWidth' ? 'width' : 'height',\r
+ size = element.getAttribute( dimension );\r
\r
- if ( size )\r
- value = checkDimension( size, value );\r
- value = checkDimension( element.getStyle( dimension ), value );\r
+ if ( size )\r
+ value = checkDimension( size, value );\r
+ value = checkDimension( element.getStyle( dimension ), value );\r
\r
- this.setValue( value );\r
- };\r
+ this.setValue( value );\r
+ };\r
+\r
+ var previewPreloader;\r
\r
- var imageDialog = function( editor, dialogType )\r
- {\r
var onImgLoadEvent = function()\r
{\r
// Image is ready.\r
original.removeListener( 'abort', onImgLoadErrorEvent );\r
\r
// Hide loader\r
- CKEDITOR.document.getById( 'ImagePreviewLoader' ).setStyle( 'display', 'none' );\r
+ CKEDITOR.document.getById( imagePreviewLoaderId ).setStyle( 'display', 'none' );\r
\r
// New image -> new domensions\r
if ( !this.dontResetSize )\r
resetSize( this );\r
\r
if ( this.firstLoad )\r
- switchLockRatio( this, 'check' );\r
+ CKEDITOR.tools.setTimeout( function(){ switchLockRatio( this, 'check' ); }, 0, this );\r
+\r
this.firstLoad = false;\r
this.dontResetSize = false;\r
};\r
this.preview.setAttribute( 'src', noimage );\r
\r
// Hide loader\r
- CKEDITOR.document.getById( 'ImagePreviewLoader' ).setStyle( 'display', 'none' );\r
+ CKEDITOR.document.getById( imagePreviewLoaderId ).setStyle( 'display', 'none' );\r
switchLockRatio( this, false ); // Unlock.\r
};\r
+\r
+ var numbering = function( id )\r
+ {\r
+ return CKEDITOR.tools.getNextId() + '_' + id;\r
+ },\r
+ btnLockSizesId = numbering( 'btnLockSizes' ),\r
+ btnResetSizeId = numbering( 'btnResetSize' ),\r
+ imagePreviewLoaderId = numbering( 'ImagePreviewLoader' ),\r
+ imagePreviewBoxId = numbering( 'ImagePreviewBox' ),\r
+ previewLinkId = numbering( 'previewLink' ),\r
+ 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
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
\r
- //Hide loader.\r
- CKEDITOR.document.getById( 'ImagePreviewLoader' ).setStyle( 'display', 'none' );\r
- // Preview\r
- this.preview = CKEDITOR.document.getById( 'previewImage' );\r
-\r
var editor = this.getParentEditor(),\r
sel = this.getParentEditor().getSelection(),\r
element = sel.getSelectedElement(),\r
link = element && element.getAscendant( 'a' );\r
\r
+ //Hide loader.\r
+ CKEDITOR.document.getById( imagePreviewLoaderId ).setStyle( 'display', 'none' );\r
+ // Create the preview before setup the dialog contents.\r
+ previewPreloader = new CKEDITOR.dom.element( 'img', editor.document );\r
+ this.preview = CKEDITOR.document.getById( previewImageId );\r
+\r
// Copy of the image\r
this.originalElement = editor.document.createElement( 'img' );\r
this.originalElement.setAttribute( 'alt', '' );\r
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
\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
this.commitContent( LINK, this.linkElement );\r
\r
// Remove empty style attribute.\r
- if( !this.imageElement.getAttribute( 'style' ) )\r
+ if ( !this.imageElement.getAttribute( 'style' ) )\r
this.imageElement.removeAttribute( 'style' );\r
\r
// Insert a new Image.\r
//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
if ( dialogType != 'image' )\r
this.hidePage( 'Link' ); //Hide Link tab.\r
var doc = this._.element.getDocument();\r
- this.addFocusable( doc.getById( 'btnResetSize' ), 5 );\r
- this.addFocusable( doc.getById( 'btnLockSizes' ), 5 );\r
+\r
+ if ( this.getContentElement( 'info', 'ratioLock' ) )\r
+ {\r
+ this.addFocusable( doc.getById( btnResetSizeId ), 5 );\r
+ this.addFocusable( doc.getById( btnLockSizesId ), 5 );\r
+ }\r
\r
this.commitContent = commitContent;\r
},\r
children :\r
[\r
{\r
- type : 'html',\r
- html : '<span>' + CKEDITOR.tools.htmlEncode( editor.lang.image.url ) + '</span>'\r
- },\r
- {\r
type : 'hbox',\r
widths : [ '280px', '110px' ],\r
align : 'right',\r
{\r
id : 'txtUrl',\r
type : 'text',\r
- label : '',\r
+ label : editor.lang.common.url,\r
+ required: true,\r
onChange : function()\r
{\r
var dialog = this.getDialog(),\r
\r
original.setCustomData( 'isReady', 'false' );\r
// Show loader\r
- var loader = CKEDITOR.document.getById( 'ImagePreviewLoader' );\r
+ var loader = CKEDITOR.document.getById( imagePreviewLoaderId );\r
if ( loader )\r
loader.setStyle( 'display', '' );\r
\r
original.on( 'error', onImgLoadErrorEvent, dialog );\r
original.on( 'abort', onImgLoadErrorEvent, dialog );\r
original.setAttribute( 'src', newUrl );\r
- dialog.preview.setAttribute( 'src', newUrl );\r
\r
+ // Query the preloader to figure out the url impacted by based href.\r
+ previewPreloader.setAttribute( 'src', newUrl );\r
+ dialog.preview.setAttribute( 'src', previewPreloader.$.src );\r
updatePreview( dialog );\r
}\r
// Dont show preview if no URL given.\r
{\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
field.setValue( url ); // And call this.onChange()\r
// Manually set the initial value.(#4191)\r
field.setInitValue();\r
- field.focus();\r
}\r
},\r
commit : function( type, element )\r
{\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
{\r
type : 'button',\r
id : 'browse',\r
+ // v-align with the 'txtUrl' field.\r
+ // TODO: We need something better than a fixed size here.\r
+ style : 'display:inline-block;margin-top:10px;',\r
align : 'center',\r
label : editor.lang.common.browseServer,\r
hidden : true,\r
id : 'txtAlt',\r
type : 'text',\r
label : editor.lang.image.alt,\r
- accessKey : 'A',\r
+ accessKey : 'T',\r
'default' : '',\r
onChange : function()\r
{\r
},\r
{\r
type : 'hbox',\r
- widths : [ '140px', '240px' ],\r
children :\r
[\r
{\r
+ id : 'basic',\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
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
commitInternally.call( this, 'advanced:txtdlgGenStyle' );\r
},\r
- validate: function()\r
+ validate : function()\r
{\r
- var aMatch = this.getValue().match( regexGetSizeOrEmpty );\r
- if ( !aMatch )\r
- alert( editor.lang.common.validateNumberFailed );\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
{\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
element.setStyle( 'width', oImageOriginal.$.width + 'px');\r
}\r
else\r
- element.setStyle( 'width', value + 'px');\r
+ element.setStyle( 'width', CKEDITOR.tools.cssLength( value ) );\r
}\r
else if ( type == CLEANUP )\r
{\r
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
commitInternally.call( this, 'advanced:txtdlgGenStyle' );\r
},\r
- validate: function()\r
+ validate : function()\r
{\r
- var aMatch = this.getValue().match( regexGetSizeOrEmpty );\r
- if ( !aMatch )\r
- alert( editor.lang.common.validateNumberFailed );\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
{\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
element.setStyle( 'height', oImageOriginal.$.height + 'px' );\r
}\r
else\r
- element.setStyle( 'height', value + 'px' );\r
+ element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) );\r
}\r
else if ( type == CLEANUP )\r
{\r
]\r
},\r
{\r
+ id : 'ratioLock',\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
- var resetButton = CKEDITOR.document.getById( 'btnResetSize' ),\r
- ratioButton = CKEDITOR.document.getById( 'btnLockSizes' );\r
+ var resetButton = CKEDITOR.document.getById( btnResetSizeId ),\r
+ ratioButton = CKEDITOR.document.getById( btnLockSizesId );\r
if ( resetButton )\r
{\r
- resetButton.on( 'click', function()\r
+ resetButton.on( 'click', function( evt )\r
{\r
resetSize( this );\r
+ evt.data && evt.data.preventDefault();\r
}, this.getDialog() );\r
resetButton.on( 'mouseover', function()\r
{\r
// Activate (Un)LockRatio button\r
if ( ratioButton )\r
{\r
- ratioButton.on( 'click', function()\r
+ ratioButton.on( 'click', function(evt)\r
{\r
var locked = switchLockRatio( this ),\r
oImageOriginal = this.originalElement,\r
updatePreview( this );\r
}\r
}\r
+ evt.data.preventDefault();\r
}, this.getDialog() );\r
ratioButton.on( 'mouseover', function()\r
{\r
}\r
},\r
html : '<div>'+\r
- '<a href="javascript:void(0)" tabindex="-1" title="' + editor.lang.image.lockRatio +\r
- '" class="cke_btn_locked" id="btnLockSizes"></a>' +\r
+ '<a href="javascript:void(0)" tabindex="-1" title="' + editor.lang.image.unlockRatio +\r
+ '" class="cke_btn_locked" id="' + btnLockSizesId + '" role="button"><span class="cke_label">' + editor.lang.image.unlockRatio + '</span></a>' +\r
'<a href="javascript:void(0)" tabindex="-1" title="' + editor.lang.image.resetSize +\r
- '" class="cke_btn_reset" id="btnResetSize"></a>'+\r
+ '" class="cke_btn_reset" id="' + btnResetSizeId + '" role="button"><span class="cke_label">' + editor.lang.image.resetSize + '</span></a>'+\r
'</div>'\r
}\r
]\r
type : 'text',\r
id : 'txtBorder',\r
width: '60px',\r
- labelLayout : 'horizontal',\r
label : editor.lang.image.border,\r
'default' : '',\r
onKeyUp : function()\r
{\r
commitInternally.call( this, 'advanced:txtdlgGenStyle' );\r
},\r
- validate: function()\r
- {\r
- var func = CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed );\r
- return func.apply( this );\r
- },\r
+ validate : CKEDITOR.dialog.validate.integer( editor.lang.image.validateBorder ),\r
setup : function( type, element )\r
{\r
if ( type == IMAGE )\r
{\r
var value,\r
borderStyle = element.getStyle( 'border-width' );\r
-\r
borderStyle = borderStyle && borderStyle.match( /^(\d+px)(?: \1 \1 \1)?$/ );\r
value = borderStyle && parseInt( borderStyle[ 1 ], 10 );\r
- !value && ( value = element.getAttribute( 'border' ) );\r
-\r
+ isNaN ( parseInt( value, 10 ) ) && ( value = element.getAttribute( 'border' ) );\r
this.setValue( value );\r
}\r
},\r
var value = parseInt( this.getValue(), 10 );\r
if ( type == IMAGE || type == PREVIEW )\r
{\r
- if ( value )\r
+ if ( !isNaN( value ) )\r
{\r
element.setStyle( 'border-width', CKEDITOR.tools.cssLength( value ) );\r
element.setStyle( 'border-style', 'solid' );\r
element.removeStyle( 'border-color' );\r
}\r
\r
- if( !internalCommit && type == IMAGE )\r
+ if ( !internalCommit && type == IMAGE )\r
element.removeAttribute( 'border' );\r
}\r
else if ( type == CLEANUP )\r
type : 'text',\r
id : 'txtHSpace',\r
width: '60px',\r
- labelLayout : 'horizontal',\r
label : editor.lang.image.hSpace,\r
'default' : '',\r
onKeyUp : function()\r
{\r
commitInternally.call( this, 'advanced:txtdlgGenStyle' );\r
},\r
- validate: function()\r
- {\r
- var func = CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed );\r
- return func.apply( this );\r
- },\r
+ validate : CKEDITOR.dialog.validate.integer( editor.lang.image.validateHSpace ),\r
setup : function( type, element )\r
{\r
if ( type == IMAGE )\r
marginRightPx = parseInt( marginRightStyle, 10 );\r
\r
value = ( marginLeftPx == marginRightPx ) && marginLeftPx;\r
- !value && ( value = element.getAttribute( 'hspace' ) );\r
+ isNaN( parseInt( value, 10 ) ) && ( value = element.getAttribute( 'hspace' ) );\r
\r
this.setValue( value );\r
}\r
var value = parseInt( this.getValue(), 10 );\r
if ( type == IMAGE || type == PREVIEW )\r
{\r
- if ( value )\r
+ if ( !isNaN( value ) )\r
{\r
element.setStyle( 'margin-left', CKEDITOR.tools.cssLength( value ) );\r
element.setStyle( 'margin-right', CKEDITOR.tools.cssLength( value ) );\r
element.removeStyle( 'margin-right' );\r
}\r
\r
- if( !internalCommit && type == IMAGE )\r
+ if ( !internalCommit && type == IMAGE )\r
element.removeAttribute( 'hspace' );\r
}\r
else if ( type == CLEANUP )\r
type : 'text',\r
id : 'txtVSpace',\r
width : '60px',\r
- labelLayout : 'horizontal',\r
label : editor.lang.image.vSpace,\r
'default' : '',\r
onKeyUp : function()\r
{\r
commitInternally.call( this, 'advanced:txtdlgGenStyle' );\r
},\r
- validate: function()\r
- {\r
- var func = CKEDITOR.dialog.validate.integer( editor.lang.common.validateNumberFailed );\r
- return func.apply( this );\r
- },\r
+ validate : CKEDITOR.dialog.validate.integer( editor.lang.image.validateVSpace ),\r
setup : function( type, element )\r
{\r
if ( type == IMAGE )\r
marginBottomPx = parseInt( marginBottomStyle, 10 );\r
\r
value = ( marginTopPx == marginBottomPx ) && marginTopPx;\r
- !value && ( value = element.getAttribute( 'vspace' ) );\r
+ isNaN ( parseInt( value, 10 ) ) && ( value = element.getAttribute( 'vspace' ) );\r
this.setValue( value );\r
}\r
},\r
var value = parseInt( this.getValue(), 10 );\r
if ( type == IMAGE || type == PREVIEW )\r
{\r
- if ( value )\r
+ if ( !isNaN( value ) )\r
{\r
element.setStyle( 'margin-top', CKEDITOR.tools.cssLength( value ) );\r
element.setStyle( 'margin-bottom', CKEDITOR.tools.cssLength( value ) );\r
element.removeStyle( 'margin-bottom' );\r
}\r
\r
- if( !internalCommit && type == IMAGE )\r
+ if ( !internalCommit && type == IMAGE )\r
element.removeAttribute( 'vspace' );\r
}\r
else if ( type == CLEANUP )\r
{\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
{\r
if ( value )\r
element.setStyle( 'float', value );\r
- else if ( !value && this.isChanged( ) )\r
+ else\r
element.removeStyle( 'float' );\r
\r
- if( !internalCommit && type == IMAGE )\r
+ if ( !internalCommit && type == IMAGE )\r
{\r
value = ( element.getAttribute( 'align' ) || '' ).toLowerCase();\r
switch( value )\r
[\r
{\r
type : 'html',\r
+ id : 'htmlPreview',\r
style : 'width:95%;',\r
- html : '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.image.preview ) +'<br>'+\r
- '<div id="ImagePreviewLoader" style="display:none"><div class="loading"> </div></div>'+\r
- '<div id="ImagePreviewBox">'+\r
- '<a href="javascript:void(0)" target="_blank" onclick="return false;" id="previewLink">'+\r
- '<img id="previewImage" src="" alt="" /></a>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. '+\r
+ html : '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.common.preview ) +'<br>'+\r
+ '<div id="' + imagePreviewLoaderId + '" class="ImagePreviewLoader" style="display:none"><div class="loading"> </div></div>'+\r
+ '<div id="' + imagePreviewBoxId + '" class="ImagePreviewBox"><table><tr><td>'+\r
+ '<a href="javascript:void(0)" target="_blank" onclick="return false;" id="' + previewLinkId + '">'+\r
+ '<img id="' + previewImageId + '" alt="" /></a>' +\r
+ ( editor.config.image_previewText ||\r
+ 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. '+\r
'Maecenas feugiat consequat diam. Maecenas metus. Vivamus diam purus, cursus a, commodo non, facilisis vitae, '+\r
- 'nulla. Aenean dictum lacinia tortor. Nunc iaculis, nibh non iaculis aliquam, orci felis euismod neque, sed ornare massa mauris sed velit. Nulla pretium mi et risus. Fusce mi pede, tempor id, cursus ac, ullamcorper nec, enim. Sed tortor. Curabitur molestie. Duis velit augue, condimentum at, ultrices a, luctus ut, orci. Donec pellentesque egestas eros. Integer cursus, augue in cursus faucibus, eros pede bibendum sem, in tempus tellus justo quis ligula. Etiam eget tortor. Vestibulum rutrum, est ut placerat elementum, lectus nisl aliquam velit, tempor aliquam eros nunc nonummy metus. In eros metus, gravida a, gravida sed, lobortis id, turpis. Ut ultrices, ipsum at venenatis fringilla, sem nulla lacinia tellus, eget aliquet turpis mauris non enim. Nam turpis. Suspendisse lacinia. Curabitur ac tortor ut ipsum egestas elementum. Nunc imperdiet gravida mauris.' +\r
- '</div>'+'</div>'\r
+ 'nulla. Aenean dictum lacinia tortor. Nunc iaculis, nibh non iaculis aliquam, orci felis euismod neque, sed ornare massa mauris sed velit. Nulla pretium mi et risus. Fusce mi pede, tempor id, cursus ac, ullamcorper nec, enim. Sed tortor. Curabitur molestie. Duis velit augue, condimentum at, ultrices a, luctus ut, orci. Donec pellentesque egestas eros. Integer cursus, augue in cursus faucibus, eros pede bibendum sem, in tempus tellus justo quis ligula. Etiam eget tortor. Vestibulum rutrum, est ut placerat elementum, lectus nisl aliquam velit, tempor aliquam eros nunc nonummy metus. In eros metus, gravida a, gravida sed, lobortis id, turpis. Ut ultrices, ipsum at venenatis fringilla, sem nulla lacinia tellus, eget aliquet turpis mauris non enim. Nam turpis. Suspendisse lacinia. Curabitur ac tortor ut ipsum egestas elementum. Nunc imperdiet gravida mauris.' ) +\r
+ '</td></tr></table></div></div>'\r
}\r
]\r
}\r
{\r
id : 'txtUrl',\r
type : 'text',\r
- label : editor.lang.image.url,\r
+ label : editor.lang.common.url,\r
style : 'width: 100%',\r
'default' : '',\r
setup : function( type, element )\r
{\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
{\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
{\r
type : 'button',\r
id : 'browse',\r
- filebrowser : 'Link:txtUrl',\r
+ filebrowser :\r
+ {\r
+ action : 'Browse',\r
+ target: 'Link:txtUrl',\r
+ url: editor.config.filebrowserImageBrowseLinkUrl\r
+ },\r
style : 'float:right',\r
hidden : true,\r
label : editor.lang.common.browseServer\r
{\r
id : 'cmbTarget',\r
type : 'select',\r
- label : editor.lang.link.target,\r
+ label : editor.lang.common.target,\r
'default' : '',\r
items :\r
[\r
- [ editor.lang.link.targetNotSet , ''],\r
- [ editor.lang.link.targetNew , '_blank'],\r
- [ editor.lang.link.targetTop , '_top'],\r
- [ editor.lang.link.targetSelf , '_self'],\r
- [ editor.lang.link.targetParent , '_parent']\r
+ [ editor.lang.common.notSet , ''],\r
+ [ editor.lang.common.targetNew , '_blank'],\r
+ [ editor.lang.common.targetTop , '_top'],\r
+ [ editor.lang.common.targetSelf , '_self'],\r
+ [ editor.lang.common.targetParent , '_parent']\r
],\r
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