update demo to match latest

This commit is contained in:
Joshua Seigler 2016-04-29 00:36:21 -04:00
parent 0a2545f3bd
commit c180d56f35
2 changed files with 77 additions and 75 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/node_modules/

View file

@ -15,8 +15,7 @@
<h1>Dash Price Widget</h1> <h1>Dash Price Widget</h1>
<style type="text/css"> <style type="text/css">/* Micro reset so global styles don't interfere */
/* Micro reset so global styles don't interfere */
.dash-ticker, .dash-ticker,
.dash-ticker *, .dash-ticker *,
@ -87,8 +86,7 @@
</label> </label>
</div> </div>
</form> </form>
<script type="application/javascript"> <script type="application/javascript">(function () {
(function () {
"use strict"; "use strict";
function fetchJSONFile(path, callback) { function fetchJSONFile(path, callback) {
@ -97,9 +95,7 @@
if (httpRequest.readyState === 4) { if (httpRequest.readyState === 4) {
if (httpRequest.status === 200) { if (httpRequest.status === 200) {
var data = JSON.parse(httpRequest.responseText); var data = JSON.parse(httpRequest.responseText);
if (callback) { if (callback) { callback(data); }
callback(data);
}
} }
} }
}; };
@ -107,10 +103,11 @@
httpRequest.send(); httpRequest.send();
} }
// this requests the file and executes a callback with the parsed result once it is available function updatePrices() {
// this requests the Dash price JSON and executes a callback with the parsed result once it is available
fetchJSONFile('https://coinmarketcap-nexuist.rhcloud.com/api/dash/price', function (data) { fetchJSONFile('https://coinmarketcap-nexuist.rhcloud.com/api/dash/price', function (data) {
var keys = Object.keys(data) var keys = Object.keys(data),
, currencyListHTML = ""; currencyListHTML = "";
for (var i = 0; i < keys.length; i++) { for (var i = 0; i < keys.length; i++) {
var thisCurrency = keys[i]; var thisCurrency = keys[i];
var nextCurrency = keys[(i < keys.length - 1 ? i + 1 : 0)]; var nextCurrency = keys[(i < keys.length - 1 ? i + 1 : 0)];
@ -120,6 +117,10 @@
} }
document.getElementById('dash-ticker--price-container').innerHTML = currencyListHTML; document.getElementById('dash-ticker--price-container').innerHTML = currencyListHTML;
}); });
}
updatePrices(); // update prices now
setInterval(updatePrices, 5 * 60 * 1000); // ...and every five minutes after this
})(); })();
</script> </script>