Ticket #6103: 6103_4.patch

File 6103_4.patch, 5.7 KB (added by Frederico Caldeira Knabben, 13 years ago)
  • _source/plugins/styles/plugin.js

     
    353353                return ( styleDefinition._ST = stylesText );
    354354        };
    355355
     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
    356385        function applyInlineStyle( range )
    357386        {
    358387                var document = range.document;
     
    371400                        return;
    372401                }
    373402
     403                // Indicates that fully selected read-only elements are to be included in the styling range.
     404                var includeReadonly = this._includeReadonly;
     405
    374406                var elementName = this.element;
    375407                var def = this._.definition;
    376408                var isUnknownElement;
     
    392424
    393425                var styleRange;
    394426
     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
    395445                while ( currentNode )
    396446                {
    397447                        var applyStyle = false;
     
    405455                        {
    406456                                var nodeType = currentNode.type;
    407457                                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' );
    408460
    409461                                if ( nodeName && currentNode.getAttribute( '_cke_bookmark' ) )
    410462                                {
     
    414466
    415467                                // Check if the current node can be a child of the style element.
    416468                                if ( !nodeName || ( dtd[ nodeName ]
     469                                        && !nodeIsNoStyle
     470                                        && ( !nodeIsReadonly || includeReadonly )
    417471                                        && ( currentNode.getPosition( lastNode ) | CKEDITOR.POSITION_PRECEDING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_PRECEDING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED )
    418472                                        && ( !def.childRule || def.childRule( currentNode ) ) ) )
    419473                                {
     
    435489                                                        styleRange.setStartBefore( currentNode );
    436490                                                }
    437491
    438                                                 // Non element nodes, or empty elements can be added
    439                                                 // 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() ) )
    441495                                                {
    442496                                                        var includedNode = currentNode;
    443497                                                        var parentNode;
     
    461515                                                        // in this style DTD, so apply the style immediately.
    462516                                                        if ( !includedNode.$.nextSibling )
    463517                                                                applyStyle = true;
    464 
    465518                                                }
    466519                                        }
    467520                                        else
     
    471524                                        applyStyle = true;
    472525
    473526                                // Get the next node to be processed.
    474                                 currentNode = currentNode.getNextSourceNode();
     527                                currentNode = currentNode.getNextSourceNode( nodeIsNoStyle || nodeIsReadonly );
    475528                        }
    476529
    477530                        // Apply the style if we have something to which apply it.
     
    13551408                var selection = document.getSelection(),
    13561409                        // Bookmark the range so we can re-select it after processing.
    13571410                        bookmarks = selection.createBookmarks( 1 ),
    1358                         ranges = selection.getRanges( 1 ),
     1411                        ranges = selection.getRanges(),
    13591412                        func = remove ? this.removeFromRange : this.applyToRange,
    13601413                        range;
    13611414
     
    13861439
    13871440        if ( doc )
    13881441        {
     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
    13891449                if ( this.state == CKEDITOR.TRISTATE_OFF )
    13901450                        this.style.apply( doc );
    13911451                else if ( this.state == CKEDITOR.TRISTATE_ON )
     
    14491509};
    14501510
    14511511/**
     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/**
    14521529 * The "styles definition set" to use in the editor. They will be used in the
    14531530 * styles combo and the Style selector of the div container. <br>
    14541531 * The styles may be defined in the page containing the editor, or can be
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy