Ticket #6462: 6462_4.patch
File 6462_4.patch, 21.0 KB (added by , 13 years ago) |
---|
-
_source/plugins/iframe/dialogs/iframe.js
13 13 frameborder : { 'true' : '1', 'false' : '0' } 14 14 }; 15 15 16 var defaultToPixel = CKEDITOR.tools.cssLength; 17 16 18 function loadValue( iframeNode ) 17 19 { 18 20 var isCheckbox = this instanceof CKEDITOR.ui.dialog.checkbox; … … 56 58 styles && styles.on( 'change', function() 57 59 { 58 60 // Synchronize width value. 59 var width = parseInt( this.getStyle( 'width', '' ) || '', 10),61 var width = this.getStyle( 'width', '' ), 60 62 txtWidth = dialog.getContentElement( 'info', 'width' ); 61 63 62 64 txtWidth && txtWidth.setValue( width, true ); 63 65 64 66 // Synchronize height value. 65 var height = parseInt( this.getStyle( 'height', '' ) || '', 10),67 var height = this.getStyle( 'height', '' ), 66 68 txtHeight = dialog.getContentElement( 'info', 'height' ); 67 69 68 70 txtHeight && txtHeight.setValue( height, true ); … … 150 152 style : 'width:100%', 151 153 labelLayout : 'vertical', 152 154 label : commonLang.width, 153 validate : CKEDITOR.dialog.validate.integer( commonLang.invalidWidth ), 155 validate : CKEDITOR.dialog.validate.cssLength( editor.lang.common.invalidCssLength ), 156 getValue : defaultToPixel, 154 157 setup : function( iframeNode, fakeImage ) 155 158 { 156 159 loadValue.apply( this, arguments ); 157 if ( fakeImage ) 158 { 159 var fakeImageWidth = parseInt( fakeImage.$.style.width, 10 ); 160 if ( !isNaN( fakeImageWidth ) ) 161 this.setValue( fakeImageWidth ); 162 } 160 fakeImage && this.setValue( fakeImage.getStyle( 'width' ) ); 163 161 }, 164 162 commit : function( iframeNode, extraStyles ) 165 163 { 166 164 commitValue.apply( this, arguments ); 167 if ( this.getValue() )168 extraStyles.width = this.getValue() + 'px';165 var val = this.getValue(); 166 val && ( extraStyles.width = val ); 169 167 }, 170 168 onChange : function() 171 169 { 172 170 var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' ), 173 171 value = this.getValue(); 174 styles && styles.updateStyle( 'width', value && ( value + 'px' ));172 styles && styles.updateStyle( 'width', value ); 175 173 } 176 174 }, 177 175 { … … 180 178 style : 'width:100%', 181 179 labelLayout : 'vertical', 182 180 label : commonLang.height, 183 validate : CKEDITOR.dialog.validate.integer( commonLang.invalidHeight ), 181 validate : CKEDITOR.dialog.validate.cssLength( editor.lang.common.invalidCssLength ), 182 getValue : defaultToPixel, 184 183 setup : function( iframeNode, fakeImage ) 185 184 { 186 185 loadValue.apply( this, arguments ); 187 if ( fakeImage ) 188 { 189 var fakeImageHeight = parseInt( fakeImage.$.style.height, 10 ); 190 if ( !isNaN( fakeImageHeight ) ) 191 this.setValue( fakeImageHeight ); 192 } 186 fakeImage && this.setValue( fakeImage.getStyle( 'height' ) ); 193 187 }, 194 188 commit : function( iframeNode, extraStyles ) 195 189 { 196 190 commitValue.apply( this, arguments ); 197 if ( this.getValue() )198 extraStyles.height = this.getValue() + 'px';191 var val = this.getValue(); 192 val && ( extraStyles.height = val ); 199 193 }, 200 194 onChange : function() 201 195 { 202 196 var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' ), 203 197 value = this.getValue(); 204 styles && styles.updateStyle( 'height', value && ( value + 'px' ));198 styles && styles.updateStyle( 'height', value ); 205 199 } 206 200 }, 207 201 { -
_source/plugins/dialogadvtab/plugin.js
136 136 137 137 getStyle : function( name, defaultValue ) 138 138 { 139 var match = this.getValue().match( new RegExp( name + '\\s*:\ s*([^;]*)', 'i') );139 var match = this.getValue().match( new RegExp( name + '\\s*:\\s*([^;]*)', 'i') ); 140 140 return match ? match[ 1 ] : defaultValue; 141 141 }, 142 142 -
_source/plugins/table/dialogs/table.js
1 /* 1 /* 2 2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. 3 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 4 */ 5 5 6 6 (function() 7 7 { 8 var widthPattern = /^(\d+(?:\.\d+)?)(px|%)$/, 9 heightPattern = /^(\d+(?:\.\d+)?)px$/; 8 var defaultToPixel = CKEDITOR.tools.cssLength; 10 9 11 10 var commitValue = function( data ) 12 11 { … … 42 41 { 43 42 // Synchronize width value. 44 43 var width = this.getStyle( 'width', '' ), 45 txtWidth = dialog.getContentElement( 'info', 'txtWidth' ), 46 cmbWidthType = dialog.getContentElement( 'info', 'cmbWidthType' ), 47 isPx = 1; 44 txtWidth = dialog.getContentElement( 'info', 'txtWidth' ); 48 45 49 if ( width )50 {51 isPx = ( width.length < 3 || width.substr( width.length - 1 ) != '%' );52 width = parseInt( width, 10 );53 }54 55 46 txtWidth && txtWidth.setValue( width, true ); 56 cmbWidthType && cmbWidthType.setValue( isPx ? 'pixels' : 'percents', true );57 47 58 48 // Synchronize height value. 59 49 var height = this.getStyle( 'height', '' ), 60 50 txtHeight = dialog.getContentElement( 'info', 'txtHeight' ); 61 51 62 height && ( height = parseInt( height, 10 ) );63 52 txtHeight && txtHeight.setValue( height, true ); 64 53 }); 65 54 } … … 224 213 } 225 214 226 215 // Set the width and height. 227 var styles = []; 228 if ( info.txtHeight ) 229 table.setStyle( 'height', CKEDITOR.tools.cssLength( info.txtHeight ) ); 230 else 231 table.removeStyle( 'height' ); 216 info.txtHeight ? table.setStyle( 'height', info.txtHeight ) : table.removeStyle( 'height' ); 217 info.txtWidth ? table.setStyle( 'width', info.txtWidth ) : table.removeStyle( 'width' ); 232 218 233 if ( info.txtWidth )234 {235 var type = info.cmbWidthType || 'pixels';236 table.setStyle( 'width', info.txtWidth + ( type == 'pixels' ? 'px' : '%' ) );237 }238 else239 table.removeStyle( 'width' );240 241 219 if ( !table.getAttribute( 'style' ) ) 242 220 table.removeAttribute( 'style' ); 243 221 } … … 423 401 style : 'width:5em', 424 402 label : editor.lang.common.width, 425 403 'default' : 500, 426 validate : CKEDITOR.dialog.validate['number']( editor.lang.table.invalidWidth ), 427 428 // Extra labelling of width unit type. 429 onLoad : function() 430 { 431 var widthType = this.getDialog().getContentElement( 'info', 'cmbWidthType' ), 432 labelElement = widthType.getElement(), 433 inputElement = this.getInputElement(), 434 ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' ); 435 436 inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) ); 437 }, 438 404 getValue : defaultToPixel, 405 validate : CKEDITOR.dialog.validate.cssLength( editor.lang.common.invalidCssLength ), 439 406 onChange : function() 440 407 { 441 408 var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' ); 442 443 if ( styles ) 444 { 445 var value = this.getValue(); 446 447 if ( value ) 448 value += this.getDialog().getContentElement( 'info', 'cmbWidthType' ).getValue() == 'percents' ? '%' : 'px'; 449 450 styles.updateStyle( 'width', value ); 451 } 409 styles && styles.updateStyle( 'width', this.getValue() ); 452 410 }, 453 454 411 setup : function( selectedTable ) 455 412 { 456 var widthMatch = widthPattern.exec( selectedTable.$.style.width ); 457 if ( widthMatch ) 458 this.setValue( widthMatch[1] ); 459 else 460 this.setValue( '' ); 413 var val = selectedTable.getStyle( 'width' ); 414 val && this.setValue( val ); 461 415 }, 462 416 commit : commitValue 463 },464 {465 id : 'cmbWidthType',466 type : 'select',467 label : editor.lang.table.widthUnit,468 labelStyle: 'visibility:hidden',469 'default' : 'pixels',470 items :471 [472 [ editor.lang.table.widthPx , 'pixels'],473 [ editor.lang.table.widthPc , 'percents']474 ],475 setup : function( selectedTable )476 {477 var widthMatch = widthPattern.exec( selectedTable.$.style.width );478 if ( widthMatch )479 this.setValue( widthMatch[2] == 'px' ? 'pixels' : 'percents' );480 },481 onChange : function()482 {483 this.getDialog().getContentElement( 'info', 'txtWidth' ).onChange();484 },485 commit : commitValue486 417 } 487 418 ] 488 419 }, … … 497 428 style : 'width:5em', 498 429 label : editor.lang.common.height, 499 430 'default' : '', 500 validate : CKEDITOR.dialog.validate['number']( editor.lang.table.invalidHeight ), 501 502 // Extra labelling of height unit type. 503 onLoad : function() 504 { 505 var heightType = this.getDialog().getContentElement( 'info', 'htmlHeightType' ), 506 labelElement = heightType.getElement(), 507 inputElement = this.getInputElement(), 508 ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' ); 509 510 inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) ); 511 }, 512 431 getValue : defaultToPixel, 432 validate : CKEDITOR.dialog.validate.cssLength( editor.lang.common.invalidCssLength ), 513 433 onChange : function() 514 434 { 515 435 var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' ); 516 517 if ( styles ) 518 { 519 var value = this.getValue(); 520 styles.updateStyle( 'height', value && ( value + 'px' ) ); 521 } 436 styles && styles.updateStyle( 'height', this.getValue() ); 522 437 }, 523 438 524 439 setup : function( selectedTable ) 525 440 { 526 var heightMatch = heightPattern.exec( selectedTable.$.style.height ); 527 if ( heightMatch ) 528 this.setValue( heightMatch[1] ); 441 var val = selectedTable.getStyle( 'width' ); 442 val && this.setValue( val ); 529 443 }, 530 444 commit : commitValue 531 },532 {533 id : 'htmlHeightType',534 type : 'html',535 html : '<div><br />' + editor.lang.table.widthPx + '</div>'536 445 } 537 446 ] 538 447 }, … … 546 455 style : 'width:3em', 547 456 label : editor.lang.table.cellSpace, 548 457 'default' : 1, 549 validate : CKEDITOR.dialog.validate ['number']( editor.lang.table.invalidCellSpacing),458 validate : CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength ), 550 459 setup : function( selectedTable ) 551 460 { 552 461 this.setValue( selectedTable.getAttribute( 'cellSpacing' ) || '' ); … … 565 474 style : 'width:3em', 566 475 label : editor.lang.table.cellPad, 567 476 'default' : 1, 568 validate : CKEDITOR.dialog.validate ['number']( editor.lang.table.invalidCellPadding),477 validate : CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength ), 569 478 setup : function( selectedTable ) 570 479 { 571 480 this.setValue( selectedTable.getAttribute( 'cellPadding' ) || '' ); -
_source/plugins/dialog/plugin.js
2320 2320 if ( typeof( elementDefinition.isChanged ) == 'function' ) 2321 2321 this.isChanged = elementDefinition.isChanged; 2322 2322 2323 // Overload 'get(set)Value' on definition. 2324 if ( typeof( elementDefinition.setValue ) == 'function' ) 2325 { 2326 this.setValue = CKEDITOR.tools.override( this.setValue, function( org ) 2327 { 2328 return function( val ){ org.call( this, elementDefinition.setValue.call( this, val ) ); }; 2329 } ); 2330 } 2331 2332 if ( typeof( elementDefinition.getValue ) == 'function' ) 2333 { 2334 this.getValue = CKEDITOR.tools.override( this.getValue, function( org ) 2335 { 2336 return function(){ return elementDefinition.getValue.call( this, org.call( this ) ); }; 2337 } ); 2338 } 2339 2323 2340 // Add events. 2324 2341 CKEDITOR.event.implementOn( this ); 2325 2342 … … 2911 2928 { 2912 2929 var notEmptyRegex = /^([a]|[^a])+$/, 2913 2930 integerRegex = /^\d*$/, 2914 numberRegex = /^\d*(?:\.\d+)?$/; 2931 numberRegex = /^\d*(?:\.\d+)?$/, 2932 htmlLengthRegex = /^([+-]?((\d*(\.\d+))|(\d*))(px|\%)?)?$/, 2933 cssLengthRegex = /^([+-]?((\d*(\.\d+))|(\d*))(px|em|ex|in|cm|mm|pt|pc|\%)?)?$/i; 2915 2934 2916 2935 CKEDITOR.VALIDATE_OR = 1; 2917 2936 CKEDITOR.VALIDATE_AND = 2; … … 2920 2939 { 2921 2940 functions : function() 2922 2941 { 2942 var args = arguments; 2923 2943 return function() 2924 2944 { 2925 2945 /** … … 2928 2948 * combine validate functions together to make more sophisticated 2929 2949 * validators. 2930 2950 */ 2931 var value = this && this.getValue ? this.getValue() : arg uments[0];2951 var value = this && this.getValue ? this.getValue() : args[ 0 ]; 2932 2952 2933 2953 var msg = undefined, 2934 2954 relation = CKEDITOR.VALIDATE_AND, 2935 2955 functions = [], i; 2936 2956 2937 for ( i = 0 ; i < arg uments.length ; i++ )2957 for ( i = 0 ; i < args.length ; i++ ) 2938 2958 { 2939 if ( typeof( arg uments[i] ) == 'function' )2940 functions.push( arg uments[i] );2959 if ( typeof( args[i] ) == 'function' ) 2960 functions.push( args[i] ); 2941 2961 else 2942 2962 break; 2943 2963 } 2944 2964 2945 if ( i < arg uments.length && typeof( arguments[i] ) == 'string' )2965 if ( i < args.length && typeof( args[i] ) == 'string' ) 2946 2966 { 2947 msg = arg uments[i];2967 msg = args[i]; 2948 2968 i++; 2949 2969 } 2950 2970 2951 if ( i < arg uments.length && typeof( arguments[i]) == 'number' )2952 relation = arg uments[i];2971 if ( i < args.length && typeof( args[i]) == 'number' ) 2972 relation = args[i]; 2953 2973 2954 2974 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false ); 2955 2975 for ( i = 0 ; i < functions.length ; i++ ) … … 2964 2984 { 2965 2985 if ( msg !== undefined ) 2966 2986 alert( msg ); 2967 if ( this && ( this.select || this.focus ) ) 2968 ( this.select || this.focus )(); 2987 if ( this.select || this.focus ) 2988 { 2989 if ( this.select ) 2990 this.select(); 2991 else 2992 this.focus(); 2993 } 2994 2969 2995 return false; 2970 2996 } 2971 2997 … … 3014 3040 return this.regex( numberRegex, msg ); 3015 3041 }, 3016 3042 3043 'cssLength' : function( msg ) 3044 { 3045 return this.functions( function( val ){ return cssLengthRegex.test( CKEDITOR.tools.trim( val ) ); }, msg ); 3046 }, 3047 3048 'htmlLength' : function( msg ) 3049 { 3050 return this.functions( function( val ){ return htmlLengthRegex.test( CKEDITOR.tools.trim( val ) ); }, msg ); 3051 }, 3052 3017 3053 equals : function( value, msg ) 3018 3054 { 3019 3055 return this.functions( function( val ){ return val == value; }, msg ); -
_source/lang/en.js
121 121 alignBottom : 'Bottom', 122 122 invalidHeight : 'Height must be a number.', 123 123 invalidWidth : 'Width must be a number.', 124 invalidCssLength : 'Value must be a valid CSS length unit.', 125 invalidHtmlLength : 'Value must be either a number in unit of pixel, or a percentage value', 124 126 125 127 // Put the voice-only part of the label in the span. 126 128 unavailable : '%1<span class="cke_accessibility">, unavailable</span>' … … 271 273 invalidBorder : 'Border size must be a number.', 272 274 invalidWidth : 'Table width must be a number.', 273 275 invalidHeight : 'Table height must be a number.', 274 invalidCellSpacing : 'Cell spacing must be a number.',275 invalidCellPadding : 'Cell padding must be a number.',276 276 277 277 cell : 278 278 { -
_source/plugins/flash/dialogs/flash.js
49 49 for ( i = 0 ; i < names.length ; i++ ) 50 50 attributesMap[ names[i] ][0]['default'] = attributesMap[ names[i] ][1]['default'] = true; 51 51 52 var defaultToPixel = CKEDITOR.tools.cssLength; 53 52 54 function loadValue( objectNode, embedNode, paramMap ) 53 55 { 54 56 var attributes = attributesMap[ this.id ]; … … 367 369 id : 'width', 368 370 style : 'width:95px', 369 371 label : editor.lang.common.width, 370 validate : CKEDITOR.dialog.validate. integer( editor.lang.common.invalidWidth ),372 validate : CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength ), 371 373 setup : function( objectNode, embedNode, paramMap, fakeImage ) 372 374 { 373 375 loadValue.apply( this, arguments ); 374 if ( fakeImage ) 375 { 376 var fakeImageWidth = parseInt( fakeImage.$.style.width, 10 ); 377 if ( !isNaN( fakeImageWidth ) ) 378 this.setValue( fakeImageWidth ); 379 } 376 fakeImage && this.setValue( fakeImage.getStyle( 'width' ) ); 380 377 }, 381 378 commit : function( objectNode, embedNode, paramMap, extraStyles ) 382 379 { 383 380 commitValue.apply( this, arguments ); 384 if ( this.getValue() )385 extraStyles.width = this.getValue() + 'px';381 var val = this.getValue(); 382 val && ( extraStyles.width = defaultToPixel( val ) ); 386 383 } 387 384 }, 388 385 { … … 390 387 id : 'height', 391 388 style : 'width:95px', 392 389 label : editor.lang.common.height, 393 validate : CKEDITOR.dialog.validate. integer( editor.lang.common.invalidHeight),390 validate : CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength ), 394 391 setup : function( objectNode, embedNode, paramMap, fakeImage ) 395 392 { 396 393 loadValue.apply( this, arguments ); 397 if ( fakeImage ) 398 { 399 var fakeImageHeight = parseInt( fakeImage.$.style.height, 10 ); 400 if ( !isNaN( fakeImageHeight ) ) 401 this.setValue( fakeImageHeight ); 402 } 394 fakeImage && this.setValue( fakeImage.getStyle( 'height' ) ); 403 395 }, 404 396 commit : function( objectNode, embedNode, paramMap, extraStyles ) 405 397 { 406 398 commitValue.apply( this, arguments ); 407 if ( this.getValue() )408 extraStyles.height = this.getValue() + 'px';399 var val = this.getValue(); 400 val && ( extraStyles.height = defaultToPixel( val ) ); 409 401 } 410 402 }, 411 403 { -
_source/core/tools.js
680 680 */ 681 681 cssLength : (function() 682 682 { 683 var decimalRegex = /^\d+(?:\.\d+)?$/;684 683 return function( length ) 685 684 { 686 return length + ( decimalRegex.test( length ) ? 'px' : '' );685 return length + ( !length || isNaN( Number( length ) ) ? '' : 'px' ); 687 686 }; 688 687 })(), 689 688 -
_source/plugins/fakeobjects/plugin.js
25 25 if ( style ) 26 26 { 27 27 // Get the width from the style. 28 var match = /(?:^|\s)width\s*:\s*( \d+)/i.exec( style ),28 var match = /(?:^|\s)width\s*:\s*(.*?)(:?;|$)/i.exec( style ), 29 29 width = match && match[1]; 30 30 31 31 // Get the height from the style. 32 match = /(?:^|\s)height\s*:\s*( \d+)/i.exec( style );32 match = /(?:^|\s)height\s*:\s*(.*?)(:?;|$)/i.exec( style ); 33 33 var height = match && match[1]; 34 34 35 35 if ( width )