From 74d93fd24a7a577bdf26975d2f04897763089241 Mon Sep 17 00:00:00 2001 From: metoro Date: Fri, 14 Mar 2014 08:42:36 +0100 Subject: Add tip option on calculator --- public/js/calculator.coffee | 16 +++++++++++++++- views/calculator/show.html | 12 +++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee index 7495576e..72af1987 100644 --- a/public/js/calculator.coffee +++ b/public/js/calculator.coffee @@ -11,6 +11,8 @@ EXCHANGE_FAIL = "Error fetching exchange rate" SOCKET_FAIL = "Error connecting to payment server" ADDRESS_FAIL = "Invalid address" +tip = 1 + g = exports ? this $(-> @@ -39,6 +41,10 @@ $(-> else setup() + $('.tipSelect').click(-> + activateTip(this.id.substring(3)) + updateTotal() + ) $('#amount').keyup(updateTotal) $('#amount').focus(-> $('#received').hide() @@ -48,6 +54,13 @@ $(-> ) ) +activateTip = (p) -> + $('.tipSelect').css('font-weight','normal') + $('.tipSelect').removeClass('active') + $('#tip'+p).css('font-weight','bold') + $('#tip'+p).addClass('active') + tip = 1+(parseFloat(p)/100) + setup = -> g.address or= '1VAnbtCAnYccECnjaMCPnWwt81EHCVgNr' g.commission or= 0 @@ -149,7 +162,7 @@ setupSocket = -> ) updateTotal = -> - amount = parseFloat($('#amount').val()) + amount = parseFloat($('#amount').val() * tip) total = (amount * 1000 / g.exchange).toFixed(5) g.receivable = (amount / g.exchange).toFixed(8) @@ -160,6 +173,7 @@ updateTotal = -> $('#qr').html('') new QRCode('qr', "bitcoin:#{g.address}?amount=#{g.receivable.toString()}") + fail = (msg) -> g.errors.push(msg) g.errors = g.errors.uniq() diff --git a/views/calculator/show.html b/views/calculator/show.html index 95ee49a1..b20f2737 100644 --- a/views/calculator/show.html +++ b/views/calculator/show.html @@ -24,7 +24,17 @@ -

+ +
+
+ 0% + 10% + 15% + 20% +
+
+ +

Please send 0.0 mBTC to


-- cgit v1.2.3