forked from ether/etherpad-lite
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: use qr-code-styling to generate qr codes (#18)
- Loading branch information
1 parent
eada79d
commit 143c0af
Showing
8 changed files
with
112 additions
and
642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,75 @@ | ||
function download(){ | ||
var link = document.createElement('a'); //Creates an 'a' element | ||
var thisImg = document.getElementById('qrcode').getElementsByTagName('img')[0]; //gets the first canvas element on the page, assuming the canvas you want to download is this element. | ||
link.download = 'qrcode.png'; //Gives the download an output link | ||
link.href = thisImg.src //Gives the data to the link | ||
link.click(); //Clicks the 'a' element we created | ||
function initialize_qrcode() { | ||
document.getElementById("embedreadonly").addEventListener('change', (changeEvent) => { | ||
generate_qrcode(); | ||
return true; | ||
}); | ||
|
||
generate_qrcode() | ||
} | ||
|
||
function update_qrcode() { | ||
delete_qrcode(); | ||
generate_qrcode(); | ||
function generate_qrcode() { | ||
const url = document.getElementById("linkinput").value; | ||
const qrCodeDiv = document.getElementById('qrcode') | ||
const width = 200; | ||
const height = 200; | ||
|
||
// clear old code: | ||
qrCodeDiv.innerHTML = ''; | ||
|
||
createQrCode(qrCodeDiv, url, width, height) | ||
} | ||
|
||
function qrCodeOptions(url, width, height) { | ||
return { | ||
width: width, | ||
height: height, | ||
type: "svg", | ||
data: url, | ||
image: "", | ||
dotsOptions: { | ||
color: '#000000', | ||
type: 'dots', | ||
}, | ||
cornersSquareOptions: { | ||
type: 'square' | ||
}, | ||
cornersDotOptions: { | ||
type: 'dot' | ||
}, | ||
backgroundOptions: { | ||
color: "#fff", | ||
}, | ||
imageOptions: { | ||
crossOrigin: "anonymous", | ||
margin: 0, | ||
}, | ||
} | ||
} | ||
|
||
function createQrCode(qrCodeDiv, url, width, height) { | ||
const canvas = document.createElement('div'); | ||
qrCodeDiv.appendChild(canvas) | ||
|
||
let qrCode = new QRCodeStyling(qrCodeOptions(url, width, height)); | ||
qrCode.append(canvas); | ||
const downloadButton = addDownloadButton(qrCode); | ||
|
||
qrCodeDiv.appendChild(downloadButton) | ||
|
||
return qrCode | ||
} | ||
|
||
function delete_qrcode() { | ||
document.getElementById('qrcode').getElementsByTagName('img')[0].remove(); | ||
document.getElementById('qrcode').getElementsByTagName('canvas')[0].remove(); | ||
function addDownloadButton(qrCode) { | ||
const downloadButton = document.createElement('button'); | ||
downloadButton.id = 'qr-code-download'; | ||
downloadButton.textContent = 'Download'; | ||
|
||
downloadButton.addEventListener('click', function(clickEvent) { | ||
qrCode.download({ name: "qr", extension: 'png' }); | ||
clickEvent.preventDefault(); | ||
clickEvent.stopPropagation(); | ||
return false; | ||
}) | ||
return downloadButton; | ||
} | ||
|
||
function generate_qrcode() { | ||
let qrlink = document.getElementById("linkinput").value; | ||
new QRCode(document.getElementById("qrcode"), qrlink); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is the license file for QR Code Styling: | ||
https://github.com/kozakdenys/qr-code-styling/blob/master/LICENSE | ||
|
||
MIT License | ||
|
||
Copyright (c) 2019 Denys Kozak | ||
|
||
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. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters