Ticket #5931: 5931_6.patch
File 5931_6.patch, 3.2 KB (added by , 13 years ago) |
---|
-
_source/plugins/styles/plugin.js
478 478 if ( applyStyle && styleRange && !styleRange.collapsed ) 479 479 { 480 480 // Build the style element, based on the style object definition. 481 var styleNode = getElement( this, document ); 481 var styleNode = getElement( this, document ), 482 styleHasAttrs = styleNode.hasAttributes(); 482 483 483 484 // Get the element that holds the entire range. 484 485 var parent = styleRange.getCommonAncestor(); 485 486 487 var removeList = { 488 styles : {}, 489 attrs : {}, 490 // Styles cannot be removed. 491 blockedStyles : {}, 492 // Attrs cannot be removed. 493 blockedAttrs : {} 494 }; 495 496 var attName, styleName, value; 497 486 498 // Loop through the parents, removing the redundant attributes 487 499 // from the element to be applied. 488 500 while ( styleNode && parent ) 489 501 { 490 502 if ( parent.getName() == elementName ) 491 503 { 492 for ( varattName in def.attributes )504 for ( attName in def.attributes ) 493 505 { 494 if ( styleNode.getAttribute( attName ) == parent.getAttribute( attName ) ) 495 styleNode.removeAttribute( attName ); 496 } 506 if ( removeList.blockedAttrs[ attName ] || !( value = parent.getAttribute( styleName ) ) ) 507 continue; 497 508 498 for ( var styleName in def.styles)499 {500 if ( styleNode.getStyle( styleName ) == parent.getStyle( styleName ) )501 styleNode.removeStyle( styleName );509 if ( styleNode.getAttribute( attName ) == value ) 510 removeList.attrs[ attName ] = 1; 511 else 512 removeList.blockedAttrs[ attName ] = 1; 502 513 } 503 514 504 if ( !styleNode.hasAttributes())515 for ( styleName in def.styles ) 505 516 { 506 styleNode = null; 507 break; 517 if ( removeList.blockedStyles[ styleName ] || !( value = parent.getStyle( styleName ) ) ) 518 continue; 519 520 if ( styleNode.getStyle( styleName ) == value ) 521 removeList.styles[ styleName ] = 1; 522 else 523 removeList.blockedStyles[ styleName ] = 1; 508 524 } 509 525 } 510 526 511 527 parent = parent.getParent(); 512 528 } 513 529 530 for ( attName in removeList.attrs ) 531 styleNode.removeAttribute( attName ); 532 533 for ( styleName in removeList.styles ) 534 styleNode.removeStyle( styleName ); 535 536 if ( styleHasAttrs && !styleNode.hasAttributes() ) 537 styleNode = null; 538 514 539 if ( styleNode ) 515 540 { 516 541 // Move the contents of the range to the style element. … … 536 561 if ( !CKEDITOR.env.ie ) 537 562 styleNode.$.normalize(); 538 563 } 564 // Style already inherit from parents, left just to clear up any internal overrides. (#5931) 565 else 566 { 567 styleNode = new CKEDITOR.dom.element( 'span' ); 568 styleRange.extractContents().appendTo( styleNode ); 569 styleRange.insertNode( styleNode ); 570 removeFromInsideElement( this, styleNode ); 571 styleNode.remove( true ); 572 } 539 573 540 574 // Style applied, let's release the range, so it gets 541 575 // re-initialization in the next loop.