Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery.fn.mswordFilter = function() {
var each = jQuery.each,
wordFilter = function( node ) {
for( var i = 0; i < node.childNodes.length; i++ ) {
var childNode = node.childNodes[ i ];
if( !childNode || !childNode.nodeType ) return;
if( childNode.nodeType === document.COMMENT_NODE ) {
node.removeChild( childNode );
}
if( childNode.nodeType === document.ELEMENT_NODE ) {
if( childNode.tagName === 'IMG' ) {
childNode.setAttribute( 'width', childNode.style.width || childNode.width );
childNode.setAttribute( 'height', childNode.style.height || childNode.height );
childNode.removeAttribute( 'class' );
childNode.removeAttribute( 'style' );
} else if( childNode.tagName === 'SPAN' ) {
while( childNode.firstChild ) {
node.insertBefore( childNode.firstChild, childNode );
}
i--;
node.removeChild( childNode );
} else if( ~'XML SCRIPT STYLE LINK META'.split( /\s/ ).indexOf( childNode.tagName ) ) {
i--;
node.removeChild( childNode );
} else if( ~'P DIV'.split( /\s/ ).indexOf( childNode.tagName ) && !childNode.innerHTML ) {
i--;
node.removeChild( childNode );
} else {
childNode.removeAttribute( 'align' );
childNode.removeAttribute( 'class' );
childNode.removeAttribute( 'style' );
wordFilter( childNode );
}
}
};
};
return this.each( function() {
wordFilter( this );
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.