Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. // Callback function when cancelling the event
  2. function cancel(e) {
  3. if (e.preventDefault) {
  4. e.preventDefault();
  5. }
  6. return false;
  7. }
  8.  
  9. function refresh_total_costs(total_costs){
  10.  
  11. $('#total-costs span').text(total_costs);
  12. }
  13.  
  14. $(document).ready(function() {
  15.  
  16. var total_costs = 0;
  17.  
  18. refresh_total_costs(total_costs);
  19.  
  20. // Get the #drop zone
  21. var drop = document.getElementById('drop');
  22.  
  23. var draggedItem = null;
  24.  
  25. // Add the Event Listener to each draggable item
  26. $('.dragable-item').each(function(index){
  27. $(this)[0].addEventListener('dragstart',function(e){
  28.  
  29. draggedItem = jQuery(this);
  30.  
  31. e.dataTransfer.setData('Text', this.id); // required otherwise doesn't work
  32.  
  33. },false);
  34. });
  35.  
  36.  
  37. drop.addEventListener('dragover', cancel);
  38. drop.addEventListener('dragenter', cancel);
  39.  
  40. drop.addEventListener('drop', function (e) {
  41.  
  42. e.preventDefault();
  43.  
  44. var html = "<a id='parentDiv' style='margin-left: 10px;'><p id='childDiv' class='number'>" + $(draggedItem).data('title') + "</p></a><br /><input type='button' value='Remove Element' onClick='removeElement('parent','child');'>";
  45.  
  46. $('#output').prepend( html );
  47.  
  48. total_costs += parseInt($(draggedItem).data('price'));
  49.  
  50. refresh_total_costs(total_costs);
  51.  
  52. return false;
  53. });
  54. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement