Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. function GetMenu( Checkout, OutputID )
  2. {
  3.  
  4. var xmlhttp;
  5.  
  6.  
  7. if ( window.XMLHttpRequest )
  8. {
  9.  
  10. xmlhttp = new XMLHttpRequest;
  11. }
  12. else
  13. {
  14.  
  15. xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
  16. }
  17.  
  18.  
  19. xmlhttp.onreadystatechange = function ()
  20. {
  21.  
  22. if (( xmlhttp.readyState == 4 ) &&
  23. ( xmlhttp.status == 200 ))
  24. {
  25.  
  26. document.getElementById( OutputID ).innerHTML = xmlhttp.responseText;
  27. }
  28. }
  29.  
  30.  
  31. xmlhttp.open( "GET", Checkout, true );
  32.  
  33. xmlhttp.send();
  34.  
  35. }
  36.  
  37.  
  38.  
  39. function StartDrag( CurrentEvent )
  40. {
  41.  
  42. CurrentEvent.dataTransfer.setData( "text/html", CurrentEvent.target.id );
  43. }
  44.  
  45.  
  46. function AllowDrop( CurrentEvent )
  47. {
  48.  
  49. CurrentEvent.preventDefault();
  50. }
  51.  
  52.  
  53. function Drop( CurrentEvent, DestinationID )
  54. {
  55.  
  56. var DataID = CurrentEvent.dataTransfer.getData( "text/html" );
  57. var OrderedItem = document.querySelector( "div[id=\"destination\"] p[id=\"" + DataID + "\"]" );
  58.  
  59. if ( null == OrderedItem )
  60. {
  61. var newItem = document.getElementById( DataID ).cloneNode( true );
  62. newItem.setAttribute( "data-count", 1 );
  63. newItem.addEventListener( "dblclick", function () { RemoveItem( DataID ); } );
  64. document.querySelector( "div[id=\"destination\"]" ).appendChild( newItem );
  65. }
  66. else
  67. {
  68. var Count = Number( OrderedItem.getAttribute( "data-count" )) + 1;
  69. OrderedItem.setAttribute( "data-count", Count );
  70. }
  71.  
  72. CurrentEvent.preventDefault();
  73.  
  74. ComputeTotal();
  75.  
  76. }
  77.  
  78. function RemoveItem(ItemId)
  79. {
  80. var DestinationItem = document.querySelector( "div[id=\"destination\"] p[id=\"" + ItemId + "\"]" );
  81.  
  82. var Count = Number( DestinationItem.getAttribute( "data-count" )) - 1;
  83.  
  84. if ( Count > 0 )
  85. {
  86. DestinationItem.setAttribute( "data-count", Count );
  87. }
  88. else
  89. {
  90. DestinationItem.parentNode.removeChild( DestinationItem );
  91. }
  92.  
  93. ComputeTotal();
  94. }
  95.  
  96.  
  97. // compute the Total
  98. function ComputeTotal ()
  99. {
  100. var PriceList = document.querySelectorAll( "div[id=\"destination\"] p" );
  101.  
  102. var Total = 0.0;
  103.  
  104.  
  105. for( var i=0; i<PriceList.length; i++ )
  106. {
  107.  
  108. Total += Number(PriceList[i].getAttribute( "data-point-value" )) *
  109. Number(PriceList[i].getAttribute( "data-count" ));
  110. }
  111. document.querySelector( "p[id=\"total\"]" ).innerHTML = "Your Total is: $" + Total;
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement