var globalColor = '#000000'; var currentLink = ''; var apiURL = 'https://qrcode-facile.fr/rest/'; var urlWebsite = 'https://qrcode-facile.fr/'; var currentID = ''; let isValidURL=false; // Builder state: the preview only counts as ready (download enabled) once the content is valid and saved. let qcfPending = false; let qcfFileReady = false; let qcfDocReady = false; let qcfLinkTimer = null; const qcfUrlPattern = /^(ftp|http|https):\/\/[^ "]+$/; function qcfFieldValue(id) { const field = document.getElementById(id); return field ? field.value.trim() : ''; } function qcfComputeReady() { const active = document.querySelector('.activeL'); switch (active ? active.getAttribute('data-id') : '') { case 'linkContainer': return qcfUrlPattern.test(qcfFieldValue('urlLink')); case 'faceContainer': return qcfUrlPattern.test(qcfFieldValue('urlFacebook')); case 'linkedinContainer': return qcfUrlPattern.test(qcfFieldValue('urlLinkedin')); case 'telContainer': return qcfFieldValue('phoneNumber').length > 3; case 'instaContainer': return qcfFieldValue('urlInsta').length > 0; case 'tikContainer': return qcfFieldValue('urlTik').length > 0; case 'fileContainer': return qcfFileReady; case 'documentContainer': return qcfDocReady; default: return false; } } function updatePreviewState() { const ready = qcfComputeReady() && !qcfPending && currentID !== ''; document.dispatchEvent(new CustomEvent('qcf:preview-state', { detail: { ready: ready, pending: qcfPending } })); } // Called on every keystroke: shows the URL hint, then saves the link once typing pauses (600ms) and only if valid. function scheduleLink(link, urlFieldId) { clearTimeout(qcfLinkTimer); currentLink = link; if (urlFieldId) { const value = qcfFieldValue(urlFieldId); isValidURL = qcfUrlPattern.test(value); $('.alertURL').attr('hidden', true); if (value !== '' && !isValidURL) { $('#' + urlFieldId).siblings('.alertURL').removeAttr('hidden'); } } qcfPending = qcfComputeReady(); updatePreviewState(); if (qcfPending) { qcfLinkTimer = setTimeout(function () { changeLinkQR(link); }, 600); } } let rangeDateAnalytics=false; const saveDateRange = (selectedDates) => { rangeDateAnalytics=selectedDates; return selectedDates; } document.addEventListener('DOMContentLoaded', () => { if(document.querySelectorAll('#calendar').length>0) { let today = new Date(); let formattedToday=today.toISOString().split('T')[0]; let todayJ7=new Date(); todayJ7.setDate(todayJ7.getDate()-7); let formattedTodayJ7=todayJ7.toISOString().split('T')[0]; console.error(formattedToday + '-' + formattedTodayJ7); const options = { type: 'multiple', months: 2, jumpMonths: 2, actions: { clickDay(event, self) { saveDateRange(self.selectedDates); }, }, settings: { lang: (typeof window.__locale !== 'undefined' ? window.__locale : 'fr-FR'), range: { disablePast: false, }, selection: { day: 'multiple-ranged', }, selected: { dates: [formattedTodayJ7 + '-' + formattedToday], year: today.getFullYear(), }, visibility: { daysOutside: false, theme: 'light', weekend: false, today: false }, }, }; const calendar = new VanillaCalendar('#calendar', options); calendar.init(); document.querySelector('#btnShowStats').addEventListener('click', () => { NProgress.start() if(rangeDateAnalytics) { try { fetch(apiURL + 'analytics', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ rangeDate: rangeDateAnalytics }) }).then(response => response.json()).then(data => { console.log(data); labels = data.labels; data = { labels: labels, datasets: data.datasets }; config.data=data; myChart.update(); NProgress.done(); let totalFlash=0; data.datasets.forEach((el) => { totalFlash+=el.data.reduce((a, b) => a + b, 0); }); document.querySelector('#totalFlashs').innerHTML=totalFlash; document.querySelector('#range-text').innerHTML=(rangeDateAnalytics.length==1) ? 'sur 1 jour' : `sur ${rangeDateAnalytics.length} jours`; }); } catch (error) { alert('Une erreur est survenue, veuillez réessayer plus tard.'); console.error(error); } } }); } var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-ui-toggle="tooltip"]')) var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { return new QCFUI.Tooltip(tooltipTriggerEl) }); }); function changeColor(colorC) { globalColor = colorC; qr._options.dotsOptions.color = colorC; // Drop preset accent colors on the corners so they follow the picked color again. ['cornersSquareOptions', 'cornersDotOptions'].forEach(function (key) { if (qr._options[key] && typeof qr._options[key] === 'object') delete qr._options[key].color; }); qr.update(); document.querySelector('#colorSwatch').value = colorC; document.querySelector('.clr-field').style.color = colorC; } function changeSizeLogo(valSize) { valSize = parseInt(valSize); qr._options.imageOptions.margin = valSize; qr.update(); } function deleteImage() { qr._options.image = ''; qr.update(); document.querySelector('.logoTemV').style.display = 'none'; } function getDataImage(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { console.log(e.target.result); qr._options.image = e.target.result; document.getElementById('logoTempVal').src = e.target.result; document.querySelector('.logoTemV').style.display = 'inline-block'; qr.update(); }; reader.readAsDataURL(input.files[0]); } } function changeStyleQR(qr_this) { qr._options.cornersSquareOptions = 'dot'; qr._options.cornersDotOptions = {}; $('.typeQR li').removeClass('selectedStyle'); $(qr_this).addClass('selectedStyle'); switch (qr_this.getAttribute('data-attr')) { case "square": qr._options.dotsOptions.type = 'square'; break; case "extra-rounded": qr._options.dotsOptions.type = 'extra-rounded'; break; case "dots": qr._options.dotsOptions.type = 'dots'; break; case "matrix": qr._options.dotsOptions.type = 'rounded'; qr._options.cornersSquareOptions = { type: 'dot' }; break; case "pastel": qr._options.dotsOptions.type = 'dot'; qr._options.cornersSquareOptions = { type: 'extra-rounded' }; break; case "classy": qr._options.dotsOptions.type = 'classy'; qr._options.cornersSquareOptions = { type: 'square' }; break; case "classy-rounded": qr._options.dotsOptions.type = 'classy-rounded'; qr._options.cornersSquareOptions = { type: 'extra-rounded' }; break; case "fluid": qr._options.dotsOptions.type = 'rounded'; qr._options.cornersSquareOptions = { type: 'extra-rounded' }; break; case "bubbles": qr._options.dotsOptions.type = 'dots'; qr._options.cornersSquareOptions = { type: 'dot' }; break; case "soft": qr._options.dotsOptions.type = 'extra-rounded'; qr._options.cornersSquareOptions = { type: 'extra-rounded' }; break; } qr.update(); } function changeLinkQR(urlLink) { document.querySelector('.alertPost').setAttribute('hidden', ''); var url = urlLink; var valid = /^(ftp|http|https):\/\/[^ "]+$/.test(url); if (!valid) { $('.alertURL').removeAttr('hidden'); isValidURL=false; } else { $('.alertURL').attr('hidden', 'true'); isValidURL=true; } $.post(apiURL + 'create-qr-code', { urlQRTemp: urlLink }).done(function (data) { qr._options.data = urlWebsite + 'redirect/' + data; qr.update(); currentLink = urlWebsite + 'redirect/' + data; currentID = data; qcfPending = false; updatePreviewState(); }); } function createQRCodeMenu(urlMenu) { $('#createQRBtn').attr('hidden', 'true'); $.post(apiURL + 'create-qr-code-menu', { urlQRTemp: urlMenu }).done(function (data, qr) { // qr.set({ // value: urlWebsite + 'redirect/' + data // }); changeLinkQR(urlWebsite + 'redirect/' + data); currentLink = urlWebsite + 'redirect/' + data; currentID = data; var qrCodeExport = document.querySelector('#qrcode canvas').toDataURL('image/png', 1.0); $.post(apiURL + 'publishQR', { QRCodeData: qrCodeExport }).done(function (data) { $('#qrcodeContainer').removeAttr('hidden'); }); }); } function debounce(func, timeout = 300) { console.log('Debunce'); let timer; return (...args) => { clearTimeout(timer); timer = setTimeout(() => { func.apply(this, args); }, timeout); }; } function transparencyPNG(el) { if (el.checked) { qr._options.backgroundOptions.color = 'rgba(0,0,0,0)'; qr.update(); } else { qr._options.backgroundOptions.color = 'rgba(255,255,255,1)'; qr.update(); } } // function checkCodePromo() // { // let promoT=document.getElementById('promoT').value; // $.post(apiURL + 'promo', { promoCode: promoT }).done(function( data ) { // let resultCode=JSON.parse(data); // if(resultCode.code!='invalid') // { // let discount=parseInt(resultCode.discount); // let priceAct=document.getElementById('priceAct'); // let price=document.getElementById('price').value; // price=price.replace(',', '.'); // price=parseFloat(price); // let newprice=price-(price*discount/100); // let stPrice=newprice*100; // stPrice=stPrice.toFixed(0); // console.log('Strip price :', stPrice); // newprice=newprice.toFixed(2); // newprice=newprice.replace('.', ','); // priceAct.innerHTML=newprice; // document.getElementById('alertResultPromo').innerHTML='
Code promotion appliqué ! ✅
'; // } // else // { // document.getElementById('alertResultPromo').innerHTML='
Code promotion invalide 🤔
'; // } // }); // } // Cook utils function setCookie(e, t, n) { var o, i = ""; n && ((o = new Date).setTime(o.getTime() + 24 * n * 60 * 60 * 1e3), i = "; expires=" + o.toUTCString()), document.cookie = e + "=" + (t || "") + i + "; path=/" } // Guided tours (intro.js 7): start once the layout has settled, skip steps whose target is missing // or hidden (e.g. on mobile), and scroll with room for the fixed header. function qcfStartTour(steps, cookieName) { if (typeof introJs === 'undefined' || getCookie(cookieName)) return; var run = function () { var visibleSteps = steps.filter(function (step) { if (!step.element) return true; var el = typeof step.element === 'string' ? document.querySelector(step.element) : step.element; if (!el || !el.getClientRects().length) return false; step.element = el; return true; }); var tour = introJs().setOptions({ skipLabel: 'x', showProgress: true, showBullets: false, prevLabel: 'Précédent', nextLabel: 'Suivant', doneLabel: 'Terminé', scrollToElement: true, scrollPadding: 120, exitOnOverlayClick: true, steps: visibleSteps }); tour.start(); window.addEventListener('resize', function () { tour.refresh(); }); setCookie(cookieName, 1, 60); }; if (document.readyState === 'complete') setTimeout(run, 400); else window.addEventListener('load', function () { setTimeout(run, 400); }, { once: true }); } function getCookie(e) { for (var t = e + "=", n = document.cookie.split(";"), o = 0; o < n.length; o++) { for (var i = n[o]; " " == i.charAt(0);)i = i.substring(1, i.length); if (0 == i.indexOf(t)) return i.substring(t.length, i.length) } return null } function eraseCookie(e) { document.cookie = e + "=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;" } function publishNoteDoc(contentEdit) { console.log(contentEdit); console.warn('token', document.getElementById('documentToken').value); let tokenDoc = document.getElementById('documentToken').value; $.post(apiURL + 'create-qr-doc', { contentDoc: contentEdit, idDoc: tokenDoc }).done(function (data) { qr._options.data = urlWebsite + 'redirect/' + data; qr.update(); currentLink = urlWebsite + 'redirect/' + data; currentID = data; qcfDocReady = $('
').html(contentEdit).text().trim() !== ''; updatePreviewState(); }); } function proChecker() { // Disabled on purpose: every builder option is free today (postQRCode always sends pQld = 0, the server only charges when pQld = 1). return false; if (document.querySelector('.typeQR li.selectedStyle').getAttribute('data-attr') != 'square' || document.querySelector('.logoTemV').style.display == 'inline-block' || document.querySelector('.activeL').getAttribute('data-id') == "fileContainer" || currentLink.indexOf('doc_') != '-1') { document.getElementById('bottom-bar-alert').classList.add('openEndAlert'); document.getElementById('alert-pro').classList.add('show'); } else { document.getElementById('bottom-bar-alert').classList.remove('openEndAlert'); document.getElementById('alert-pro').classList.remove('show'); } } function postQRCode() { // Checking if QR Code is valid before posting let typeData=document.querySelector('.activeL').getAttribute('data-id'); let validQR=true; switch(typeData) { case "linkContainer": if(!isValidURL) { validQR=false; } break; case "telContainer": if(document.querySelector('#phoneNumber').value.length==0) { validQR=false; } break; case "instaContainer": if(document.querySelector('#urlInsta').value.length==0) { validQR=false; } break; case "faceContainer": if(document.querySelector('#urlFacebook').value.length==0) { validQR=false; } break; case "linkedinContainer": if(document.querySelector('#urlLinkedin').value.length==0) { validQR=false; } break; case "tikContainer": if(document.querySelector('#urlTik').value.length==0) { validQR=false; } break; } if(!validQR) { document.querySelector('.alertPost').removeAttribute('hidden'); return; } else { document.querySelector('.alertPost').setAttribute('hidden', ''); } document.body.style.opacity = '0.5'; fullQuality = document.querySelector('#qrcode canvas').toDataURL('image/png', 1.0); document.getElementById('tempQRCode').value = fullQuality; document.getElementById('tempIDQR').value = currentID; if (document.querySelector('.typeQR li.selectedStyle').getAttribute('data-attr') != 'square') { document.getElementById('pQld').value = '0'; } if (document.querySelector('.logoTemV').style.display == 'inline-block') { document.getElementById('pQld').value = '0'; } if (document.querySelector('.activeL').getAttribute('data-id') == "fileContainer") { document.getElementById('pQld').value = '0'; } if (currentLink.indexOf('doc_') != '-1') { document.getElementById('pQld').value = '0'; } document.getElementById('qrCreationForm').submit(); } let qr; if (document.getElementById('qrcode')) { if (document.querySelectorAll('#dropzone').length > 0) { Dropzone.autoDiscover = false; let myDropzone = new Dropzone("div#dropzone", { url: "https://qrcode-facile.fr//rest/upload-file", maxFiles: 1, maxFilesize: 26214400, acceptedFiles: "image/jpeg,image/png,image/gif,application/epub+zip,text/calendar,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.text,audio/ogg,application/pdf,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,image/svg+xml,font/ttf,text/plain,audio/wav,audio/webm,image/webp,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/zip", maxfilesexceeded: function (file) { this.removeAllFiles(); this.addFile(file); } }); myDropzone.on("success", function (file, responseText) { qcfFileReady = true; changeLinkQR(responseText); }); myDropzone.on('complete', file => { qcfStartTour([{ intro: "Votre fichier vient d'être uploadé, il est maintenant contenu directement dans ce QR Code ✨", element: '#qrcode' }, { element: '.optionQR', intro: "Personnalisez ensuite tous les aspects de votre QR, et passez au téléchargement !" }], 'uploadForm'); }); } gtag('event', 'open_builder_qrsimple', { }); /* var qrcode = new QRCode("qrcode", { text: "http://qrcode-facile.fr/", width: 900, height: 900, colorDark : globalColor, colorLight : "#ffffff", correctLevel : QRCode.CorrectLevel.H }); */ /* var qr = new QRious({ element: document.getElementById('qrcode') }); qr.set({ background: 'white', backgroundAlpha: 1, foreground: 'black', foregroundAlpha: 1, level: 'H', padding: 40, size: 700, value: 'https://qrcode-facile.fr/' }); */ qr = new QRCodeStyling({ width: 500, height: 500, type: "canvas", data: "https://qrcode-facile.fr/", dotsOptions: { color: "#0f172a" }, backgroundOptions: { color: "#ffffff", }, imageOptions: { crossOrigin: "anonymous", margin: 20 } }); console.log('QR Code loaded'); qr.append(document.getElementById("qrcode")); Coloris({ wrap: true, theme: 'polaroid', swatchesOnly: true, themeMode: 'dark', margin: 2, format: 'hex', formatToggle: false, alpha: false, forceAlpha: false, swatchesOnly: false, focusInput: true, selectInput: false, clearButton: true, clearLabel: 'RAZ', swatches: [ '#264653', '#2a9d8f', '#e9c46a', 'rgb(244,162,97)', '#e76f51', '#d62828', 'navy', '#07b', '#0096c7', '#00b4d880', 'rgba(0,119,182,0.8)' ], inline: false, defaultColor: '#000000' }); const customColorPickerTrigger = document.getElementById('customColorPickerTrigger'); const colorPickerInput = document.getElementById('colorSwatch'); if (customColorPickerTrigger && colorPickerInput) { customColorPickerTrigger.addEventListener('click', function () { colorPickerInput.click(); }); } if (document.querySelector('#urlLink')) { document.addEventListener('coloris:pick', event => { changeColor(event.detail.color); }); [ ['urlLink', function (value) { return value; }, true], ['phoneNumber', function (value) { return 'tel:' + value; }, false], ['urlFacebook', function (value) { return value; }, true], ['urlInsta', function (value) { return 'https://instagram.com/' + value.replace('@', ''); }, false], ['urlTik', function (value) { return 'https://www.tiktok.com/@' + value.replace('@', ''); }, false], ['urlLinkedin', function (value) { return value; }, true], ].forEach(function (source) { const field = document.getElementById(source[0]); if (!field) return; field.addEventListener('input', function () { scheduleLink(source[1](field.value.trim()), source[2] ? source[0] : null); }); }); $('.selectorSoft li').click(function (el) { $('.selectorSoft li').removeClass('activeL'); $('.toolbox').removeClass('activeToolbox'); el.currentTarget.classList.add('activeL'); document.querySelector('#' + el.currentTarget.getAttribute('data-id')).classList.add('activeToolbox'); updatePreviewState(); }); $('.commonColors li span').click(function (el) { changeColor(getComputedStyle(el.currentTarget)['backgroundColor']); }); $(document).ready(function () { $('#documentContent').summernote({ placeholder: '', tabsize: 2, height: 450, lang: (typeof window.__locale !== 'undefined' ? window.__locale : 'fr-FR'), toolbar: [ ['style', ['style']], ['font', ['bold', 'italic', 'underline', 'clear']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['insert', ['link', 'picture']], ], callbacks: { onChange: function (contents, $editable) { publishNoteDoc(contents); } } }); $('#documentContent').on('change', function (el) { console.log('hiiiii'); }); }); qcfStartTour([{ intro: "Bienvenue sur QR Code Facile ! Découvrez les 3 étapes pour tout comprendre 🚀" }, { element: '.selectorSoft', intro: "Sélectionnez ici le type de QR Code que vous souhaitez créer ! Par défaut \"Lien\" devrait vous convenir !" }, { element: '#urlLink', intro: "Renseignez-ici l'adresse du site Web que contiendra le QR Code, un simple copier-coller fait le job ✅" }, { element: '.optionQR', intro: "Avant-dernière étape, personnalisez votre QR Code à votre goût, en changeant sa couleur par exemple, et c'est terminé !" }, { element: '#previewCard [data-download]', intro: "Cliquez maintenant simplement sur le bouton je télécharge mon QR Code 🎊" }], 'stepByStep'); let proCheckerNode = document.querySelector("#qrcode"); let config = { attributes: true, childList: true, subtree: true }; let observer = new MutationObserver(proChecker); observer.observe(proCheckerNode, config); updatePreviewState(); } }