more styling
[roojs1] / Roo / htmleditor / FilterTableWidth.js
1 /**
2  * @class Roo.htmleditor.FilterTableWidth
3   try and remove table width data - as that frequently messes up other stuff.
4  * 
5  *      was cleanTableWidths.
6  *
7  * Quite often pasting from word etc.. results in tables with column and widths.
8  * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
9  *
10  * @constructor
11  * Run a new Table Filter
12  * @param {Object} config Configuration options
13  */
14
15 Roo.htmleditor.FilterTableWidth = function(cfg)
16 {
17     // no need to apply config.
18     this.tag = ['TABLE', 'TD', 'TR', 'TH', 'THEAD', 'TBODY' ];
19     this.walk(cfg.node);
20 }
21
22 Roo.extend(Roo.htmleditor.FilterTableWidth, Roo.htmleditor.Filter,
23 {
24      
25      
26     
27     replaceTag: function(node) {
28         
29         
30       
31         if (node.hasAttribute('width')) {
32             node.removeAttribute('width');
33         }
34         
35          
36         if (node.hasAttribute("style")) {
37             // pretty basic...
38             
39             var styles = node.getAttribute("style").split(";");
40             var nstyle = [];
41             Roo.each(styles, function(s) {
42                 if (!s.match(/:/)) {
43                     return;
44                 }
45                 var kv = s.split(":");
46                 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
47                     return;
48                 }
49                 // what ever is left... we allow.
50                 nstyle.push(s);
51             });
52             node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
53             if (!nstyle.length) {
54                 node.removeAttribute('style');
55             }
56         }
57         
58         return true; // continue doing children..
59     }
60 });