mirror of
https://github.com/seigler/Dash-price-widget
synced 2025-07-27 08:06:09 +00:00
create project structure, using npm as a build tool
This commit is contained in:
parent
c13b0bdd2f
commit
4dd6e2020b
6 changed files with 124 additions and 1 deletions
32
assets/scripts/app.js
Normal file
32
assets/scripts/app.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
(function () {
|
||||
"use strict";
|
||||
window.JSON || document.write('<scr' + 'ipt 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),
|
||||
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;
|
||||
});
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue