-
Notifications
You must be signed in to change notification settings - Fork 38
/
jquery.debug.uncompressed.js
74 lines (71 loc) · 2.72 KB
/
jquery.debug.uncompressed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Simple jQuery logger / debugger.
* Based on: http://jquery.com/plugins/Authoring/
* See var DEBUG below for turning debugging/logging on and off.
* Modified by Stephane Lenclud to support logging key/value object
*
* @version 20080225
* @since 2006-07-10
* @copyright Copyright (c) 2006 Glyphix Studio, Inc. http://www.glyphix.com, Copyright (c) 2008 Stephane Lenclud.
* @author Brad Brizendine <brizbane@gmail.com>
* @license MIT http://www.opensource.org/licenses/mit-license.php
* @requires >= jQuery 1.0.3
*/
// global debug switch ... add DEBUG = true; somewhere after jquery.debug.js is loaded to turn debugging on
var DEBUG = true;
(function($) {
// shamelessly ripped off from http://getfirebug.com/
if (!("console" in window) || !("firebug" in console)){
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
// create the logging div
$('body').append('<div id="DEBUG"><ol></ol></div>');
// attach a function to each of the firebug methods
window.console = {};
for (var i = 0; i < names.length; ++i){
window.console[names[i]] = function(msg){
var $debug = $("#DEBUG");
$debug.find('ol').append( '<li>' + msg + '</li>' );
$debug.scrollTop($debug[0].scrollHeight);
};
}
}
/*
* debug
* Simply loops thru each jquery item and logs it
*/
$.fn.debug = function() {
return this.each(function(){
$.log(this);
});
};
/*
* log
* Send it anything, and it will add a line to the logging console.
* If firebug is installed, it simple send the item to firebug.
* If not, it creates a string representation of the html element (if message is an object), or just uses the supplied value (if not an object).
*/
$.log = function(message){
// only if debugging is on
if( window.DEBUG ){
// if no firebug, build a debug line from the actual html element if it's an object, or just send the string
var str = message;
if( !('firebug' in console) ){
if( typeof(message) == 'object' ){
if (message.nodeName) {
str = '<';
str += message.nodeName.toLowerCase();
for( var i = 0; i < message.attributes.length; i++ ){
str += ' ' + message.attributes[i].nodeName.toLowerCase() + '="' + message.attributes[i].nodeValue + '"';
}
str += '>';
} else {
for(var key in message) {
str += key + " : " + (message[key]) + ", ";
}
}
}
}
console.debug(str);
}
};
})(jQuery);