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,67 +15,66 @@
<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 *,
.dash-ticker *:before, .dash-ticker *:before,
.dash-ticker *:after { .dash-ticker *:after {
box-sizing: inherit; box-sizing: inherit;
vertical-align: baseline; vertical-align: baseline;
font-weight: inherit; font-weight: inherit;
font-family: inherit; font-family: inherit;
font-style: inherit; font-style: inherit;
font-size: 100%; font-size: 100%;
border: 0 none; border: 0 none;
outline: 0; outline: 0;
padding: 0; padding: 0;
margin: 0; margin: 0;
line-height: 1; line-height: 1;
} }
.dash-ticker { .dash-ticker {
display: block; display: block;
max-width: 20em; max-width: 20em;
margin: 0.5em auto; margin: 0.5em auto;
border-radius: 0.5em; border-radius: 0.5em;
background-color: #1D76BC; background-color: #1D76BC;
box-sizing: border-box; box-sizing: border-box;
color: white; color: white;
padding: 0.5em; padding: 0.5em;
font-family: serif; font-family: serif;
} }
.dash-ticker .dash-ticker--title { .dash-ticker .dash-ticker--title {
font-size: 2em; font-size: 2em;
float: left; float: left;
height: 1em; height: 1em;
width: 1em; width: 1em;
overflow: hidden; overflow: hidden;
text-indent: -999px; text-indent: -999px;
background-image: url("data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIKCSB3aWR0aD0iMjI2Ljc3N3B4IiBoZWlnaHQ9IjIyNi43NzdweC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R0aD0iMjI2Ljc3N3B4IiBoZWlnaHQ9IjIyNi43NzdweCIgdmlld0JveD0iMCAwIDIyNi43NzcgMjI2Ljc3NyIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMjI2Ljc3NyAyMjYuNzc3IgoJIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8cGF0aCBmaWxsPSIjRkZGRkZGIiBkPSJNMTEzLjM4OCwwQzUwLjc2NiwwLDAsNTAuNzY2LDAsMTEzLjM4OGMwLDYyLjYyMyw1MC43NjYsMTEzLjM4OSwxMTMuMzg5LDExMy4zODkKCWM2Mi42MjMsMCwxMTMuMzg5LTUwLjc2NiwxMTMuMzg5LTExMy4zODlDMjI2Ljc3Nyw1MC43NjYsMTc2LjAxMSwwLDExMy4zODgsMHogTTU2LjU2MiwxMDQuODAyaDQ1LjI2NmwtNS4yMzgsMTcuMDI0SDUxLjMyNgoJTDU2LjU2MiwxMDQuODAyeiBNMTczLjgzLDk2Ljc3M2MtMS44MDEsNi41MDYtNy42NTYsMjYuMDIzLTEwLjA1OSwzMi45NDVjLTIuNCw2LjkyMi02LjgyOSwxMi43MzQtMTIuNTA2LDE2LjA1NwoJYy01LjY3NiwzLjMyMy03Ljc5Nyw0LjcxMi0xNS43MzEsNC43MTJINTQuMzAzbDUuNzIxLTE4LjU0Mmg3Ni4zOTVsMTEuNDE0LTM3LjEwOWgtNzUuNzlsNS43MjItMTguNTQxYzAsMCw4My42OTgsMCw4NC41NzcsMAoJYzMuODc1LDAsOC45OTYsMS43OTIsMTEuNDg4LDYuNjM5QzE3Ni4zMjEsODcuNzc1LDE3NS42MjksOTAuMjY3LDE3My44Myw5Ni43NzN6Ii8+Cjwvc3ZnPgo=");
background-size: 100% 100%; background-size: 100% 100%;
} }
#dash-ticker--price-container { #dash-ticker--price-container {
font-size: 2em; font-size: 2em;
text-align: center; text-align: center;
} }
#dash-ticker--price-container > input { #dash-ticker--price-container > input {
position: fixed; position: fixed;
right: -200px; right: -200px;
} }
#dash-ticker--price-container > input + label { #dash-ticker--price-container > input + label {
display: none; display: none;
cursor: pointer; cursor: pointer;
} }
#dash-ticker--price-container > input:checked + label { #dash-ticker--price-container > input:checked + label {
display: block; display: block;
} }
</style> </style>
<form class="dash-ticker"> <form class="dash-ticker">
<div class="dash-ticker--title">Dash Price</div> <div class="dash-ticker--title">Dash Price</div>
@ -87,30 +86,28 @@
</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) {
var httpRequest = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); var httpRequest = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
httpRequest.onreadystatechange = function () { httpRequest.onreadystatechange = function () {
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);
}
}
} }
}; }
httpRequest.open('GET', path); };
httpRequest.send(); httpRequest.open('GET', path);
} 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,7 +117,11 @@
} }
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>
<script src="http://gist-it.appspot.com/https://github.com/seigler/Dash-html-ticker/blob/master/dist/index.html"></script> <script src="http://gist-it.appspot.com/https://github.com/seigler/Dash-html-ticker/blob/master/dist/index.html"></script>