mirror of
https://github.com/lrsjng/jquery-qrcode.git
synced 2026-08-13 04:11:36 +08:00
Adds check for canvas and fallback to div.
This commit is contained in:
+18
-6
@@ -6,10 +6,17 @@
|
|||||||
(function ($) {
|
(function ($) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Wrapper for the original QR code generator.
|
// Check if canvas is available in the browser (as Modernizr does)
|
||||||
var createQr = function (typeNumber, correctLevel, text) {
|
var canvasAvailable = (function () {
|
||||||
|
|
||||||
// qrcode is the single public function that will be defined by the `QR Code Generator`
|
var elem = document.createElement('canvas');
|
||||||
|
return !!(elem.getContext && elem.getContext('2d'));
|
||||||
|
}()),
|
||||||
|
|
||||||
|
// Wrapper for the original QR code generator.
|
||||||
|
createQr = function (typeNumber, correctLevel, text) {
|
||||||
|
|
||||||
|
// `qrcode` is the single public function that will be defined by the `QR Code Generator`
|
||||||
// at the end of the file.
|
// at the end of the file.
|
||||||
var qr = qrcode(typeNumber, correctLevel);
|
var qr = qrcode(typeNumber, correctLevel);
|
||||||
qr.addData(text);
|
qr.addData(text);
|
||||||
@@ -117,6 +124,13 @@
|
|||||||
return $div;
|
return $div;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
createHTML = function (options) {
|
||||||
|
|
||||||
|
var settings = $.extend({}, defaults, options);
|
||||||
|
|
||||||
|
return canvasAvailable && settings.render === 'canvas' ? createCanvas(settings) : createDiv(settings);
|
||||||
|
},
|
||||||
|
|
||||||
// Plugin
|
// Plugin
|
||||||
// ======
|
// ======
|
||||||
|
|
||||||
@@ -145,11 +159,9 @@
|
|||||||
// -------------------
|
// -------------------
|
||||||
$.fn.qrcode = function(options) {
|
$.fn.qrcode = function(options) {
|
||||||
|
|
||||||
var settings = $.extend({}, defaults, options);
|
|
||||||
|
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
|
|
||||||
$(this).append(settings.render === 'canvas' ? createCanvas(settings) : createDiv(settings));
|
$(this).append(createHTML(options));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user