2017-09-09 19:22:04 +02:00
|
|
|
//
|
|
|
|
// Vex modals
|
|
|
|
//
|
|
|
|
|
2018-03-01 13:14:20 +01:00
|
|
|
/* global vex, fetch, ClipboardJS, QRious */
|
2017-09-09 19:22:04 +02:00
|
|
|
/* exported krlcModals */
|
|
|
|
|
|
|
|
/* eslint-disable spaced-comment */
|
|
|
|
//=require vex-js/dist/js/vex.combined.js
|
2017-09-21 16:40:26 +02:00
|
|
|
//=require clipboard/dist/clipboard.js
|
2017-09-21 19:22:52 +02:00
|
|
|
//=require qrious/dist/qrious.js
|
2017-09-09 19:22:04 +02:00
|
|
|
/* eslint-enable spaced-comment */
|
|
|
|
|
|
|
|
const krlcModals = (() => { // eslint-disable-line no-unused-vars
|
|
|
|
const _config = {
|
2017-09-09 21:20:59 +02:00
|
|
|
btcVexTriggers: document.querySelectorAll('.js-vex-btc')
|
2017-09-09 19:22:04 +02:00
|
|
|
}
|
|
|
|
|
2017-09-09 21:20:59 +02:00
|
|
|
let btcAddress
|
2017-09-21 16:40:26 +02:00
|
|
|
let ethAddress
|
2017-09-09 21:20:59 +02:00
|
|
|
|
2017-09-09 19:22:04 +02:00
|
|
|
const _private = {
|
2017-09-09 21:20:59 +02:00
|
|
|
getBtcAddress() {
|
|
|
|
const url = '/api/site.json'
|
|
|
|
|
|
|
|
fetch(url)
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(data_ => {
|
|
|
|
btcAddress = data_[0].author.bitcoin
|
2017-09-21 16:40:26 +02:00
|
|
|
ethAddress = data_[0].author.ether
|
2017-09-09 21:20:59 +02:00
|
|
|
})
|
|
|
|
.catch(err => console.error(err))
|
|
|
|
|
2017-09-21 16:40:26 +02:00
|
|
|
return {btcAddress, ethAddress}
|
2017-09-09 21:20:59 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
vexBtc() {
|
|
|
|
_config.btcVexTriggers.forEach(el => {
|
2017-09-09 19:22:04 +02:00
|
|
|
el.addEventListener('click', e => {
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
vex.defaultOptions.className = 'vex-theme-kremalicious vex-bitcoin'
|
|
|
|
vex.dialog.buttons.YES.text = 'Close'
|
2017-09-21 16:40:26 +02:00
|
|
|
vex.open({unsafeContent: `
|
|
|
|
<h3 class="vex__title">Say thanks</h3>
|
|
|
|
<div class="grid grid--full grid-medium--half grid--gutters">
|
|
|
|
<div class="grid__col">
|
|
|
|
<h4>Bitcoin</h4>
|
2017-09-21 19:22:52 +02:00
|
|
|
<canvas class="qr" id="qr-btc"></canvas>
|
|
|
|
<pre class="highlight"><code id="btcAddress" class="btcAddress nt" value="${btcAddress}">${btcAddress}</code><button class="btn" data-clipboard-target="#btcAddress" title="Copy to clipboard"><svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 22 22"><path d="M16 8v8H8v4h12V8h-4zm0-2h6v16H6v-6H0V0h16v6zM2 2v12h12V2H2z"></path></svg></button></pre>
|
2017-09-21 16:40:26 +02:00
|
|
|
</div>
|
|
|
|
<div class="grid__col">
|
|
|
|
<h4>Ethereum</h4>
|
2017-09-21 19:22:52 +02:00
|
|
|
<canvas class="qr" id="qr-eth"></canvas>
|
|
|
|
<pre class="highlight"><code id="ethAddress" class="ethAddress nt" value="${ethAddress}">${ethAddress}</code><button class="btn" data-clipboard-target="#ethAddress" title="Copy to clipboard"><svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 22 22"><path d="M16 8v8H8v4h12V8h-4zm0-2h6v16H6v-6H0V0h16v6zM2 2v12h12V2H2z"></path></svg></button></pre>
|
2017-09-21 16:40:26 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
|
2017-09-21 19:51:56 +02:00
|
|
|
// Generate QR codes
|
2017-09-21 19:22:52 +02:00
|
|
|
const qrBtc = new QRious({
|
|
|
|
element: document.getElementById('qr-btc'),
|
|
|
|
value: btcAddress
|
|
|
|
})
|
|
|
|
|
|
|
|
const qrEth = new QRious({
|
|
|
|
element: document.getElementById('qr-eth'),
|
|
|
|
value: ethAddress
|
|
|
|
})
|
|
|
|
|
2017-09-21 19:51:56 +02:00
|
|
|
const qrOptions = {
|
|
|
|
backgroundAlpha: 0,
|
|
|
|
foreground: '#6b7f88',
|
|
|
|
size: 160
|
|
|
|
}
|
|
|
|
|
|
|
|
qrBtc.set(qrOptions)
|
|
|
|
qrEth.set(qrOptions)
|
2017-09-21 19:22:52 +02:00
|
|
|
|
|
|
|
// Clipboard button
|
2018-03-01 13:08:10 +01:00
|
|
|
const clipboard = new ClipboardJS('.btn')
|
2017-09-21 16:40:26 +02:00
|
|
|
|
|
|
|
clipboard.on('success', e => {
|
|
|
|
e.trigger.classList.add('success')
|
|
|
|
e.clearSelection()
|
|
|
|
})
|
2017-09-09 21:20:59 +02:00
|
|
|
})
|
2017-09-09 19:22:04 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2017-09-09 21:20:59 +02:00
|
|
|
init() {
|
|
|
|
_private.getBtcAddress()
|
|
|
|
_private.vexBtc()
|
|
|
|
}
|
2017-09-09 19:22:04 +02:00
|
|
|
}
|
|
|
|
})(); // eslint-disable-line semi
|