// Cafe menu items. We will fetch these from the server at startup var items; // Order array - initially empty var order = []; // Work-around for missing JQuery.postJSON jQuery["postJSON"] = function(url,data,callback) { $.ajax({ url:url, type:'POST', data:JSON.stringify(data), contentType:'application/json', dataType:'json', success: callback }); }; // Search the items list for the item with the given id function findItem(id) { var n, length; length = items.length; for(n = 0;n < length;n++) if(items[n].iditem == id) return items[n]; return items[0]; } // Event handler for order button function orderItem() { // Each of the order buttons has the id of the associated // object hidden in its data-id attribute. Find that item // and push it onto the order list. var item = findItem($(this).attr('data-id')); order.push(item); // The View Order button is initially hidden. As soon // as the user orders an item we will want to make it // visible. $('button#viewOrder').show(); // Blur the button to remove the undesirable focussed appearance $(this).blur(); } // Reloads the menu table function displayItems(items) { var table, newRow, buttonTD, orderButton; var n, length; // Remove any existing entries from the table $('#menu tr').remove(); // Add new rows for the items in the list length = items.length; for(n = 0;n < length;n++) { newRow = $('').html(''+items[n].name+'$'+items[n].cost/100+''); orderButton = $('