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             st.appendChild(document.createTextNode("\n" + 
24                 '#fauxconsole{' +
25                 '    position:absolute;' +
26                 '    top:0;'+
27                 '    right:0;'+
28                 '    width:300px;'+
29                 '    border:1px solid #999;'+
30                 '    font-family:courier,monospace;'+
31                 '    background:#eee;'+
32                 '    font-size:10px;'+
33                 '    padding:10px;'+
34                 '}'+
35                 'html>body #fauxconsole{'+
36                 '    position:fixed;'+
37                 '}'+
38                 '#fauxconsole a{'+
39                 '    float:right;'+
40                 '    padding-left:1em;'+
41                 '    padding-bottom:.5em;'+
42                 '    text-align:right;'+
43                 '}')); 
44             
45             
46             document.getElementsByTagName("head")[0].appendChild(st);
47             
48             
49         },
50         hide:function(){
51             console.d.style.display='none';
52         },
53         show:function(){
54             console.d.style.display='block';
55         },
56         log:function(o){
57             console.d.innerHTML+='<br/>'+o;
58             console.show();
59         },
60         clear:function(){
61             console.d.parentNode.removeChild(console.d);
62             console.init();
63             console.show();
64         },
65         /*Simon Willison rules*/
66         addLoadEvent:function(func){
67             var oldonload=window.onload;
68             if(typeof window.onload!='function'){
69                 window.onload=func;
70             }else{
71                 window.onload=function(){
72                     if(oldonload){
73                         oldonload();
74                     }
75                     func();
76                 };
77             }
78         }
79     };
80     console.addLoadEvent(console.init);
81 }