implement displaying qr codes for crypto donations

This commit is contained in:
Brian Picciano 2018-09-05 17:17:35 -04:00
parent d1446c6d6f
commit 6898959fce
5 changed files with 115 additions and 7 deletions

View File

@ -12,4 +12,6 @@
{%- if jekyll.environment == 'production' and site.google_analytics -%} {%- if jekyll.environment == 'production' and site.google_analytics -%}
{%- include google-analytics.html -%} {%- include google-analytics.html -%}
{%- endif -%} {%- endif -%}
<script src="{{ "/assets/main.js" | relative_url }}"></script>
</head> </head>

View File

@ -1,12 +1,14 @@
<header id="title-header" role="banner"> <header id="title-header" role="banner">
<div class="row row-vertically-centered"> <div class="row row-vertically-centered">
<div class="eight columns"> <div class="five columns">
<h1 class="title"> <h1 class="title">
<a href="{{ "/" | relative_url }}">{{ site.title | escape }}</a> <a href="{{ "/" | relative_url }}">{{ site.title | escape }}</a>
</h1> </h1>
</div> </div>
<div class="four columns light"> <div id="crypto-display" class="four columns"></div>
<div class="three columns light">
<div class="social"> <div class="social">
<span class="spaced">RSS/Social:</span> <span class="spaced">RSS/Social:</span>
<a class="spaced" href="{{ 'feed.xml' | relative_url }}"> <a class="spaced" href="{{ 'feed.xml' | relative_url }}">
@ -22,15 +24,15 @@
<div class="donation"> <div class="donation">
<span>If you like what I do, consider donating!</span><br/> <span>If you like what I do, consider donating!</span><br/>
<span> <span>
<a href="https://cash.me/$mediocregopher">USD</a> <a href="https://cash.me/$mediocregopher" target="_blank">USD</a>
<a href="bitcoin:1KSqgPBQ7VWc5yxUT2DsB3VpsvRyahL2k8">BTC</a> <a class="crypto" href="bitcoin:18kqNYjUZ4zNEp4VjE3pKPLBitUy6U76rk">BTC</a>
LTC <a class="crypto" href="litecoin:LZgyna6Nw4phzWv24QP4xgUi7hC9DDHV7o">LTC</a>
ETH <a class="crypto" href="ethereum:0xB8e1608059174760f4652178303f7c7a59121922">ETH</a>
ZEC <a class="crypto" href="zcash:zcMmjd2gNetan9QciRExVdTb64ZEYPjk8w6NiEXnLRcDbVQQxZ9xvKH3Ab3y7uccCrN5HRvR5YVvq684gC1drvnYadp3Yz2">ZEC</a>
</span> </span>
</div> </div>
</div> </div>

View File

@ -43,6 +43,40 @@ ul {
margin-right: 0.5em; margin-right: 0.5em;
} }
#crypto-display {
margin-right: 2rem;
}
/* the qr library uses a canvas to generate the qr code then base64's it into a
* separate img tag. For an instant the original canvas shows though, creating
* an annoying visual, so this ensures that that doesn't happen. */
#crypto-display-qr canvas {
display: none;
}
#crypto-display-qr img {
width: 100%;
}
#crypto-display-addr {
word-wrap: break-word;
margin-top: 1em;
}
#crypto-display-x {
text-align: center;
margin-top: 1em;
}
#crypto-display-x span:hover {
cursor: pointer;
font-weight: bold;
}
#crypto-display-x span {
cursor: pointer;
}
#posts-list { #posts-list {
margin-top: 3rem; margin-top: 3rem;
list-style: none; list-style: none;

69
assets/main.js Normal file
View File

@ -0,0 +1,69 @@
console.log("main.js started");
// For asynchronously loading the qr code library, loadQRLib returns a promise
// which will be resolved when the library is loaded.
var qrLibProm;
var loadQRLib = () => {
if (qrLibProm) { return qrLibProm; }
qrLibProm = new Promise((resolve, reject) => {
console.log("loading qrcode.min.js");
var script = document.createElement('script');
script.src = "/assets/qrcode.min.js";
script.async = true;
script.onload = () => { resolve(); };
document.querySelectorAll('head')[0].appendChild(script);
});
return qrLibProm;
};
document.addEventListener("DOMContentLoaded", () => {
console.log("DOM loaded");
var cryptoDisplay = document.querySelector('#crypto-display');
var clearCryptoDisplay = () => {
while(cryptoDisplay.firstChild) {
cryptoDisplay.removeChild(cryptoDisplay.firstChild);
}
};
console.log("setting up crypto buttons");
document.querySelectorAll('.crypto').forEach((el) => {
var href = el.href;
el.href="#";
el.onclick = () => {
var parts = href.split(":");
if (parts.length != 2) {
console.error(el, "href not properly formatted");
return;
}
var currency = parts[0];
var address = parts[1];
clearCryptoDisplay();
var cryptoDisplayQR = document.createElement('div');
cryptoDisplayQR.id = "crypto-display-qr";
var cryptoDisplayAddr = document.createElement('div');
cryptoDisplayAddr.id = "crypto-display-addr";
cryptoDisplayAddr.innerHTML = '<span>'+currency + " address: " + address + '</span>';
var cryptoDisplayX = document.createElement('div');
cryptoDisplayX.id = "crypto-display-x";
cryptoDisplayX.onclick = clearCryptoDisplay;
cryptoDisplayX.innerHTML = '<span>X</span>';
cryptoDisplay.appendChild(cryptoDisplayQR);
cryptoDisplay.appendChild(cryptoDisplayAddr);
cryptoDisplay.appendChild(cryptoDisplayX);
loadQRLib().then(() => {
new QRCode(cryptoDisplayQR, {
text: currency,
width: 512,
height: 512,
});
});
};
});
})

1
assets/qrcode.min.js vendored Normal file

File diff suppressed because one or more lines are too long