Ticket #6103: 6103_5.patch

File 6103_5.patch, 7.3 KB (added by Frederico Caldeira Knabben, 13 years ago)
  • _source/plugins/colorbutton/plugin.js

     
    100100                                                var colorStyle = config['colorButton_' + type + 'Style'];
    101101
    102102                                                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                                                        };
    107115
     116                                                if ( colorStyle.includeReadonly == undefined )
     117                                                        colorStyle.includeReadonly = !editor.config.disableReadonlyStyling;
     118
    108119                                                new CKEDITOR.style( colorStyle, { color : color } ).apply( editor.document );
    109120                                        }
    110121
     
    181192
    182193                        return output.join( '' );
    183194                }
     195
     196                function isUnstylable( ele )
     197                {
     198                        return ( ele.getAttribute( 'contentEditable' ) == 'false' ) || ele.getAttribute( 'data-cke-nostyle' );
     199                }
    184200        }
    185201});
    186202
  • _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;
     
    375404                var def = this._.definition;
    376405                var isUnknownElement;
    377406
     407                // Indicates that fully selected read-only elements are to be included in the styling range.
     408                var includeReadonly = def.includeReadonly;
     409               
     410                if ( includeReadonly == undefined )
     411                        includeReadonly = this._.includeReadonly;
     412
    378413                // Get the DTD definition for the element. Defaults to "span".
    379414                var dtd = CKEDITOR.dtd[ elementName ] || ( isUnknownElement = true, CKEDITOR.dtd.span );
    380415
     
    392427
    393428                var styleRange;
    394429
     430                // Check if the boundaries are inside non stylable elements.
     431                var firstUnstylable = getUnstylableParent( firstNode ),
     432                        lastUnstylable = getUnstylableParent( lastNode );
     433
     434                // If the first element can't be styled, we'll start processing right
     435                // after its unstylable root.
     436                if ( firstUnstylable )
     437                        currentNode = firstUnstylable.getNextSourceNode( true );                       
     438
     439                // If the last element can't be styled, we'll stop processing on its
     440                // unstylable root.
     441                if ( lastUnstylable )
     442                        lastNode = lastUnstylable;
     443
     444                // Do nothing if the current node now follows the last node to be processed.
     445                if ( currentNode.getPosition( lastNode ) == CKEDITOR.POSITION_FOLLOWING )
     446                        currentNode = 0;
     447
    395448                while ( currentNode )
    396449                {
    397450                        var applyStyle = false;
     
    405458                        {
    406459                                var nodeType = currentNode.type;
    407460                                var nodeName = nodeType == CKEDITOR.NODE_ELEMENT ? currentNode.getName() : null;
     461                                var nodeIsReadonly = nodeName && ( currentNode.getAttribute( 'contentEditable' ) == 'false' );
     462                                var nodeIsNoStyle = nodeName && currentNode.getAttribute( 'data-cke-nostyle' );
    408463
    409464                                if ( nodeName && currentNode.getAttribute( '_cke_bookmark' ) )
    410465                                {
     
    414469
    415470                                // Check if the current node can be a child of the style element.
    416471                                if ( !nodeName || ( dtd[ nodeName ]
     472                                        && !nodeIsNoStyle
     473                                        && ( !nodeIsReadonly || includeReadonly )
    417474                                        && ( currentNode.getPosition( lastNode ) | CKEDITOR.POSITION_PRECEDING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_PRECEDING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED )
    418475                                        && ( !def.childRule || def.childRule( currentNode ) ) ) )
    419476                                {
     
    435492                                                        styleRange.setStartBefore( currentNode );
    436493                                                }
    437494
    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() ) )
     495                                                // Non element nodes, readonly elements, or empty
     496                                                // elements can be added completely to the range.
     497                                                if ( nodeType == CKEDITOR.NODE_TEXT || nodeIsReadonly || ( nodeType == CKEDITOR.NODE_ELEMENT && !currentNode.getChildCount() ) )
    441498                                                {
    442499                                                        var includedNode = currentNode;
    443500                                                        var parentNode;
     
    461518                                                        // in this style DTD, so apply the style immediately.
    462519                                                        if ( !includedNode.$.nextSibling )
    463520                                                                applyStyle = true;
    464 
    465521                                                }
    466522                                        }
    467523                                        else
     
    471527                                        applyStyle = true;
    472528
    473529                                // Get the next node to be processed.
    474                                 currentNode = currentNode.getNextSourceNode();
     530                                currentNode = currentNode.getNextSourceNode( nodeIsNoStyle || nodeIsReadonly );
    475531                        }
    476532
    477533                        // Apply the style if we have something to which apply it.
     
    13551411                var selection = document.getSelection(),
    13561412                        // Bookmark the range so we can re-select it after processing.
    13571413                        bookmarks = selection.createBookmarks( 1 ),
    1358                         ranges = selection.getRanges( 1 ),
     1414                        ranges = selection.getRanges(),
    13591415                        func = remove ? this.removeFromRange : this.applyToRange,
    13601416                        range;
    13611417
     
    13861442
    13871443        if ( doc )
    13881444        {
     1445                // Set the includeReadonly priv property as a backup if the it's not
     1446                // available in the style definition.
     1447                this.style._.includeReadonly = !editor.config.disableReadonlyStyling;
     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