4 |
2006-08-18 Dobrica Pavlinusic <dpavlin@rot13.org> |
2006-08-18 Dobrica Pavlinusic <dpavlin@rot13.org> |
5 |
*/ |
*/ |
6 |
|
|
7 |
var _log_count; |
var _jql; |
8 |
|
|
9 |
$.log = { |
$.log = { |
10 |
|
|
17 |
return m; |
return m; |
18 |
}, |
}, |
19 |
|
|
20 |
counter: function() { |
insert: function(class, m) { |
21 |
$('#debug-counter').html( |
if (! _jql) this.create(); |
22 |
'<span class="log-info">'+_log_count.info+'</span> ' + |
|
23 |
'<span class="log-debug">'+_log_count.debug+'</span> ' + |
_jql.count[ class ]++; |
24 |
'<span class="log-error">'+_log_count.error+'</span>' |
|
25 |
|
var html = '<div class="jql-' + class + '"' |
26 |
|
if ( ! _jql.on[class] ) html += ' style="display:none"'; |
27 |
|
html += '>' + m + '</div>'; |
28 |
|
$('#jql-log').append( html ); |
29 |
|
//$('#jql-log').prepend( html ); |
30 |
|
|
31 |
|
// refresh count |
32 |
|
$('#jql-counter').html( |
33 |
|
'<span class="jql-info">'+_jql.count.info+'</span> ' + |
34 |
|
'<span class="jql-debug">'+_jql.count.debug+'</span> ' + |
35 |
|
'<span class="jql-error">'+_jql.count.error+'</span>' |
36 |
); |
); |
|
}, |
|
37 |
|
|
38 |
toggle: function() { |
// poor man's scroll to bottom |
39 |
$('#debug').toggle(); |
var e = document.getElementById('jql-log'); |
40 |
$('#debug_show').toggle(); |
e.scrollTop = e.scrollHeight - e.clientHeight; |
|
return false; |
|
41 |
}, |
}, |
42 |
|
|
43 |
/* public functions */ |
/* public functions */ |
45 |
create: function() { |
create: function() { |
46 |
|
|
47 |
$('body').append( |
$('body').append( |
48 |
'<div id="debug" class="debug">' + |
'<div id="jql" class="jql"><div id="jql-bar">' + |
49 |
'<a class="hide" href="#" onclick="javascript:return $.log.toggle();">X</a>' + |
'<a href="#" onclick="javascript:return $.log.clean();">clean</a> | ' + |
50 |
'</div>' + |
'<a href="#" class=".jql-info" onclick="javascript:return $.log.toggle(\'info\');">info</a> ' + |
51 |
'<div id="debug_show" class="debug">' + |
'<a href="#" class=".jql-debug" onclick="javascript:return $.log.toggle(\'debug\');">debug</a> ' + |
52 |
'<a class="hide" href="#" onclick="javascript:return $.log.toggle();"><span id="debug-counter">?</span></a>' + |
'<a href="#" class=".jql-error" onclick="javascript:return $.log.toggle(\'error\');">error</a> | ' + |
53 |
|
'<a href="#" onclick="javascript:return $.log.toggle();">close</a>' + |
54 |
|
'</div><div id="jql-log"></div></div>' + |
55 |
|
'<div id="jql-show" class="jql">' + |
56 |
|
'<a href="#" onclick="javascript:return $.log.toggle();"><span id="jql-counter">?</span></a>' + |
57 |
'</div>' |
'</div>' |
58 |
); |
); |
59 |
|
|
60 |
_log_count = { |
_jql = { |
61 |
info: 0, |
count: { |
62 |
debug: 0, |
info: 0, |
63 |
error: 0 |
debug: 0, |
64 |
|
error: 0 |
65 |
|
}, |
66 |
|
on: { |
67 |
|
info: true, |
68 |
|
debug: true, |
69 |
|
error: true |
70 |
|
} |
71 |
}; |
}; |
72 |
|
|
73 |
this.debug('created logger'); |
this.debug('created logger'); |
74 |
}, |
}, |
75 |
|
|
76 |
info: function() { |
/* onclick events */ |
77 |
if (arguments) { |
|
78 |
if (! _log_count) this.create(); |
toggle: function( what ) { |
79 |
_log_count.info++; |
if (what) { |
80 |
$('#debug').append( '<div class="log-info">'+this.join(arguments)+'</div>' ); |
$.log.debug('toggle '+what); |
81 |
this.counter(); |
$('.jql-'+what).toggle(); |
82 |
|
_jql.on[what] = ! _jql.on[what]; |
83 |
|
} else { |
84 |
|
$.log.debug('toggle logger'); |
85 |
|
$('#jql').toggle(); |
86 |
|
$('#jql-show').toggle(); |
87 |
} |
} |
88 |
|
return false; |
89 |
|
}, |
90 |
|
|
91 |
|
clean: function() { |
92 |
|
$('#jql-log').html(''); |
93 |
|
}, |
94 |
|
|
95 |
|
/* public methods to call from your code */ |
96 |
|
|
97 |
|
info: function() { |
98 |
|
if (arguments) this.insert( 'info', this.join(arguments) ); |
99 |
}, |
}, |
100 |
debug: function() { |
debug: function() { |
101 |
if (arguments) { |
if (arguments) this.insert( 'debug', this.join(arguments) ); |
|
if (! _log_count) this.create(); |
|
|
_log_count.debug++; |
|
|
$('#debug').append( '<div class="log-debug">'+this.join(arguments)+'</div>' ); |
|
|
this.counter(); |
|
|
} |
|
102 |
}, |
}, |
103 |
error: function() { |
error: function() { |
104 |
if (arguments) { |
if (arguments) this.insert( 'error', this.join(arguments) ); |
|
if (! _log_count) this.create(); |
|
|
_log_count.error++; |
|
|
$('#debug').append( '<div class="log-error">'+this.join(arguments)+'</div>' ); |
|
|
this.counter(); |
|
|
} |
|
105 |
} |
} |
106 |
}; |
}; |
107 |
|
|