From 719d2fd2824faecdec49a4280c30f5a326737a3d Mon Sep 17 00:00:00 2001 From: Harri Sarsa Date: Fri, 23 Aug 2013 12:43:31 +0300 Subject: [PATCH] adde Barcode scanner .js files --- BarcodeScanner/README.md | 22 ++++++ BarcodeScanner/www/barcodescanner.android.js | 72 +++++++++++++++++++ BarcodeScanner/www/barcodescanner.js | 76 ++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 BarcodeScanner/README.md create mode 100644 BarcodeScanner/www/barcodescanner.android.js create mode 100644 BarcodeScanner/www/barcodescanner.js diff --git a/BarcodeScanner/README.md b/BarcodeScanner/README.md new file mode 100644 index 0000000..b949d90 --- /dev/null +++ b/BarcodeScanner/README.md @@ -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 `" 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: + `` +* config.ios.xml: + `` + diff --git a/BarcodeScanner/www/barcodescanner.android.js b/BarcodeScanner/www/barcodescanner.android.js new file mode 100644 index 0000000..9af26b3 --- /dev/null +++ b/BarcodeScanner/www/barcodescanner.android.js @@ -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"); +} diff --git a/BarcodeScanner/www/barcodescanner.js b/BarcodeScanner/www/barcodescanner.js new file mode 100644 index 0000000..c1df94e --- /dev/null +++ b/BarcodeScanner/www/barcodescanner.js @@ -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() +} + +})();