JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / core / tools.js
index 2492beb..5d0573c 100644 (file)
@@ -680,14 +680,43 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                 */\r
                cssLength : (function()\r
                {\r
-                       var decimalRegex = /^\d+(?:\.\d+)?$/;\r
                        return function( length )\r
                        {\r
-                               return length + ( decimalRegex.test( length ) ? 'px' : '' );\r
+                               return length + ( !length || isNaN( Number( length ) ) ? '' : 'px' );\r
                        };\r
                })(),\r
 \r
                /**\r
+                * Convert the specified CSS length value to the calculated pixel length inside this page.\r
+                * <strong>Note:</strong> Percentage based value is left intact.\r
+                * @param {String} cssLength CSS length value.\r
+                */\r
+               convertToPx : ( function ()\r
+                       {\r
+                               var calculator;\r
+\r
+                               return function( cssLength )\r
+                               {\r
+                                       if ( !calculator )\r
+                                       {\r
+                                               calculator = CKEDITOR.dom.element.createFromHtml(\r
+                                                               '<div style="position:absolute;left:-9999px;' +\r
+                                                               'top:-9999px;margin:0px;padding:0px;border:0px;"' +\r
+                                                               '></div>', CKEDITOR.document );\r
+                                               CKEDITOR.document.getBody().append( calculator );\r
+                                       }\r
+\r
+                                       if ( !(/%$/).test( cssLength ) )\r
+                                       {\r
+                                               calculator.setStyle( 'width', cssLength );\r
+                                               return calculator.$.clientWidth;\r
+                                       }\r
+\r
+                                       return cssLength;\r
+                               };\r
+                       } )(),\r
+\r
+               /**\r
                 * String specified by {@param str} repeats {@param times} times.\r
                 * @param str\r
                 * @param times\r