X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fcore%2Ftools.js;h=5d0573c40386caae1ee4834169816dc9c227fec7;hp=2492beb2a16a63539e9b2119d341bf063d199d51;hb=f0610347140239143439a511ee2bd48cb784f470;hpb=4e70ea24db840898be8cc21c950363a52a2a6aba diff --git a/_source/core/tools.js b/_source/core/tools.js index 2492beb..5d0573c 100644 --- a/_source/core/tools.js +++ b/_source/core/tools.js @@ -680,14 +680,43 @@ For licensing, see LICENSE.html or http://ckeditor.com/license */ cssLength : (function() { - var decimalRegex = /^\d+(?:\.\d+)?$/; return function( length ) { - return length + ( decimalRegex.test( length ) ? 'px' : '' ); + return length + ( !length || isNaN( Number( length ) ) ? '' : 'px' ); }; })(), /** + * Convert the specified CSS length value to the calculated pixel length inside this page. + * Note: Percentage based value is left intact. + * @param {String} cssLength CSS length value. + */ + convertToPx : ( function () + { + var calculator; + + return function( cssLength ) + { + if ( !calculator ) + { + calculator = CKEDITOR.dom.element.createFromHtml( + '
', CKEDITOR.document ); + CKEDITOR.document.getBody().append( calculator ); + } + + if ( !(/%$/).test( cssLength ) ) + { + calculator.setStyle( 'width', cssLength ); + return calculator.$.clientWidth; + } + + return cssLength; + }; + } )(), + + /** * String specified by {@param str} repeats {@param times} times. * @param str * @param times