First version of Dash-price-ticker

This commit is contained in:
Joshua 2016-04-26 23:33:07 -04:00
parent ba5f21dee0
commit c13b0bdd2f

99
Dash-price-ticker.html Normal file
View file

@ -0,0 +1,99 @@
<style type="text/css">
/* Micro reset so global styles don't interfere */
.dash-ticker,
.dash-ticker *,
.dash-ticker *:before,
.dash-ticker *:after {
box-sizing: inherit;
vertical-align: baseline;
font-weight: inherit;
font-family: inherit;
font-style: inherit;
font-size: 100%;
border: 0 none;
outline: 0;
padding: 0;
margin: 0;
}
.dash-ticker {
display: block;
max-width: 20em;
margin: 0.5em auto;
border-radius: 0.5em;
background-color: rgba(0,0,0,0.125);
box-sizing: border-box;
color: inherit;
padding: 0.5em;
}
.dash-ticker .dash-ticker--title {
text-align: center;
font-size: 1.5em;
padding-bottom: 0.125em;
border-bottom: 1px solid rgba(0,0,0,0.5);
margin-bottom: 0.25em;
}
#dash-ticker--price-container {
font-size: 2em;
text-align: center;
}
#dash-ticker--price-container > input {
position: fixed;
right: -200px;
}
#dash-ticker--price-container > input + label {
display: none;
cursor: pointer;
}
#dash-ticker--price-container > input:checked + label {
display: block;
}
</style>
<form class="dash-ticker">
<div class="dash-ticker--title">Dash Price</div>
<div id="dash-ticker--price-container" title="Click to change currency">
<input type="radio" name="currency" id="USD" checked />
<label>
<span class="dash-ticker--price">Loading...</span>
<span class="dash-ticker--currency"></span>
</label>
</div>
</form>
<script>
(function () {
window.JSON || document.write('<script src="//cdnjs.cloudflare.com/ajax/libs/json3/3.2.4/json3.min.js"><\/scr'+'ipt>');
function fetchJSONFile(path, callback) {
var httpRequest = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200) {
var data = JSON.parse(httpRequest.responseText);
if (callback) callback(data);
}
}
};
httpRequest.open('GET', path);
httpRequest.send();
}
// this requests the file and executes a callback with the parsed result once it is available
fetchJSONFile('https://coinmarketcap-nexuist.rhcloud.com/api/dash/price', function(data){
var keys = Object.keys(data);
var currencyListHTML = "";
for (var i = 0; i < keys.length; i++) {
var thisCurrency = keys[i];
var nextCurrency = keys[(i < keys.length - 1 ? i + 1 : 0)];
var currencyValue = data[keys[i]];
var currencyString = (currencyValue.toPrecision(3).length > currencyValue.toFixed(2) ? currencyValue.toPrecision(3) : currencyValue.toFixed(2));
currencyListHTML += '<input type="radio" name="currency" id="dash-ticker-currencies-' + thisCurrency + '"' + (i == 0 ? ' checked' : '') + ' /><label for="dash-ticker-currencies-' + nextCurrency + '"><span class="dash-ticker--price">' + currencyString + '</span> <span class="dash-ticker--currency">' + thisCurrency.toUpperCase() + '</span></label>';
}
document.getElementById('dash-ticker--price-container').innerHTML = currencyListHTML;
});
})();
</script>