draglistgroup.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2010 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <title>goog.fx.DragListGroup</title>
  10. <meta charset="utf-8">
  11. <script src="../base.js"></script>
  12. <script>
  13. goog.require('goog.dom');
  14. goog.require('goog.fx.DragListDirection');
  15. goog.require('goog.fx.DragListGroup');
  16. </script>
  17. <link rel="stylesheet" href="css/demo.css">
  18. <style>
  19. body {
  20. font-family: verdana, sans-serif;
  21. }
  22. .hr_clear {
  23. float: none;
  24. clear: both;
  25. height: 0px;
  26. padding: 10px 0px 0px 0px;
  27. border: 0px;
  28. margin: 0px;
  29. visibility: hidden;
  30. }
  31. .bug {
  32. color: red;
  33. font-style: italic;
  34. }
  35. .horiz1_class,
  36. .horiz3_class,
  37. .horiz5_class {
  38. padding: 8px 12px;
  39. /* box_height + 2 * (padding + border + margin) =
  40. 50 + 2 * (5 + 2 + 4) = 72px */
  41. height: 72px;
  42. border: 2px solid #000000;
  43. }
  44. .horiz1_class { float: left; }
  45. .horiz3_class { float: left; }
  46. .horiz5_class { float: left; }
  47. .horiz1_class div { float: left; }
  48. .horiz3_class div { float: right; }
  49. .horiz5_class div { float: left; }
  50. .horiz5_class {
  51. width: 288px;
  52. height: 216px;
  53. }
  54. .vert_table td {
  55. vertical-align: top;
  56. padding: 0px 20px;
  57. }
  58. .vert1_class,
  59. .vert2_class {
  60. padding: 12px 8px;
  61. /* box_width + 2 * (padding + border + margin) =
  62. 50 + 2 * (5 + 2 + 2) = 68px */
  63. width: 68px;
  64. border: 2px solid #000000;
  65. }
  66. div.red_box,
  67. div.yellow_box,
  68. div.blue_box,
  69. div.purple_box {
  70. width: 50px;
  71. height: 50px;
  72. padding: 5px;
  73. margin: 4px 2px;
  74. font-family: verdana, sans-serif;
  75. font-size: 36px;
  76. font-weight: bold;
  77. text-align: center;
  78. }
  79. div.red_box {
  80. border: 2px solid #CC0000;
  81. color: #CC0000;
  82. }
  83. div.yellow_box {
  84. border: 2px solid #CCCC00;
  85. color: #CCCC00;
  86. }
  87. div.blue_box {
  88. border: 2px solid #0000CC;
  89. color: #0000CC;
  90. }
  91. div.purple_box {
  92. border: 2px solid #993399;
  93. color: #993399;
  94. }
  95. #test {
  96. background-color: #CCFFCC;
  97. width: 100px;
  98. height: 100px;
  99. padding: 13px;
  100. border: 11px solid #339933;
  101. margin: 15px;
  102. }
  103. /* The following styles are used in the JS. */
  104. .cursor_pointer {
  105. cursor: pointer;
  106. }
  107. .cursor_move {
  108. cursor: move;
  109. -moz-user-select: none;
  110. }
  111. .opacity_40 {
  112. opacity: 0.4;
  113. -moz-opacity: 0.4;
  114. filter: alpha(opacity=40);
  115. }
  116. .drag_hover_class {
  117. border-color: #009900;
  118. background-color: #CCFFCC;
  119. }
  120. </style>
  121. </head>
  122. <body>
  123. <h1>goog.fx.DragListGroup</h1>
  124. <h2>You can drag any squares into any of the first 4 lists.</h2>
  125. <hr class="hr_clear">
  126. <h4>Horizontal list 1 (grows right):</h4>
  127. <div id="horiz1_div" class="horiz1_class">
  128. <div class="red_box">1</div>
  129. <div class="red_box">2</div>
  130. <div class="red_box">3</div>
  131. <div class="red_box">4</div>
  132. </div>
  133. <hr class="hr_clear">
  134. <table class="vert_table">
  135. <tr>
  136. <td>
  137. <h4>Vertical list 1:</h4>
  138. <div id="vert1_div" class="vert1_class">
  139. <div class="blue_box">1</div>
  140. <div class="blue_box">2</div>
  141. <div class="blue_box">3</div>
  142. <div class="blue_box">4</div>
  143. </div>
  144. </td>
  145. <td>
  146. <h4>Vertical list 2 (style changes on drag hover):</h4>
  147. <div id="vert2_div" class="vert2_class">
  148. <div class="purple_box">1</div>
  149. <div class="purple_box">2</div>
  150. <div class="purple_box">3</div>
  151. <div class="purple_box">4</div>
  152. </div>
  153. </td>
  154. </tr>
  155. </table>
  156. <hr class="hr_clear">
  157. <h4>Horizontal list 3 (grows left):</h4>
  158. <p class="bug">Bug: drop position is off by one.</p>
  159. <div id="horiz3_div" class="horiz3_class">
  160. <div class="yellow_box">1</div>
  161. <div class="yellow_box">2</div>
  162. <div class="yellow_box">3</div>
  163. <div class="yellow_box">4</div>
  164. </div>
  165. <hr class="hr_clear">
  166. <h4>Horizontal list 5 (grows right, has multiple rows, hysteresis is enabled):</h4>
  167. <p class="bug">Bug: can't drop into the last row.</p>
  168. <div id="horiz5_div" class="horiz5_class">
  169. <div class="blue_box">11</div>
  170. <div class="blue_box">22</div>
  171. <div class="blue_box">33</div>
  172. <div class="blue_box">44</div>
  173. <div class="blue_box">55</div>
  174. <div class="blue_box">66</div>
  175. <div class="blue_box">77</div>
  176. <div class="blue_box">88</div>
  177. <div class="blue_box">99</div>
  178. </div>
  179. <hr class="hr_clear">
  180. <h4>The items in this list can be moved around with shift-dragging:</h4>
  181. <div id="horiz6_div" class="horiz1_class">
  182. <div class="red_box">1</div>
  183. <div class="red_box">2</div>
  184. <div class="red_box">3</div>
  185. <div class="red_box">4</div>
  186. </div>
  187. <hr class="hr_clear">
  188. <h4>The items have different width:</h4>
  189. <p class="bug">
  190. Bug: the drop positions are off.
  191. For example try moving box 1 a bit to the left.
  192. </p>
  193. <div id="horiz7_div" class="horiz1_class">
  194. <div class="red_box" style="width: 200px">1</div>
  195. <div class="red_box">2</div>
  196. <div class="red_box" style="width: 200px">3</div>
  197. <div class="red_box">4</div>
  198. </div>
  199. <hr class="hr_clear">
  200. <script>
  201. var dlg = new goog.fx.DragListGroup();
  202. dlg.setDragItemHoverClass('cursor_move');
  203. dlg.setDraggerElClass('cursor_move opacity_40');
  204. dlg.addDragList(goog.dom.getElement('horiz1_div'),
  205. goog.fx.DragListDirection.RIGHT);
  206. dlg.addDragList(goog.dom.getElement('horiz3_div'),
  207. goog.fx.DragListDirection.LEFT);
  208. dlg.addDragList(goog.dom.getElement('vert1_div'),
  209. goog.fx.DragListDirection.DOWN);
  210. dlg.addDragList(goog.dom.getElement('vert2_div'),
  211. goog.fx.DragListDirection.DOWN, true, 'drag_hover_class');
  212. dlg.init();
  213. var dlg2 = new goog.fx.DragListGroup();
  214. dlg2.setDragItemHoverClass('cursor_move');
  215. dlg2.setDraggerElClass('cursor_move opacity_40');
  216. dlg2.setCurrDragItemClass('opacity_40');
  217. dlg2.setIsCurrDragItemAlwaysDisplayed();
  218. dlg2.addDragList(goog.dom.getElement('horiz5_div'),
  219. goog.fx.DragListDirection.RIGHT_2D);
  220. dlg2.setHysteresis(5);
  221. dlg2.init();
  222. var dlg3 = new goog.fx.DragListGroup();
  223. dlg3.setDragItemHoverClass('cursor_move');
  224. dlg3.setDraggerElClass('cursor_move opacity_40');
  225. dlg3.addDragList(goog.dom.getElement('horiz6_div'),
  226. goog.fx.DragListDirection.RIGHT);
  227. goog.events.listen(dlg3, goog.fx.DragListGroup.EventType.BEFOREDRAGSTART,
  228. function(e) {
  229. if (!e.event.shiftKey) {
  230. e.preventDefault();
  231. }
  232. });
  233. dlg3.init();
  234. var dlg4 = new goog.fx.DragListGroup();
  235. dlg4.setDragItemHoverClass('cursor_move');
  236. dlg4.setDraggerElClass('cursor_move opacity_40');
  237. dlg4.setIsCurrDragItemAlwaysDisplayed();
  238. dlg4.addDragList(goog.dom.getElement('horiz7_div'),
  239. goog.fx.DragListDirection.RIGHT);
  240. dlg4.init();
  241. </script>
  242. </body>
  243. </html>