Ticket #4125: 4125_5.patch

File 4125_5.patch, 3.9 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/removeformat/plugin.js

     
    1515                                label : editor.lang.removeFormat,
    1616                                command : 'removeFormat'
    1717                        });
     18
     19                editor._.removeFormat = { filters: [] };
    1820        }
    1921});
    2022
     
    3234                                var removeAttributes = editor._.removeAttributes ||
    3335                                        ( editor._.removeAttributes = editor.config.removeFormatAttributes.split( ',' ) );
    3436
     37                                var filter = CKEDITOR.plugins.removeformat.filter;
    3538                                var ranges = editor.getSelection().getRanges();
    3639
    3740                                for ( var i = 0, range ; range = ranges[ i ] ; i++ )
     
    7073                                                                break;
    7174
    7275                                                        // If this element can be removed (even partially).
    73                                                         if ( tagsRegex.test( pathElement.getName() ) )
     76                                                        if ( tagsRegex.test( pathElement.getName() ) && filter( editor, pathElement ) )
    7477                                                                node.breakParent( pathElement );
    7578                                                }
    7679                                        };
     
    9295                                                var nextNode = currentNode.getNextSourceNode( false, CKEDITOR.NODE_ELEMENT );
    9396
    9497                                                // This node must not be a fake element.
    95                                                 if ( !( currentNode.getName() == 'img' && currentNode.getAttribute( '_cke_realelement' ) ) )
     98                                                if ( !( currentNode.getName() == 'img'
     99                                                        && currentNode.getAttribute( '_cke_realelement' ) )
     100                                                        && filter( editor, currentNode ) )
    96101                                                {
    97102                                                        // Remove elements nodes that match with this style rules.
    98103                                                        if ( tagsRegex.test( currentNode.getName() ) )
     
    110115                                editor.getSelection().selectRanges( ranges );
    111116                        }
    112117                }
    113         }
     118        },
     119
     120        filter : function ( editor, element )
     121        {
     122                var filters = editor._.removeFormat.filters;
     123                for ( var i = 0; i < filters.length; i++ )
     124                {
     125                        if ( filters[ i ]( element ) === false )
     126                                return false;
     127                }
     128                return true;
     129        }
    114130};
    115131
    116132/**
     133 * Add to a collection of functions to decide whether a specific
     134 * element should be considered as formatting element and thus
     135 * could be removed during <b>removeFormat</b> command,
     136 * Note: Only available with the existence of 'removeformat' plugin.
     137 * @since 3.3
     138 * @default []
     139 * @example
     140 *  // Don't remove empty span
     141 *  editor.addRemoveFormatFilter.push( function( element )
     142 *              {
     143 *                      return !( element.is( 'span' ) && CKEDITOR.tools.isEmpty( element.getAttributes() ) );
     144 *              });
     145 */
     146CKEDITOR.editor.prototype.addRemoveFormatFilter = function( func )
     147{
     148        this._.removeFormat.filters.push( func );
     149};
     150
     151/**
    117152 * A comma separated list of elements to be removed when executing the "remove
    118153 " format" command. Note that only inline elements are allowed.
    119154 * @type String
  • _source/plugins/scayt/plugin.js

     
    636636
    637637                afterInit : function( editor )
    638638                {
    639                         // Prevent word marker line from displaying in elements path. (#3570)
    640                         var elementsPathFilters;
    641                         if ( editor._.elementsPath && ( elementsPathFilters = editor._.elementsPath.filters ) )
    642                         {
    643                                 elementsPathFilters.push( function( element )
    644                                 {
    645                                         if ( element.hasAttribute( 'scaytid' ) )
    646                                                 return false;
    647                                 } );
    648                         }
     639                        // Prevent word marker line from displaying in elements path and been removed when cleaning format. (#3570) (#4125)
     640                        var elementsPathFilters, removeFormatFilters,
     641                                        scaytFilter = function( element )
     642                                        {
     643                                                if ( element.hasAttribute( 'scaytid' ) )
     644                                                        return false;
     645                                        };
    649646
     647                        if ( editor._.elementsPath && ( elementsPathFilters = editor._.elementsPath.filters ) )
     648                                elementsPathFilters.push( scaytFilter );
     649
     650                        editor.addRemoveFormatFilter && editor.addRemoveFormatFilter( scaytFilter );
     651
    650652                }
    651653        });
    652654})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy