de742375e7244d40506919811a1ae46a95eff8fd
[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     this.walk(cfg.node);
16 }
17
18 Roo.extend(Roo.htmleditor.FilterKeepChildren, Roo.htmleditor.FilterBlack,
19 {
20     
21   
22     replaceTag : function(node)
23     {
24         // walk children...
25         //Roo.log(node);
26         var ar = Array.from(node.childNodes);
27         //remove first..
28         for (var i = 0; i < ar.length; i++) {
29             if (ar[i].nodeType == 1) {
30                 if (
31                     (typeof(this.tag) == 'object' && this.tag.indexOf(ar[i].tagName) > -1)
32                     || // array and it matches
33                     (typeof(this.tag) == 'string' && this.tag == ar[i].tagName)
34                 ) {
35                     this.replaceTag(ar[i]); // child is blacklisted as well...
36                     continue;
37                 }
38             }
39         }  
40         ar = Array.from(node.childNodes);
41         for (var i = 0; i < ar.length; i++) {
42          
43             node.removeChild(ar[i]);
44             // what if we need to walk these???
45             node.parentNode.insertBefore(ar[i], node);
46             if (this.tag !== false) {
47                 this.walk(ar[i]);
48                 
49             }
50         }
51         node.parentNode.removeChild(node);
52         return false; // don't walk children
53         
54         
55     }
56 });