Tree_directory.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. Namespace.register("U.Control.td"); //浏览列表命名空间
  2. //14通信G5-2丘润成 15互联网-3叶延裕
  3. /*window.onload = function () {
  4. U.Control.td.A();
  5. }*/
  6. U.Control.td.c = [{ "name": "张三", "pid": "0", "id": "1" }, { "name": "李四", "pid": "0", "id": "111" },{ "name": "lalala", "pid": "1", "id": "2" }, { "name": "zzm", "pid": "2", "id": "3"}];
  7. U.Control.td.A = function () {
  8. if ($(".left_con")[0]) {
  9. $(".left_con")[0].parentNode.removeChild($(".left_con")[0]);
  10. }
  11. var mlk = $$("div", { "className": "left_con" },$("body")[0]);
  12. var ssk = $$("div", { "className": "select" }, mlk);
  13. var sskin = $$("input", { "placeholder": "请输入关键字..." }, ssk);
  14. var i;
  15. for (i in U.Control.td.c) {
  16. if (U.Control.td.c[i].pid == 0) {
  17. var fml = $$("div", { "id": U.Control.td.c[i].id, "style": { "width": "95%", "margin-left": "3%", "float": "left", "cursor": "pointer", "display": "block"} }, mlk);
  18. var fmlsxk = $$("div", { "className": "wenjian" }, fml);
  19. var fmlzk = $$("div", { "className": "zk" }, fmlsxk);
  20. var fmlwz = $$("div", { "className": "gj" }, fmlsxk);
  21. var fmlwzm = $$("div", { "className": "content", "innerHTML": U.Control.td.c[i].name }, fmlsxk);
  22. fml.setAttribute("pid", 0);
  23. U.Control.td.ZJ(fmlsxk); //用于判断子目录是否隐藏的函数
  24. if (U.Control.td.B(U.Control.td.c[i].id) == 0) {
  25. $("#" + U.Control.td.c[i].id)[0].children[0].children[0].style.background = "none";
  26. } //用来检查是否有子级目录并生成div的函数
  27. }
  28. }
  29. return mlk;
  30. }
  31. U.Control.td.B = function (pid) {
  32. var Wture = 0
  33. var i;
  34. for (i in U.Control.td.c) {
  35. if (U.Control.td.c[i].pid == pid) {
  36. var zml = $$("div", { "id": U.Control.td.c[i].id, "style": { "margin-left": "10px", "float": "left", "display": "none"} }, $("#" + pid)[0]);
  37. var zmlsxk = $$("div", { "className": "wenjian" }, zml);
  38. var zmlzk = $$("div", { "className": "zk" }, zmlsxk);
  39. var zmlwz = $$("div", { "className": "gj" }, zmlsxk);
  40. var zmlwzm = $$("div", { "className": "content", "innerHTML": U.Control.td.c[i].name }, zmlsxk);
  41. zml.setAttribute("pid", pid);
  42. U.Control.td.ZJ(zmlsxk); //用于判断子目录是否隐藏的函数
  43. if (U.Control.td.B(U.Control.td.c[i].id) == 0) {
  44. $("#" + U.Control.td.c[i].id)[0].children[0].children[0].style.background = "none";
  45. } //用来检查是否有子级目录并生成div的函数//用来检查是否有子级目录并生成div的函数
  46. Wture = 1;
  47. }
  48. }
  49. if (Wture == 0) {
  50. return 0;
  51. }
  52. }
  53. U.Control.td.ZJ = function (ml) {
  54. ml.onclick = function () {
  55. var zml = ml.nextSibling;
  56. if (zml && zml.style.display == "block") {
  57. zml.style.display = "none";
  58. ml.children[0].style.background = "url(http://d.1473.cn/controls/pc/Tree_directory/img/jmz.png)";
  59. ml.children[0].style.backgroundSize = "100% 100%";
  60. ml.children[1].style.background = "url(http://d.1473.cn/controls/pc/Tree_directory/img/gj.png)"
  61. ml.children[1].style.backgroundSize = "100% 100%";
  62. return;
  63. }
  64. else if (zml && zml.style.display == "none") {
  65. zml.style.display = "block";
  66. ml.children[0].style.background = "url(http://d.1473.cn/controls/pc/Tree_directory/img/jzk.png)";
  67. ml.children[0].style.backgroundSize = "100% 100%";
  68. ml.children[1].style.background = "url(http://d.1473.cn/controls/pc/Tree_directory/img/kj.png)"
  69. ml.children[1].style.backgroundSize = "100% 100%";
  70. return;
  71. }
  72. else {
  73. return;
  74. }
  75. }
  76. }
  77. U.Control.td.Add = function (pid, name) {
  78. var id = Guid.newGuid();
  79. var addml = $$("div", { "id": id, "style": { "width": "95%", "margin-left": "3%", "float": "left", "cursor": "pointer", "display": "block"} }, $("#" + pid)[0]);
  80. var addsxk = $$("div", { "className": "wenjian" }, addml);
  81. var addzk = $$("div", { "className": "zk" }, addsxk);
  82. var addwz = $$("div", { "className": "gj" }, addsxk);
  83. var addwzm = $$("div", { "className": "content", "innerHTML": name }, addsxk);
  84. addml.setAttribute("pid", pid);
  85. var addmldx = { "name": name, "pid": pid, "id": id };
  86. U.Control.td.c.push(addmldx);
  87. U.Control.td.A();
  88. }
  89. U.Control.td.Del = function (pid) {
  90. document.getElementById(pid).parentNode.removeChild(document.getElementById(pid));
  91. }