more styling
[roojs1] / Roo / htmleditor / FilterLongBr.js
1 /**
2  * @class Roo.htmleditor.FilterLongBr
3  * BR/BR/BR - keep a maximum of 2...
4  * @constructor
5  * Run a new Long BR Filter
6  * @param {Object} config Configuration options
7  */
8
9 Roo.htmleditor.FilterLongBr = function(cfg)
10 {
11     // no need to apply config.
12     this.walk(cfg.node);
13 }
14
15 Roo.extend(Roo.htmleditor.FilterLongBr, Roo.htmleditor.Filter,
16 {
17     
18      
19     tag : 'BR',
20     
21      
22     replaceTag : function(node)
23     {
24         
25         var ps = node.nextSibling;
26         while (ps && ps.nodeType == 3 && ps.nodeValue.trim().length < 1) {
27             ps = ps.nextSibling;
28         }
29         
30         if (!ps &&  [ 'TD', 'TH', 'LI', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ].indexOf(node.parentNode.tagName) > -1) { 
31             node.parentNode.removeChild(node); // remove last BR inside one fo these tags
32             return false;
33         }
34         
35         if (!ps || ps.nodeType != 1) {
36             return false;
37         }
38         
39         if (!ps || ps.tagName != 'BR') {
40            
41             return false;
42         }
43         
44         
45         
46         
47         
48         if (!node.previousSibling) {
49             return false;
50         }
51         var ps = node.previousSibling;
52         
53         while (ps && ps.nodeType == 3 && ps.nodeValue.trim().length < 1) {
54             ps = ps.previousSibling;
55         }
56         if (!ps || ps.nodeType != 1) {
57             return false;
58         }
59         // if header or BR before.. then it's a candidate for removal.. - as we only want '2' of these..
60         if (!ps || [ 'BR', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ].indexOf(ps.tagName) < 0) {
61             return false;
62         }
63         
64         node.parentNode.removeChild(node); // remove me...
65         
66         return false; // no need to do children
67
68     }
69     
70 });