X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fremoveformat%2Fplugin.js;h=84d7947656389937dd085e22cea6f554cd84c8e8;hb=8665a7c6c60586526e32e8941fe2896739b6ebfb;hp=b8231ddebefc5773b085fb6f8732eb40724e29a8;hpb=7cd80714081a8ffdf4a1a8d2c72f120ed5ef3d6d;p=ckeditor.git diff --git a/_source/plugins/removeformat/plugin.js b/_source/plugins/removeformat/plugin.js index b8231dd..84d7947 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,7 +95,9 @@ 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() ) ) @@ -110,10 +115,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