ux/ieconsole.js
[roojs1] / ux / ieconsole.js
1 /* Faux Console by Chris Heilmann http://wait-till-i.com */ 
2 if(!window.console){
3         var console={
4                 init:function(){
5                         console.d=document.createElement('div');
6                         document.body.appendChild(console.d);
7                         var a=document.createElement('a');
8                         a.href='javascript:console.hide()';
9             a.innerHTML='close';
10             console.d.appendChild(a);
11             var a=document.createElement('a');
12             a.href='javascript:console.clear();';
13             a.innerHTML='clear';
14             console.d.appendChild(a);
15             var id='fauxconsole';
16             if(!document.getElementById(id)){
17                 console.d.id=id;
18             }
19             console.hide();
20             var st = document.createElement('style');
21             st.type="text/css";
22             st.media="all";
23             
24             var cssStr = "div {color:blue;}";
25             var style = document.createElement("style");
26             style.setAttribute("type", "text/css");
27              
28             style.styleSheet.cssText = "\n" + 
29                 '#fauxconsole{' +
30                 '    position:absolute;' +
31                 '    top:0;'+
32                 '    right:0;'+
33                 '    width:300px;'+
34                 '    border:1px solid #999;'+
35                 '    font-family:courier,monospace;'+
36                 '    background:#eee;'+
37                 '    font-size:10px;'+
38                 '    padding:10px;'+
39                 '}'+
40                 'html>body #fauxconsole{'+
41                 '    position:fixed;'+
42                 '}'+
43                 '#fauxconsole a{'+
44                 '    float:right;'+
45                 '    padding-left:1em;'+
46                 '    padding-bottom:.5em;'+
47                 '    text-align:right;'+
48                 '}'; 
49             
50             
51             document.getElementsByTagName("head")[0].appendChild(st);
52             
53             
54         },
55         hide:function(){
56             console.d.style.display='none';
57         },
58         show:function(){
59             console.d.style.display='block';
60         },
61         log:function(o){
62             console.d.innerHTML+='<br/>'+o;
63             console.show();
64         },
65         clear:function(){
66             console.d.parentNode.removeChild(console.d);
67             console.init();
68             console.show();
69         },
70         /*Simon Willison rules*/
71         addLoadEvent:function(func){
72             var oldonload=window.onload;
73             if(typeof window.onload!='function'){
74                 window.onload=func;
75             }else{
76                 window.onload=function(){
77                     if(oldonload){
78                         oldonload();
79                     }
80                     func();
81                 };
82             }
83         }
84     };
85     console.addLoadEvent(console.init);
86 }