Ticket #536: 536.patch

File 536.patch, 4.7 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/stylescombo/plugin.js

     
    109109                                                var style = styles[ value ],
    110110                                                        selection = editor.getSelection();
    111111
    112                                                 if ( style.type == CKEDITOR.STYLE_OBJECT )
    113                                                 {
    114                                                         var element = selection.getSelectedElement();
    115                                                         if ( element )
    116                                                                 style.applyToObject( element );
    117 
    118                                                         return;
    119                                                 }
    120 
    121112                                                var elementPath = new CKEDITOR.dom.elementPath( selection.getStartElement() );
    122113
    123114                                                if ( style.type == CKEDITOR.STYLE_INLINE && style.checkActive( elementPath ) )
     
    169160                                                var selection = editor.getSelection();
    170161
    171162                                                var element = selection.getSelectedElement(),
    172                                                         elementName = element && element.getName(),
    173163                                                        elementPath = new CKEDITOR.dom.elementPath( element || selection.getStartElement() );
    174164
    175165                                                var counter = [ 0, 0, 0, 0 ];
     
    180170                                                        var style = styles[ name ],
    181171                                                                type = style.type;
    182172
    183                                                         if ( type == CKEDITOR.STYLE_OBJECT )
    184                                                         {
    185                                                                 if ( element && style.element == elementName )
    186                                                                 {
    187                                                                         if ( style.checkElementRemovable( element, true ) )
    188                                                                                 this.mark( name );
    189 
    190                                                                         counter[ type ]++;
    191                                                                 }
    192                                                                 else
    193                                                                         this.hideItem( name );
     173                                                        if ( style.checkActive( elementPath ) )
     174                                                                this.mark( name );
     175                                                        else if ( type == CKEDITOR.STYLE_OBJECT && !style.checkApplicable( elementPath ) )
     176                                                        {
     177                                                                this.hideItem( name );
     178                                                                counter[ type ]--;
    194179                                                        }
    195                                                         else
    196                                                         {
    197                                                                 if ( style.checkActive( elementPath ) )
    198                                                                         this.mark( name );
    199180
    200                                                                 counter[ type ]++;
    201                                                         }
    202                                                 }
     181                                                        counter[ type ]++;
     182                                                }
    203183
    204184                                                if ( !counter[ CKEDITOR.STYLE_BLOCK ] )
    205185                                                        this.hideGroup( lang[ 'panelTitle' + String( CKEDITOR.STYLE_BLOCK ) ] );
  • _source/plugins/styles/plugin.js

     
    127127                                                        applyInlineStyle
    128128                                                : this.type == CKEDITOR.STYLE_BLOCK ?
    129129                                                        applyBlockStyle
     130                                                : this.type == CKEDITOR.STYLE_OBJECT ?
     131                                                        applyObjectStyle
    130132                                                : null ).call( this, range );
    131133                },
    132134
     
    154156                                case CKEDITOR.STYLE_BLOCK :
    155157                                        return this.checkElementRemovable( elementPath.block || elementPath.blockLimit, true );
    156158
     159                                case CKEDITOR.STYLE_OBJECT :
    157160                                case CKEDITOR.STYLE_INLINE :
    158161
    159162                                        var elements = elementPath.elements;
    160163
    161164                                        for ( var i = 0, element ; i < elements.length ; i++ )
    162165                                        {
    163                                                 element = elements[i];
     166                                                element = elements[ i ];
    164167
    165                                                 if ( element == elementPath.block || element == elementPath.blockLimit )
     168                                                if ( this.type == CKEDITOR.STYLE_INLINE
     169                                                          && ( element == elementPath.block || element == elementPath.blockLimit ) )
    166170                                                        continue;
    167171
     172                                                if( this.type == CKEDITOR.STYLE_OBJECT
     173                                                         && !( element.getName() in objectElements ) )
     174                                                                continue;
     175
    168176                                                if ( this.checkElementRemovable( element, true ) )
    169177                                                        return true;
    170178                                        }
    171179                        }
    172180                        return false;
    173181                },
    174 
     182               
     183                checkApplicable : function( elementPath )
     184                {
     185                        switch ( this.type )
     186                        {
     187                                case CKEDITOR.STYLE_INLINE :
     188                                case CKEDITOR.STYLE_BLOCK :
     189                                        return true;
     190
     191                                case CKEDITOR.STYLE_OBJECT :
     192                                        return elementPath.lastElement.getAscendant( this.element, true );
     193                        }
     194                },
     195
    175196                // Checks if an element, or any of its attributes, is removable by the
    176197                // current style definition.
    177198                checkElementRemovable : function( element, fullMatch )
     
    668689                range.moveToBookmark( bookmark );
    669690}
    670691
     692        function applyObjectStyle( range )
     693        {
     694                var root = range.getCommonAncestor( true, true ),
     695                                element = root.getAscendant( this.element, true );
     696                element && setupElement( element, this );
     697        }
     698
    671699        function applyBlockStyle( range )
    672700        {
    673701                // Serializible bookmarks is needed here since
  • _source/plugins/stylescombo/styles/default.js

     
    8181                        'border' : '2',
    8282                        'align' : 'right'
    8383                }
    84         }
     84        },
     85
     86        { name : 'Borderless Table'             , element : 'table', styles: { 'border-style': 'hidden', 'background-color' : '#E6E6FA' } },
     87        { name : 'Square Bulleted List'         , element : 'ul', styles : { 'list-style-type' : 'square' } }
     88
    8589]);
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy