Skip to content

Commit

Permalink
adde Barcode scanner .js files
Browse files Browse the repository at this point in the history
  • Loading branch information
Harri Sarsa committed Aug 23, 2013
1 parent 3aefc00 commit 719d2fd
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
22 changes: 22 additions & 0 deletions BarcodeScanner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
BarcodeScanner
==============

Cross-platform BarcodeScanner for Cordova / PhoneGap. Verified to work with [AppGyver Steroids](http://www.appgyver.com/steroids).

From [iOS](https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner) and [Android](https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner) repos

## Using the plugin ##

### Configuration for Steroids

The BarcodeScanner plugin is bundled in with AppGyver Scanner, so there's no need to install it separately. Simply copy the JavaScript files in the `www` directory to your project and load them in your app, e.g. with a `<script src="/plugins/barcodescanner.js"></script>" tag.

Note that you only need to load the `barcodescanner.js` file – on Android, the `barcodescanner.android.js` file is used automatically instead. Read more at [Steroids Guides](http://guides.appgyver.com/steroids/guides/android/android-extension/).

You also need to make sure that your `config.platform.xml` file has the correct tag defined:

* config.android.xml:
`<plugin name="BarcodeScanner" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"/>`
* config.ios.xml:
`<plugin name="org.apache.cordova.barcodeScanner" value="CDVBarcodeScanner" />`

72 changes: 72 additions & 0 deletions BarcodeScanner/www/barcodescanner.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* cordova is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) Matt Kane 2010
* Copyright (c) 2011, IBM Corporation
*/

cordova.define("cordova/plugins/barcodescanner",
function(require, exports, module) {
var exec = require("cordova/exec");
var BarcodeScanner = function() {};

//-------------------------------------------------------------------
BarcodeScanner.prototype.scan = function(successCallback, errorCallback) {
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', []);
};

//-------------------------------------------------------------------
BarcodeScanner.prototype.encode = function(type, data, successCallback, errorCallback, options) {
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', 'encode', [{"type": type, "data": data, "options": options}]);
};

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

});

cordova.define("cordova/plugin/BarcodeConstants",
function(require, exports, module) {
module.exports = {
Encode:{
TEXT_TYPE: "TEXT_TYPE",
EMAIL_TYPE: "EMAIL_TYPE",
PHONE_TYPE: "PHONE_TYPE",
SMS_TYPE: "SMS_TYPE",
}
};
});
//-------------------------------------------------------------------
var BarcodeScanner = cordova.require('cordova/plugin/BarcodeConstants');

if(!window.plugins) {
window.plugins = {};
}
if (!window.plugins.barcodeScanner) {
window.plugins.barcodeScanner = cordova.require("cordova/plugins/barcodescanner");
}
76 changes: 76 additions & 0 deletions BarcodeScanner/www/barcodescanner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* PhoneGap/Cordova is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) Matt Kane 2010
* Copyright (c) 2010, IBM Corporation
*/

;(function(){

//-------------------------------------------------------------------
var BarcodeScanner = function() {
}

//-------------------------------------------------------------------
BarcodeScanner.Encode = {
TEXT_TYPE: "TEXT_TYPE",
EMAIL_TYPE: "EMAIL_TYPE",
PHONE_TYPE: "PHONE_TYPE",
SMS_TYPE: "SMS_TYPE",
CONTACT_TYPE: "CONTACT_TYPE",
LOCATION_TYPE: "LOCATION_TYPE"
}

//-------------------------------------------------------------------
BarcodeScanner.prototype.scan = function(success, fail, options) {
function successWrapper(result) {
result.cancelled = (result.cancelled == 1)
success.call(null, result)
}

if (!fail) { fail = function() {}}

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

if (typeof success != "function") {
fail("success callback parameter must be a function")
return
}

if ( null == options )
options = []

return Cordova.exec(successWrapper, fail, "org.apache.cordova.barcodeScanner", "scan", options)
}

//-------------------------------------------------------------------
BarcodeScanner.prototype.encode = function(type, data, success, fail, options) {
if (!fail) { fail = function() {}}

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

if (typeof success != "function") {
fail("success callback parameter must be a function")
return
}

return Cordova.exec(success, fail, "org.apache.cordova.barcodeScanner", "encode", [{type: type, data: data, options: options}])
}

//-------------------------------------------------------------------

// remove Cordova.addConstructor since it was not supported on PhoneGap 2.0
if (!window.plugins) window.plugins = {}

if (!window.plugins.barcodeScanner) {
window.plugins.barcodeScanner = new BarcodeScanner()
}

})();

0 comments on commit 719d2fd

Please sign in to comment.