From 5ff6c7051867ed14ecbbc391709f25106c1bef1f Mon Sep 17 00:00:00 2001 From: piernov Date: Sun, 24 Apr 2016 22:27:33 +0200 Subject: Add client side JS shop functions --- js/shop.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 js/shop.js (limited to 'js/shop.js') diff --git a/js/shop.js b/js/shop.js new file mode 100644 index 0000000..00636e1 --- /dev/null +++ b/js/shop.js @@ -0,0 +1,57 @@ +function displayShop(ret) { + var tmphtml = "

Select an item to buy it:

"; + tmphtml += "" + document.getElementById("tab2").innerHTML = tmphtml; +} + +function displayInventory(items) { + for(var i=0; i < items.length; i++) { + addItem(items[i]); + } +} + +function buildShop() { + sendRequest("craftmine.php", "op=buildShop", function(ret) { + displayShop(ret); + debitAccount(ret.cost); + }); +} + +function addItem(ret) { + var itemhtml = "
  • "; + itemhtml += ""; + itemhtml += "
  • "; + + var invcontent = document.getElementById("tab3"); + + if(invcontent.children.length <= 1) + { + var tmphtml = "

    Your bag contains the following items:

    "; + tmphtml += "" + invcontent.innerHTML = tmphtml; + } else + invcontent.getElementsByTagName('ul')[0].innerHTML += itemhtml; + + showInfo(ret.desc); +} + +function buyItem(name) { + sendRequest("craftmine.php", "op=buyItem&item="+name, function(ret) { + addItem(ret); + debitAccount(ret.cost); + }); +} + +function useItem(name) { + sendRequest("craftmine.php", "op=useItem&item="+name, function(ret) { + }); +} + -- cgit v1.2.3-54-g00ecf From 8140617aeb2f32f7095a443ca743c6d6915739c6 Mon Sep 17 00:00:00 2001 From: alexichi Date: Mon, 25 Apr 2016 13:45:05 +0200 Subject: change class of Hire a Miner, and change type submit to button for items --- index.xhtml | 2 +- js/shop.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'js/shop.js') diff --git a/index.xhtml b/index.xhtml index 1685eb9..aa29615 100644 --- a/index.xhtml +++ b/index.xhtml @@ -31,7 +31,7 @@
    - +
    diff --git a/js/shop.js b/js/shop.js index 00636e1..22ca85f 100644 --- a/js/shop.js +++ b/js/shop.js @@ -25,7 +25,7 @@ function buildShop() { function addItem(ret) { var itemhtml = "
  • "; - itemhtml += ""; + itemhtml += ""; itemhtml += "
  • "; var invcontent = document.getElementById("tab3"); -- cgit v1.2.3-54-g00ecf