5c6252a562bc71186bc353c6828053cfa8e9e005.svn-base 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. if (!dojo._hasResource["dojo._firebug.firebug"]) { // _hasResource checks added
  2. // by build. Do not use
  3. // _hasResource directly in
  4. // your code.
  5. dojo._hasResource["dojo._firebug.firebug"] = true;
  6. dojo.provide("dojo._firebug.firebug");
  7. dojo.deprecated = function(/* String */behaviour, /* String? */extra, /* String? */
  8. removal) {
  9. // summary:
  10. // Log a debug message to indicate that a behavior has been
  11. // deprecated.
  12. // extra: Text to append to the message.
  13. // removal:
  14. // Text to indicate when in the future the behavior will be removed.
  15. var message = "DEPRECATED: " + behaviour;
  16. if (extra) {
  17. message += " " + extra;
  18. }
  19. if (removal) {
  20. message += " -- will be removed in version: " + removal;
  21. }
  22. console.debug(message);
  23. }
  24. dojo.experimental = function(/* String */moduleName, /* String? */extra) {
  25. // summary: Marks code as experimental.
  26. // description:
  27. // This can be used to mark a function, file, or module as
  28. // experimental. Experimental code is not ready to be used, and the
  29. // APIs are subject to change without notice. Experimental code may be
  30. // completed deleted without going through the normal deprecation
  31. // process.
  32. // moduleName:
  33. // The name of a module, or the name of a module file or a specific
  34. // function
  35. // extra:
  36. // some additional message for the user
  37. // example:
  38. // | dojo.experimental("dojo.data.Result");
  39. // example:
  40. // | dojo.experimental("dojo.weather.toKelvin()", "PENDING approval from
  41. // NOAA");
  42. var message = "EXPERIMENTAL: " + moduleName
  43. + " -- APIs subject to change without notice.";
  44. if (extra) {
  45. message += " " + extra;
  46. }
  47. console.debug(message);
  48. }
  49. // FIREBUG LITE
  50. // summary: Firebug Lite, the baby brother to Joe Hewitt's Firebug for
  51. // Mozilla Firefox
  52. // description:
  53. // Opens a console for logging, debugging, and error messages.
  54. // Contains partial functionality to Firebug. See function list below.
  55. // NOTE:
  56. // Firebug is a Firefox extension created by Joe Hewitt (see license). You
  57. // do not need Dojo to run Firebug.
  58. // Firebug Lite is included in Dojo by permission from Joe Hewitt
  59. // If you are new to Firebug, or used to the Dojo 0.4 dojo.debug, you can
  60. // learn Firebug
  61. // functionality by reading the function comments below or visiting
  62. // http://www.getfirebug.com/docs.html
  63. // NOTE:
  64. // To test Firebug Lite in Firefox, set console = null;
  65. //
  66. // example:
  67. // Supports inline objects in object inspector window (only simple trace of
  68. // dom nodes, however)
  69. // | console.log("my object", {foo:"bar"})
  70. // example:
  71. // Option for console to open in popup window
  72. // | var djConfig = {isDebug: true, popup:true };
  73. // example:
  74. // Option for console height (ignored for popup)
  75. // | var djConfig = {isDebug: true, debugHeight:100 };
  76. if (((!("console" in window)) || (!("firebug" in console)))
  77. && ((djConfig["noFirebugLite"] !== true))) {
  78. (function() {
  79. // don't build a firebug frame in iframes
  80. try {
  81. if (window != window.parent) {
  82. // but if we've got a parent logger, connect to it
  83. if (window.parent["console"]) {
  84. window.console = window.parent.console;
  85. }
  86. return;
  87. }
  88. } catch (e) {
  89. }
  90. window.console = {
  91. log : function() {
  92. // summary:
  93. // Sends arguments to console.
  94. logFormatted(arguments, "");
  95. },
  96. debug : function() {
  97. // summary:
  98. // Sends arguments to console. Missing finctionality to show
  99. // script line of trace.
  100. logFormatted(arguments, "debug");
  101. },
  102. info : function() {
  103. // summary:
  104. // Sends arguments to console, highlighted with (I) icon.
  105. logFormatted(arguments, "info");
  106. },
  107. warn : function() {
  108. // summary:
  109. // Sends warning arguments to console, highlighted with (!)
  110. // icon and blue style.
  111. logFormatted(arguments, "warning");
  112. },
  113. error : function() {
  114. // summary:
  115. // Sends error arguments (object) to console, highlighted
  116. // with (X) icon and yellow style
  117. // NEW: error object now displays in object inspector
  118. logFormatted(arguments, "error");
  119. },
  120. assert : function(truth, message) {
  121. // summary:
  122. // Tests for true. Throws exception if false.
  123. if (!truth) {
  124. var args = [];
  125. for (var i = 1; i < arguments.length; ++i) {
  126. args.push(arguments[i]);
  127. }
  128. logFormatted(
  129. args.length ? args : ["Assertion Failure"],
  130. "error");
  131. throw message ? message : "Assertion Failure";
  132. }
  133. },
  134. dir : function(object) {
  135. // summary:
  136. // Traces object. Only partially implemented.
  137. var html = [];
  138. var pairs = [];
  139. for (var name in object) {
  140. try {
  141. pairs.push([name, object[name]]);
  142. } catch (e) {
  143. /* squelch */
  144. }
  145. }
  146. pairs.sort(function(a, b) {
  147. return a[0] < b[0] ? -1 : 1;
  148. });
  149. html.push('<table>');
  150. for (var i = 0; i < pairs.length; ++i) {
  151. var name = pairs[i][0], value = pairs[i][1];
  152. html
  153. .push(
  154. '<tr>',
  155. '<td class="propertyNameCell"><span class="propertyName">',
  156. escapeHTML(name), '</span></td>',
  157. '<td><span class="propertyValue">');
  158. appendObject(value, html);
  159. html.push('</span></td></tr>');
  160. }
  161. html.push('</table>');
  162. logRow(html, "dir");
  163. },
  164. dirxml : function(node) {
  165. // summary:
  166. //
  167. var html = [];
  168. appendNode(node, html);
  169. logRow(html, "dirxml");
  170. },
  171. group : function() {
  172. // summary:
  173. // collects log messages into a group, starting with this
  174. // call and ending with
  175. // groupEnd(). Missing collapse functionality
  176. logRow(arguments, "group", pushGroup);
  177. },
  178. groupEnd : function() {
  179. // summary:
  180. // Closes group. See above
  181. logRow(arguments, "", popGroup);
  182. },
  183. time : function(name) {
  184. // summary:
  185. // Starts timers assigned to name given in argument. Timer
  186. // stops and displays on timeEnd(title);
  187. // example:
  188. // | console.time("load");
  189. // | console.time("myFunction");
  190. // | console.timeEnd("load");
  191. // | console.timeEnd("myFunction");
  192. timeMap[name] = (allGetServerTime()).getTime();
  193. },
  194. timeEnd : function(name) {
  195. // summary:
  196. // See above.
  197. if (name in timeMap) {
  198. var delta = (allGetServerTime()).getTime() - timeMap[name];
  199. logFormatted([name + ":", delta + "ms"]);
  200. delete timeMap[name];
  201. }
  202. },
  203. count : function() {
  204. // summary:
  205. // Not supported
  206. this.warn(["count() not supported."]);
  207. },
  208. trace : function() {
  209. // summary:
  210. // Not supported
  211. this.warn(["trace() not supported."]);
  212. },
  213. profile : function() {
  214. // summary:
  215. // Not supported
  216. this.warn(["profile() not supported."]);
  217. },
  218. profileEnd : function() {
  219. },
  220. clear : function() {
  221. // summary:
  222. // Clears message console. Do not call this directly
  223. consoleBody.innerHTML = "";
  224. },
  225. open : function() {
  226. // summary:
  227. // Opens message console. Do not call this directly
  228. toggleConsole(true);
  229. },
  230. close : function() {
  231. // summary:
  232. // Closes message console. Do not call this directly
  233. if (frameVisible) {
  234. toggleConsole();
  235. }
  236. },
  237. closeObjectInspector : function() {
  238. // summary:
  239. // Closes object inspector and opens message console. Do not
  240. // call this directly
  241. consoleObjectInspector.innerHTML = "";
  242. consoleObjectInspector.style.display = "none";
  243. consoleBody.style.display = "block";
  244. }
  245. };
  246. // ***************************************************************************
  247. // using global objects so they can be accessed
  248. // most of the objects in this script are run anonomously
  249. var _firebugDoc = document;
  250. var _firebugWin = window;
  251. var __consoleAnchorId__ = 0;
  252. var consoleFrame = null;
  253. var consoleBody = null;
  254. var commandLine = null;
  255. var frameVisible = false;
  256. var messageQueue = [];
  257. var groupStack = [];
  258. var timeMap = {};
  259. var clPrefix = ">>> ";
  260. // ***************************************************************************
  261. function toggleConsole(forceOpen) {
  262. frameVisible = forceOpen || !frameVisible;
  263. if (consoleFrame) {
  264. consoleFrame.style.display = frameVisible
  265. ? "block"
  266. : "none";
  267. }
  268. }
  269. function focusCommandLine() {
  270. toggleConsole(true);
  271. if (commandLine) {
  272. commandLine.focus();
  273. }
  274. }
  275. openWin = function() {
  276. var win = window
  277. .open("", "_firebug",
  278. "status=0,menubar=0,resizable=1,width=640,height=480,scrollbars=1,addressbar=0");
  279. var newDoc = win.document;
  280. HTMLstring = '<html><head><title>Firebug Lite</title></head>\n';
  281. HTMLstring += '<body bgColor="#CCCCCC">\n';
  282. // Testing access to dojo from the popup window
  283. /*
  284. * HTMLstring+='<button onclick="(function(){
  285. * console.log(dojo.version.toString()); })()">Test Parent Dojo</button>\n';
  286. */
  287. HTMLstring += '<div id="fb"></div>';
  288. HTMLstring += '</body></html>';
  289. newDoc.write(HTMLstring);
  290. newDoc.close();
  291. return win;
  292. }
  293. function createFrame() {
  294. if (consoleFrame) {
  295. return;
  296. }
  297. if (djConfig.popup) {
  298. _firebugWin = openWin();
  299. _firebugDoc = _firebugWin.document;
  300. djConfig.debugContainerId = 'fb';
  301. var containerHeight = "100%";
  302. // connecting popup
  303. _firebugWin.console = window.console;
  304. _firebugWin.dojo = window.dojo;
  305. } else {
  306. _firebugDoc = document;
  307. var containerHeight = (djConfig.debugHeight)
  308. ? djConfig.debugHeight + "px"
  309. : "300px";
  310. }
  311. var styleElement = _firebugDoc.createElement("link");
  312. styleElement.href = dojo.moduleUrl("dojo._firebug",
  313. "firebug.css");
  314. styleElement.rel = "stylesheet";
  315. styleElement.type = "text/css";
  316. var styleParent = _firebugDoc.getElementsByTagName("head");
  317. if (styleParent) {
  318. styleParent = styleParent[0];
  319. }
  320. if (!styleParent) {
  321. styleParent = _firebugDoc.getElementsByTagName("html")[0];
  322. }
  323. if (dojo.isIE) {
  324. window.setTimeout(function() {
  325. styleParent.appendChild(styleElement);
  326. }, 0);
  327. } else {
  328. styleParent.appendChild(styleElement);
  329. }
  330. if (typeof djConfig != "undefined"
  331. && djConfig["debugContainerId"]) {
  332. consoleFrame = _firebugDoc
  333. .getElementById(djConfig.debugContainerId);
  334. }
  335. if (!consoleFrame) {
  336. consoleFrame = _firebugDoc.createElement("div");
  337. _firebugDoc.body.appendChild(consoleFrame);
  338. }
  339. consoleFrame.className += " firebug";
  340. consoleFrame.style.height = containerHeight;
  341. consoleFrame.style.display = (frameVisible ? "block" : "none");
  342. var closeStr = (djConfig.popup)
  343. ? ""
  344. : ' <a href="javascript:;" onclick="console.close(); return false;">Close</a>';
  345. consoleFrame.innerHTML = '<div id="firebugToolbar">'
  346. + ' <a href="javascript:;" onclick="console.clear(); return false;">Clear</a>'
  347. + ' <span class="firebugToolbarRight">' + closeStr
  348. + ' </span>' + '</div>'
  349. + '<input type="text" id="firebugCommandLine">'
  350. + '<div id="firebugLog"></div>'
  351. + '<div id="objectLog" style="display:none;"></div>';
  352. var toolbar = _firebugDoc.getElementById("firebugToolbar");
  353. toolbar.onmousedown = onSplitterMouseDown;
  354. commandLine = _firebugDoc.getElementById("firebugCommandLine");
  355. addEvent(commandLine, "keydown", onCommandLineKeyDown);
  356. addEvent(_firebugDoc, dojo.isIE || dojo.isSafari
  357. ? "keydown"
  358. : "keypress", onKeyDown);
  359. consoleBody = _firebugDoc.getElementById("firebugLog");
  360. consoleObjectInspector = _firebugDoc
  361. .getElementById("objectLog");
  362. layout();
  363. flush();
  364. }
  365. dojo.addOnLoad(createFrame);
  366. function evalCommandLine() {
  367. var text = commandLine.value;
  368. commandLine.value = "";
  369. logRow([clPrefix, text], "command");
  370. var value;
  371. try {
  372. value = eval(text);
  373. } catch (e) {
  374. console.debug(e);
  375. /* squelch */
  376. }
  377. console.log(value);
  378. }
  379. function layout() {
  380. var toolbar = consoleBody.ownerDocument
  381. .getElementById("firebugToolbar");
  382. var height = consoleFrame.offsetHeight
  383. - (toolbar.offsetHeight + commandLine.offsetHeight);
  384. consoleBody.style.top = toolbar.offsetHeight + "px";
  385. consoleBody.style.height = height + "px";
  386. commandLine.style.top = (consoleFrame.offsetHeight - commandLine.offsetHeight)
  387. + "px";
  388. }
  389. function logRow(message, className, handler) {
  390. if (consoleBody) {
  391. writeMessage(message, className, handler);
  392. } else {
  393. messageQueue.push([message, className, handler]);
  394. }
  395. }
  396. function flush() {
  397. var queue = messageQueue;
  398. messageQueue = [];
  399. for (var i = 0; i < queue.length; ++i) {
  400. writeMessage(queue[i][0], queue[i][1], queue[i][2]);
  401. }
  402. }
  403. function writeMessage(message, className, handler) {
  404. var isScrolledToBottom = consoleBody.scrollTop
  405. + consoleBody.offsetHeight >= consoleBody.scrollHeight;
  406. handler = handler || writeRow;
  407. handler(message, className);
  408. if (isScrolledToBottom) {
  409. consoleBody.scrollTop = consoleBody.scrollHeight
  410. - consoleBody.offsetHeight;
  411. }
  412. }
  413. function appendRow(row) {
  414. var container = groupStack.length
  415. ? groupStack[groupStack.length - 1]
  416. : consoleBody;
  417. container.appendChild(row);
  418. }
  419. function writeRow(message, className) {
  420. var row = consoleBody.ownerDocument.createElement("div");
  421. row.className = "logRow"
  422. + (className ? " logRow-" + className : "");
  423. row.innerHTML = message.join("");
  424. appendRow(row);
  425. }
  426. function pushGroup(message, className) {
  427. logFormatted(message, className);
  428. var groupRow = consoleBody.ownerDocument.createElement("div");
  429. groupRow.className = "logGroup";
  430. var groupRowBox = consoleBody.ownerDocument
  431. .createElement("div");
  432. groupRowBox.className = "logGroupBox";
  433. groupRow.appendChild(groupRowBox);
  434. appendRow(groupRowBox);
  435. groupStack.push(groupRowBox);
  436. }
  437. function popGroup() {
  438. groupStack.pop();
  439. }
  440. // ***************************************************************************
  441. function logFormatted(objects, className) {
  442. var html = [];
  443. var format = objects[0];
  444. var objIndex = 0;
  445. if (typeof(format) != "string") {
  446. format = "";
  447. objIndex = -1;
  448. }
  449. var parts = parseFormat(format);
  450. for (var i = 0; i < parts.length; ++i) {
  451. var part = parts[i];
  452. if (part && typeof(part) == "object") {
  453. var object = objects[++objIndex];
  454. part.appender(object, html);
  455. } else {
  456. appendText(part, html);
  457. }
  458. }
  459. var ids = [];
  460. var obs = [];
  461. for (var i = objIndex + 1; i < objects.length; ++i) {
  462. appendText(" ", html);
  463. var object = objects[i];
  464. if (!object) {
  465. continue;
  466. }
  467. if (typeof(object) == "string") {
  468. appendText(object, html);
  469. } else if (object.nodeType == 1) {
  470. // simple tracing of dom nodes
  471. appendText("< " + object.tagName + " id=\"" + object.id
  472. + "\" />", html);
  473. } else {
  474. // Create link for object inspector
  475. // need to create an ID for this link, since it is
  476. // currently text
  477. var id = "_a" + __consoleAnchorId__++;
  478. ids.push(id);
  479. // need to save the object, so the arrays line up
  480. obs.push(object)
  481. var str = '<a id="' + id
  482. + '" href="javascript:void(0);">'
  483. + getObjectAbbr(object) + '</a>';
  484. appendLink(str, html);
  485. }
  486. }
  487. logRow(html, className);
  488. // Now that the row is inserted in the DOM, loop through all of
  489. // the links that were just created
  490. for (var i = 0; i < ids.length; i++) {
  491. var btn = _firebugDoc.getElementById(ids[i]);
  492. if (!btn) {
  493. continue;
  494. }
  495. // store the object in the dom btn for reference later
  496. // avoid parsing these objects unless necessary
  497. btn.obj = obs[i];
  498. dojo.connect(btn, "onclick", function() {
  499. // hide rows
  500. consoleBody.style.display = "none";
  501. consoleObjectInspector.style.display = "block";
  502. // create a back button
  503. var bkBtn = '<a href="javascript:console.closeObjectInspector();">&nbsp;<<&nbsp;Back</a>';
  504. consoleObjectInspector.innerHTML = bkBtn + "<pre>"
  505. + printObject(this.obj) + "</pre>";
  506. })
  507. }
  508. }
  509. function parseFormat(format) {
  510. var parts = [];
  511. var reg = /((^%|[^\\]%)(\d+)?(\.)([a-zA-Z]))|((^%|[^\\]%)([a-zA-Z]))/;
  512. var appenderMap = {
  513. s : appendText,
  514. d : appendInteger,
  515. i : appendInteger,
  516. f : appendFloat
  517. };
  518. for (var m = reg.exec(format); m; m = reg.exec(format)) {
  519. var type = m[8] ? m[8] : m[5];
  520. var appender = type in appenderMap
  521. ? appenderMap[type]
  522. : appendObject;
  523. var precision = m[3] ? parseInt(m[3]) : (m[4] == "."
  524. ? -1
  525. : 0);
  526. parts.push(format.substr(0, m[0][0] == "%"
  527. ? m.index
  528. : m.index + 1));
  529. parts.push({
  530. appender : appender,
  531. precision : precision
  532. });
  533. format = format.substr(m.index + m[0].length);
  534. }
  535. parts.push(format);
  536. return parts;
  537. }
  538. function escapeHTML(value) {
  539. function replaceChars(ch) {
  540. switch (ch) {
  541. case "<" :
  542. return "&lt;";
  543. case ">" :
  544. return "&gt;";
  545. case "&" :
  546. return "&amp;";
  547. case "'" :
  548. return "&#39;";
  549. case '"' :
  550. return "&quot;";
  551. }
  552. return "?";
  553. };
  554. return String(value).replace(/[<>&"']/g, replaceChars);
  555. }
  556. function objectToString(object) {
  557. try {
  558. return object + "";
  559. } catch (e) {
  560. return null;
  561. }
  562. }
  563. // ***************************************************************************
  564. function appendLink(object, html) {
  565. // needed for object links - no HTML escaping
  566. html.push(objectToString(object));
  567. }
  568. function appendText(object, html) {
  569. html.push(escapeHTML(objectToString(object)));
  570. }
  571. function appendNull(object, html) {
  572. html.push('<span class="objectBox-null">',
  573. escapeHTML(objectToString(object)), '</span>');
  574. }
  575. function appendString(object, html) {
  576. html.push('<span class="objectBox-string">&quot;',
  577. escapeHTML(objectToString(object)), '&quot;</span>');
  578. }
  579. function appendInteger(object, html) {
  580. html.push('<span class="objectBox-number">',
  581. escapeHTML(objectToString(object)), '</span>');
  582. }
  583. function appendFloat(object, html) {
  584. html.push('<span class="objectBox-number">',
  585. escapeHTML(objectToString(object)), '</span>');
  586. }
  587. function appendFunction(object, html) {
  588. var reName = /function ?(.*?)\(/;
  589. var m = reName.exec(objectToString(object));
  590. var name = m ? m[1] : "function";
  591. html.push('<span class="objectBox-function">',
  592. escapeHTML(name), '()</span>');
  593. }
  594. function appendObject(object, html) {
  595. try {
  596. if (object == undefined) {
  597. appendNull("undefined", html);
  598. } else if (object == null) {
  599. appendNull("null", html);
  600. } else if (typeof object == "string") {
  601. appendString(object, html);
  602. } else if (typeof object == "number") {
  603. appendInteger(object, html);
  604. } else if (typeof object == "function") {
  605. appendFunction(object, html);
  606. } else if (object.nodeType == 1) {
  607. appendSelector(object, html);
  608. } else if (typeof object == "object") {
  609. appendObjectFormatted(object, html);
  610. } else {
  611. appendText(object, html);
  612. }
  613. } catch (e) {
  614. /* squelch */
  615. }
  616. }
  617. function appendObjectFormatted(object, html) {
  618. var text = objectToString(object);
  619. var reObject = /\[object (.*?)\]/;
  620. var m = reObject.exec(text);
  621. html.push('<span class="objectBox-object">', m ? m[1] : text,
  622. '</span>')
  623. }
  624. function appendSelector(object, html) {
  625. html.push('<span class="objectBox-selector">');
  626. html.push('<span class="selectorTag">',
  627. escapeHTML(object.nodeName.toLowerCase()), '</span>');
  628. if (object.id) {
  629. html.push('<span class="selectorId">#',
  630. escapeHTML(object.id), '</span>');
  631. }
  632. if (object.className) {
  633. html.push('<span class="selectorClass">.',
  634. escapeHTML(object.className), '</span>');
  635. }
  636. html.push('</span>');
  637. }
  638. function appendNode(node, html) {
  639. if (node.nodeType == 1) {
  640. html.push('<div class="objectBox-element">',
  641. '&lt;<span class="nodeTag">', node.nodeName
  642. .toLowerCase(), '</span>');
  643. for (var i = 0; i < node.attributes.length; ++i) {
  644. var attr = node.attributes[i];
  645. if (!attr.specified) {
  646. continue;
  647. }
  648. html.push('&nbsp;<span class="nodeName">',
  649. attr.nodeName.toLowerCase(),
  650. '</span>=&quot;<span class="nodeValue">',
  651. escapeHTML(attr.nodeValue), '</span>&quot;')
  652. }
  653. if (node.firstChild) {
  654. html.push('&gt;</div><div class="nodeChildren">');
  655. for (var child = node.firstChild; child; child = child.nextSibling) {
  656. appendNode(child, html);
  657. }
  658. html
  659. .push(
  660. '</div><div class="objectBox-element">&lt;/<span class="nodeTag">',
  661. node.nodeName.toLowerCase(),
  662. '&gt;</span></div>');
  663. } else {
  664. html.push('/&gt;</div>');
  665. }
  666. } else if (node.nodeType == 3) {
  667. html.push('<div class="nodeText">',
  668. escapeHTML(node.nodeValue), '</div>');
  669. }
  670. }
  671. // ***************************************************************************
  672. function addEvent(object, name, handler) {
  673. if (document.all) {
  674. object.attachEvent("on" + name, handler);
  675. } else {
  676. object.addEventListener(name, handler, false);
  677. }
  678. }
  679. function removeEvent(object, name, handler) {
  680. if (document.all) {
  681. object.detachEvent("on" + name, handler);
  682. } else {
  683. object.removeEventListener(name, handler, false);
  684. }
  685. }
  686. function cancelEvent(event) {
  687. if (document.all) {
  688. event.cancelBubble = true;
  689. } else {
  690. event.stopPropagation();
  691. }
  692. }
  693. function onError(msg, href, lineNo) {
  694. var html = [];
  695. var lastSlash = href.lastIndexOf("/");
  696. var fileName = lastSlash == -1 ? href : href.substr(lastSlash
  697. + 1);
  698. html.push('<span class="errorMessage">', msg, '</span>',
  699. '<div class="objectBox-sourceLink">', fileName,
  700. ' (line ', lineNo, ')</div>');
  701. logRow(html, "error");
  702. };
  703. // After converting to div instead of iframe, now getting two
  704. // keydowns right away in IE 6.
  705. // Make sure there is a little bit of delay.
  706. var onKeyDownTime = (allGetServerTime()).getTime();
  707. function onKeyDown(event) {
  708. var timestamp = (allGetServerTime()).getTime();
  709. if (timestamp > onKeyDownTime + 200) {
  710. var event = dojo.fixEvent(event);
  711. var keys = dojo.keys;
  712. var ekc = event.keyCode;
  713. onKeyDownTime = timestamp;
  714. if (ekc == keys.F12) {
  715. toggleConsole();
  716. } else if ((ekc == keys.NUMPAD_ENTER || ekc == 76)
  717. && event.shiftKey
  718. && (event.metaKey || event.ctrlKey)) {
  719. focusCommandLine();
  720. } else {
  721. return;
  722. }
  723. cancelEvent(event);
  724. }
  725. }
  726. function onSplitterMouseDown(event) {
  727. if (dojo.isSafari || dojo.isOpera) {
  728. return;
  729. }
  730. addEvent(document, "mousemove", onSplitterMouseMove);
  731. addEvent(document, "mouseup", onSplitterMouseUp);
  732. for (var i = 0; i < frames.length; ++i) {
  733. addEvent(frames[i].document, "mousemove",
  734. onSplitterMouseMove);
  735. addEvent(frames[i].document, "mouseup", onSplitterMouseUp);
  736. }
  737. }
  738. function onSplitterMouseMove(event) {
  739. var win = document.all
  740. ? event.srcElement.ownerDocument.parentWindow
  741. : event.target.ownerDocument.defaultView;
  742. var clientY = event.clientY;
  743. if (win != win.parent) {
  744. clientY += win.frameElement
  745. ? win.frameElement.offsetTop
  746. : 0;
  747. }
  748. var height = consoleFrame.offsetTop + consoleFrame.clientHeight;
  749. var y = height - clientY;
  750. consoleFrame.style.height = y + "px";
  751. layout();
  752. }
  753. function onSplitterMouseUp(event) {
  754. removeEvent(document, "mousemove", onSplitterMouseMove);
  755. removeEvent(document, "mouseup", onSplitterMouseUp);
  756. for (var i = 0; i < frames.length; ++i) {
  757. removeEvent(frames[i].document, "mousemove",
  758. onSplitterMouseMove);
  759. removeEvent(frames[i].document, "mouseup",
  760. onSplitterMouseUp);
  761. }
  762. }
  763. function onCommandLineKeyDown(event) {
  764. if (event.keyCode == 13) {
  765. evalCommandLine();
  766. } else if (event.keyCode == 27) {
  767. commandLine.value = "";
  768. }
  769. }
  770. // ***************************************************************************************************
  771. // Print Object Helpers
  772. getAtts = function(o) {
  773. // Get amount of items in an object
  774. if (dojo.isArray(o)) {
  775. return "[array with " + o.length + " slots]";
  776. } else {
  777. var i = 0;
  778. for (var nm in o) {
  779. i++;
  780. }
  781. return "{object with " + i + " items}";
  782. }
  783. }
  784. printObject = function(o, i, txt) {
  785. // Recursively trace object, indenting to represent depth for
  786. // display in object inspector
  787. // TODO: counter to prevent overly complex or looped objects
  788. // (will probably help with dom nodes)
  789. var br = "\n"; // using a <pre>... otherwise we'd need a <br />
  790. var ind = " ";
  791. txt = (txt) ? txt : "";
  792. i = (i) ? i : ind;
  793. for (var nm in o) {
  794. if (typeof(o[nm]) == "object") {
  795. txt += i + nm + " -> " + getAtts(o[nm]) + br;
  796. txt += printObject(o[nm], i + ind);
  797. } else {
  798. txt += i + nm + " : " + o[nm] + br;
  799. }
  800. }
  801. return txt;
  802. }
  803. getObjectAbbr = function(obj) {
  804. // Gets an abbreviation of an object for display in log
  805. // X items in object, including id
  806. // X items in an array
  807. // TODO: Firebug Sr. actually goes by char count
  808. var isError = (obj instanceof Error);
  809. var nm = obj.id || obj.name || obj.ObjectID || obj.widgetId;
  810. if (!isError && nm) {
  811. return "{" + nm + "}";
  812. }
  813. var obCnt = 2;
  814. var arCnt = 4;
  815. var cnt = 0;
  816. if (isError) {
  817. nm = "[ Error: "
  818. + (obj["message"] || obj["description"] || obj)
  819. + " ]";
  820. } else if (dojo.isArray(obj)) {
  821. nm = "[";
  822. for (var i = 0; i < obj.length; i++) {
  823. nm += obj[i] + ","
  824. if (i > arCnt) {
  825. nm += " ... (" + obj.length + " items)";
  826. break;
  827. }
  828. }
  829. nm += "]";
  830. } else if ((!dojo.isObject(obj)) || dojo.isString(obj)) {
  831. nm = obj + "";
  832. } else {
  833. nm = "{";
  834. for (var i in obj) {
  835. cnt++
  836. if (cnt > obCnt)
  837. break;
  838. nm += i + "=" + obj[i] + " ";
  839. }
  840. nm += "}"
  841. }
  842. return nm;
  843. }
  844. // *************************************************************************************
  845. window.onerror = onError;
  846. addEvent(document, dojo.isIE || dojo.isSafari
  847. ? "keydown"
  848. : "keypress", onKeyDown);
  849. if ((document.documentElement.getAttribute("debug") == "true")
  850. || (djConfig.isDebug)) {
  851. toggleConsole(true);
  852. }
  853. })();
  854. }
  855. }