X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Ftools.js;h=5d0573c40386caae1ee4834169816dc9c227fec7;hb=refs%2Ftags%2Fv3.6.1;hp=cd46ba456601281bc9710f51d6ce8f606383bf12;hpb=9afde8772159bd3436f1f5b7862960307710ae5a;p=ckeditor.git diff --git a/_source/core/tools.js b/_source/core/tools.js index cd46ba4..5d0573c 100644 --- a/_source/core/tools.js +++ b/_source/core/tools.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 */ @@ -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