Support reading position from query params
This commit is contained in:
parent
05bc6514d6
commit
909a36d76f
|
@ -38,19 +38,18 @@ templ Overlay(lnurl string, lnaddr string) {
|
|||
<script>
|
||||
const qr = document.getElementById("qr");
|
||||
|
||||
let currentX = 0;
|
||||
let currentY = 0;
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
let queryX = parseInt(urlParams.get('x'));
|
||||
let queryY = parseInt(urlParams.get('y'));
|
||||
const [localX,localY] = localStorage.getItem('qrPosition')?.split(',').map(Number) ?? [0,0];
|
||||
|
||||
let currentX = !isNaN(queryX) ? queryX : localX;
|
||||
let currentY = !isNaN(queryY) ? queryY : localY;
|
||||
qr.style.transform = `translate(${currentX}px, ${currentY}px)`;
|
||||
|
||||
let startX = 0;
|
||||
let startY = 0;
|
||||
|
||||
const savedPosition = localStorage.getItem('qrPosition');
|
||||
if (savedPosition) {
|
||||
const [x, y] = savedPosition.split(',').map(Number);
|
||||
currentX = x;
|
||||
currentY = y;
|
||||
qr.style.transform = `translate(${currentX}px, ${currentY}px)`;
|
||||
}
|
||||
|
||||
qr.addEventListener("dragstart", (e) => {
|
||||
startX = e.clientX - currentX;
|
||||
startY = e.clientY - currentY;
|
||||
|
@ -70,6 +69,7 @@ templ Overlay(lnurl string, lnaddr string) {
|
|||
currentY = e.clientY - startY;
|
||||
qr.style.transform = `translate(${currentX}px, ${currentY}px)`;
|
||||
localStorage.setItem('qrPosition', `${currentX},${currentY}`);
|
||||
window.location.search = `?x=${currentX}&y=${currentY}`
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
Loading…
Reference in New Issue