Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GetMenu( Checkout, OutputID )
- {
- var xmlhttp;
- if ( window.XMLHttpRequest )
- {
- xmlhttp = new XMLHttpRequest;
- }
- else
- {
- xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
- }
- xmlhttp.onreadystatechange = function ()
- {
- if (( xmlhttp.readyState == 4 ) &&
- ( xmlhttp.status == 200 ))
- {
- document.getElementById( OutputID ).innerHTML = xmlhttp.responseText;
- }
- }
- xmlhttp.open( "GET", Checkout, true );
- xmlhttp.send();
- }
- function StartDrag( CurrentEvent )
- {
- CurrentEvent.dataTransfer.setData( "text/html", CurrentEvent.target.id );
- }
- function AllowDrop( CurrentEvent )
- {
- CurrentEvent.preventDefault();
- }
- function Drop( CurrentEvent, DestinationID )
- {
- var DataID = CurrentEvent.dataTransfer.getData( "text/html" );
- var OrderedItem = document.querySelector( "div[id=\"destination\"] p[id=\"" + DataID + "\"]" );
- if ( null == OrderedItem )
- {
- var newItem = document.getElementById( DataID ).cloneNode( true );
- newItem.setAttribute( "data-count", 1 );
- newItem.addEventListener( "dblclick", function () { RemoveItem( DataID ); } );
- document.querySelector( "div[id=\"destination\"]" ).appendChild( newItem );
- }
- else
- {
- var Count = Number( OrderedItem.getAttribute( "data-count" )) + 1;
- OrderedItem.setAttribute( "data-count", Count );
- }
- CurrentEvent.preventDefault();
- ComputeTotal();
- }
- function RemoveItem(ItemId)
- {
- var DestinationItem = document.querySelector( "div[id=\"destination\"] p[id=\"" + ItemId + "\"]" );
- var Count = Number( DestinationItem.getAttribute( "data-count" )) - 1;
- if ( Count > 0 )
- {
- DestinationItem.setAttribute( "data-count", Count );
- }
- else
- {
- DestinationItem.parentNode.removeChild( DestinationItem );
- }
- ComputeTotal();
- }
- // compute the Total
- function ComputeTotal ()
- {
- var PriceList = document.querySelectorAll( "div[id=\"destination\"] p" );
- var Total = 0.0;
- for( var i=0; i<PriceList.length; i++ )
- {
- Total += Number(PriceList[i].getAttribute( "data-point-value" )) *
- Number(PriceList[i].getAttribute( "data-count" ));
- }
- document.querySelector( "p[id=\"total\"]" ).innerHTML = "Your Total is: $" + Total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement