| 759 | | } |
| | 759 | }, |
| | 760 | |
| | 761 | /** |
| | 762 | * Try to avoid differences in the style attribute. |
| | 763 | * |
| | 764 | * @param {String} styleText The style data to be normalized. |
| | 765 | * @param {Boolean} [nativeNormalize=false] Parse the data using the browser. |
| | 766 | * @returns {String} The normalized value. |
| | 767 | */ |
| | 768 | normalizeCssText: function( styleText, nativeNormalize ) { |
| | 769 | var props = [], |
| | 770 | name, |
| | 771 | parsedProps = CKEDITOR.tools.parseCssText( styleText, true, nativeNormalize ); |
| | 772 | |
| | 773 | for ( name in parsedProps ) |
| | 774 | props.push( name + ':' + parsedProps[ name ] ); |
| | 775 | |
| | 776 | props.sort(); |
| | 777 | |
| | 778 | return props.length ? ( props.join( ';' ) + ';' ) : ''; |
| | 779 | }, |
| | 780 | |
| | 781 | /** |
| | 782 | * Find and convert <code>rgb(x,x,x)</code> colors definition to hexadecimal notation. |
| | 783 | * @param {String} styleText The style data (or just a string containing rgb colors) to be converted. |
| | 784 | * @returns {String} The style data with rgb colors converted to hexadecimal equivalents. |
| | 785 | */ |
| | 786 | convertRgbToHex: function( styleText ) { |
| | 787 | return styleText.replace( /(?:rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/gi, function( match, red, green, blue ) { |
| | 788 | var color = [ red, green, blue ]; |
| | 789 | // Add padding zeros if the hex value is less than 0x10. |
| | 790 | for ( var i = 0; i < 3; i++ ) |
| | 791 | color[ i ] = ( '0' + parseInt( color[ i ], 10 ).toString( 16 ) ).slice( -2 ); |
| | 792 | return '#' + color.join( '' ); |
| | 793 | }); |
| | 794 | }, |
| | 795 | |
| | 796 | /** |
| | 797 | * Turn inline style text properties into one hash. |
| | 798 | * |
| | 799 | * @param {String} styleText The style data to be parsed. |
| | 800 | * @param {Boolean} [normalize=false] Normalize properties and values |
| | 801 | * (e.g. trim spaces, convert to lower case). |
| | 802 | * @param {Boolean} [nativeNormalize=false] Parse the data using the browser. |
| | 803 | * @returns {String} The object containing parsed properties. |
| | 804 | */ |
| | 805 | parseCssText: function( styleText, normalize, nativeNormalize ) { |
| | 806 | var retval = {}; |
| | 807 | |
| | 808 | if ( nativeNormalize ) { |
| | 809 | // Injects the style in a temporary span object, so the browser parses it, |
| | 810 | // retrieving its final format. |
| | 811 | var temp = new CKEDITOR.dom.element( 'span' ); |
| | 812 | temp.setAttribute( 'style', styleText ); |
| | 813 | styleText = CKEDITOR.tools.convertRgbToHex( temp.getAttribute( 'style' ) || '' ); |
| | 814 | } |
| | 815 | |
| | 816 | // IE will leave a single semicolon when failed to parse the style text. (#3891) |
| | 817 | if ( !styleText || styleText == ';' ) |
| | 818 | return retval; |
| | 819 | |
| | 820 | styleText.replace( /"/g, '"' ).replace( /\s*([^:;\s]+)\s*:\s*([^;]+)\s*(?=;|$)/g, function( match, name, value ) { |
| | 821 | if ( normalize ) { |
| | 822 | name = name.toLowerCase(); |
| | 823 | // Normalize font-family property, ignore quotes and being case insensitive. (#7322) |
| | 824 | // http://www.w3.org/TR/css3-fonts/#font-family-the-font-family-property |
| | 825 | if ( name == 'font-family' ) |
| | 826 | value = value.toLowerCase().replace( /["']/g, '' ).replace( /\s*,\s*/g, ',' ); |
| | 827 | value = CKEDITOR.tools.trim( value ); |
| | 828 | } |
| | 829 | |
| | 830 | retval[ name ] = value; |
| | 831 | }); |
| | 832 | return retval; |
| | 833 | } |
| | 834 | |