/[drupal]/contributions/modules/carbon/carbon_debug.js
ViewVC logotype

Contents of /contributions/modules/carbon/carbon_debug.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Tue Apr 28 13:00:55 2009 UTC (6 months, 4 weeks ago) by johnackers
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Changes since 1.2: +2 -2 lines
File MIME type: text/javascript
Ensure that default scope value set correctly and corresponding text is shown.
1 /* $Id: carbon_debug.js,v 1.2 2009/04/20 14:34:40 johnackers Exp $
2 *
3 * These js functions dump objects below #main
4 *
5 */
6
7 Drupal.behaviors.carbon_debug = function () {
8 {
9 fieldset = $('#footer').append(
10 "<fieldset class='collapsible collapsed' id='debugPanel'>" +
11 "<legend>ajax log</legend>" +
12 "<div id='debugLog'></div>" +
13 "</fieldset>");
14 addJQueryForm();
15 Drupal.behaviors.collapse(fieldset);
16 $('div#nojavascript').remove();
17 log("carbon_debug initialised and logging");
18 }};
19
20
21
22 /**
23 * Put up a box into which jQuery requests can be processed
24 * @param none
25 * @return null
26 */
27
28 function addJQueryForm()
29 {
30 formHTML =
31 '<form id="jQueryEval">' +
32 '<input type="submit" maxlength="30" name="jquery" value="evaluate jQuery" />' +
33 '<input type="text" maxlength="30" name="query" class="queryText" description="try #jQueryEval"/>' +
34 '</form>';
35
36 $('#debugPanel').append("<p>" + formHTML + "</p>").submit( function() { return handleJQueryRequest() } );
37 }
38
39
40 function handleJQueryRequest()
41 {
42 theQuery = $("form#jQueryEval > input.queryText").attr("value");
43 res = $(theQuery);
44 // for (var item in res)
45 logJQueryObject(theQuery, res);
46 return false ;
47 }
48
49
50
51 /**
52 * used to report Ajax transfer error
53 * @param msg
54 * @return
55 */
56
57 function handleError(msg)
58 {
59 alert( "js Error, data got: " + msg);
60 }
61
62
63 // logging functions. There should be no naming conflicts as
64 // all the functions are controlled by the carbon noudule (apart
65 // from drupal here).
66
67 function log(text)
68 {
69 var div = document.getElementById("debugLog");
70 // text.replace(/\n/, "<BR/>")
71 if (div == null)
72 alert(Date().substr(16,8) + " #debugLog has been wiped out! " + text.substr(0,80) );
73 else
74 div.innerHTML += "<br/>" + Date().substr(16,8) + " " + text ;
75 }
76
77
78 function logObject(obj)
79 {
80 logObject2("", obj);
81 }
82
83 function logObject2(prefix, obj)
84 {
85 log(dumpObj(prefix, obj,"",0));
86 }
87
88
89 var MAX_DUMP_DEPTH = 2;
90
91 function dumpObj(name, obj, indent, depth)
92 {
93 var output = "" ;
94
95 if (depth > MAX_DUMP_DEPTH) {
96 return output ;
97 }
98 if (typeof obj == "object") {
99 var child = null;
100
101 indent += "&nbsp;&nbsp;&nbsp;&nbsp;";
102 for (var item in obj)
103 {
104 try {
105 child = obj[item];
106 output += dumpObj(name + "." + item, child, indent, depth + 1);
107 } catch (e) {
108 output += "<Unable to Evaluate" + item + ">";
109 }
110 }
111 return output;
112 }
113 else
114 {
115 if (typeof obj == "string")
116 {
117 output += indent + name + ":s: " + obj + "<br/>";
118 }
119 if (typeof obj == "boolean")
120 {
121 output += indent + name + ":b: " + obj + "<br/>";
122 }
123 if (typeof obj == "number")
124 {
125 output += indent + name + ":n: " + obj + "<br/>";
126 }
127 }
128 return output ;
129 }
130
131
132 function logJQueryObject(prefix, a)
133 {
134 if (a == undefined)
135 {
136 log("logJQueryObject: too few arguments"); return ;
137 }
138 logObject2(prefix, a);
139 }
140
141
142 // js debug functions
143
144 //pre-submit callback
145 function showRequest(formData, jqForm, options) {
146 // formData is an array; here we use $.param to convert it to a string to display it
147 // but the form plugin does this for you automatically when it submits the data
148 var queryString = $.param(formData);
149
150 // jqForm is a jQuery object encapsulating the form element. To access the
151 // DOM element for the form do this:
152 // var formElement = jqForm[0];
153 log('About to submit: ' + queryString);
154 log('About to URL: ' + options.url);
155 // here we could return false to prevent the form from being submitted;
156 // returning anything other than false will allow the form submit to continue
157 return true;
158 }
159
160
161 //post-submit callback
162 function showResponse(responseText, statusText) {
163 // for normal html responses, the first argument to the success callback
164 // is the XMLHttpRequest object's responseText property
165
166 // if the ajaxForm method was passed an Options Object with the dataType
167 // property set to 'xml' then the first argument to the success callback
168 // is the XMLHttpRequest object's responseXML property
169
170 // if the ajaxForm method was passed an Options Object with the dataType
171 // property set to 'json' then the first argument to the success callback
172 // is the json data object returned by the server
173
174 alert('status: ' + statusText + '\n\nresponseText: \n' + responseText.substr +
175 '\n\nThe output div should have already been updated with the responseText.');
176 }

  ViewVC Help
Powered by ViewVC 1.1.2