Skip to content

Commit

Permalink
Maintenance.
Browse files Browse the repository at this point in the history
  • Loading branch information
lrsjng committed May 26, 2016
1 parent a186351 commit 761ecaa
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 129 deletions.
95 changes: 49 additions & 46 deletions dist/jquery-qrcode.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
/*! jquery-qrcode v0.13.4 - https://larsjung.de/jquery-qrcode/ */

This comment has been minimized.

Copy link
@bhoylloza

bhoylloza Dec 8, 2018

dellete

/*! jquery-qrcode v0.14.0 - https://larsjung.de/jquery-qrcode/ */
(function (vendor_qrcode) {
'use strict';

var $ = jQuery; // eslint-disable-line no-undef
var jq = window.jQuery;

// Check if canvas is available in the browser (as Modernizr does)
var hasCanvas = (function () {
var elem = document.createElement('canvas');
return !!(elem.getContext && elem.getContext('2d'));
}());

// Wrapper for the original QR code generator.
function QRCode(text, level, version, quiet) {
var qr = vendor_qrcode(version, level);
qr.addData(text);
qr.make();
function createQRCode(text, level, version, quiet) {
var qr = {};

var vqr = vendor_qrcode(version, level);
vqr.addData(text);
vqr.make();

quiet = quiet || 0;

var qrModuleCount = qr.getModuleCount();
var quietModuleCount = qr.getModuleCount() + 2 * quiet;
var qrModuleCount = vqr.getModuleCount();
var quietModuleCount = vqr.getModuleCount() + 2 * quiet;

function isDark(row, col) {
row -= quiet;
Expand All @@ -22,55 +30,50 @@
if (row < 0 || row >= qrModuleCount || col < 0 || col >= qrModuleCount) {
return false;
}

return qr.isDark(row, col);
return vqr.isDark(row, col);
}

var addBlank = function (l, t, r, b) {
var prevIsDark = this.isDark; // eslint-disable-line no-invalid-this
function addBlank(l, t, r, b) {
var prevIsDark = qr.isDark;
var moduleSize = 1 / quietModuleCount;

this.isDark = function (row, col) { // eslint-disable-line no-invalid-this
qr.isDark = function (row, col) {
var ml = col * moduleSize;
var mt = row * moduleSize;
var mr = ml + moduleSize;
var mb = mt + moduleSize;

return prevIsDark(row, col) && (l > mr || ml > r || t > mb || mt > b);
};
};
}

this.text = text;
this.level = level;
this.version = version;
this.moduleCount = quietModuleCount;
this.isDark = isDark;
this.addBlank = addBlank;
}
qr.text = text;
qr.level = level;
qr.version = version;
qr.moduleCount = quietModuleCount;
qr.isDark = isDark;
qr.addBlank = addBlank;

// Check if canvas is available in the browser (as Modernizr does)
var hasCanvas = (function () {
var elem = document.createElement('canvas');
return Boolean(elem.getContext && elem.getContext('2d'));
}());
return qr;
}

// Returns a minimal QR code for the given text starting with version `minVersion`.
// Returns `undefined` if `text` is too long to be encoded in `maxVersion`.
function createQRCode(text, level, minVersion, maxVersion, quiet) {
function createMinQRCode(text, level, minVersion, maxVersion, quiet) {
minVersion = Math.max(1, minVersion || 1);
maxVersion = Math.min(40, maxVersion || 40);
for (var version = minVersion; version <= maxVersion; version += 1) {
try {
return new QRCode(text, level, version, quiet);
return createQRCode(text, level, version, quiet);
} catch (err) {/* empty */}
}
return null;
return undefined;
}

function drawBackgroundLabel(qr, context, settings) {
var size = settings.size;
var font = 'bold ' + (settings.mSize * size) + 'px ' + settings.fontname;
var ctx = $('<canvas/>')[0].getContext('2d');
var font = 'bold ' + settings.mSize * size + 'px ' + settings.fontname;
var ctx = jq('<canvas/>')[0].getContext('2d');

ctx.font = font;

Expand Down Expand Up @@ -120,7 +123,7 @@
}

function drawBackground(qr, context, settings) {
if ($(settings.background).is('img')) {
if (jq(settings.background).is('img')) {
context.drawImage(settings.background, 0, 0, settings.size, settings.size);
} else if (settings.background) {
context.fillStyle = settings.background;
Expand Down Expand Up @@ -254,7 +257,7 @@
fn(qr, context, settings, l, t, w, row, col);
}
}
if ($(settings.fill).is('img')) {
if (jq(settings.fill).is('img')) {
context.strokeStyle = 'rgba(0,0,0,0.5)';
context.lineWidth = 2;
context.stroke();
Expand All @@ -274,12 +277,12 @@

// Draws QR code to the given `canvas` and returns it.
function drawOnCanvas(canvas, settings) {
var qr = createQRCode(settings.text, settings.ecLevel, settings.minVersion, settings.maxVersion, settings.quiet);
var qr = createMinQRCode(settings.text, settings.ecLevel, settings.minVersion, settings.maxVersion, settings.quiet);
if (!qr) {
return null;
}

var $canvas = $(canvas).data('qrcode', qr);
var $canvas = jq(canvas).data('qrcode', qr);
var context = $canvas[0].getContext('2d');

drawBackground(qr, context, settings);
Expand All @@ -290,18 +293,18 @@

// Returns a `canvas` element representing the QR code for the given settings.
function createCanvas(settings) {
var $canvas = $('<canvas/>').attr('width', settings.size).attr('height', settings.size);
var $canvas = jq('<canvas/>').attr('width', settings.size).attr('height', settings.size);
return drawOnCanvas($canvas, settings);
}

// Returns an `image` element representing the QR code for the given settings.
function createImage(settings) {
return $('<img/>').attr('src', createCanvas(settings)[0].toDataURL('image/png'));
return jq('<img/>').attr('src', createCanvas(settings)[0].toDataURL('image/png'));
}

// Returns a `div` element representing the QR code for the given settings.
function createDiv(settings) {
var qr = createQRCode(settings.text, settings.ecLevel, settings.minVersion, settings.maxVersion, settings.quiet);
var qr = createMinQRCode(settings.text, settings.ecLevel, settings.minVersion, settings.maxVersion, settings.quiet);
if (!qr) {
return null;
}
Expand Down Expand Up @@ -336,7 +339,7 @@
'background-color': settings.fill
};

var $div = $('<div/>').data('qrcode', qr).css(containerCSS);
var $div = jq('<div/>').data('qrcode', qr).css(containerCSS);

if (settings_bgColor) {
$div.css('background-color', settings_bgColor);
Expand All @@ -345,7 +348,7 @@
for (row = 0; row < moduleCount; row += 1) {
for (col = 0; col < moduleCount; col += 1) {
if (qr.isDark(row, col)) {
$('<div/>')
jq('<div/>')
.css(darkCSS)
.css({
left: offset + col * moduleSize,
Expand Down Expand Up @@ -428,14 +431,14 @@

// Register the plugin
// -------------------
$.fn.qrcode = function (options) {
var settings = $.extend({}, defaults, options);
jq.fn.qrcode = function (options) {
var settings = jq.extend({}, defaults, options);

return this.each(function () {
if (this.nodeName.toLowerCase() === 'canvas') { // eslint-disable-line no-invalid-this
drawOnCanvas(this, settings); // eslint-disable-line no-invalid-this
return this.each(function (idx, el) {
if (el.nodeName.toLowerCase() === 'canvas') {
drawOnCanvas(el, settings);
} else {
$(this).append(createHTML(settings)); // eslint-disable-line no-invalid-this
jq(el).append(createHTML(settings));
}
});
};
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery-qrcode.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jquery-qrcode",
"displayName": "jQuery.qrcode",
"version": "0.13.4",
"version": "0.14.0",
"description": "Generate QR codes dynamically.",
"homepage": "https://larsjung.de/jquery-qrcode/",
"bugs": "https://github.com/lrsjng/jquery-qrcode/issues",
Expand Down
1 change: 0 additions & 1 deletion src/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

rules:
func-names: 0
func-style: 0
no-var: 0
prefer-arrow-callback: 0
strict: 0
Binary file modified src/demo/dummy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 35 additions & 34 deletions src/demo/scripts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function () {
'use strict';

var $ = jQuery; // eslint-disable-line no-undef
var jq = window.jQuery;
var guiValuePairs = [
['size', 'px'],
['minversion', ''],
Expand All @@ -13,41 +13,41 @@
];

function updateGui() {
$.each(guiValuePairs, function (idx, pair) {
var $label = $('label[for="' + pair[0] + '"]');
$label.text($label.text().replace(/:.*/, ': ' + $('#' + pair[0]).val() + pair[1]));
jq.each(guiValuePairs, function (idx, pair) {
var $label = jq('label[for="' + pair[0] + '"]');
$label.text($label.text().replace(/:.*/, ': ' + jq('#' + pair[0]).val() + pair[1]));
});
}

function updateQrCode() {
var options = {
render: $('#render').val(),
ecLevel: $('#eclevel').val(),
minVersion: parseInt($('#minversion').val(), 10),
render: jq('#render').val(),
ecLevel: jq('#eclevel').val(),
minVersion: parseInt(jq('#minversion').val(), 10),

fill: $('#fill').val(),
background: $('#background').val(),
// fill: $('#img-buffer')[0],
fill: jq('#fill').val(),
background: jq('#background').val(),
// fill: jq('#img-buffer')[0],

text: $('#text').val(),
size: parseInt($('#size').val(), 10),
radius: parseInt($('#radius').val(), 10) * 0.01,
quiet: parseInt($('#quiet').val(), 10),
text: jq('#text').val(),
size: parseInt(jq('#size').val(), 10),
radius: parseInt(jq('#radius').val(), 10) * 0.01,
quiet: parseInt(jq('#quiet').val(), 10),

mode: parseInt($('#mode').val(), 10),
mode: parseInt(jq('#mode').val(), 10),

mSize: parseInt($('#msize').val(), 10) * 0.01,
mPosX: parseInt($('#mposx').val(), 10) * 0.01,
mPosY: parseInt($('#mposy').val(), 10) * 0.01,
mSize: parseInt(jq('#msize').val(), 10) * 0.01,
mPosX: parseInt(jq('#mposx').val(), 10) * 0.01,
mPosY: parseInt(jq('#mposy').val(), 10) * 0.01,

label: $('#label').val(),
fontname: $('#font').val(),
fontcolor: $('#fontcolor').val(),
label: jq('#label').val(),
fontname: jq('#font').val(),
fontcolor: jq('#fontcolor').val(),

image: $('#img-buffer')[0]
image: jq('#img-buffer')[0]
};

$('#container').empty().qrcode(options);
jq('#container').empty().qrcode(options);
}

function update() {
Expand All @@ -56,28 +56,29 @@
}

function onImageInput() {
var input = $('#image')[0];
var input = jq('#image')[0];
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (event) {
$('#img-buffer').attr('src', event.target.result);
$('#mode').val('4');
jq('#img-buffer').attr('src', event.target.result);
jq('#mode').val('4');
setTimeout(update, 250);
};
reader.readAsDataURL(input.files[0]);
}
}

function download() {
$('#download').attr('href', $('#container canvas')[0].toDataURL('image/png'));
jq('#download').attr('href', jq('#container canvas')[0].toDataURL('image/png'));
}


$(function () {
$('#download').on('click', download);
$('#image').on('change', onImageInput);
$('input, textarea, select').on('input change', update);
$(window).load(update);
function init() {
jq('#download').on('click', download);
jq('#image').on('change', onImageInput);
jq('input, textarea, select').on('input change', update);
jq(window).load(update);
update();
});
}

jq(init);
}());
Loading

0 comments on commit 761ecaa

Please sign in to comment.