Ticket #6103: 6103_4.patch
File 6103_4.patch, 5.7 KB (added by , 13 years ago) |
---|
-
_source/plugins/styles/plugin.js
353 353 return ( styleDefinition._ST = stylesText ); 354 354 }; 355 355 356 // Gets the parent element which blocks the styling for an element. This 357 // can be done through read-only elements (contenteditable=false) or 358 // elements with the "data-cke-nostyle" attribute. 359 function getUnstylableParent( element ) 360 { 361 var unstylable, 362 editable; 363 364 while ( ( element = element.getParent() ) ) 365 { 366 if ( element.getName() == 'body' ) 367 break; 368 369 if ( element.getAttribute( 'data-cke-nostyle' ) ) 370 unstylable = element; 371 else if ( !editable ) 372 { 373 var contentEditable = element.getAttribute( 'contentEditable' ); 374 375 if ( contentEditable == 'false' ) 376 unstylable = element; 377 else if ( contentEditable == 'true' ) 378 editable = 1; 379 } 380 } 381 382 return unstylable; 383 } 384 356 385 function applyInlineStyle( range ) 357 386 { 358 387 var document = range.document; … … 371 400 return; 372 401 } 373 402 403 // Indicates that fully selected read-only elements are to be included in the styling range. 404 var includeReadonly = this._includeReadonly; 405 374 406 var elementName = this.element; 375 407 var def = this._.definition; 376 408 var isUnknownElement; … … 392 424 393 425 var styleRange; 394 426 427 // Check if the boundaries are inside non stylable elements. 428 var firstUnstylable = getUnstylableParent( firstNode ), 429 lastUnstylable = getUnstylableParent( lastNode ); 430 431 // If the first element can't be styled, we'll start processing right 432 // after its unstylable root. 433 if ( firstUnstylable ) 434 currentNode = firstUnstylable.getNextSourceNode( true ); 435 436 // If the last element can't be styled, we'll stop processing on its 437 // unstylable root. 438 if ( lastUnstylable ) 439 lastNode = lastUnstylable; 440 441 // Do nothing if the current node now follows the last node to be processed. 442 if ( currentNode.getPosition( lastNode ) == CKEDITOR.POSITION_FOLLOWING ) 443 currentNode = 0; 444 395 445 while ( currentNode ) 396 446 { 397 447 var applyStyle = false; … … 405 455 { 406 456 var nodeType = currentNode.type; 407 457 var nodeName = nodeType == CKEDITOR.NODE_ELEMENT ? currentNode.getName() : null; 458 var nodeIsReadonly = nodeName && ( currentNode.getAttribute( 'contentEditable' ) == 'false' ); 459 var nodeIsNoStyle = nodeName && currentNode.getAttribute( 'data-cke-nostyle' ); 408 460 409 461 if ( nodeName && currentNode.getAttribute( '_cke_bookmark' ) ) 410 462 { … … 414 466 415 467 // Check if the current node can be a child of the style element. 416 468 if ( !nodeName || ( dtd[ nodeName ] 469 && !nodeIsNoStyle 470 && ( !nodeIsReadonly || includeReadonly ) 417 471 && ( currentNode.getPosition( lastNode ) | CKEDITOR.POSITION_PRECEDING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_PRECEDING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED ) 418 472 && ( !def.childRule || def.childRule( currentNode ) ) ) ) 419 473 { … … 435 489 styleRange.setStartBefore( currentNode ); 436 490 } 437 491 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() ) )492 // Non element nodes, readonly elements, or empty 493 // elements can be added completely to the range. 494 if ( nodeType == CKEDITOR.NODE_TEXT || nodeIsReadonly || ( nodeType == CKEDITOR.NODE_ELEMENT && !currentNode.getChildCount() ) ) 441 495 { 442 496 var includedNode = currentNode; 443 497 var parentNode; … … 461 515 // in this style DTD, so apply the style immediately. 462 516 if ( !includedNode.$.nextSibling ) 463 517 applyStyle = true; 464 465 518 } 466 519 } 467 520 else … … 471 524 applyStyle = true; 472 525 473 526 // Get the next node to be processed. 474 currentNode = currentNode.getNextSourceNode( );527 currentNode = currentNode.getNextSourceNode( nodeIsNoStyle || nodeIsReadonly ); 475 528 } 476 529 477 530 // Apply the style if we have something to which apply it. … … 1355 1408 var selection = document.getSelection(), 1356 1409 // Bookmark the range so we can re-select it after processing. 1357 1410 bookmarks = selection.createBookmarks( 1 ), 1358 ranges = selection.getRanges( 1),1411 ranges = selection.getRanges(), 1359 1412 func = remove ? this.removeFromRange : this.applyToRange, 1360 1413 range; 1361 1414 … … 1386 1439 1387 1440 if ( doc ) 1388 1441 { 1442 // _includeReadonly is the computed value of the includeReadonly 1443 // property, if available, or the disableReadonlyStyling setting. 1444 this.style._includeReadonly = 1445 ( this.style.includeReadonly == undefined ? 1446 !editor.config.disableReadonlyStyling : 1447 this.style.includeReadonly ); 1448 1389 1449 if ( this.state == CKEDITOR.TRISTATE_OFF ) 1390 1450 this.style.apply( doc ); 1391 1451 else if ( this.state == CKEDITOR.TRISTATE_ON ) … … 1449 1509 }; 1450 1510 1451 1511 /** 1512 * Indicates that fully selected read-only elements will be included when 1513 * applying the style (for inline styles only). 1514 * @name CKEDITOR.style.includeReadonly 1515 * @type Boolean 1516 * @default false 1517 * @since 3.5 1518 */ 1519 1520 /** 1521 * Disables inline styling on read-only elements. 1522 * @name CKEDITOR.config.disableReadonlyStyling 1523 * @type Boolean 1524 * @default false 1525 * @since 3.5 1526 */ 1527 1528 /** 1452 1529 * The "styles definition set" to use in the editor. They will be used in the 1453 1530 * styles combo and the Style selector of the div container. <br> 1454 1531 * The styles may be defined in the page containing the editor, or can be