Fix #7300 - namespace cleaning on word
[roojs1] / Roo / htmleditor / FilterKeepChildren.js
1 /**
2  * @class Roo.htmleditor.FilterKeepChildren
3  * remove tags but keep children
4  * @constructor
5  * Run a new Keep Children Filter
6  * @param {Object} config Configuration options
7  */
8
9 Roo.htmleditor.FilterKeepChildren = function(cfg)
10 {
11     Roo.apply(this, cfg);
12     if (this.tag === false) {
13         return; // dont walk.. (you can use this to use this just to do a child removal on a single tag )
14     }
15     // hacky?
16     if ((typeof(this.tag) == 'object' && this.tag.indexOf(":") > -1)) {
17         this.cleanNamespace = true;
18     }
19         
20     this.walk(cfg.node);
21 }
22
23 Roo.extend(Roo.htmleditor.FilterKeepChildren, Roo.htmleditor.FilterBlack,
24 {
25     cleanNamespace : false, // should really be an option, rather than using ':' inside of this tag.
26   
27     replaceTag : function(node)
28     {
29         // walk children...
30         //Roo.log(node.tagName);
31         var ar = Array.from(node.childNodes);
32         //remove first..
33         
34         for (var i = 0; i < ar.length; i++) {
35             var e = ar[i];
36             if (e.nodeType == 1) {
37                 if (
38                     (typeof(this.tag) == 'object' && this.tag.indexOf(e.tagName) > -1)
39                     || // array and it matches
40                     (typeof(this.tag) == 'string' && this.tag == e.tagName)
41                     ||
42                     (e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'object' && this.tag.indexOf(":") > -1)
43                     ||
44                     (e.tagName.indexOf(":") > -1 && typeof(this.tag) == 'string' && this.tag == ":")
45                 ) {
46                     this.replaceTag(ar[i]); // child is blacklisted as well...
47                     continue;
48                 }
49             }
50         }  
51         ar = Array.from(node.childNodes);
52         for (var i = 0; i < ar.length; i++) {
53          
54             node.removeChild(ar[i]);
55             // what if we need to walk these???
56             node.parentNode.insertBefore(ar[i], node);
57             if (this.tag !== false) {
58                 this.walk(ar[i]);
59                 
60             }
61         }
62         //Roo.log("REMOVE:" + node.tagName);
63         node.parentNode.removeChild(node);
64         return false; // don't walk children
65         
66         
67     }
68 });