aboutsummaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2020-03-06 20:00:14 -0500
committerPaul Duncan <pabs@pablotron.org>2020-03-06 20:00:14 -0500
commit11bcdbc1070552dfc99df332d554e99057281d1b (patch)
treee2ac14edb6709555008eea76bc439ea83a27576c /public
parentb6df5d6739975848fc10893700d78cdd616a0c96 (diff)
downloadalonzo-mood-calculator-11bcdbc1070552dfc99df332d554e99057281d1b.tar.bz2
alonzo-mood-calculator-11bcdbc1070552dfc99df332d554e99057281d1b.zip
asdf
Diffstat (limited to 'public')
-rw-r--r--public/face.js26
-rw-r--r--public/index.html22
2 files changed, 40 insertions, 8 deletions
diff --git a/public/face.js b/public/face.js
index 2e8d722..11cb309 100644
--- a/public/face.js
+++ b/public/face.js
@@ -1,6 +1,14 @@
jQuery(function($) {
"use strict";
+ var BASE_PRICE = 55.73;
+ var CURRENT = 10;
+ var DATA_URL = './current.json';
+
+ function to_percent(ask) {
+ return Math.round((r.ask - BASE_PRICE) / BASE_PRICE * 10000) / 100.0;
+ }
+
/**
* get the current time, in milliseconds since the epoch.
*/
@@ -175,8 +183,24 @@ jQuery(function($) {
$('#rate').keyup(tick).focus();
$('.set-rate').click(function() {
- $('#rate').val($(this).data('val'));
+ var val = $(this).data('val');
+
+ // set value
+ $('#rate').val((val == 'current') ? current : val);
+
+ // stop event
return false;
});
+
+ $.ajax({
+ method: 'GET',
+ url: DATA_URL,
+ dataType: 'json'
+ }).fail(function(r) {
+ alert("Couldn't fetch current data.");
+ }).done(function(r) {
+ CURRENT = to_percent(r.ask);
+ $('#rate').val(CURRENT);
+ });
});
diff --git a/public/index.html b/public/index.html
index d852330..43eeed9 100644
--- a/public/index.html
+++ b/public/index.html
@@ -18,7 +18,7 @@
<p id='controls'>
<label for='rate'>Stock Price Change (Percent):</label><br/>
- <input
+ <input
type='number'
id='rate'
value='0'
@@ -26,14 +26,22 @@
/>
<button
- class='set-rate'
+ class='set-rate'
data-val='-10'
title='Set change to minimum.'
>
Min
</button>
- <button
+ <button
+ class='set-rate'
+ data-val='0'
+ title='Set change to zero.'
+ >
+ Clear
+ </button>
+
+ <button
class='set-rate'
data-val='10'
title='Set change to maximum.'
@@ -41,12 +49,12 @@
Max
</button>
- <button
+ <button
class='set-rate'
- data-val='0'
- title='Reset change to zero.'
+ data-val='current'
+ title='Set to today&apos; price.'
>
- Reset
+ Current
</button>
</p>
</div>