X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fremoveformat%2Fplugin.js;h=d54bfb350ca45e0ad755ec60451baa6c1232e2e7;hb=055b6b0792ce7dc53d47af606b367c04b927c2ab;hp=b8231ddebefc5773b085fb6f8732eb40724e29a8;hpb=7cd80714081a8ffdf4a1a8d2c72f120ed5ef3d6d;p=ckeditor.git diff --git a/_source/plugins/removeformat/plugin.js b/_source/plugins/removeformat/plugin.js index b8231dd..d54bfb3 100644 --- a/_source/plugins/removeformat/plugin.js +++ b/_source/plugins/removeformat/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -15,6 +15,8 @@ CKEDITOR.plugins.add( 'removeformat', label : editor.lang.removeFormat, command : 'removeFormat' }); + + editor._.removeFormat = { filters: [] }; } }); @@ -32,6 +34,7 @@ CKEDITOR.plugins.removeformat = var removeAttributes = editor._.removeAttributes || ( editor._.removeAttributes = editor.config.removeFormatAttributes.split( ',' ) ); + var filter = CKEDITOR.plugins.removeformat.filter; var ranges = editor.getSelection().getRanges(); for ( var i = 0, range ; range = ranges[ i ] ; i++ ) @@ -70,7 +73,7 @@ CKEDITOR.plugins.removeformat = break; // If this element can be removed (even partially). - if ( tagsRegex.test( pathElement.getName() ) ) + if ( tagsRegex.test( pathElement.getName() ) && filter( editor, pathElement ) ) node.breakParent( pathElement ); } }; @@ -92,13 +95,18 @@ CKEDITOR.plugins.removeformat = var nextNode = currentNode.getNextSourceNode( false, CKEDITOR.NODE_ELEMENT ); // This node must not be a fake element. - if ( !( currentNode.getName() == 'img' && currentNode.getAttribute( '_cke_realelement' ) ) ) + if ( !( currentNode.getName() == 'img' + && currentNode.getAttribute( '_cke_realelement' ) ) + && filter( editor, currentNode ) ) { // Remove elements nodes that match with this style rules. if ( tagsRegex.test( currentNode.getName() ) ) currentNode.remove( true ); else + { currentNode.removeAttributes( removeAttributes ); + editor.fire( 'removeFormatCleanup', currentNode ); + } } currentNode = nextNode; @@ -110,10 +118,45 @@ CKEDITOR.plugins.removeformat = editor.getSelection().selectRanges( ranges ); } } + }, + + /** + * Perform the remove format filters on the passed element. + * @param {CKEDITOR.editor} editor + * @param {CKEDITOR.dom.element} element + */ + filter : function ( editor, element ) + { + var filters = editor._.removeFormat.filters; + for ( var i = 0; i < filters.length; i++ ) + { + if ( filters[ i ]( element ) === false ) + return false; + } + return true; } }; /** + * Add to a collection of functions to decide whether a specific + * element should be considered as formatting element and thus + * could be removed during removeFormat command, + * Note: Only available with the existence of 'removeformat' plugin. + * @since 3.3 + * @param {Function} func The function to be called, which will be passed a {CKEDITOR.dom.element} element to test. + * @example + * // Don't remove empty span + * editor.addRemoveFormatFilter.push( function( element ) + * { + * return !( element.is( 'span' ) && CKEDITOR.tools.isEmpty( element.getAttributes() ) ); + * }); + */ +CKEDITOR.editor.prototype.addRemoveFormatFilter = function( func ) +{ + this._.removeFormat.filters.push( func ); +}; + +/** * A comma separated list of elements to be removed when executing the "remove " format" command. Note that only inline elements are allowed. * @type String @@ -130,3 +173,10 @@ CKEDITOR.config.removeFormatTags = 'b,big,code,del,dfn,em,font,i,ins,kbd,q,samp, * @example */ CKEDITOR.config.removeFormatAttributes = 'class,style,lang,width,height,align,hspace,valign'; + +/** + * Fired after an element was cleaned by the removeFormat plugin. + * @name CKEDITOR#removeFormatCleanup + * @event + * @param {Object} data.element The element that was cleaned up. + */