Ticket #6103: 6103_6.patch
File 6103_6.patch, 7.5 KB (added by , 13 years ago) |
---|
-
_source/plugins/colorbutton/plugin.js
100 100 var colorStyle = config['colorButton_' + type + 'Style']; 101 101 102 102 colorStyle.childRule = type == 'back' ? 103 // It's better to apply background color as the innermost style. (#3599) 104 function(){ return false; } : 105 // Fore color style must be applied inside links instead of around it. 106 function( element ){ return element.getName() != 'a'; }; 103 function( element ) 104 { 105 // It's better to apply background color as the innermost style. (#3599) 106 // Except for "unstylable elements". (#6103) 107 return isUnstylable( element ); 108 } 109 : 110 function( element ) 111 { 112 // Fore color style must be applied inside links instead of around it. 113 return element.getName() != 'a' || isUnstylable( element ); 114 }; 107 115 108 116 new CKEDITOR.style( colorStyle, { color : color } ).apply( editor.document ); 109 117 } … … 181 189 182 190 return output.join( '' ); 183 191 } 192 193 function isUnstylable( ele ) 194 { 195 return ( ele.getAttribute( 'contentEditable' ) == 'false' ) || ele.getAttribute( 'data-cke-nostyle' ); 196 } 184 197 } 185 198 }); 186 199 -
_source/plugins/styles/plugin.js
5 5 6 6 CKEDITOR.plugins.add( 'styles', 7 7 { 8 requires : [ 'selection' ] 8 requires : [ 'selection' ], 9 init : function( editor ) 10 { 11 // This doesn't look like correct, but it's the safest way to proper 12 // pass the disableReadonlyStyling configuration to the style system 13 // without having to change any method signature in the API. (#6103) 14 editor.on( 'contentDom', function() 15 { 16 editor.document.setCustomData( 'cke_includeReadonly', !editor.config.disableReadonlyStyling ); 17 }); 18 } 9 19 }); 10 20 11 21 /** … … 353 363 return ( styleDefinition._ST = stylesText ); 354 364 }; 355 365 366 // Gets the parent element which blocks the styling for an element. This 367 // can be done through read-only elements (contenteditable=false) or 368 // elements with the "data-cke-nostyle" attribute. 369 function getUnstylableParent( element ) 370 { 371 var unstylable, 372 editable; 373 374 while ( ( element = element.getParent() ) ) 375 { 376 if ( element.getName() == 'body' ) 377 break; 378 379 if ( element.getAttribute( 'data-cke-nostyle' ) ) 380 unstylable = element; 381 else if ( !editable ) 382 { 383 var contentEditable = element.getAttribute( 'contentEditable' ); 384 385 if ( contentEditable == 'false' ) 386 unstylable = element; 387 else if ( contentEditable == 'true' ) 388 editable = 1; 389 } 390 } 391 392 return unstylable; 393 } 394 356 395 function applyInlineStyle( range ) 357 396 { 358 397 var document = range.document; … … 375 414 var def = this._.definition; 376 415 var isUnknownElement; 377 416 417 // Indicates that fully selected read-only elements are to be included in the styling range. 418 var includeReadonly = def.includeReadonly; 419 420 // If the read-only inclusion is not available in the definition, try 421 // to get it from the document data. 422 if ( includeReadonly == undefined ) 423 includeReadonly = document.getCustomData( 'cke_includeReadonly' ); 424 378 425 // Get the DTD definition for the element. Defaults to "span". 379 426 var dtd = CKEDITOR.dtd[ elementName ] || ( isUnknownElement = true, CKEDITOR.dtd.span ); 380 427 … … 392 439 393 440 var styleRange; 394 441 442 // Check if the boundaries are inside non stylable elements. 443 var firstUnstylable = getUnstylableParent( firstNode ), 444 lastUnstylable = getUnstylableParent( lastNode ); 445 446 // If the first element can't be styled, we'll start processing right 447 // after its unstylable root. 448 if ( firstUnstylable ) 449 currentNode = firstUnstylable.getNextSourceNode( true ); 450 451 // If the last element can't be styled, we'll stop processing on its 452 // unstylable root. 453 if ( lastUnstylable ) 454 lastNode = lastUnstylable; 455 456 // Do nothing if the current node now follows the last node to be processed. 457 if ( currentNode.getPosition( lastNode ) == CKEDITOR.POSITION_FOLLOWING ) 458 currentNode = 0; 459 395 460 while ( currentNode ) 396 461 { 397 462 var applyStyle = false; … … 405 470 { 406 471 var nodeType = currentNode.type; 407 472 var nodeName = nodeType == CKEDITOR.NODE_ELEMENT ? currentNode.getName() : null; 473 var nodeIsReadonly = nodeName && ( currentNode.getAttribute( 'contentEditable' ) == 'false' ); 474 var nodeIsNoStyle = nodeName && currentNode.getAttribute( 'data-cke-nostyle' ); 408 475 409 476 if ( nodeName && currentNode.getAttribute( '_cke_bookmark' ) ) 410 477 { … … 414 481 415 482 // Check if the current node can be a child of the style element. 416 483 if ( !nodeName || ( dtd[ nodeName ] 484 && !nodeIsNoStyle 485 && ( !nodeIsReadonly || includeReadonly ) 417 486 && ( currentNode.getPosition( lastNode ) | CKEDITOR.POSITION_PRECEDING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_PRECEDING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED ) 418 487 && ( !def.childRule || def.childRule( currentNode ) ) ) ) 419 488 { … … 435 504 styleRange.setStartBefore( currentNode ); 436 505 } 437 506 438 // Non element nodes, or empty elements can be added439 // completely to the range.440 if ( nodeType == CKEDITOR.NODE_TEXT || ( nodeType == CKEDITOR.NODE_ELEMENT && !currentNode.getChildCount() ) )507 // Non element nodes, readonly elements, or empty 508 // elements can be added completely to the range. 509 if ( nodeType == CKEDITOR.NODE_TEXT || nodeIsReadonly || ( nodeType == CKEDITOR.NODE_ELEMENT && !currentNode.getChildCount() ) ) 441 510 { 442 511 var includedNode = currentNode; 443 512 var parentNode; … … 461 530 // in this style DTD, so apply the style immediately. 462 531 if ( !includedNode.$.nextSibling ) 463 532 applyStyle = true; 464 465 533 } 466 534 } 467 535 else … … 471 539 applyStyle = true; 472 540 473 541 // Get the next node to be processed. 474 currentNode = currentNode.getNextSourceNode( );542 currentNode = currentNode.getNextSourceNode( nodeIsNoStyle || nodeIsReadonly ); 475 543 } 476 544 477 545 // Apply the style if we have something to which apply it. … … 1355 1423 var selection = document.getSelection(), 1356 1424 // Bookmark the range so we can re-select it after processing. 1357 1425 bookmarks = selection.createBookmarks( 1 ), 1358 ranges = selection.getRanges( 1),1426 ranges = selection.getRanges(), 1359 1427 func = remove ? this.removeFromRange : this.applyToRange, 1360 1428 range; 1361 1429 … … 1449 1517 }; 1450 1518 1451 1519 /** 1520 * Indicates that fully selected read-only elements will be included when 1521 * applying the style (for inline styles only). 1522 * @name CKEDITOR.style.includeReadonly 1523 * @type Boolean 1524 * @default false 1525 * @since 3.5 1526 */ 1527 1528 /** 1529 * Disables inline styling on read-only elements. 1530 * @name CKEDITOR.config.disableReadonlyStyling 1531 * @type Boolean 1532 * @default false 1533 * @since 3.5 1534 */ 1535 1536 /** 1452 1537 * The "styles definition set" to use in the editor. They will be used in the 1453 1538 * styles combo and the Style selector of the div container. <br> 1454 1539 * The styles may be defined in the page containing the editor, or can be