1 | /** |
---|
2 | * t29v6 Logging subsystem |
---|
3 | * |
---|
4 | * Logging on client side is splitted in two parts: |
---|
5 | * 1. Javascript console.log calls which won't offend the user |
---|
6 | * 2. the t29.log class to notify the user. |
---|
7 | * |
---|
8 | * Considering console.log, the code is borrowed by HTML5 Boilerplate |
---|
9 | * |
---|
10 | * |
---|
11 | **/ |
---|
12 | |
---|
13 | // usage: log('inside coolFunc', this, arguments); |
---|
14 | // paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ |
---|
15 | window.log = function(){ |
---|
16 | log.history = log.history || []; // store logs to an array for reference |
---|
17 | log.history.push(arguments); |
---|
18 | if(this.console) { |
---|
19 | arguments.callee = arguments.callee.caller; |
---|
20 | var newarr = [].slice.call(arguments); |
---|
21 | (typeof console.log === 'object' ? log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr)); |
---|
22 | } |
---|
23 | }; |
---|
24 | |
---|
25 | // make it safe to use console.log always |
---|
26 | (function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try |
---|
27 | {console.log();return window.console;}catch(err){return window.console={};}})()); |
---|
28 | |
---|
29 | |
---|
30 | if(!t29) window.t29 = {}; // the t29 namespace |
---|
31 | t29.log = {}; // the t29.log namespace |
---|
32 | |
---|
33 | t29.log.setup = function() { |
---|
34 | // setup our spaces |
---|
35 | t29.log.$panel = $(".messages.panel"); |
---|
36 | t29.log.$end = $(".messages.footer"); |
---|
37 | |
---|
38 | // find end messages and push them to the first |
---|
39 | if((end_li = t29.log.$end.find("li")).length) { |
---|
40 | end_li.appendTo(t29.log.$panel); |
---|
41 | t29.log.$end.hide(); // hide bottom panel |
---|
42 | t29.log.$panel.removeClass("empty"); // show top panel |
---|
43 | } |
---|
44 | |
---|
45 | // setup some functions |
---|
46 | levels = ["emerg", "alert", "crit", "error", "warn", "notice", "info"]; |
---|
47 | $.each(levels, function() { |
---|
48 | level = this; |
---|
49 | t29.log[level] = function(msg) { t29.log.append(level, msg) } |
---|
50 | }); |
---|
51 | } |
---|
52 | |
---|
53 | t29.log.append = function(level, msg) { |
---|
54 | // tell the panel that it's now not empty (thus it will become CSS visible) |
---|
55 | t29.log.$panel.removeClass("empty"); |
---|
56 | |
---|
57 | if(jQuery.type(msg) == "string") |
---|
58 | s = msg; |
---|
59 | else { |
---|
60 | s = ""; |
---|
61 | if(msg.dismissable) s += "<button class='close'>×</button>"; |
---|
62 | if(msg.heading) s += "<h5>"+msg.heading+"</h5>"; |
---|
63 | if(msg.text) s += "<p>"+msg.text+"</p>"; |
---|
64 | } |
---|
65 | infoelement = $("<li>", {"class": level}).html(s).hide().appendTo(t29.log.$panel).slideDown(); |
---|
66 | |
---|
67 | // fill eventual close button with action |
---|
68 | $(infoelement).find("button.close").click(function(){ |
---|
69 | $(this).closest("li").slideUp(); |
---|
70 | }); |
---|
71 | } |
---|