/**
* @class Roo.htmleditor.Filter
* Base Class for filtering htmleditor stuff. - do not use this directly - extend it.
* @cfg {DomElement} node The node to iterate and filter
* @cfg {boolean|String|Array} tag Tags to replace
* @constructor
* Create a new Filter.
* @param {Object} config Configuration options
*/
Roo.htmleditor.Filter = function(cfg) {
Roo.apply(this.cfg);
// this does not actually call walk as it's really just a abstract class
}
Roo.htmleditor.Filter.prototype = {
node: false,
tag: false,
// overrride to do replace comments.
replaceComment : false,
// overrride to do replace or do stuff with tags..
replaceTag : false,
walk : function(dom)
{
Roo.each( Array.from(dom.childNodes), function( e ) {
switch(true) {
case e.nodeType == 8 && this.replaceComment !== false: // comment
this.replaceComment(e);
return;
case e.nodeType != 1: //not a node.
return;
case this.tag === true: // everything
case typeof(this.tag) == 'object' && this.tag.indexOf(e.tagName) > -1: // array and it matches.
case typeof(this.tag) == 'string' && this.tag == e.tagName: // array and it matches.
if (this.replaceTag && false === this.replaceTag(e)) {
return;
}
if (e.hasChildNodes()) {
this.walk(e);
}
return;
default: // tags .. that do not match.
if (e.hasChildNodes()) {
this.walk(e);
}
}
}, this);
}
};