console.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.help.console"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.help.console"] = true;
  8. dojo.provide("dojox.help.console");
  9. dojo.require("dojox.help._base");
  10. dojo.mixin(dojox.help, {
  11. _plainText: function(str){
  12. return str.replace(/(<[^>]*>|&[^;]{2,6};)/g, '');
  13. },
  14. _displayLocated: function(located){
  15. var obj = {};
  16. dojo.forEach(located, function(item){ obj[item[0]] = dojo.isMoz ? { toString: function(){ return "Click to view"; }, item: item[1] } : item[1]; });
  17. console.dir(obj);
  18. },
  19. _displayHelp: function(loading, obj){
  20. if(loading){
  21. var message = "Help for: " + obj.name;
  22. console.log(message);
  23. var underline = "";
  24. for(var i = 0; i < message.length; i++){
  25. underline += "=";
  26. }
  27. console.log(underline);
  28. }else if(!obj){
  29. console.log("No documentation for this object");
  30. }else{
  31. var anything = false;
  32. for(var attribute in obj){
  33. var value = obj[attribute];
  34. if(attribute == "returns" && obj.type != "Function" && obj.type != "Constructor"){
  35. continue;
  36. }
  37. if(value && (!dojo.isArray(value) || value.length)){
  38. anything = true;
  39. console.info(attribute.toUpperCase());
  40. value = dojo.isString(value) ? dojox.help._plainText(value) : value;
  41. if(attribute == "returns"){
  42. var returns = dojo.map(value.types || [], "return item.title;").join("|");
  43. if(value.summary){
  44. if(returns){
  45. returns += ": ";
  46. }
  47. returns += dojox.help._plainText(value.summary);
  48. }
  49. console.log(returns || "Uknown");
  50. }else if(attribute == "parameters"){
  51. for(var j = 0, parameter; parameter = value[j]; j++){
  52. var type = dojo.map(parameter.types, "return item.title").join("|");
  53. console.log((type) ? (parameter.name + ": " + type) : parameter.name);
  54. var summary = "";
  55. if(parameter.optional){
  56. summary += "Optional. ";
  57. }
  58. if(parameter.repating){
  59. summary += "Repeating. ";
  60. }
  61. summary += dojox.help._plainText(parameter.summary);
  62. if(summary){
  63. summary = " - " + summary;
  64. for(var k = 0; k < parameter.name.length; k++){
  65. summary = " " + summary;
  66. }
  67. console.log(summary);
  68. }
  69. }
  70. }else{
  71. console.log(value);
  72. }
  73. }
  74. }
  75. if(!anything){
  76. console.log("No documentation for this object");
  77. }
  78. }
  79. }
  80. });
  81. dojox.help.init();
  82. }