/*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
{\r
return functions.push( function()\r
{\r
- fn.apply( scope || this, arguments );\r
+ return fn.apply( scope || this, arguments );\r
}) - 1;\r
},\r
\r
*/\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
genKey : function()\r
{\r
return Array.prototype.slice.call( arguments ).join( '-' );\r
+ },\r
+\r
+ /**\r
+ * Try to avoid differences in the style attribute.\r
+ *\r
+ * @param {String} styleText The style data to be normalized.\r
+ * @param {Boolean} [nativeNormalize=false] Parse the data using the browser.\r
+ * @returns {String} The normalized value.\r
+ */\r
+ normalizeCssText: function( styleText, nativeNormalize ) {\r
+ var props = [],\r
+ name,\r
+ parsedProps = CKEDITOR.tools.parseCssText( styleText, true, nativeNormalize );\r
+\r
+ for ( name in parsedProps )\r
+ props.push( name + ':' + parsedProps[ name ] );\r
+\r
+ props.sort();\r
+\r
+ return props.length ? ( props.join( ';' ) + ';' ) : '';\r
+ },\r
+\r
+ /**\r
+ * Find and convert <code>rgb(x,x,x)</code> colors definition to hexadecimal notation.\r
+ * @param {String} styleText The style data (or just a string containing rgb colors) to be converted.\r
+ * @returns {String} The style data with rgb colors converted to hexadecimal equivalents.\r
+ */\r
+ convertRgbToHex: function( styleText ) {\r
+ return styleText.replace( /(?:rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/gi, function( match, red, green, blue ) {\r
+ var color = [ red, green, blue ];\r
+ // Add padding zeros if the hex value is less than 0x10.\r
+ for ( var i = 0; i < 3; i++ )\r
+ color[ i ] = ( '0' + parseInt( color[ i ], 10 ).toString( 16 ) ).slice( -2 );\r
+ return '#' + color.join( '' );\r
+ });\r
+ },\r
+\r
+ /**\r
+ * Turn inline style text properties into one hash.\r
+ *\r
+ * @param {String} styleText The style data to be parsed.\r
+ * @param {Boolean} [normalize=false] Normalize properties and values\r
+ * (e.g. trim spaces, convert to lower case).\r
+ * @param {Boolean} [nativeNormalize=false] Parse the data using the browser.\r
+ * @returns {String} The object containing parsed properties.\r
+ */\r
+ parseCssText: function( styleText, normalize, nativeNormalize ) {\r
+ var retval = {};\r
+\r
+ if ( nativeNormalize ) {\r
+ // Injects the style in a temporary span object, so the browser parses it,\r
+ // retrieving its final format.\r
+ var temp = new CKEDITOR.dom.element( 'span' );\r
+ temp.setAttribute( 'style', styleText );\r
+ styleText = CKEDITOR.tools.convertRgbToHex( temp.getAttribute( 'style' ) || '' );\r
+ }\r
+\r
+ // IE will leave a single semicolon when failed to parse the style text. (#3891)\r
+ if ( !styleText || styleText == ';' )\r
+ return retval;\r
+\r
+ styleText.replace( /"/g, '"' ).replace( /\s*([^:;\s]+)\s*:\s*([^;]+)\s*(?=;|$)/g, function( match, name, value ) {\r
+ if ( normalize ) {\r
+ name = name.toLowerCase();\r
+ // Normalize font-family property, ignore quotes and being case insensitive. (#7322)\r
+ // http://www.w3.org/TR/css3-fonts/#font-family-the-font-family-property\r
+ if ( name == 'font-family' )\r
+ value = value.toLowerCase().replace( /["']/g, '' ).replace( /\s*,\s*/g, ',' );\r
+ value = CKEDITOR.tools.trim( value );\r
+ }\r
+\r
+ retval[ name ] = value;\r
+ });\r
+ return retval;\r
}\r
+\r
};\r
})();\r
\r