inliner.js
[app.webkitpdf] / inliner.js
1
2
3
4 (function(){
5     
6     var camelize = function(a,b){
7         return b.toUpperCase();
8     }
9     
10     var keys = ['fontFamily','fontSize','fontWeight','fontStyle','color',
11         'textTransform','textDecoration','letterSpacing','wordSpacing',
12         'lineHeight','textAlign','verticalAlign','direction','backgroundColor',
13         'backgroundImage','backgroundRepeat','backgroundposition',
14         'backgroundAttachment','opacity','width','height','top','right','bottom',
15         'left','marginTop','marginRight','marginBottom','marginLeft',
16         'paddingTop','paddingRight','paddingBottom','paddingLeft',
17         'borderTopWidth','borderRightWidth','borderBottomWidth',
18         'borderLeftWidth','borderTopColor','borderRightColor',
19         'borderBottomColor','borderLeftColor','borderTopStyle',
20         'borderRightStyle','borderBottomStyle','borderLeftStyle','position',
21         'display','visibility','zIndex','overflowX','overflowY','whiteSpace',
22         'clip','float','clear','cursor','listStyleImage','listStylePosition',
23         'listStyleType','markerOffset'
24     ];
25     
26     var fillStyle = function(dom)
27     {
28         if (!dom || dom.nodeType != 1) {
29             return;
30         }
31         console.log(dom.nodeName);
32         
33         var style = window.getComputedStyle(dom, null);
34         if (style.display == 'none') {
35             dom.parentElement.removeChild(dom);
36             return;
37         }
38         
39         for (var i = dom.childNodes.length -1; i--; i> -1) {
40             fillStyle(dom.childNodes[i]);
41         }
42         
43         
44         
45         //var pstyle = false;
46         //if (dom.nodeName != 'BODY') {
47         //    pstyle = window.getComputedStyle(dom.parentElement, null);
48         //}
49          
50         
51         
52         //if (dom.nodeName == 'LI') {            throw 'done';        }
53         
54         
55         for(var i=0;i<style.length;i++){
56             var prop = style[i];
57             var camel = prop.replace(/\-([a-z])/g, camelize);
58             var val = style.getPropertyValue(prop);
59             //returns[camel] = val;
60             
61             // idea... if the parent has the same style.. then do not apply it to the child?
62             //if (pstyle && pstyle[prop] == val) {
63             //    continue;
64             //}
65             console.log(prop + '=' + val);
66             
67             dom.style[camel] = val;
68          
69             
70         }
71         var es = dom.getAttribute('style');
72         console.log(node.nodeName + '::' + es);
73         dom.setAtrtribute('style', es);
74         
75         //return returns;
76     }
77     var el = document.querySelector('body');
78     fillStyle(el);
79     
80     var matches = document.getElementsByTagName('style');
81     for(var i =0;i < matches.length;i++) {
82         matches[i].parentElement.removeChild(matches[i]);
83     }
84     var matches = document.getElementsByTagName('link');
85     for(var i =0;i < matches.length;i++) {
86         matches[i].parentElement.removeChild(matches[i]);
87     }
88      
89     
90 })();