-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Harri Sarsa
committed
Aug 23, 2013
1 parent
3aefc00
commit 719d2fd
Showing
3 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" />` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
|
||
})(); |