X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Ftools.js;h=148c588caebf3a87042d6902415c568c766568fa;hb=2f22c0c38f17e75be5541089076885442aaa2377;hp=ee00f91feba5207ed21c3a7664f45632e52cd396;hpb=039a051ccf3901311661022a30afd60fc38130c9;p=ckeditor.git diff --git a/_source/core/tools.js b/_source/core/tools.js index ee00f91..148c588 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-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -638,7 +638,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { return functions.push( function() { - fn.apply( scope || this, arguments ); + return fn.apply( scope || this, arguments ); }) - 1; }, @@ -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