Finalize
This commit is contained in:
46
README.md
Normal file
46
README.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# QRCode.js
|
||||||
|
QRCode.js is javascript library for making QRCode. QRCode.js supports Cross-browser with HTML5 Canvas and table tag in DOM.
|
||||||
|
QRCode.js has no dependencies.
|
||||||
|
|
||||||
|
## Basic Usages
|
||||||
|
```
|
||||||
|
<div id="qrcode"></div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
new QRCode(document.getElementById("qrcode"), "http://jindo.dev.naver.com/collie");
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
or with some options
|
||||||
|
|
||||||
|
```
|
||||||
|
<div id="qrcode"></div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var qrcode = new QRCode(document.getElementById("qrcode"), {
|
||||||
|
text: "http://jindo.dev.naver.com/collie",
|
||||||
|
width: 128,
|
||||||
|
height: 128,
|
||||||
|
colorDark : "#000000",
|
||||||
|
colorLight : "#ffffff",
|
||||||
|
correctLevel : QRCode.CorrectLevel.H
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
and you can use some methods
|
||||||
|
|
||||||
|
```
|
||||||
|
qrcode.clear(); // clear the code.
|
||||||
|
qrcode.makeCode("http://naver.com"); // make another code.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Browser Compatibility
|
||||||
|
IE6~10, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, Windows Mobile, ETC.
|
||||||
|
|
||||||
|
## License
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
## Contact
|
||||||
|
twitter @davidshimjs
|
||||||
|
|
||||||
|
[](https://bitdeli.com/free "Bitdeli Badge")
|
||||||
|
|
||||||
193
index-svg.html
193
index-svg.html
@@ -1,27 +1,181 @@
|
|||||||
<!DOCTYPE html
|
<!DOCTYPE html>
|
||||||
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
<html lang="en">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">
|
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Cross-Browser QRCode generator for Javascript</title>
|
<title>QR Code Generator</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
|
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
|
||||||
<script type="text/javascript" src="jquery.min.js"></script>
|
<script type="text/javascript" src="jquery.min.js"></script>
|
||||||
<script type="text/javascript" src="qrcode.js"></script>
|
<script type="text/javascript" src="qrcode.js"></script>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||||
|
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
background: white;
|
||||||
|
border-radius: 20px;
|
||||||
|
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
|
||||||
|
padding: 40px;
|
||||||
|
max-width: 600px;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
font-size: 2.5em;
|
||||||
|
font-weight: 300;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-group {
|
||||||
|
margin-bottom: 25px;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 15px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#text {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 250px;
|
||||||
|
padding: 15px 20px;
|
||||||
|
border: 2px solid #e1e8ed;
|
||||||
|
border-radius: 25px;
|
||||||
|
font-size: 16px;
|
||||||
|
outline: none;
|
||||||
|
transition: border-color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
#text:focus {
|
||||||
|
border-color: #4a5568;
|
||||||
|
}
|
||||||
|
|
||||||
|
#color {
|
||||||
|
width: 60px;
|
||||||
|
height: 50px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 25px;
|
||||||
|
cursor: pointer;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#download {
|
||||||
|
background: linear-gradient(45deg, #4a5568, #2d3748);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 15px 25px;
|
||||||
|
border-radius: 25px;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
#download:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.qr-container {
|
||||||
|
margin: 30px 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
background: #f8f9fa;
|
||||||
|
border-radius: 15px;
|
||||||
|
padding: 20px;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
#qrcode {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#qrcode svg {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: none;
|
||||||
|
width: auto;
|
||||||
|
height: auto;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: white;
|
||||||
|
padding: 10px;
|
||||||
|
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
margin-top: 20px;
|
||||||
|
color: #666;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.container {
|
||||||
|
padding: 25px;
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 2em;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-group {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
#text {
|
||||||
|
min-width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<input id="text" type="text" value="http://jindo.dev.naver.com/collie" style="width:80%" />
|
<div class="container">
|
||||||
<input id="color" type="color" value="#004c93" style="margin-left:10px;" />
|
<h1>QR Code Generator</h1>
|
||||||
<button id="download" onclick="downloadSVG()" style="margin-left:10px; padding:5px 10px;">Download SVG</button>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
<div class="input-group">
|
||||||
<g id="qrcode" />
|
<input id="text" type="text" value="https://git.0n8.de/BerriJ/onlyqr"
|
||||||
</svg>
|
placeholder="Enter text or URL to generate QR code" />
|
||||||
|
<input id="color" type="color" value="#004c93" title="Choose QR code color" />
|
||||||
|
<button id="download" onclick="downloadSVG()">Download SVG</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="qr-container">
|
||||||
|
<div id="qrcode"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="footer">
|
||||||
|
Enter any text or URL above to generate a QR code
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="footer" style="margin-top: 10px; font-size: 12px; color: #999;">
|
||||||
|
Made with ❤️ using <a href="https://github.com/davidshimjs/qrcodejs" target="_blank"
|
||||||
|
style="color: #667; text-decoration: none;">QRCode.js by davidshimjs</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var qrcode = new QRCode(document.getElementById("qrcode"), {
|
var qrcode = new QRCode(document.getElementById("qrcode"), {
|
||||||
width: 250,
|
|
||||||
height: 250,
|
|
||||||
useSVG: true,
|
|
||||||
colorDark: "#004c93"
|
colorDark: "#004c93"
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -30,22 +184,13 @@
|
|||||||
var elColor = document.getElementById("color");
|
var elColor = document.getElementById("color");
|
||||||
|
|
||||||
if (!elText.value) {
|
if (!elText.value) {
|
||||||
alert("Input a text");
|
alert("Please enter some text");
|
||||||
elText.focus();
|
elText.focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qrcode._htOption.colorDark = elColor.value;
|
qrcode._htOption.colorDark = elColor.value;
|
||||||
qrcode.makeCode(elText.value);
|
qrcode.makeCode(elText.value);
|
||||||
|
|
||||||
// Update size based on module count
|
|
||||||
var moduleCount = qrcode._oQRCode.getModuleCount();
|
|
||||||
var size = moduleCount * 10;
|
|
||||||
qrcode._htOption.width = size;
|
|
||||||
qrcode._htOption.height = size;
|
|
||||||
|
|
||||||
// Regenerate with new size
|
|
||||||
qrcode.makeCode(elText.value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
makeCode();
|
makeCode();
|
||||||
@@ -65,7 +210,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
function downloadSVG() {
|
function downloadSVG() {
|
||||||
var svg = document.querySelector('svg');
|
var svg = document.querySelector('#qrcode svg');
|
||||||
var svgData = new XMLSerializer().serializeToString(svg);
|
var svgData = new XMLSerializer().serializeToString(svg);
|
||||||
var svgBlob = new Blob([svgData], { type: "image/svg+xml;charset=utf-8" });
|
var svgBlob = new Blob([svgData], { type: "image/svg+xml;charset=utf-8" });
|
||||||
var svgUrl = URL.createObjectURL(svgBlob);
|
var svgUrl = URL.createObjectURL(svgBlob);
|
||||||
|
|||||||
268
qrcode.js
268
qrcode.js
@@ -183,8 +183,6 @@ var QRCode;
|
|||||||
var _htOption = this._htOption;
|
var _htOption = this._htOption;
|
||||||
var _el = this._el;
|
var _el = this._el;
|
||||||
var nCount = oQRCode.getModuleCount();
|
var nCount = oQRCode.getModuleCount();
|
||||||
var nWidth = Math.floor(_htOption.width / nCount);
|
|
||||||
var nHeight = Math.floor(_htOption.height / nCount);
|
|
||||||
|
|
||||||
this.clear();
|
this.clear();
|
||||||
|
|
||||||
@@ -195,7 +193,7 @@ var QRCode;
|
|||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
var svg = makeSVG("svg" , {'viewBox': '0 0 ' + String(nCount) + " " + String(nCount), 'width': '100%', 'height': '100%', 'fill': _htOption.colorLight});
|
var svg = makeSVG("svg" , {'viewBox': '0 0 ' + String(nCount) + " " + String(nCount), 'width': String(10 * nCount), 'height': String(10 * nCount), 'fill': _htOption.colorLight});
|
||||||
svg.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink");
|
svg.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink");
|
||||||
_el.appendChild(svg);
|
_el.appendChild(svg);
|
||||||
|
|
||||||
@@ -212,6 +210,7 @@ var QRCode;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Drawing.prototype.clear = function () {
|
Drawing.prototype.clear = function () {
|
||||||
while (this._el.hasChildNodes())
|
while (this._el.hasChildNodes())
|
||||||
this._el.removeChild(this._el.lastChild);
|
this._el.removeChild(this._el.lastChild);
|
||||||
@@ -219,245 +218,11 @@ var QRCode;
|
|||||||
return Drawing;
|
return Drawing;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var useSVG = document.documentElement.tagName.toLowerCase() === "svg";
|
var useSVG = true;
|
||||||
|
|
||||||
// Drawing in DOM by using Table tag
|
// Always use SVG rendering by default
|
||||||
var Drawing = useSVG ? svgDrawer : !_isSupportCanvas() ? (function () {
|
var Drawing = svgDrawer;
|
||||||
var Drawing = function (el, htOption) {
|
|
||||||
this._el = el;
|
|
||||||
this._htOption = htOption;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draw the QRCode
|
|
||||||
*
|
|
||||||
* @param {QRCode} oQRCode
|
|
||||||
*/
|
|
||||||
Drawing.prototype.draw = function (oQRCode) {
|
|
||||||
var _htOption = this._htOption;
|
|
||||||
var _el = this._el;
|
|
||||||
var nCount = oQRCode.getModuleCount();
|
|
||||||
var nWidth = Math.floor(_htOption.width / nCount);
|
|
||||||
var nHeight = Math.floor(_htOption.height / nCount);
|
|
||||||
var aHTML = ['<table style="border:0;border-collapse:collapse;">'];
|
|
||||||
|
|
||||||
for (var row = 0; row < nCount; row++) {
|
|
||||||
aHTML.push('<tr>');
|
|
||||||
|
|
||||||
for (var col = 0; col < nCount; col++) {
|
|
||||||
aHTML.push('<td style="border:0;border-collapse:collapse;padding:0;margin:0;width:' + nWidth + 'px;height:' + nHeight + 'px;background-color:' + (oQRCode.isDark(row, col) ? _htOption.colorDark : _htOption.colorLight) + ';"></td>');
|
|
||||||
}
|
|
||||||
|
|
||||||
aHTML.push('</tr>');
|
|
||||||
}
|
|
||||||
|
|
||||||
aHTML.push('</table>');
|
|
||||||
_el.innerHTML = aHTML.join('');
|
|
||||||
|
|
||||||
// Fix the margin values as real size.
|
|
||||||
var elTable = _el.childNodes[0];
|
|
||||||
var nLeftMarginTable = (_htOption.width - elTable.offsetWidth) / 2;
|
|
||||||
var nTopMarginTable = (_htOption.height - elTable.offsetHeight) / 2;
|
|
||||||
|
|
||||||
if (nLeftMarginTable > 0 && nTopMarginTable > 0) {
|
|
||||||
elTable.style.margin = nTopMarginTable + "px " + nLeftMarginTable + "px";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear the QRCode
|
|
||||||
*/
|
|
||||||
Drawing.prototype.clear = function () {
|
|
||||||
this._el.innerHTML = '';
|
|
||||||
};
|
|
||||||
|
|
||||||
return Drawing;
|
|
||||||
})() : (function () { // Drawing in Canvas
|
|
||||||
function _onMakeImage() {
|
|
||||||
this._elImage.src = this._elCanvas.toDataURL("image/png");
|
|
||||||
this._elImage.style.display = "block";
|
|
||||||
this._elCanvas.style.display = "none";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Android 2.1 bug workaround
|
|
||||||
// http://code.google.com/p/android/issues/detail?id=5141
|
|
||||||
if (this._android && this._android <= 2.1) {
|
|
||||||
var factor = 1 / window.devicePixelRatio;
|
|
||||||
var drawImage = CanvasRenderingContext2D.prototype.drawImage;
|
|
||||||
CanvasRenderingContext2D.prototype.drawImage = function (image, sx, sy, sw, sh, dx, dy, dw, dh) {
|
|
||||||
if (("nodeName" in image) && /img/i.test(image.nodeName)) {
|
|
||||||
for (var i = arguments.length - 1; i >= 1; i--) {
|
|
||||||
arguments[i] = arguments[i] * factor;
|
|
||||||
}
|
|
||||||
} else if (typeof dw == "undefined") {
|
|
||||||
arguments[1] *= factor;
|
|
||||||
arguments[2] *= factor;
|
|
||||||
arguments[3] *= factor;
|
|
||||||
arguments[4] *= factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
drawImage.apply(this, arguments);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether the user's browser supports Data URI or not
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Function} fSuccess Occurs if it supports Data URI
|
|
||||||
* @param {Function} fFail Occurs if it doesn't support Data URI
|
|
||||||
*/
|
|
||||||
function _safeSetDataURI(fSuccess, fFail) {
|
|
||||||
var self = this;
|
|
||||||
self._fFail = fFail;
|
|
||||||
self._fSuccess = fSuccess;
|
|
||||||
|
|
||||||
// Check it just once
|
|
||||||
if (self._bSupportDataURI === null) {
|
|
||||||
var el = document.createElement("img");
|
|
||||||
var fOnError = function() {
|
|
||||||
self._bSupportDataURI = false;
|
|
||||||
|
|
||||||
if (self._fFail) {
|
|
||||||
self._fFail.call(self);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var fOnSuccess = function() {
|
|
||||||
self._bSupportDataURI = true;
|
|
||||||
|
|
||||||
if (self._fSuccess) {
|
|
||||||
self._fSuccess.call(self);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
el.onabort = fOnError;
|
|
||||||
el.onerror = fOnError;
|
|
||||||
el.onload = fOnSuccess;
|
|
||||||
el.src = "data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; // the Image contains 1px data.
|
|
||||||
return;
|
|
||||||
} else if (self._bSupportDataURI === true && self._fSuccess) {
|
|
||||||
self._fSuccess.call(self);
|
|
||||||
} else if (self._bSupportDataURI === false && self._fFail) {
|
|
||||||
self._fFail.call(self);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Drawing QRCode by using canvas
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
* @param {HTMLElement} el
|
|
||||||
* @param {Object} htOption QRCode Options
|
|
||||||
*/
|
|
||||||
var Drawing = function (el, htOption) {
|
|
||||||
this._bIsPainted = false;
|
|
||||||
this._android = _getAndroid();
|
|
||||||
|
|
||||||
this._htOption = htOption;
|
|
||||||
this._elCanvas = document.createElement("canvas");
|
|
||||||
this._elCanvas.width = htOption.width;
|
|
||||||
this._elCanvas.height = htOption.height;
|
|
||||||
el.appendChild(this._elCanvas);
|
|
||||||
this._el = el;
|
|
||||||
this._oContext = this._elCanvas.getContext("2d");
|
|
||||||
this._bIsPainted = false;
|
|
||||||
this._elImage = document.createElement("img");
|
|
||||||
this._elImage.alt = "Scan me!";
|
|
||||||
this._elImage.style.display = "none";
|
|
||||||
this._el.appendChild(this._elImage);
|
|
||||||
this._bSupportDataURI = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draw the QRCode
|
|
||||||
*
|
|
||||||
* @param {QRCode} oQRCode
|
|
||||||
*/
|
|
||||||
Drawing.prototype.draw = function (oQRCode) {
|
|
||||||
var _elImage = this._elImage;
|
|
||||||
var _oContext = this._oContext;
|
|
||||||
var _htOption = this._htOption;
|
|
||||||
|
|
||||||
var nCount = oQRCode.getModuleCount();
|
|
||||||
var nWidth = _htOption.width / nCount;
|
|
||||||
var nHeight = _htOption.height / nCount;
|
|
||||||
var nRoundedWidth = Math.round(nWidth);
|
|
||||||
var nRoundedHeight = Math.round(nHeight);
|
|
||||||
|
|
||||||
_elImage.style.display = "none";
|
|
||||||
this.clear();
|
|
||||||
|
|
||||||
for (var row = 0; row < nCount; row++) {
|
|
||||||
for (var col = 0; col < nCount; col++) {
|
|
||||||
var bIsDark = oQRCode.isDark(row, col);
|
|
||||||
var nLeft = col * nWidth;
|
|
||||||
var nTop = row * nHeight;
|
|
||||||
_oContext.strokeStyle = bIsDark ? _htOption.colorDark : _htOption.colorLight;
|
|
||||||
_oContext.lineWidth = 1;
|
|
||||||
_oContext.fillStyle = bIsDark ? _htOption.colorDark : _htOption.colorLight;
|
|
||||||
_oContext.fillRect(nLeft, nTop, nWidth, nHeight);
|
|
||||||
|
|
||||||
// 안티 앨리어싱 방지 처리
|
|
||||||
_oContext.strokeRect(
|
|
||||||
Math.floor(nLeft) + 0.5,
|
|
||||||
Math.floor(nTop) + 0.5,
|
|
||||||
nRoundedWidth,
|
|
||||||
nRoundedHeight
|
|
||||||
);
|
|
||||||
|
|
||||||
_oContext.strokeRect(
|
|
||||||
Math.ceil(nLeft) - 0.5,
|
|
||||||
Math.ceil(nTop) - 0.5,
|
|
||||||
nRoundedWidth,
|
|
||||||
nRoundedHeight
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this._bIsPainted = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make the image from Canvas if the browser supports Data URI.
|
|
||||||
*/
|
|
||||||
Drawing.prototype.makeImage = function () {
|
|
||||||
if (this._bIsPainted) {
|
|
||||||
_safeSetDataURI.call(this, _onMakeImage);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return whether the QRCode is painted or not
|
|
||||||
*
|
|
||||||
* @return {Boolean}
|
|
||||||
*/
|
|
||||||
Drawing.prototype.isPainted = function () {
|
|
||||||
return this._bIsPainted;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear the QRCode
|
|
||||||
*/
|
|
||||||
Drawing.prototype.clear = function () {
|
|
||||||
this._oContext.clearRect(0, 0, this._elCanvas.width, this._elCanvas.height);
|
|
||||||
this._bIsPainted = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @param {Number} nNumber
|
|
||||||
*/
|
|
||||||
Drawing.prototype.round = function (nNumber) {
|
|
||||||
if (!nNumber) {
|
|
||||||
return nNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Math.floor(nNumber * 1000) / 1000;
|
|
||||||
};
|
|
||||||
|
|
||||||
return Drawing;
|
|
||||||
})();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type by string length
|
* Get the type by string length
|
||||||
*
|
*
|
||||||
@@ -558,15 +323,10 @@ var QRCode;
|
|||||||
if (typeof el == "string") {
|
if (typeof el == "string") {
|
||||||
el = document.getElementById(el);
|
el = document.getElementById(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._htOption.useSVG) {
|
|
||||||
Drawing = svgDrawer;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._android = _getAndroid();
|
|
||||||
this._el = el;
|
this._el = el;
|
||||||
this._oQRCode = null;
|
this._oQRCode = null;
|
||||||
this._oDrawing = new Drawing(this._el, this._htOption);
|
this._oDrawing = new svgDrawer(this._el, this._htOption);
|
||||||
|
|
||||||
if (this._htOption.text) {
|
if (this._htOption.text) {
|
||||||
this.makeCode(this._htOption.text);
|
this.makeCode(this._htOption.text);
|
||||||
@@ -583,21 +343,7 @@ var QRCode;
|
|||||||
this._oQRCode.addData(sText);
|
this._oQRCode.addData(sText);
|
||||||
this._oQRCode.make();
|
this._oQRCode.make();
|
||||||
this._el.title = sText;
|
this._el.title = sText;
|
||||||
this._oDrawing.draw(this._oQRCode);
|
this._oDrawing.draw(this._oQRCode);
|
||||||
this.makeImage();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make the Image from Canvas element
|
|
||||||
* - It occurs automatically
|
|
||||||
* - Android below 3 doesn't support Data-URI spec.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
QRCode.prototype.makeImage = function () {
|
|
||||||
if (typeof this._oDrawing.makeImage == "function" && (!this._android || this._android >= 3)) {
|
|
||||||
this._oDrawing.makeImage();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user