Ticket #5931: 5931_3.patch
File 5931_3.patch, 3.5 KB (added by , 14 years ago) |
---|
-
_source/plugins/styles/plugin.js
479 479 { 480 480 // Build the style element, based on the style object definition. 481 481 var styleNode = getElement( this, document ); 482 483 482 // Get the element that holds the entire range. 484 483 var parent = styleRange.getCommonAncestor(); 485 484 485 var styleRange2 = styleRange.clone(); 486 styleRange2.shrink(); 487 var innerStyle = styleRange2.getCommonAncestor(); 488 489 if ( innerStyle.$ != parent.$ ) 490 { 491 for ( attName in def.attributes ) 492 { 493 if ( innerStyle.hasAttribute( attName ) ) 494 innerStyle.removeAttribute( attName ); 495 } 496 497 for ( styleName in def.styles ) 498 { 499 if ( innerStyle.getStyle( styleName ) ) 500 innerStyle.removeStyle( styleName ); 501 } 502 503 if ( !innerStyle.getAttribute( 'style' ) ) 504 innerStyle.removeAttribute( 'style' ); 505 506 if ( !innerStyle.hasAttributes() ) 507 { 508 var target = innerStyle.getParent(); 509 var child; 510 while ( child = innerStyle.$.lastChild ) 511 target.$.insertBefore( innerStyle.$.removeChild( child ), innerStyle.$.nextSibling ); 512 innerStyle.remove(); 513 } 514 } 515 516 var removeList = { 517 styles : {}, 518 attrs : {}, 519 // Styles cannot be removed. 520 blockedStyles : {}, 521 // Attrs cannot be removed. 522 blockedAttrs : {} 523 }; 524 525 var attName, styleName, value; 526 486 527 // Loop through the parents, removing the redundant attributes 487 528 // from the element to be applied. 488 529 while ( styleNode && parent ) 489 530 { 490 531 if ( parent.getName() == elementName ) 491 532 { 492 for ( varattName in def.attributes )533 for ( attName in def.attributes ) 493 534 { 494 if ( styleNode.getAttribute( attName ) == parent.getAttribute( attName ) ) 495 styleNode.removeAttribute( attName ); 496 } 535 if ( removeList.blockedAttrs[ attName ] || !( value = parent.getAttribute( styleName ) ) ) 536 continue; 497 537 498 for ( var styleName in def.styles)499 {500 if ( styleNode.getStyle( styleName ) == parent.getStyle( styleName ) )501 styleNode.removeStyle( styleName );538 if ( styleNode.getAttribute( attName ) == value ) 539 removeList.attrs[ attName ] = 1; 540 else 541 removeList.blockedAttrs[ attName ] = 1; 502 542 } 503 543 504 if ( !styleNode.hasAttributes())544 for ( styleName in def.styles ) 505 545 { 506 styleNode = null; 507 break; 546 if ( removeList.blockedStyles[ styleName ] || !( value = parent.getStyle( styleName ) ) ) 547 continue; 548 549 if ( styleNode.getStyle( styleName ) == value ) 550 removeList.styles[ styleName ] = 1; 551 else 552 removeList.blockedStyles[ styleName ] = 1; 508 553 } 509 554 } 510 555 511 556 parent = parent.getParent(); 512 557 } 513 558 559 for ( attName in removeList.attrs ) 560 { 561 // Skip prototype extensions. 562 if ( !removeList.attrs.hasOwnProperty( attName ) ) 563 continue; 564 styleNode.removeAttribute( attName ); 565 } 566 567 for ( styleName in removeList.styles ) 568 { 569 // Skip prototype extensions. 570 if ( !removeList.styles.hasOwnProperty( styleName ) ) 571 continue; 572 styleNode.removeStyle( styleName ); 573 } 574 575 if ( !styleNode.hasAttributes() ) 576 styleNode = null; 577 514 578 if ( styleNode ) 515 579 { 516 580 // Move the contents of the range to the style element.