X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fimage%2Fdialogs%2Fimage.js;h=e793a898ecc68c5b2e6c2ee07184c1541aeb5fe4;hb=refs%2Ftags%2Fv3.6.1;hp=9c5f4e55d85b2a9fa425e35d7c5eb6e8fe1da4f5;hpb=9afde8772159bd3436f1f5b7862960307710ae5a;p=ckeditor.git diff --git a/_source/plugins/image/dialogs/image.js b/_source/plugins/image/dialogs/image.js index 9c5f4e5..e793a89 100644 --- a/_source/plugins/image/dialogs/image.js +++ b/_source/plugins/image/dialogs/image.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -115,17 +115,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var switchLockRatio = function( dialog, value ) { + if ( !dialog.getContentElement( 'info', 'ratioLock' ) ) + return null; + var oImageOriginal = dialog.originalElement; // Dialog may already closed. (#5505) 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,24 +143,29 @@ 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 ratioButton.addClass( 'cke_btn_unlocked' ); - var lang = dialog._.editor.lang.image, - label = lang[ dialog.lockRatio ? 'unlockRatio' : 'lockRatio' ]; + ratioButton.setAttribute( 'aria-checked', dialog.lockRatio ); - ratioButton.setAttribute( 'title', label ); - ratioButton.getFirst().setText( label ); + // Ratio button hc presentation - WHITE SQUARE / BLACK SQUARE + if ( CKEDITOR.env.hc ) + { + var icon = ratioButton.getChild( 0 ); + icon.setHtml( dialog.lockRatio ? CKEDITOR.env.ie ? '\u25A0': '\u25A3' : CKEDITOR.env.ie ? '\u25A1' : '\u25A2' ); + } return dialog.lockRatio; }; @@ -168,8 +175,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var oImageOriginal = dialog.originalElement; if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' ) { - dialog.setValueOf( 'info', 'txtWidth', oImageOriginal.$.width ); - dialog.setValueOf( 'info', 'txtHeight', oImageOriginal.$.height ); + var widthField = dialog.getContentElement( 'info', 'txtWidth' ), + heightField = dialog.getContentElement( 'info', 'txtHeight' ); + widthField && widthField.setValue( oImageOriginal.$.width ); + heightField && heightField.setValue( oImageOriginal.$.height ); } updatePreview( dialog ); }; @@ -196,7 +205,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 ) @@ -262,9 +271,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license previewImageId = numbering( 'previewImage' ); return { - title : ( dialogType == 'image' ) ? editor.lang.image.title : editor.lang.image.titleButton, + title : editor.lang.image[ dialogType == 'image' ? 'title' : 'titleButton' ], minWidth : 420, - minHeight : CKEDITOR.env.ie && CKEDITOR.env.quirks? 360: 310, + minHeight : 360, onShow : function() { this.imageElement = false; @@ -275,6 +284,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 +345,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 +429,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 ); @@ -449,8 +459,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( dialogType != 'image' ) this.hidePage( 'Link' ); //Hide Link tab. var doc = this._.element.getDocument(); - this.addFocusable( doc.getById( btnResetSizeId ), 5 ); - this.addFocusable( doc.getById( btnLockSizesId ), 5 ); + + if ( this.getContentElement( 'info', 'ratioLock' ) ) + { + this.addFocusable( doc.getById( btnResetSizeId ), 5 ); + this.addFocusable( doc.getById( btnLockSizesId ), 5 ); + } this.commitContent = commitContent; }, @@ -547,8 +561,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { if ( type == IMAGE && ( this.getValue() || this.isChanged() ) ) { - element.data( 'cke-saved-src', decodeURI( this.getValue() ) ); - element.setAttribute( 'src', decodeURI( this.getValue() ) ); + element.data( 'cke-saved-src', this.getValue() ); + element.setAttribute( 'src', this.getValue() ); } else if ( type == CLEANUP ) { @@ -610,6 +624,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license children : [ { + id : 'basic', type : 'vbox', children : [ @@ -635,10 +650,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 +664,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 +700,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 +714,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 ) { @@ -725,6 +741,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license ] }, { + id : 'ratioLock', type : 'html', style : 'margin-top:30px;width:40px;height:40px;', onLoad : function() @@ -734,10 +751,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() { @@ -766,7 +783,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license updatePreview( this ); } } - evt.data.preventDefault(); + evt.data && evt.data.preventDefault(); }, this.getDialog() ); ratioButton.on( 'mouseover', function() { @@ -779,8 +796,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } }, html : '
'+ - '' + editor.lang.image.unlockRatio + '' + + '' + editor.lang.image.lockRatio + '' + '' + editor.lang.image.resetSize + ''+ '
' @@ -1056,6 +1073,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license [ { type : 'html', + id : 'htmlPreview', style : 'width:95%;', html : '
' + CKEDITOR.tools.htmlEncode( editor.lang.common.preview ) +'
'+ ''+ @@ -1102,9 +1120,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { if ( this.getValue() || this.isChanged() ) { - element.data( 'cke-saved-href', decodeURI( this.getValue() ) ); - element.setAttribute( 'href', 'javascript:void(0)/*' + - CKEDITOR.tools.getNextNumber() + '*/' ); + var url = decodeURI( this.getValue() ); + element.data( 'cke-saved-href', url ); + element.setAttribute( 'href', url ); if ( this.getValue() || !editor.config.image_removeLinkByEmptyURL ) this.getDialog().addLink = true;