more styling
[roojs1] / Roo / htmleditor / FilterStyleToTag.js
1
2 /**
3  * @class Roo.htmleditor.FilterStyleToTag
4  * part of the word stuff... - certain 'styles' should be converted to tags.
5  * eg.
6  *   font-weight: bold -> bold
7  *   ?? super / subscrit etc..
8  * 
9  * @constructor
10 * Run a new style to tag filter.
11 * @param {Object} config Configuration options
12  */
13 Roo.htmleditor.FilterStyleToTag = function(cfg)
14 {
15     
16     this.tags = {
17         B  : [ 'fontWeight' , 'bold'],
18         I :  [ 'fontStyle' , 'italic'],
19         //pre :  [ 'font-style' , 'italic'],
20         // h1.. h6 ?? font-size?
21         SUP : [ 'verticalAlign' , 'super' ],
22         SUB : [ 'verticalAlign' , 'sub' ]
23         
24         
25     };
26     
27     Roo.apply(this, cfg);
28      
29     
30     this.walk(cfg.node);
31     
32     
33     
34 }
35
36
37 Roo.extend(Roo.htmleditor.FilterStyleToTag, Roo.htmleditor.Filter,
38 {
39     tag: true, // all tags
40     
41     tags : false,
42     
43     
44     replaceTag : function(node)
45     {
46         
47         
48         if (node.getAttribute("style") === null) {
49             return true;
50         }
51         var inject = [];
52         for (var k in this.tags) {
53             if (node.style[this.tags[k][0]] == this.tags[k][1]) {
54                 inject.push(k);
55                 node.style.removeProperty(this.tags[k][0]);
56             }
57         }
58         if (!inject.length) {
59             return true; 
60         }
61         var cn = Array.from(node.childNodes);
62         var nn = node;
63         Roo.each(inject, function(t) {
64             var nc = node.ownerDocument.createElement(t);
65             nn.appendChild(nc);
66             nn = nc;
67         });
68         for(var i = 0;i < cn.length;cn++) {
69             node.removeChild(cn[i]);
70             nn.appendChild(cn[i]);
71         }
72         return true /// iterate thru
73     }
74     
75 })