aboutsummaryrefslogtreecommitdiffstats
path: root/static/js/index.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/index.coffee')
-rw-r--r--static/js/index.coffee44
1 files changed, 44 insertions, 0 deletions
diff --git a/static/js/index.coffee b/static/js/index.coffee
new file mode 100644
index 00000000..090abbe2
--- /dev/null
+++ b/static/js/index.coffee
@@ -0,0 +1,44 @@
+#= require js/jquery-1.8.2.min.js
+#= require js/bootstrap.min.js
+
+g = exports ? this
+
+$(->
+ fetchExchangeRate('ask')
+ fetchExchangeRate('bid')
+
+ $('#username').blur(->
+ $.get(
+ "/#{$(this).val()}/exists",
+ username: $(this).val(),
+ (data) ->
+ if data is "true"
+ $('#username').prev().css('color', 'red').html('Username (taken)')
+ g.preventSubmit = true
+ else
+ $('#username').prev().css('color', 'black').html('Username')
+ g.preventSubmit = false
+ )
+ )
+
+ $('#signup').submit(->
+ return false if g.preventSubmit
+ return true
+ )
+)
+
+fetchExchangeRate = (type) ->
+ commission = 0.015
+ commission *= -1 if type is 'bid'
+
+ $.ajax(
+ url: "/ticker?symbol=virtexCAD&type=#{type}&amount=100",
+ success: (exchange) ->
+ if not exchange?
+ exchange = '??'
+
+ exchange = exchange - exchange * commission
+ $("##{type}").html(exchange.toFixed(2))
+ error: ->
+ $("##{type}").html('??')
+ )