Ticket #7387: 7387.patch

File 7387.patch, 3.7 KB (added by Alfonso Martínez de Lizarrondo, 13 years ago)

Proposed patch

  • _source/core/dom/node.js

     
    534534                        return false;
    535535                },
    536536
     537                /**
     538                 * Get an ascendant whose tag name is included in
     539                 * the provided hash object
     540                 */
     541                getAscendantInHash : function( hash, includeSelf )
     542                {
     543                        var $ = this.$;
     544
     545                        if ( !includeSelf )
     546                                $ = $.parentNode;
     547
     548                        while ( $ )
     549                        {
     550                                if ( $.nodeName && hash[ $.nodeName.toLowerCase() ] )
     551                                        return new CKEDITOR.dom.node( $ );
     552
     553                                $ = $.parentNode;
     554                        }
     555                        return null;
     556                },
     557
    537558                move : function( target, toStart )
    538559                {
    539560                        target.append( this.remove(), toStart );
  • _source/plugins/styles/plugin.js

     
    100100
    101101                var element = this.element = ( styleDefinition.element || '*' ).toLowerCase();
    102102
    103                 this.type =
     103                // A style definition can specify how it wants to be applied, although it
     104                // might not work as expected (can't really create a td out of nowhere)
     105                this.type = styleDefinition.type ||
    104106                        blockElements[ element ] ?
    105107                                CKEDITOR.STYLE_BLOCK
    106108                        : objectElements[ element ] ?
     
    108110                        :
    109111                                CKEDITOR.STYLE_INLINE;
    110112
     113                // Optionally a definition can define a set of elements that it can be applied to
     114                this.elements = styleDefinition.elements;
     115                // In that case, it will be applied like an object style: only to existing elements
     116                if ( this.elements )
     117                        this.type = CKEDITOR.STYLE_OBJECT
     118
    111119                this._ =
    112120                {
    113121                        definition : styleDefinition
     
    179187                                                          && ( element == elementPath.block || element == elementPath.blockLimit ) )
    180188                                                        continue;
    181189
    182                                                 if( this.type == CKEDITOR.STYLE_OBJECT
    183                                                          && !( element.getName() in objectElements ) )
     190                                                if( this.type == CKEDITOR.STYLE_OBJECT )
     191                                                {
     192                                                        var name = element.getName();
     193                                                        if ( name != this.element &&
     194                                                                !(this.elements && ( name in this.elements)) )
    184195                                                                continue;
     196                                                }
    185197
    186198                                                if ( this.checkElementRemovable( element, true ) )
    187199                                                        return true;
     
    203215                                        break;
    204216
    205217                                case CKEDITOR.STYLE_OBJECT :
    206                                         return elementPath.lastElement.getAscendant( this.element, true );
     218                                        var root = elementPath.lastElement;
     219                                        return this.elements ? root.getAscendantInHash( this.elements, true ) : root.getAscendant( this.element, true );
    207220                        }
    208221
    209222                        return true;
     
    217230                                return false;
    218231
    219232                        var def = this._.definition,
    220                                 attribs;
     233                                attribs,
     234                                name = element.getName();
    221235
    222236                        // If the element name is the same as the style name.
    223                         if ( element.getName() == this.element )
     237                        if ( name == this.element || ( this.elements && name in this.elements ) )
    224238                        {
    225239                                // If no attributes are defined in the element.
    226240                                if ( !fullMatch && !element.hasAttributes() )
     
    814828        function applyObjectStyle( range )
    815829        {
    816830                var root = range.getCommonAncestor( true, true ),
    817                         element = root.getAscendant( this.element, true );
     831                        element = this.elements ? root.getAscendantInHash( this.elements, true ) : root.getAscendant( this.element, true );
    818832                element && setupElement( element, this );
    819833        }
    820834
    821835        function removeObjectStyle( range )
    822836        {
    823837                var root = range.getCommonAncestor( true, true ),
    824                         element = root.getAscendant( this.element, true );
     838                        element = this.elements ? root.getAscendantInHash( this.elements, true ) : root.getAscendant( this.element, true );
    825839
    826840                if ( !element )
    827841                        return;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy