2
0

tree.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <!DOCTYPE html>
  2. <html><head>
  3. <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  4. <title>Fancytree - Example: Drag'n'drop</title>
  5. <!--
  6. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
  7. <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js" type="text/javascript"></script>
  8. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js" type="text/javascript"></script>
  9. <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js" type="text/javascript"></script>
  10. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.js" type="text/javascript"></script>
  11. <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.js" type="text/javascript"></script>
  12. <script src="http://codeorigin.jquery.com/jquery-2.0.3.js" type="text/javascript"></script>
  13. <script src="http://codeorigin.jquery.com/ui/1.10.3/jquery-ui.js" type="text/javascript"></script>
  14. -->
  15. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js" type="text/javascript"></script>
  16. <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js" type="text/javascript"></script>
  17. <link href="../../node_modules/jquery.fancytree/dist/skin-win7/ui.fancytree.css" rel="stylesheet" type="text/css" class="skinswitcher">
  18. <!--
  19. <script src="jquery.fancytree.js" type="text/javascript"></script>
  20. <script src="jquery.fancytree.dnd.js" type="text/javascript"></script>
  21. -->
  22. <script src="../../node_modules/jquery.fancytree/dist/jquery.fancytree.js" type="text/javascript"></script>
  23. <script src="../../node_modules/jquery.fancytree/dist/modules/jquery.fancytree.dnd.js" type="text/javascript"></script>
  24. <!-- Start_Exclude: This block is not part of the sample code -->
  25. <link href="sample.css" rel="stylesheet" type="text/css">
  26. <script src="sample.js" type="text/javascript"></script>
  27. <!-- End_Exclude -->
  28. <style type="text/css">
  29. #draggableSample, #droppableSample {
  30. height:100px;
  31. padding:0.5em;
  32. width:150px;
  33. border:1px solid #AAAAAA;
  34. }
  35. #draggableSample {
  36. background-color: silver;
  37. color:#222222;
  38. }
  39. #droppableSample {
  40. background-color: maroon;
  41. color: white;
  42. }
  43. #droppableSample.drophover {
  44. border: 1px solid green;
  45. }
  46. </style>
  47. <!-- Add code to initialize the tree when the document is loaded: -->
  48. <script type="text/javascript">
  49. $(function(){
  50. // Attach the fancytree widget to an existing <div id="tree"> element
  51. // and pass the tree options as an argument to the fancytree() function:
  52. $("#tree").fancytree({
  53. extensions: ["dnd"],
  54. source: [
  55. {"title": "simple node (no explicit id, so a default key is generated)" },
  56. {"key": "2", "title": "item1 with key and tooltip", "tooltip": "Look, a tool tip!" },
  57. {"key": "3", "title": "<span>item2 with <b>html</b> inside a span tag</span>" },
  58. {"key": "4", "title": "node 4" },
  59. {"key": "5", "title": "using href", "href": "http://www.wwWendt.de/" },
  60. {"key": "6", "title": "node with some extra classes (will be added to the generated markup)", "extraClasses": "my-extra-class" },
  61. {"key": "10", "title": "Folder 1", "folder": true, "children": [
  62. {"key": "10_1", "title": "Sub-item 1.1", "children": [
  63. {"key": "10_1_1", "title": "Sub-item 1.1.1"},
  64. {"key": "10_1_2", "title": "Sub-item 1.1.2"}
  65. ]},
  66. {"key": "10_2", "title": "Sub-item 1.2", "children": [
  67. {"key": "10_2_1", "title": "Sub-item 1.2.1"},
  68. {"key": "10_2_2", "title": "Sub-item 1.2.2"}
  69. ]}
  70. ]},
  71. {"key": "20", "title": "Simple node with active children (expand)", "expanded": true, "children": [
  72. {"key": "20_1", "title": "Sub-item 2.1", "children": [
  73. {"key": "20_1_1", "title": "Sub-item 2.1.1"},
  74. {"key": "20_1_2", "title": "Sub-item 2.1.2"}
  75. ]},
  76. {"key": "20_2", "title": "Sub-item 2.2", "children": [
  77. {"key": "20_2_1", "title": "Sub-item 2.2.1"},
  78. {"key": "20_2_2", "title": "Sub-item 2.2.2"}
  79. ]}
  80. ]},
  81. {"key": "30", "title": "Lazy folder", "folder": true, "lazy": true },
  82. {"key": "31", "title": "Lazy folder 2", "folder": true, "lazy": true },
  83. {"key": "32", "title": "Lazy folder 3", "folder": true, "lazy": true }
  84. ]
  85. ,
  86. dnd: {
  87. preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
  88. preventRecursiveMoves: true, // Prevent dropping nodes on own descendants
  89. autoExpandMS: 400,
  90. onDragStart: function(node) {
  91. /** This function MUST be defined to enable dragging for the tree.
  92. * Return false to cancel dragging of node.
  93. */
  94. return true;
  95. },
  96. onDragEnter: function(node, sourceNode) {
  97. /** sourceNode may be null for non-fancytree droppables.
  98. * Return false to disallow dropping on node. In this case
  99. * onDragOver and onDragLeave are not called.
  100. * Return 'over', 'before, or 'after' to force a hitMode.
  101. * Return ['before', 'after'] to restrict available hitModes.
  102. * Any other return value will calc the hitMode from the cursor position.
  103. */
  104. // Prevent dropping a parent below another parent (only sort
  105. // nodes under the same parent)
  106. /* if(node.parent !== sourceNode.parent){
  107. return false;
  108. }
  109. // Don't allow dropping *over* a node (would create a child)
  110. return ["before", "after"];
  111. */
  112. return true;
  113. },
  114. onDrop: function(node, sourceNode, hitMode, ui, draggable) {
  115. /** This function MUST be defined to enable dropping of items on
  116. * the tree.
  117. */
  118. sourceNode.moveTo(node, hitMode);
  119. }
  120. },
  121. activate: function(e, data) {
  122. // alert("activate " + data.node);
  123. }
  124. });
  125. });
  126. </script>
  127. </head>
  128. <body class="example">
  129. <h1>Example: 'dnd' extension</h1>
  130. <div class="description">
  131. This sample shows drag'n'drop support.
  132. </div>
  133. <div>
  134. <label for="skinswitcher">Skin:</label> <select id="skinswitcher"><option value="xp">XP</option><option value="vista">Vista (classic Dynatree)</option><option value="win7">Win7</option><option value="win8">Win8</option><option value="lion">Lion</option></select>
  135. </div>
  136. <!-- Add a <table> element where the tree should appear: -->
  137. <div id="tree">
  138. <ul class="ui-fancytree fancytree-container" tabindex="0"><li class=""><span class="fancytree-node fancytree-exp-n fancytree-ico-c"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title">simple node (no explicit id, so a default key is generated)</span></span></li><li class=""><span class="fancytree-node fancytree-exp-n fancytree-ico-c"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title" title="Look, a tool tip!">item1 with key and tooltip</span></span></li><li class=""><span class="fancytree-node fancytree-exp-n fancytree-ico-c"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title"><span>item2 with <b>html</b> inside a span tag</span></span></span></li><li class=""><span class="fancytree-node fancytree-exp-n fancytree-ico-c"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title">node 4</span></span></li><li class=""><span class="fancytree-node fancytree-exp-n fancytree-ico-c"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title">using href</span></span></li><li class=""><span class="fancytree-node my-extra-class fancytree-exp-n fancytree-ico-c"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title">node with some extra classes (will be added to the generated markup)</span></span></li><li class=""><span class="fancytree-node fancytree-folder fancytree-has-children fancytree-exp-c fancytree-ico-cf"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title">Folder 1</span></span></li><li class=""><span class="fancytree-node fancytree-expanded fancytree-has-children fancytree-exp-e fancytree-ico-e"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title">Simple node with active children (expand)</span></span><ul><li class=""><span class="fancytree-node fancytree-has-children fancytree-exp-c fancytree-ico-c"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title">Sub-item 2.1</span></span></li><li class="fancytree-lastsib"><span class="fancytree-node fancytree-has-children fancytree-lastsib fancytree-exp-cl fancytree-ico-c"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title">Sub-item 2.2</span></span></li></ul></li><li class=""><span class="fancytree-node fancytree-folder fancytree-has-children fancytree-lazy fancytree-exp-cd fancytree-ico-cf"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title">Lazy folder</span></span></li><li class=""><span class="fancytree-node fancytree-folder fancytree-has-children fancytree-lazy fancytree-exp-cd fancytree-ico-cf"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title">Lazy folder 2</span></span></li><li class="fancytree-lastsib"><span class="fancytree-node fancytree-folder fancytree-has-children fancytree-lastsib fancytree-lazy fancytree-exp-cdl fancytree-ico-cf"><span class="fancytree-expander"></span><span class="fancytree-icon"></span><span class="fancytree-title">Lazy folder 3</span></span></li></ul></div>
  139. <!-- Start_Exclude: This block is not part of the sample code -->
  140. <hr>
  141. <p class="sample-links no_code">
  142. <a class="hideInsideFS" href="https://github.com/mar10/fancytree" style="display: none;">jquery.fancytree.js project home</a>
  143. <a class="hideOutsideFS" href="#">Link to this page</a>
  144. <a class="hideInsideFS" href="index.html" style="display: none;">Example Browser</a>
  145. <a href="#" id="codeExample">View source code</a>
  146. </p><p class="version-info">Fancytree 2.0.0-1, jQuery UI 1.10.4, jQuery 1.11.1</p>
  147. <pre id="sourceCode" class="prettyprint" style="display:none"></pre>
  148. <!-- End_Exclude -->
  149. </body></html>