Merge pull request #37 from spro/master
consistent options handling between draw and drawBitArray
This commit is contained in:
commit
35228d901b
2 changed files with 14 additions and 20 deletions
|
@ -127,7 +127,6 @@ QRCodeDraw.prototype = {
|
|||
var args = Array.prototype.slice.call(arguments),
|
||||
cb = args.pop(),
|
||||
text = args.shift(),
|
||||
errorCorrectLevel = args.shift(),
|
||||
options = args.shift() || {};
|
||||
|
||||
//argument processing
|
||||
|
@ -136,20 +135,12 @@ QRCodeDraw.prototype = {
|
|||
// or support proc open to libqrencode
|
||||
throw new Error('callback required as last argument');
|
||||
}
|
||||
|
||||
cb = arguments[arguments.length-1];
|
||||
|
||||
if(arguments.length > 2){
|
||||
errorCorrectLevel = arguments[2];
|
||||
}
|
||||
|
||||
|
||||
//this interface kinda sucks - there is very small likelyhood of this ever being async
|
||||
this.QRVersion(text,errorCorrectLevel,(options||{}).version,function(e,t,l,ec){
|
||||
this.QRVersion(text,options.errorCorrectLevel,options.version,function(e,t,l,ec){
|
||||
text = t,level = l,error = e,errorCorrectLevel = ec;
|
||||
});
|
||||
|
||||
|
||||
if(!level) {
|
||||
//if we are unable to find an appropriate qr level error out
|
||||
cb(error,[],0);
|
||||
|
|
23
qrcode.js
23
qrcode.js
|
@ -44,6 +44,16 @@ exports.getMaxChars = function(minErrorCorrectionLevel,width,moduleScale){
|
|||
console.log('this doesnt work yet. comming soon =)');
|
||||
};
|
||||
|
||||
var parseOptions = function(options) {
|
||||
var textKeys = {'minimum':"L",'medium':"M",'high':"Q",'max':"H"}
|
||||
if(options.errorCorrectLevel) {
|
||||
var ec = options.errorCorrectLevel;
|
||||
if(textKeys[ec]){
|
||||
options.errorCorrectLevel = textKeys[ec];
|
||||
}
|
||||
}
|
||||
return options;
|
||||
};
|
||||
|
||||
// returns Canvas Object with qr code drawn on it
|
||||
/*
|
||||
|
@ -59,15 +69,7 @@ var draw = exports.draw = function(text,options,cb){
|
|||
|
||||
text = args.shift();
|
||||
options = args.shift()||{};
|
||||
var textKeys = {'minimum':"L",'medium':"M",'high':"Q",'max':"H"}
|
||||
if(options.errorCorrectLevel) {
|
||||
var ec = options.errorCorrectLevel;
|
||||
if(textKeys[ec]){
|
||||
options.errorCorrectLevel = textKeys[ec];
|
||||
}
|
||||
}
|
||||
|
||||
//-------------^^^^^^^^^
|
||||
options=parseOptions(options);
|
||||
|
||||
//NOTE the width and height are determined from within the qr code lib and are not configurable from the outside yet
|
||||
|
||||
|
@ -168,9 +170,10 @@ exports.drawBitArray = function(text,options,cb){
|
|||
cb = options;
|
||||
options = {};
|
||||
}
|
||||
options = parseOptions(options);
|
||||
|
||||
var drawInstance = new QRCodeDraw();
|
||||
drawInstance.drawBitArray(text,function(error,bits,width){
|
||||
drawInstance.drawBitArray(text,options,function(error,bits,width){
|
||||
cb(error,bits,width);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue