Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
added data type check, and uri prepending for encode method
Browse files Browse the repository at this point in the history
  • Loading branch information
scheideman committed Dec 4, 2015
1 parent d5e84c9 commit 1cf6376
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
48 changes: 35 additions & 13 deletions src/blackberry10/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ var barcodescanner,
resultObjs = {},
readCallback,
_utils = require("../../lib/utils"),
qr = require('plugin/BarcodeScanner/qrcode.js');


_qr = require('plugin/BarcodeScanner/qrcode.js');

const SMS_URI_ONE = "smsto:",
SMS_URI_TWO = "sms:",
EMAIL_URI = "mailto:",
PHONE_URI = "tel:+1",
SMS_TYPE = "SMS_TYPE",
PHONE_TYPE = "PHONE_TYPE",
EMAIL_TYPE = "EMAIL_TYPE",
TEXT_TYPE = "TEXT_TYPE";

module.exports = {

Expand Down Expand Up @@ -57,29 +63,45 @@ module.exports = {
data = values["data"];
type = values["type"];

if(data == "" || data == undefined || data.length == 0){
result.error("Data was not specified", false);
if(data == "" || data == undefined){
result.error("Data to be encoded was not specified", false);
return;
}
if(type == "" || type == undefined){
type = "TEXT_TYPE";
type = TEXT_TYPE;
}

if(type == SMS_TYPE){
var check_one = data.substring(0,6).toLowerCase();
var check_two = data.substring(0,4).toLowerCase();
if(!(check_one == SMS_URI_ONE || check_two == SMS_URI_TWO)){
data = SMS_URI_ONE+data;
}
}else if(type == EMAIL_TYPE){
var check = data.substring(0,7).toLowerCase();
if(check != EMAIL_URI){
data = EMAIL_URI+data;
}
}else if(type == PHONE_TYPE){
var check = data.substring(0,4).toLowerCase();
if(check != PHONE_URI){
data = PHONE_URI+data;
}
}

console.log("Type: "+type + " Data: " + data);

//Make QRcode using javascript library
//Make QRcode using qrcode.js
var bdiv = document.createElement('div');
var tdiv = document.createElement('div');
var options = {
text: data,
width: 128,
height: 128,
width: 256,
height: 256,
colorDark : "#000000",
colorLight : "#ffffff",
};
var qrcode = qr.makeQRcode(bdiv, options);

var imageURI = qrcode._oDrawing._elCanvas.toDataURL();

var imageURI = _qr.makeQRcode(bdiv, options);

try{
result.ok(imageURI,false);
Expand Down
2 changes: 1 addition & 1 deletion src/blackberry10/qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ var QRCode;
module.exports = {
makeQRcode : function(el, vOption){
var qrcode = new QRCode(el, vOption);
return qrcode
return qrcode._oDrawing._elCanvas.toDataURL();
}
}
})();
5 changes: 2 additions & 3 deletions www/blackberry10/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ var stopRead = function stopRead (succ, fail) {
var encode = function(type, data, succ, fail) {
var value = null,
success = function (data, response) {
value = data;
succ(data["image"]);
succ(data);
},
failure = function (data, response) {
fail(data)
fail(data);
};
exec(success, failure, _ID, "encode",null,[type,data]);
};
Expand Down

0 comments on commit 1cf6376

Please sign in to comment.