411cd3c9634fe5d48a1877f5ea344277f9205a82
[roojs1] / Roo / htmleditor / Filter.js
1  
2 /**
3  * @class Roo.htmleditor.Filter
4  * Base Class for filtering htmleditor stuff. - do not use this directly - extend it.
5  * @cfg {DomElement} node The node to iterate and filter
6  * @cfg {boolean|String|Array} tag Tags to replace 
7  * @constructor
8  * Create a new Filter.
9  * @param {Object} config Configuration options
10  */
11
12
13
14 Roo.htmleditor.Filter = function(cfg) {
15     Roo.apply(this.cfg);
16     // this does not actually call walk as it's really just a abstract class
17 }
18
19
20 Roo.htmleditor.Filter.prototype = {
21     
22     node: false,
23     
24     tag: false,
25
26     // overrride to do replace comments.
27     replaceComment : false,
28     
29     // overrride to do replace or do stuff with tags..
30     replaceTag : false,
31     
32     walk : function(dom)
33     {
34         Roo.each( Array.from(dom.childNodes), function( e ) {
35             switch(true) {
36                 
37                 case e.nodeType == 8 &&  this.replaceComment  !== false: // comment
38                     this.replaceComment(e);
39                     return;
40                 
41                 case e.nodeType != 1: //not a node.
42                     return;
43                 
44                 case this.tag === true: // everything
45                 case e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'object' && this.tag.indexOf(":") > -1:
46                 case e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'string' && this.tag == ":":
47                 case typeof(this.tag) == 'object' && this.tag.indexOf(e.tagName) > -1: // array and it matches.
48                 case typeof(this.tag) == 'string' && this.tag == e.tagName: // array and it matches.
49                     if (this.replaceTag && false === this.replaceTag(e)) {
50                         return;
51                     }
52                     if (e.hasChildNodes()) {
53                         this.walk(e);
54                     }
55                     return;
56                 
57                 default:    // tags .. that do not match.
58                     if (e.hasChildNodes()) {
59                         this.walk(e);
60                     }
61             }
62             
63         }, this);
64         
65     }
66 };