ldc-tousenselle/resources/js/front.js

71 lines
2.3 KiB
JavaScript
Vendored

/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
let scratchEl = document.getElementById('scratchElement');
let scratchContainer = document.getElementById('scratchContainer');
if (scratchEl) {
let Scratchcard = require('scratchcard');
let painter = new Scratchcard.Painter();
let lineSpace = 30;
painter.reset = function reset(ctx, width, height) {
ctx.fillStyle = '#cccccc';
ctx.globalCompositeOperation = 'source-over';
ctx.fillRect(0, 0, width, height);
ctx.font = '2rem sans-serif';
ctx.fillStyle = '#FFF';
ctx.textAlign = 'center';
ctx.fillText('GRATTEZ POUR DÉCOUVRIR', width / 2, height / 2 - (lineSpace / 2));
ctx.fillText('SI VOUS AVEZ GAGNÉ', width / 2, height / 2 + (lineSpace / 2));
};
let scratchcard;
try {
scratchcard = new Scratchcard(scratchEl.children.namedItem('scratchImage'), {
realtime: false,
painter: painter
});
} catch (error) {
alert(error);
throw error;
}
scratchcard.getWrapper().style.zIndex = 2;
scratchcard.on('progress', function onProgress(progress) {
if ((progress > 0.7) && (progress < 1)) {
scratchcard.complete();
}
});
let setCanvas = () => {
let height = scratchcard.getCanvas().height
let width = scratchcard.getCanvas().width
scratchContainer.style.top = '-' + height + 'px'
scratchContainer.style.width = width + 'px'
scratchContainer.style.height = height + 'px'
}
window.addEventListener('resize', setCanvas)
window.addEventListener('load', (event) => {
setCanvas()
})
setCanvas()
setTimeout(setCanvas(), 400)
}
let wPdf = document.getElementById('unclaimedWin')
let dPdfLinks = document.getElementsByClassName('winnerPdf')
if (dPdfLinks.length) {
for (let dPdfLink of dPdfLinks) {
dPdfLink.addEventListener('click', (e) => {
console.log('click')
e.preventDefault()
window.open(dPdfLink.href.replace('ID', wPdf.value), '_blank').focus()
})
}
}