Ticket #4125: 4125_7.patch

File 4125_7.patch, 4.1 KB (added by Garry Yao, 13 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        /**
     121         * Perform the remove format filters on the passed element.
     122         * @param {CKEDITOR.editor} editor
     123         * @param {CKEDITOR.dom.element} element
     124         */
     125        filter : function ( editor, element )
     126        {
     127                var filters = editor._.removeFormat.filters;
     128                for ( var i = 0; i < filters.length; i++ )
     129                {
     130                        if ( filters[ i ]( element ) === false )
     131                                return false;
     132                }
     133                return true;
     134        }
    114135};
    115136
    116137/**
     138 * Add to a collection of functions to decide whether a specific
     139 * element should be considered as formatting element and thus
     140 * could be removed during <b>removeFormat</b> command,
     141 * Note: Only available with the existence of 'removeformat' plugin.
     142 * @since 3.3
     143 * @param {Function} func The function to be called, which will be passed a {CKEDITOR.dom.element} element to test.
     144 * @example
     145 *  // Don't remove empty span
     146 *  editor.addRemoveFormatFilter.push( function( element )
     147 *              {
     148 *                      return !( element.is( 'span' ) && CKEDITOR.tools.isEmpty( element.getAttributes() ) );
     149 *              });
     150 */
     151CKEDITOR.editor.prototype.addRemoveFormatFilter = function( func )
     152{
     153        this._.removeFormat.filters.push( func );
     154};
     155
     156/**
    117157 * A comma separated list of elements to be removed when executing the "remove
    118158 " format" command. Note that only inline elements are allowed.
    119159 * @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,
     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