71429cd4f7fb450f921076d8a1435fa85e457279.svn-base 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>Dojo DnD test</title>
  5. <style type="text/css">
  6. @import "../../resources/dojo.css";
  7. @import "../../resources/dnd.css";
  8. @import "dndDefault.css";
  9. body {
  10. padding: 1em;
  11. background: #ededed;
  12. }
  13. .container {
  14. width: 100px;
  15. display: block;
  16. }
  17. .clear {
  18. clear: both;
  19. }
  20. </style>
  21. <script type="text/javascript" src="../../dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
  22. <script type="text/javascript" src="../../dnd/Container.js"></script>
  23. <script type="text/javascript" src="../../dnd/Selector.js"></script>
  24. <script type="text/javascript" src="../../dnd/Source.js"></script>
  25. <script type="text/javascript" src="../../dnd/Avatar.js"></script>
  26. <script type="text/javascript" src="../../dnd/Manager.js"></script>
  27. <script type="text/javascript">
  28. dojo.require("dojo.parser");
  29. dojo.require("dojo.dnd.Source");
  30. var c1;
  31. function init(){
  32. c1 = new dojo.dnd.Source("container1");
  33. c1.insertNodes(false, [1, "A", [1, 2, 3],
  34. function(x){ return x + x; },
  35. {toString: function(){ return "CUSTOM!"; }},
  36. null]);
  37. // example subscribe to events
  38. dojo.subscribe("/dnd/start", function(source){
  39. console.debug("Starting the drop", source);
  40. });
  41. dojo.subscribe("/dnd/drop/before", function(source, nodes, copy, target){
  42. if(target == c1){
  43. console.debug(copy ? "Copying from" : "Moving from", source, "to", target, "before", target.before);
  44. }
  45. });
  46. dojo.subscribe("/dnd/drop", function(source, nodes, copy, target){
  47. if(target == c1){
  48. console.debug(copy ? "Copying from" : "Moving from", source, "to", target, "before", target.before);
  49. }
  50. });
  51. dojo.connect(c4, "onDndDrop", function(source, nodes, copy, target){
  52. if(target == c4){
  53. console.debug(copy ? "Copying from" : "Moving from", source);
  54. }
  55. });
  56. };
  57. dojo.addOnLoad(init);
  58. </script>
  59. </head>
  60. <body>
  61. <h1 class="testTitle">Dojo DnD test</h1>
  62. <p>Elements of both sources/targets were created dynamically.</p>
  63. <p>Following selection modes are supported by default:</p>
  64. <ul>
  65. <li>Simple click &mdash; selects a single element, all other elements will be unselected.</li>
  66. <li>Ctrl+click &mdash; toggles a selection state of an element (use Meta key on Mac).</li>
  67. <li>Shift+click &mdash; selects a range of element from the previous anchor to the current element.</li>
  68. <li>Ctrl+Shift+click &mdash; adds a range of element from the previous anchor to the current element (use Meta key on Mac).</li>
  69. </ul>
  70. <p>Following drop modes are supported by default:</p>
  71. <ul>
  72. <li>Simple drop &mdash; moves elements to the valid target removing them from the source. It can be used to reorganize elements within a single source/target.</li>
  73. <li>Ctrl+drop &mdash; copies elements to the valid target (use Meta key on Mac).</li>
  74. </ul>
  75. <div id="dragLists">
  76. <div style="float: left; margin: 5px;">
  77. <h3>Source 1</h3>
  78. <div id="container1" class="container"></div>
  79. </div>
  80. <div style="float: left; margin: 5px;">
  81. <h3>Source 2</h3>
  82. <div dojoType="dojo.dnd.Source" jsId="c2" class="container">
  83. <div class="dojoDndItem">Item <strong>X</strong></div>
  84. <div class="dojoDndItem">Item <strong>Y</strong></div>
  85. <div class="dojoDndItem">Item <strong>Z</strong></div>
  86. </div>
  87. </div>
  88. <div style="float: left; margin: 5px;">
  89. <h3>Source 3</h3>
  90. <div dojoType="dojo.dnd.Source" jsId="c3" class="container">
  91. <script type="dojo/method" event="creator" args="item, hint">
  92. // this is custom creator, which changes the avatar representation
  93. var node = dojo.doc.createElement("div"), s = String(item);
  94. node.id = dojo.dnd.getUniqueId();
  95. node.className = "dojoDndItem";
  96. node.innerHTML = (hint != "avatar" || s.indexOf("Item") < 0) ?
  97. s : "<strong style='color: darkred'>Special</strong> " + s;
  98. return {node: node, data: item, type: ["text"]};
  99. </script>
  100. <div class="dojoDndItem">Item <strong>Alpha</strong></div>
  101. <div class="dojoDndItem">Item <strong>Beta</strong></div>
  102. <div class="dojoDndItem">Item <strong>Gamma</strong></div>
  103. <div class="dojoDndItem">Item <strong>Delta</strong></div>
  104. </div>
  105. </div>
  106. <div style="float: left; margin: 5px;">
  107. <h3>Pure Target 4</h3>
  108. <div dojoType="dojo.dnd.Target" jsId="c4" class="container">
  109. <div class="dojoDndItem">One item</div>
  110. </div>
  111. </div>
  112. <div class="clear"></div>
  113. </div>
  114. <p>HTML after</p>
  115. </body>
  116. </html>