drag_fun.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - copyNode / moveNode</TITLE>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <link rel="stylesheet" href="../../../css/demo.css" type="text/css">
  7. <link rel="stylesheet" href="../../../css/zTreeStyle/zTreeStyle.css" type="text/css">
  8. <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
  9. <script type="text/javascript" src="../../../js/jquery.ztree.core-3.5.js"></script>
  10. <script type="text/javascript" src="../../../js/jquery.ztree.excheck-3.5.js"></script>
  11. <script type="text/javascript" src="../../../js/jquery.ztree.exedit-3.5.js"></script>
  12. <SCRIPT type="text/javascript">
  13. <!--
  14. var setting = {
  15. view: {
  16. selectedMulti: false
  17. },
  18. edit: {
  19. enable: true,
  20. showRemoveBtn: false,
  21. showRenameBtn: false
  22. },
  23. data: {
  24. simpleData: {
  25. enable: true
  26. }
  27. },
  28. callback: {
  29. beforeDrag: beforeDrag,
  30. beforeClick: beforeClick
  31. }
  32. };
  33. var zNodes =[
  34. { id:1, pId:0, name:"parent node 1", open:true},
  35. { id:11, pId:1, name:"leaf node 1-1"},
  36. { id:12, pId:1, name:"leaf node 1-2"},
  37. { id:13, pId:1, name:"leaf node 1-3"},
  38. { id:2, pId:0, name:"parent node 2", open:true},
  39. { id:21, pId:2, name:"leaf node 2-1"},
  40. { id:22, pId:2, name:"leaf node 2-2"},
  41. { id:23, pId:2, name:"leaf node 2-3"},
  42. { id:3, pId:0, name:"parent node 3", open:true },
  43. { id:31, pId:3, name:"leaf node 3-1"},
  44. { id:32, pId:3, name:"leaf node 3-2"},
  45. { id:33, pId:3, name:"leaf node 3-3"}
  46. ];
  47. function fontCss(treeNode) {
  48. var aObj = $("#" + treeNode.tId + "_a");
  49. aObj.removeClass("copy").removeClass("cut");
  50. if (treeNode === curSrcNode) {
  51. if (curType == "copy") {
  52. aObj.addClass(curType);
  53. } else {
  54. aObj.addClass(curType);
  55. }
  56. }
  57. }
  58. function beforeDrag(treeId, treeNodes) {
  59. return false;
  60. }
  61. function beforeClick(treeId, treeNode) {
  62. return !treeNode.isCur;
  63. }
  64. var curSrcNode, curType;
  65. function setCurSrcNode(treeNode) {
  66. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  67. if (curSrcNode) {
  68. delete curSrcNode.isCur;
  69. var tmpNode = curSrcNode;
  70. curSrcNode = null;
  71. fontCss(tmpNode);
  72. }
  73. curSrcNode = treeNode;
  74. if (!treeNode) return;
  75. curSrcNode.isCur = true;
  76. zTree.cancelSelectedNode();
  77. fontCss(curSrcNode);
  78. }
  79. function copy(e) {
  80. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  81. nodes = zTree.getSelectedNodes();
  82. if (nodes.length == 0) {
  83. alert("Please select one node at first...");
  84. return;
  85. }
  86. curType = "copy";
  87. setCurSrcNode(nodes[0]);
  88. }
  89. function cut(e) {
  90. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  91. nodes = zTree.getSelectedNodes();
  92. if (nodes.length == 0) {
  93. alert("Please select one node at first...");
  94. return;
  95. }
  96. curType = "cut";
  97. setCurSrcNode(nodes[0]);
  98. }
  99. function paste(e) {
  100. if (!curSrcNode) {
  101. alert("Please select one node to copy or cut at first...");
  102. return;
  103. }
  104. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  105. nodes = zTree.getSelectedNodes(),
  106. targetNode = nodes.length>0? nodes[0]:null;
  107. if (curSrcNode === targetNode) {
  108. alert("Can't move, the same source node and destination node.");
  109. return;
  110. } else if (curType === "cut" && ((!!targetNode && curSrcNode.parentTId === targetNode.tId) || (!targetNode && !curSrcNode.parentTId))) {
  111. alert("Can't move, source node is the target node's child.");
  112. return;
  113. } else if (curType === "copy") {
  114. targetNode = zTree.copyNode(targetNode, curSrcNode, "inner");
  115. } else if (curType === "cut") {
  116. targetNode = zTree.moveNode(targetNode, curSrcNode, "inner");
  117. if (!targetNode) {
  118. alert("Cutting failure, source node is the target node's parent.");
  119. }
  120. targetNode = curSrcNode;
  121. }
  122. setCurSrcNode();
  123. delete targetNode.isCur;
  124. zTree.selectNode(targetNode);
  125. }
  126. $(document).ready(function(){
  127. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  128. $("#copy").bind("click", copy);
  129. $("#cut").bind("click", cut);
  130. $("#paste").bind("click", paste);
  131. });
  132. //-->
  133. </SCRIPT>
  134. <style type="text/css">
  135. .ztree li a.copy{padding-top:0; background-color:#316AC5; color:white; border:1px #316AC5 solid;}
  136. .ztree li a.cut{padding-top:0; background-color:silver; color:#111; border:1px #316AC5 dotted;}
  137. </style>
  138. </HEAD>
  139. <BODY>
  140. <h1>Move / Copy - zTree methods</h1>
  141. <h6>[ File Path: exedit/drag_fun.html ]</h6>
  142. <div class="content_wrap">
  143. <div class="zTreeDemoBackground left">
  144. <ul id="treeDemo" class="ztree"></ul>
  145. </div>
  146. <div class="right">
  147. <ul class="info">
  148. <li class="title"><h2>1, Explanation of 'copyNode / moveNode' method</h2>
  149. <ul class="list">
  150. <li>Use 'copyNode / moveNode' method can also be achieved copy / move nodes.</li>
  151. <li><p>Try to copy or cut node:<br/>
  152. &nbsp;&nbsp;&nbsp;&nbsp;[ <a id="copy" href="#" title="copy" onclick="return false;">copy</a> ]
  153. &nbsp;&nbsp;&nbsp;&nbsp;[ <a id="cut" href="#" title="cut" onclick="return false;">cut</a> ]
  154. &nbsp;&nbsp;&nbsp;&nbsp;[ <a id="paste" href="#" title="paste" onclick="return false;">paste</a> ]</p>
  155. <li class="highlight_red">How to use 'zTreeObj.copyNode / moveNode' method, please see the API documentation.</li>
  156. </ul>
  157. </li>
  158. <li class="title"><h2>2, Explanation of setting</h2>
  159. <ul class="list">
  160. <li>Same as 'Normal Drag Node Operation'</li>
  161. </ul>
  162. </li>
  163. <li class="title"><h2>3, Explanation of treeNode</h2>
  164. <ul class="list">
  165. <li>Same as 'Normal Drag Node Operation'</li>
  166. </ul>
  167. </li>
  168. </ul>
  169. </div>
  170. </div>
  171. </BODY>
  172. </HTML>