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

Commit

Permalink
Merge pull request #5 from stevengill/master
Browse files Browse the repository at this point in the history
Remove cordova.define & update ID for npm move
  • Loading branch information
Steve Gill committed May 21, 2015
2 parents 4e5af0c + 50d3f0a commit b17891c
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 120 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
BarcodeScanner
==============
# PhoneGap Plugin BarcodeScanner
================================

Cross-platform BarcodeScanner for Cordova / PhoneGap.

Follows the [Cordova Plugin spec](http://cordova.apache.org/docs/en/3.0.0/plugin_ref_spec.md), so that it works with [Plugman](https://github.com/apache/cordova-plugman).

## Installation

phonegap plugin add phonegap-plugin-barcodescanner

### Supported Platforms

- Android
Expand Down
42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "phonegap-plugin-barcodescanner",
"version": "3.0.0",
"description": "You can use the BarcodeScanner plugin to scan different types of barcodes (using the device's camera) and get the metadata encoded in them for processing within your application.",
"cordova": {
"id": "phonegap-plugin-barcodescanner",
"platforms": [
"ios",
"android",
"windows8",
"windows",
"wp8",
"browser"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/phonegap/phonegap-plugin-barcodescanner.git"
},
"keywords": [
"ecosystem:cordova",
"ecosystem:phonegap",
"cordova-ios",
"cordova-android",
"cordova-windows8",
"cordova-windows",
"cordova-wp8",
"cordova-browser"
],
"engines": [
{
"name": "cordova",
"version": ">=3.0.0"
}
],
"author": "Adobe PhoneGap Team",
"license": "MIT",
"bugs": {
"url": "https://github.com/phonegap/phonegap-plugin-barcodescanner/issues"
},
"homepage": "https://github.com/phonegap/phonegap-plugin-barcodescanner#readme"
}
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?><plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.phonegap.plugins.barcodescanner"
version="2.2.0">
id="phonegap-plugin-barcodescanner"
version="3.0.0">

<name>BarcodeScanner</name>
<description>You can use the BarcodeScanner plugin to scan different types of barcodes (using the device's camera) and get the metadata encoded in them for processing within your application.</description>
Expand Down
221 changes: 105 additions & 116 deletions www/barcodescanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,131 +6,120 @@
* Copyright (c) 2011, IBM Corporation
*/

var ScannerLoader = function (require, exports, module) {

var exec = require("cordova/exec");

/**
* Constructor.
*
* @returns {BarcodeScanner}
*/
function BarcodeScanner() {

/**
* Encoding constants.
*
* @type Object
*/
this.Encode = {
TEXT_TYPE: "TEXT_TYPE",
EMAIL_TYPE: "EMAIL_TYPE",
PHONE_TYPE: "PHONE_TYPE",
SMS_TYPE: "SMS_TYPE"
// CONTACT_TYPE: "CONTACT_TYPE", // TODO: not implemented, requires passing a Bundle class from Javascript to Java
// LOCATION_TYPE: "LOCATION_TYPE" // TODO: not implemented, requires passing a Bundle class from Javascript to Java
};

/**
* Barcode format constants, defined in ZXing library.
*
* @type Object
*/
this.format = {
"all_1D": 61918,
"aztec": 1,
"codabar": 2,
"code_128": 16,
"code_39": 4,
"code_93": 8,
"data_MATRIX": 32,
"ean_13": 128,
"ean_8": 64,
"itf": 256,
"maxicode": 512,
"msi": 131072,
"pdf_417": 1024,
"plessey": 262144,
"qr_CODE": 2048,
"rss_14": 4096,
"rss_EXPANDED": 8192,
"upc_A": 16384,
"upc_E": 32768,
"upc_EAN_EXTENSION": 65536
};
};

/**
* Read code from scanner.
*
* @param {Function} successCallback This function will recieve a result object: {
* text : '12345-mock', // The code that was scanned.
* format : 'FORMAT_NAME', // Code format.
* cancelled : true/false, // Was canceled.
* }
* @param {Function} errorCallback
*/
BarcodeScanner.prototype.scan = function (successCallback, errorCallback, config) {

if(config instanceof Array) {
// do nothing
} else {
if(typeof(config) === 'object') {
config = [ config ];
} else {
config = [];
}
}

if (errorCallback == null) {
errorCallback = function () {
};
}

if (typeof errorCallback != "function") {
console.log("BarcodeScanner.scan failure: failure parameter not a function");
return;
}

if (typeof successCallback != "function") {
console.log("BarcodeScanner.scan failure: success callback parameter must be a function");
return;
}

exec(successCallback, errorCallback, 'BarcodeScanner', 'scan', config);
};
var exec = require("cordova/exec");

//-------------------------------------------------------------------
BarcodeScanner.prototype.encode = function (type, data, successCallback, errorCallback, options) {
if (errorCallback == null) {
errorCallback = function () {
};
}

if (typeof errorCallback != "function") {
console.log("BarcodeScanner.encode failure: failure parameter not a function");
return;
}

if (typeof successCallback != "function") {
console.log("BarcodeScanner.encode failure: success callback parameter must be a function");
return;
}

exec(successCallback, errorCallback, 'BarcodeScanner', 'encode', [
{"type": type, "data": data, "options": options}
]);
/**
* Constructor.
*
* @returns {BarcodeScanner}
*/
function BarcodeScanner() {

/**
* Encoding constants.
*
* @type Object
*/
this.Encode = {
TEXT_TYPE: "TEXT_TYPE",
EMAIL_TYPE: "EMAIL_TYPE",
PHONE_TYPE: "PHONE_TYPE",
SMS_TYPE: "SMS_TYPE"
// CONTACT_TYPE: "CONTACT_TYPE", // TODO: not implemented, requires passing a Bundle class from Javascript to Java
// LOCATION_TYPE: "LOCATION_TYPE" // TODO: not implemented, requires passing a Bundle class from Javascript to Java
};

/**
* Barcode format constants, defined in ZXing library.
*
* @type Object
*/
this.format = {
"all_1D": 61918,
"aztec": 1,
"codabar": 2,
"code_128": 16,
"code_39": 4,
"code_93": 8,
"data_MATRIX": 32,
"ean_13": 128,
"ean_8": 64,
"itf": 256,
"maxicode": 512,
"msi": 131072,
"pdf_417": 1024,
"plessey": 262144,
"qr_CODE": 2048,
"rss_14": 4096,
"rss_EXPANDED": 8192,
"upc_A": 16384,
"upc_E": 32768,
"upc_EAN_EXTENSION": 65536
};
};

/**
* Read code from scanner.
*
* @param {Function} successCallback This function will recieve a result object: {
* text : '12345-mock', // The code that was scanned.
* format : 'FORMAT_NAME', // Code format.
* cancelled : true/false, // Was canceled.
* }
* @param {Function} errorCallback
*/
BarcodeScanner.prototype.scan = function (successCallback, errorCallback, config) {

if(config instanceof Array) {
// do nothing
} else {
if(typeof(config) === 'object') {
config = [ config ];
} else {
config = [];
}
}

if (errorCallback == null) {
errorCallback = function () {
};
}

var barcodeScanner = new BarcodeScanner();
module.exports = barcodeScanner;
if (typeof errorCallback != "function") {
console.log("BarcodeScanner.scan failure: failure parameter not a function");
return;
}

if (typeof successCallback != "function") {
console.log("BarcodeScanner.scan failure: success callback parameter must be a function");
return;
}

ScannerLoader(require, exports, module);
exec(successCallback, errorCallback, 'BarcodeScanner', 'scan', config);
};

cordova.define("cordova/plugin/BarcodeScanner", ScannerLoader);
//-------------------------------------------------------------------
BarcodeScanner.prototype.encode = function (type, data, successCallback, errorCallback, options) {
if (errorCallback == null) {
errorCallback = function () {
};
}

if (typeof errorCallback != "function") {
console.log("BarcodeScanner.encode failure: failure parameter not a function");
return;
}

if (typeof successCallback != "function") {
console.log("BarcodeScanner.encode failure: success callback parameter must be a function");
return;
}

exec(successCallback, errorCallback, 'BarcodeScanner', 'encode', [
{"type": type, "data": data, "options": options}
]);
};

var barcodeScanner = new BarcodeScanner();
module.exports = barcodeScanner;

0 comments on commit b17891c

Please sign in to comment.