comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:8f4df159f06b
1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local Io = require "luan:Io.luan"
4 local Http = require "luan:http/Http.luan"
5 local Utils = require "site:/lib/Utils.luan"
6 local base_url = Utils.base_url or error()
7 local Shared = require "site:/lib/Shared.luan"
8 local head = Shared.head or error()
9 local body_header = Shared.body_header or error()
10 local footer = Shared.footer or error()
11 local User = require "site:/lib/User.luan"
12
13
14 return function()
15 local user = User.current_required()
16 if user==nil then return end
17 local url = base_url().."/"..user.name
18 Io.stdout = Http.response.text_writer()
19 %>
20 <!doctype html>
21 <html lang="en">
22 <head>
23 <% head() %>
24 <title>Link My Style</title>
25 <style>
26 div[body] {
27 text-align: center;
28 }
29 [qrcode] {
30 display: inline-block;
31 }
32 a[download] {
33 display: inline-block !important;
34 width: 256px !important;
35 }
36 </style>
37 <script type="text/javascript" src="qrcode.js"></script>
38 </head>
39 <body onload="setHref()">
40 <div full>
41 <% body_header() %>
42 <div body>
43 <h1>QR Code</h1>
44 <span qrcode></span>
45 <p><a download="linkmystyle" button big>Download</a></p>
46 </div>
47 <% footer() %>
48 </div>
49 </body>
50 <script>
51 'use strict';
52
53 let qrcode = new QRCode( document.querySelector('[qrcode]'), {
54 text: '<%=url%>',
55 width: 256,
56 height: 256,
57 } );
58 //console.log(qrcode);
59 function setHref() {
60 let a = document.querySelector('a[download]');
61 let img = document.querySelector('[qrcode] img');
62 //console.log(img.src);
63 a.href = img.src;
64 }
65 </script>
66 </html>
67 <%
68 end