diff src/qr_code.html.luan @ 0:8f4df159f06b

start public repo
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 11 Jul 2025 20:57:49 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/qr_code.html.luan	Fri Jul 11 20:57:49 2025 -0600
@@ -0,0 +1,68 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+local Utils = require "site:/lib/Utils.luan"
+local base_url = Utils.base_url or error()
+local Shared = require "site:/lib/Shared.luan"
+local head = Shared.head or error()
+local body_header = Shared.body_header or error()
+local footer = Shared.footer or error()
+local User = require "site:/lib/User.luan"
+
+
+return function()
+	local user = User.current_required()
+	if user==nil then return end
+	local url = base_url().."/"..user.name
+	Io.stdout = Http.response.text_writer()
+%>
+<!doctype html>
+<html lang="en">
+	<head>
+<%		head() %>
+		<title>Link My Style</title>
+		<style>
+			div[body] {
+				text-align: center;
+			}
+			[qrcode] {
+				display: inline-block;
+			}
+			a[download] {
+				display: inline-block !important;
+				width: 256px !important;
+			}
+		</style>
+		<script type="text/javascript" src="qrcode.js"></script>
+	</head>
+	<body onload="setHref()">
+	<div full>
+<%		body_header() %>
+		<div body>
+			<h1>QR Code</h1>
+			<span qrcode></span>
+			<p><a download="linkmystyle" button big>Download</a></p>
+		</div>
+<%		footer() %>
+	</div>
+	</body>
+	<script>
+		'use strict';
+
+		let qrcode = new QRCode( document.querySelector('[qrcode]'), {
+			text: '<%=url%>',
+			width: 256,
+			height: 256,
+		} );
+		//console.log(qrcode);
+		function setHref() {
+			let a = document.querySelector('a[download]');
+			let img = document.querySelector('[qrcode] img');
+			//console.log(img.src);
+			a.href = img.src;
+		}
+	</script>
+</html>
+<%
+end