Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

91 line
2.8KB

  1. /** Modified from original Node-Red source, for audio system visualization
  2. * vim: set ts=4:
  3. * Copyright 2013 IBM Corp.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. **/
  17. RED.sidebar.info = (function() {
  18. var content = document.createElement("div");
  19. content.id = "tab-info";
  20. content.style.paddingTop = "4px";
  21. content.style.paddingLeft = "4px";
  22. content.style.paddingRight = "4px";
  23. RED.sidebar.addTab("info",content);
  24. function jsonFilter(key,value) {
  25. if (key === "") {
  26. return value;
  27. }
  28. var t = typeof value;
  29. if ($.isArray(value)) {
  30. return "[array:"+value.length+"]";
  31. } else if (t === "object") {
  32. return "[object]"
  33. } else if (t === "string") {
  34. if (value.length > 30) {
  35. return value.substring(0,30)+" ...";
  36. }
  37. }
  38. return value;
  39. }
  40. function refresh(node) {
  41. var table = '<table class="node-info"><tbody>';
  42. table += "<tr><td>Type</td><td>&nbsp;"+node.type+"</td></tr>";
  43. table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>";
  44. table += '<tr class="blank"><td colspan="2">&nbsp;Properties</td></tr>';
  45. for (var n in node._def.defaults) {
  46. if (node._def.defaults.hasOwnProperty(n)) {
  47. var val = node[n]||"";
  48. var type = typeof val;
  49. if (type === "string") {
  50. if (val.length > 30) {
  51. val = val.substring(0,30)+" ...";
  52. }
  53. val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
  54. } else if (type === "number") {
  55. val = val.toString();
  56. } else if ($.isArray(val)) {
  57. val = "[<br/>";
  58. for (var i=0;i<Math.min(node[n].length,10);i++) {
  59. var vv = JSON.stringify(node[n][i],jsonFilter," ").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
  60. val += "&nbsp;"+i+": "+vv+"<br/>";
  61. }
  62. if (node[n].length > 10) {
  63. val += "&nbsp;... "+node[n].length+" items<br/>";
  64. }
  65. val += "]";
  66. } else {
  67. val = JSON.stringify(val,jsonFilter," ");
  68. val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
  69. }
  70. table += "<tr><td>&nbsp;"+n+"</td><td>"+val+"</td></tr>";
  71. }
  72. }
  73. table += "</tbody></table><br/>";
  74. table += '<div class="node-help">'+($("script[data-help-name|='"+node.type+"']").html()||"")+"</div>";
  75. $("#tab-info").html(table);
  76. }
  77. return {
  78. refresh:refresh,
  79. clear: function() {
  80. $("#tab-info").html("");
  81. }
  82. }
  83. })();