Adds check for canvas and fallback to div.

pull/1/head
Lars Jung 13 years ago
parent aedc9ca141
commit a4eab68927

@ -6,10 +6,17 @@
(function ($) {
'use strict';
// Check if canvas is available in the browser (as Modernizr does)
var canvasAvailable = (function () {
var elem = document.createElement('canvas');
return !!(elem.getContext && elem.getContext('2d'));
}()),
// Wrapper for the original QR code generator.
var createQr = function (typeNumber, correctLevel, text) {
createQr = function (typeNumber, correctLevel, text) {
// qrcode is the single public function that will be defined by the `QR Code Generator`
// `qrcode` is the single public function that will be defined by the `QR Code Generator`
// at the end of the file.
var qr = qrcode(typeNumber, correctLevel);
qr.addData(text);
@ -117,6 +124,13 @@
return $div;
},
createHTML = function (options) {
var settings = $.extend({}, defaults, options);
return canvasAvailable && settings.render === 'canvas' ? createCanvas(settings) : createDiv(settings);
},
// Plugin
// ======
@ -145,11 +159,9 @@
// -------------------
$.fn.qrcode = function(options) {
var settings = $.extend({}, defaults, options);
return this.each(function () {
$(this).append(settings.render === 'canvas' ? createCanvas(settings) : createDiv(settings));
$(this).append(createHTML(options));
});
};

Loading…
Cancel
Save