Ticket #7498: 7498_3.patch
File 7498_3.patch, 6.6 KB (added by , 13 years ago) |
---|
-
_source/plugins/colorbutton/plugin.js
120 120 121 121 editor.fire( 'saveSnapshot' ); 122 122 123 // Clean up any conflicting style within the range.124 new CKEDITOR.style( config['colorButton_' + type + 'Style'], { color : 'inherit' } ).remove( editor.document );125 123 126 124 if ( color ) 127 125 { … … 141 139 return element.getName() != 'a' || isUnstylable( element ); 142 140 }; 143 141 144 new CKEDITOR.style( colorStyle, { color : color } ).apply( editor.document ); 145 } 142 var style = new CKEDITOR.style( colorStyle, { color : color } ); 143 144 var selection = editor.getSelection(), 145 range = selection.getRanges()[ 0 ], 146 elementPath = new CKEDITOR.dom.elementPath( range.startContainer ), 147 elements = elementPath.elements, 148 isRemove; 149 150 // Check if the current selected element is removable by this color style. 151 for ( var i = 0 ; i < elements.length ; i++ ) 152 { 153 if ( style.checkElementRemovable( elements[ i ] ) ) 154 { 155 isRemove = 1; 156 break; 157 } 158 } 146 159 160 if ( isRemove ) 161 style.remove( editor.document ); 162 else 163 { 164 // Clean up any conflicting style within the range. 165 new CKEDITOR.style( CKEDITOR.tools.extend( {}, config['colorButton_' + type + 'Style'], 166 { splitOnRemove : 1 } ), { color : 'inherit' } ).remove( editor.document ); 167 style.apply( editor.document ); 168 } 169 } 170 147 171 editor.fire( 'saveSnapshot' ); 148 172 }); 149 173 -
_source/plugins/styles/plugin.js
654 654 range.enlarge( CKEDITOR.ENLARGE_ELEMENT, 1 ); 655 655 656 656 var bookmark = range.createBookmark(), 657 startNode = bookmark.startNode; 657 startNode = bookmark.startNode, 658 endNode = bookmark.endNode, 659 me = this; 658 660 661 /* 662 * Find out the style ancestor that needs to be broken down at startNode 663 * and endNode. 664 */ 665 function breakNodes() 666 { 667 var startPath = new CKEDITOR.dom.elementPath( startNode.getParent() ), 668 endPath = endNode && new CKEDITOR.dom.elementPath( endNode.getParent() ), 669 breakStart = null, 670 breakEnd = null; 671 for ( var i = 0 ; i < startPath.elements.length ; i++ ) 672 { 673 var element = startPath.elements[ i ]; 674 675 if ( element == startPath.block || element == startPath.blockLimit ) 676 break; 677 678 if ( me.checkElementRemovable( element ) ) 679 breakStart = element; 680 } 681 for ( i = 0 ; endPath && i < endPath.elements.length ; i++ ) 682 { 683 element = endPath.elements[ i ]; 684 685 if ( element == endPath.block || element == endPath.blockLimit ) 686 break; 687 688 if ( me.checkElementRemovable( element ) ) 689 breakEnd = element; 690 } 691 692 if ( breakEnd ) 693 endNode.breakParent( breakEnd ); 694 if ( breakStart ) 695 startNode.breakParent( breakStart ); 696 } 697 659 698 if ( range.collapsed ) 660 699 { 661 700 … … 688 727 boundaryElement = element; 689 728 boundaryElement.match = isStart ? 'start' : 'end'; 690 729 } 730 // If presents collapsed range will split the current style element but not remove the whole element. 731 else if ( this._.definition.splitOnRemove ) 732 breakNodes(); 691 733 else 692 734 { 693 735 /* … … 734 776 * Now our range isn't collapsed. Lets walk from the start node to the end 735 777 * node via DFS and remove the styles one-by-one. 736 778 */ 737 var endNode = bookmark.endNode,738 me = this;739 740 /*741 * Find out the style ancestor that needs to be broken down at startNode742 * and endNode.743 */744 function breakNodes()745 {746 var startPath = new CKEDITOR.dom.elementPath( startNode.getParent() ),747 endPath = new CKEDITOR.dom.elementPath( endNode.getParent() ),748 breakStart = null,749 breakEnd = null;750 for ( var i = 0 ; i < startPath.elements.length ; i++ )751 {752 var element = startPath.elements[ i ];753 754 if ( element == startPath.block || element == startPath.blockLimit )755 break;756 757 if ( me.checkElementRemovable( element ) )758 breakStart = element;759 }760 for ( i = 0 ; i < endPath.elements.length ; i++ )761 {762 element = endPath.elements[ i ];763 764 if ( element == endPath.block || element == endPath.blockLimit )765 break;766 767 if ( me.checkElementRemovable( element ) )768 breakEnd = element;769 }770 771 if ( breakEnd )772 endNode.breakParent( breakEnd );773 if ( breakStart )774 startNode.breakParent( breakStart );775 }776 779 breakNodes(); 777 780 778 781 // Now, do the DFS walk. … … 1459 1462 return prop + names.join( ',' ); 1460 1463 }); 1461 1464 1465 // Convert CSS color schema. 1466 styleText = rgbToHex( styleText ); 1467 1462 1468 // Shrinking white-spaces around colon and semi-colon (#4147). 1463 1469 // Compensate tail semi-colon. 1464 1470 return styleText.replace( /\s*([;:])\s*/, '$1' ) … … 1484 1490 return retval; 1485 1491 } 1486 1492 1493 function rgbToHex( cssStyle ) 1494 { 1495 return cssStyle.replace( /(?:rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/gi, function( match, red, green, blue ) 1496 { 1497 red = parseInt( red, 10 ).toString( 16 ); 1498 green = parseInt( green, 10 ).toString( 16 ); 1499 blue = parseInt( blue, 10 ).toString( 16 ); 1500 var color = [red, green, blue] ; 1501 1502 // Add padding zeros if the hex value is less than 0x10. 1503 for ( var i = 0 ; i < color.length ; i++ ) 1504 color[i] = String( '0' + color[i] ).slice( -2 ) ; 1505 1506 return '#' + color.join( '' ) ; 1507 }); 1508 } 1509 1510 1487 1511 /** 1488 1512 * Compare two bunch of styles, with the speciality that value 'inherit' 1489 1513 * is treated as a wildcard which will match any value. -
_source/plugins/font/plugin.js
70 70 if ( this.getValue() == value ) 71 71 style.remove( editor.document ); 72 72 else 73 { 74 // Clean up any conflicting style within the range. 75 new CKEDITOR.style( CKEDITOR.tools.extend( {}, config[ 'fontSize_style' ], 76 { splitOnRemove : 1 } ) , { 'size' : 'inherit' } ).remove( editor.document ); 73 77 style.apply( editor.document ); 78 } 74 79 75 80 editor.fire( 'saveSnapshot' ); 76 81 },