Ticket #6103: 6103_6.patch

File 6103_6.patch, 7.5 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
    108116                                                new CKEDITOR.style( colorStyle, { color : color } ).apply( editor.document );
    109117                                        }
     
    181189
    182190                        return output.join( '' );
    183191                }
     192
     193                function isUnstylable( ele )
     194                {
     195                        return ( ele.getAttribute( 'contentEditable' ) == 'false' ) || ele.getAttribute( 'data-cke-nostyle' );
     196                }
    184197        }
    185198});
    186199
  • _source/plugins/styles/plugin.js

     
    55
    66CKEDITOR.plugins.add( 'styles',
    77{
    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        }
    919});
    1020
    1121/**
     
    353363                return ( styleDefinition._ST = stylesText );
    354364        };
    355365
     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
    356395        function applyInlineStyle( range )
    357396        {
    358397                var document = range.document;
     
    375414                var def = this._.definition;
    376415                var isUnknownElement;
    377416
     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
    378425                // Get the DTD definition for the element. Defaults to "span".
    379426                var dtd = CKEDITOR.dtd[ elementName ] || ( isUnknownElement = true, CKEDITOR.dtd.span );
    380427
     
    392439
    393440                var styleRange;
    394441
     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
    395460                while ( currentNode )
    396461                {
    397462                        var applyStyle = false;
     
    405470                        {
    406471                                var nodeType = currentNode.type;
    407472                                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' );
    408475
    409476                                if ( nodeName && currentNode.getAttribute( '_cke_bookmark' ) )
    410477                                {
     
    414481
    415482                                // Check if the current node can be a child of the style element.
    416483                                if ( !nodeName || ( dtd[ nodeName ]
     484                                        && !nodeIsNoStyle
     485                                        && ( !nodeIsReadonly || includeReadonly )
    417486                                        && ( currentNode.getPosition( lastNode ) | CKEDITOR.POSITION_PRECEDING | CKEDITOR.POSITION_IDENTICAL | CKEDITOR.POSITION_IS_CONTAINED ) == ( CKEDITOR.POSITION_PRECEDING + CKEDITOR.POSITION_IDENTICAL + CKEDITOR.POSITION_IS_CONTAINED )
    418487                                        && ( !def.childRule || def.childRule( currentNode ) ) ) )
    419488                                {
     
    435504                                                        styleRange.setStartBefore( currentNode );
    436505                                                }
    437506
    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() ) )
     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() ) )
    441510                                                {
    442511                                                        var includedNode = currentNode;
    443512                                                        var parentNode;
     
    461530                                                        // in this style DTD, so apply the style immediately.
    462531                                                        if ( !includedNode.$.nextSibling )
    463532                                                                applyStyle = true;
    464 
    465533                                                }
    466534                                        }
    467535                                        else
     
    471539                                        applyStyle = true;
    472540
    473541                                // Get the next node to be processed.
    474                                 currentNode = currentNode.getNextSourceNode();
     542                                currentNode = currentNode.getNextSourceNode( nodeIsNoStyle || nodeIsReadonly );
    475543                        }
    476544
    477545                        // Apply the style if we have something to which apply it.
     
    13551423                var selection = document.getSelection(),
    13561424                        // Bookmark the range so we can re-select it after processing.
    13571425                        bookmarks = selection.createBookmarks( 1 ),
    1358                         ranges = selection.getRanges( 1 ),
     1426                        ranges = selection.getRanges(),
    13591427                        func = remove ? this.removeFromRange : this.applyToRange,
    13601428                        range;
    13611429
     
    14491517};
    14501518
    14511519/**
     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/**
    14521537 * The "styles definition set" to use in the editor. They will be used in the
    14531538 * styles combo and the Style selector of the div container. <br>
    14541539 * 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