Ticket #5528: 5528.2.patch
File 5528.2.patch, 9.6 KB (added by , 14 years ago) |
---|
-
_source/core/dom/element.js
1118 1118 */ 1119 1119 setStyle : function( name, value ) 1120 1120 { 1121 // Update the DOM style 1121 1122 this.$.style[ CKEDITOR.tools.cssStyleToDomStyle( name ) ] = value; 1123 1124 // Invalidate the stored style 1125 // TODO: update correctly 1126 this.removeAttribute( '_cke_saved_style' ); 1122 1127 return this; 1123 1128 }, 1124 1129 -
_source/core/tools.js
1 /*1 /* 2 2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. 3 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 4 */ … … 346 346 }, 347 347 348 348 /** 349 * Try to avoid differences in the style attribute 350 * @param {String} The style data to be normalized 351 * @param {Boolean} Parse the data using the browser 352 * @returns {String} The normalized value. 353 */ 354 normalizeCssText : function( unparsedCssText, nativeNormalize ) 355 { 356 var styleText; 357 if ( nativeNormalize !== false ) 358 { 359 // Injects the style in a temporary span object, so the browser parses it, 360 // retrieving its final format. 361 var temp = new CKEDITOR.dom.element( 'span' ); 362 temp.setAttribute( 'style', unparsedCssText ); 363 styleText = temp.getAttribute( 'style' ) || ''; 364 } 365 else 366 styleText = unparsedCssText; 367 368 if ( !styleText ) 369 return styleText; 370 371 // Lowercase properties in IE #5930 372 CKEDITOR.env.ie && ( styleText = styleText.replace( /(?:(^\s*|;\s*)([^\:]+))/g, function( match, separator, name ) 373 { 374 return separator + name.toLowerCase(); 375 }) ); 376 377 styleText = CKEDITOR.tools.convertRGBToHex( styleText ); 378 379 // Shrinking white-spaces around colon and semi-colon (#4147). 380 // Compensate tail semi-colon. 381 return styleText.replace( /\s*([;:])\s*/g, '$1' ) 382 .replace( /;$/, '') 383 // Trimming spaces after comma (e.g. font-family name)(#4107). 384 .replace( /,\s+/g, ',' ); 385 }, 386 387 /** 388 * Convert a CSS rgb(R, G, B) color back to #RRGGBB format. 389 * @param Css style string (can include more than one color 390 * @return Converted css style. 391 */ 392 convertRGBToHex : function( cssStyle ) 393 { 394 return cssStyle.replace( /(?:rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/gi, function( match, red, green, blue ) 395 { 396 red = parseInt( red, 10 ).toString( 16 ); 397 green = parseInt( green, 10 ).toString( 16 ); 398 blue = parseInt( blue, 10 ).toString( 16 ); 399 var color = [red, green, blue] ; 400 401 // Add padding zeros if the hex value is less than 0x10. 402 for ( var i = 0 ; i < color.length ; i++ ) 403 color[i] = String( '0' + color[i] ).slice( -2 ) ; 404 405 return '#' + color.join( '' ) ; 406 }); 407 }, 408 409 /** 349 410 * Gets a unique number for this CKEDITOR execution session. It returns 350 411 * progressive numbers starting at 1. 351 412 * @function -
_source/plugins/htmldataprocessor/plugin.js
43 43 // 1. For IE version >=8, empty blocks are displayed correctly themself in wysiwiyg; 44 44 // 2. For the rest, at least table cell and list item need no filler space. 45 45 // (#6248) 46 if ( fromSource && CKEDITOR.env.ie && 46 if ( fromSource && CKEDITOR.env.ie && 47 47 ( document.documentMode > 7 48 48 || block.name in CKEDITOR.dtd.tr 49 49 || block.name in CKEDITOR.dtd.$listItem ) ) … … 79 79 block.add( new CKEDITOR.htmlParser.text( '\xa0' ) ); 80 80 } 81 81 82 // The current style might have updated values for position or size if the user 83 // has manually resized or moved an absolutely positioned element 84 function updateStyles( current, saved) 85 { 86 // Properties that we want to update 87 // these ones aren't "distorted" or destroyed by the browsers like what happens with "background" 88 // or vendor specific prefixes (-moz, -o, -webkit, -ms) 89 // So we get them from the current style and replace them in the saved style 90 var properties = [ 'width', 'height', 'top', 'left', 'right', 'bottom' ], 91 propertyReg, 92 partialStyle = ''; 93 94 for ( var i = 0 ; i < properties.length ; i++ ) 95 { 96 propertyReg = new RegExp( '(?:^|;)\s*(' + properties[ i ] + '\s*:.+)(?:$|;)', 'i') ; 97 var match = current.match( propertyReg ); 98 match && ( partialStyle += ';' + match[ 1 ] ); 99 saved = saved.replace( propertyReg, '' ); 100 } 101 102 // Combine the old and current styles and clean up extra semi-colons 103 return ( saved + CKEDITOR.tools.normalizeCssText( partialStyle ) ) 104 .replace( /;+/g, ';' ) 105 .replace( /(^;|;$)/, '' ); 106 } 107 82 108 var dtd = CKEDITOR.dtd; 83 109 84 110 // Find out the list of block-like tags that can contain <br>. … … 149 175 savedAttributeName = '_cke_saved_' + attributeNames[ i ]; 150 176 savedAttributeName in attribs && ( delete attribs[ attributeNames[ i ] ] ); 151 177 } 178 // Process style 179 if ( '_cke_saved_style' in attribs ) 180 { 181 // Size might have been adjusted by manually resizing the object, also position of absolutely positioned elements 182 attribs[ 'style' ] = updateStyles( attribs[ 'style' ], attribs[ '_cke_saved_style' ]); 183 delete attribs[ '_cke_saved_style' ]; 184 } 185 else 186 { 187 // Process to generate normalized output 188 attribs[ 'style' ] && (attribs[ 'style' ] = CKEDITOR.tools.normalizeCssText( attribs[ 'style' ], false )); 189 } 152 190 } 153 191 154 192 return element; … … 247 285 for ( i in blockLikeTags ) 248 286 defaultHtmlBlockFilterRules.elements[ i ] = extendBlockForOutput; 249 287 250 if ( CKEDITOR.env.ie )251 {252 // IE outputs style attribute in capital letters. We should convert253 // them back to lower case.254 defaultHtmlFilterRules.attributes.style = function( value, element )255 {256 return value.toLowerCase();257 };258 }259 260 288 function protectReadOnly( element ) 261 289 { 262 290 element.attributes.contenteditable = "false"; … … 273 301 } 274 302 275 303 var protectAttributeRegex = /<((?:a|area|img|input)[\s\S]*?\s)((href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))([^>]*)>/gi, 304 protectStyleRegex = /\s(style\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))/gi, 276 305 findSavedSrcRegex = /\s_cke_saved_src\s*=/; 277 306 278 307 var protectElementsRegex = /(?:<style(?=[ >])[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi, … … 285 314 286 315 function protectAttributes( html ) 287 316 { 288 returnhtml.replace( protectAttributeRegex, function( tag, beginning, fullAttr, attrName, end )317 html = html.replace( protectAttributeRegex, function( tag, beginning, fullAttr, attrName, end ) 289 318 { 290 319 // We should not rewrite the _cke_saved_src attribute (#5218) 291 320 if ( attrName == 'src' && findSavedSrcRegex.test( tag ) ) … … 293 322 else 294 323 return '<' + beginning + fullAttr + ' _cke_saved_' + fullAttr + end + '>'; 295 324 }); 325 326 return html.replace( protectStyleRegex, '$& _cke_saved_$1' ); 296 327 } 297 328 298 329 function protectElements( html ) -
_source/plugins/styles/plugin.js
1 /*1 /* 2 2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. 3 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 4 */ … … 231 231 232 232 // Special treatment for 'style' attribute is required. 233 233 if ( attName == 'style' ? 234 compareCssText( attribs[ attName ], normalizeCssText( elementAttr, false ) )234 compareCssText( attribs[ attName ], CKEDITOR.tools.normalizeCssText( elementAttr, false ) ) 235 235 : attribs[ attName ] == elementAttr ) 236 236 { 237 237 if ( !fullMatch ) … … 345 345 // Browsers make some changes to the style when applying them. So, here 346 346 // we normalize it to the browser format. 347 347 if ( stylesText.length ) 348 stylesText = normalizeCssText( stylesText );348 stylesText = CKEDITOR.tools.normalizeCssText( stylesText ); 349 349 350 350 stylesText += specialStylesText; 351 351 … … 1287 1287 return temp[ isStyle ? 'getStyle' : 'getAttribute' ]( name ); 1288 1288 } 1289 1289 1290 // Make the comparison of style text easier by standardizing it.1291 function normalizeCssText( unparsedCssText, nativeNormalize )1292 {1293 var styleText;1294 if ( nativeNormalize !== false )1295 {1296 // Injects the style in a temporary span object, so the browser parses it,1297 // retrieving its final format.1298 var temp = new CKEDITOR.dom.element( 'span' );1299 temp.setAttribute( 'style', unparsedCssText );1300 styleText = temp.getAttribute( 'style' ) || '';1301 }1302 else1303 styleText = unparsedCssText;1304 1305 // Shrinking white-spaces around colon and semi-colon (#4147).1306 // Compensate tail semi-colon.1307 return styleText.replace( /\s*([;:])\s*/, '$1' )1308 .replace( /([^\s;])$/, '$1;')1309 // Trimming spaces after comma(#4107),1310 // remove quotations(#6403),1311 // mostly for differences on "font-family".1312 .replace( /,\s+/g, ',' )1313 .replace( /\"/g,'' )1314 .toLowerCase();1315 }1316 1317 1290 // Turn inline style text properties into one hash. 1318 1291 function parseStyleText( styleText ) 1319 1292 {