fix #8042 - clean up empty tags
[roojs1] / Roo / htmleditor / FilterEmpty.js
1 /**
2  * @class Roo.htmleditor.FilterEmpty
3  * filter empty elements
4  * @constructor
5  * Run a new Empty Filter
6  * @param {Object} config Configuration options
7  */
8
9 Roo.htmleditor.FilterEmpty = function(cfg)
10 {
11     // no need to apply config.
12     this.walk(cfg.node);
13 }
14
15 Roo.extend(Roo.htmleditor.FilterEmpty, Roo.htmleditor.FilterBlack,
16 {
17      
18     tag : true,
19      
20  
21     replaceTag : function(node)
22     {
23         // start from leaf node
24         if(node.hasChildNodes()) {
25             this.walk(node);
26         }
27
28         // only filter empty leaf element with certain tags
29         if(
30             ['B', 'I', 'U', 'S'].indexOf(node.tagName) < 0
31             ||
32             node.attributes && node.attributes.length > 0
33             ||
34             node.hasChildNodes()
35         ) {
36             return false; // don't walk
37         }
38
39         Roo.htmleditor.FilterBlack.prototype.replaceTag.call(this, node);
40         return false; // don't walk
41      
42     }
43     
44 });