X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fremoveformat%2Fplugin.js;h=84d7947656389937dd085e22cea6f554cd84c8e8;hp=97b858abd225ed8b015806a537587803c6075abf;hb=8665a7c6c60586526e32e8941fe2896739b6ebfb;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1 diff --git a/_source/plugins/removeformat/plugin.js b/_source/plugins/removeformat/plugin.js index 97b858a..84d7947 100644 --- a/_source/plugins/removeformat/plugin.js +++ b/_source/plugins/removeformat/plugin.js @@ -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