Guest User

Untitled

a guest
Apr 26th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. <!-- The dnd-list directive allows to drop elements into it.
  2. The dropped data will be added to the referenced list -->
  3. <ul dnd-list="list">
  4. <!-- The dnd-draggable directive makes an element draggable and will
  5. transfer the object that was assigned to it. If an element was
  6. dragged away, you have to remove it from the original list
  7. yourself using the dnd-moved attribute -->
  8. <li ng-repeat="item in list"
  9. dnd-draggable="item"
  10. dnd-moved="list.splice($index, 1)"
  11. dnd-effect-allowed="move"
  12. dnd-selected="models.selected = item"
  13. ng-class="{'selected': models.selected === item}"
  14. >
  15. {{item.label}}
  16. </li>
  17. </ul>
  18.  
  19. /**
  20. * The dnd-list should always have a min-height,
  21. * otherwise you can't drop to it once it's empty
  22. */
  23. .simpleDemo ul[dnd-list] {
  24. min-height: 42px;
  25. padding-left: 0px;
  26. }
  27.  
  28. /**
  29. * The dndDraggingSource class will be applied to
  30. * the source element of a drag operation. It makes
  31. * sense to hide it to give the user the feeling
  32. * that he's actually moving it.
  33. */
  34. .simpleDemo ul[dnd-list] .dndDraggingSource {
  35. display: none;
  36. }
  37.  
  38. /**
  39. * An element with .dndPlaceholder class will be
  40. * added to the dnd-list while the user is dragging
  41. * over it.
  42. */
  43. .simpleDemo ul[dnd-list] .dndPlaceholder {
  44. background-color: #ddd;
  45. display: block;
  46. min-height: 42px;
  47. }
  48.  
  49. .simpleDemo ul[dnd-list] li {
  50. background-color: #fff;
  51. border: 1px solid #ddd;
  52. border-top-right-radius: 4px;
  53. border-top-left-radius: 4px;
  54. display: block;
  55. padding: 10px 15px;
  56. margin-bottom: -1px;
  57. }
  58.  
  59. /**
  60. * Show selected elements in green
  61. */
  62. .simpleDemo ul[dnd-list] li.selected {
  63. background-color: #dff0d8;
  64. color: #3c763d;
  65. }
  66.  
  67. angular.module("demo").controller("SimpleDemoController", function($scope) {
  68.  
  69. $scope.models = {
  70. selected: null,
  71. lists: {"A": [], "B": []}
  72. };
  73.  
  74. // Generate initial model
  75. for (var i = 1; i <= 3; ++i) {
  76. $scope.models.lists.A.push({label: "Item A" + i});
  77. $scope.models.lists.B.push({label: "Item B" + i});
  78. }
  79.  
  80. // Model to JSON for demo purpose
  81. $scope.$watch('models', function(model) {
  82. $scope.modelAsJson = angular.toJson(model, true);
  83. }, true);
  84.  
  85. });
Add Comment
Please, Sign In to add comment