/[Frey]/trunk/static/Frey/jQuery/log.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/static/Frey/jQuery/log.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 763 - (hide annotations)
Tue Dec 9 20:31:25 2008 UTC (15 years, 5 months ago) by dpavlin
File MIME type: application/javascript
File size: 2723 byte(s)
 r3622@llin (orig r741):  dpavlin | 2008-12-06 17:35:43 +0100
 initial import of no pager code from
 http://blog.rot13.org/2006/08/fun_with_jquery.html

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

  ViewVC Help
Powered by ViewVC 1.1.26