Skip to content

Commit

Permalink
Move the QR code link to the connectedhomeip gh-pages branch (#19874)
Browse files Browse the repository at this point in the history
* Add support to display QR code

* Provide mechanism to input QR code text on the page

* Restyled by clang-format

* Restyled by prettier

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
dhrishi and restyled-commits authored Jun 23, 2022
1 parent a855317 commit 1c463fd
Show file tree
Hide file tree
Showing 4 changed files with 1,332 additions and 0 deletions.
14 changes: 14 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
The MIT License (MIT)
---------------------
Copyright (c) 2012 davidshimjs

Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
112 changes: 112 additions & 0 deletions qrcode.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
body {
margin: 0;
padding: 0;
}
.wrapper {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100vh;
background: #f2f2f2;
font-family: 'Roboto', sans-serif;
}

.wrapper div {
text-align: center;
}

.logo {
display: block;
margin: 0 auto 1rem;
}

#qrcode img {
margin: 2rem auto;
}

p {
margin-bottom: 0;
margin-top: 0;
line-height: 24px;
}

#payload {
font-weight: bold;
}

#qr {
margin-bottom: 3rem;
}
button {
margin-bottom: 0;
font-weight: 400;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
background-image: none;
border: 1px solid transparent;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
border-radius: 4px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
color: #fff;
background-color: #5cb85c;
border-color: #4cae4c;
margin-top: 1rem;
}

@media print {
form,
.footer,
.noprint {
display: none;
}
}

#error {
color: #dc3545;
}

.footer {
background: #eaeaea;
padding: 8px;
}

.footer a {
font-weight: bold;
color: #000000;
}

.footer:visited {
color: #000;
}

.input-box {
width: 400px;
padding: 0.345rem 0.75rem;
margin: 1rem auto;
font-size: 14px;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: 0.25rem;
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.qrcode-btn {
margin-top: 0;
}

#qrcode-container {
display: none;
margin: 1rem auto;
}
111 changes: 111 additions & 0 deletions qrcode.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
href="https://fonts.googleapis.com/css?family=Roboto&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="qrcode.css" />
<title>CHIP: QR Code</title>
</head>

<body>
<div class="wrapper">
<div class="container">

<form onsubmit="onSubmitData()" id="qrgeneratorform">
<input
type="text"
id="qrcodetext"
placeholder="Enter QR Code Text"
class="input-box"
/>
<button type="submit" class="qrcode-btn">
Generate QRcode
</button>
</form>

<div id="qrcode-container">
<div class="qrconde-wrapper">
<div>
<h4>
Please scan with your CHIPTool app.
</h4>
<div id="qrcode"></div>
</div>

<div id="payload-info">
<p id="payload"></p>
<p>
This QR code is unique for your device. You may
print a copy of this for subsequent use.
</p>

<button onclick="window.print()" class="noprint">
Print QR Code
</button>
</div>
</div>
</div>
</div>

<div class="footer">
<p>
This QR code is generated using
<a
href="https://davidshimjs.github.io/qrcodejs/"
target="_blank"
>qrcodejs</a
>
</p>
</div>
</div>
<script src="qrcode.min.js"></script>
<script type="text/javascript">
let data;
let qrcontainer = document.querySelector('#qrcode-container');
let qrcodeform = document.querySelector('#qrgeneratorform');

let link = new URLSearchParams(window.location.search);
let linkdata = link.get('data');

if (linkdata) {
qrcodeform.style.display = 'none';
}

function generateQRcode(data) {
document.querySelector(
'#payload'
).innerHTML = `Payload: ${data}`;
var qrcode = new QRCode(document.getElementById('qrcode'), {
text: data,
width: 250,
height: 250,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H,
});
}

function showQRcodeBlock(data) {
if (data) {
qrcontainer.style.display = 'block';
}
}

if (linkdata) {
showQRcodeBlock(linkdata);
generateQRcode(linkdata);
}

function onSubmitData() {
event.preventDefault();
let data = document.querySelector('#qrcodetext').value;
showQRcodeBlock(data);
generateQRcode(data);
}
</script>
</body>
</html>
Loading

0 comments on commit 1c463fd

Please sign in to comment.