Advertisement
Guest User

barcodescanner.js

a guest
Oct 25th, 2013
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * PhoneGap/Cordova is available under *either* the terms of the modified BSD license *or* the
  3.  * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
  4.  *
  5.  * Copyright (c) Matt Kane 2010
  6.  * Copyright (c) 2010, IBM Corporation
  7.  */
  8. cordova.define("cordova/plugin/barcodescanner", function(require, exports, module) {
  9.   var exec = require('cordova/exec');
  10.   var BarcodeScanner = function() { };
  11.  
  12. //-------------------------------------------------------------------
  13. BarcodeScanner.Encode = {
  14.         TEXT_TYPE:     "TEXT_TYPE",
  15.         EMAIL_TYPE:    "EMAIL_TYPE",
  16.         PHONE_TYPE:    "PHONE_TYPE",
  17.         SMS_TYPE:      "SMS_TYPE",
  18.         CONTACT_TYPE:  "CONTACT_TYPE",
  19.         LOCATION_TYPE: "LOCATION_TYPE"
  20. }
  21.  
  22. //-------------------------------------------------------------------
  23. BarcodeScanner.prototype.scan = function(success, fail, options) {
  24.     function successWrapper(result) {
  25.         result.cancelled = (result.cancelled == 1)
  26.         success.call(null, result)
  27.     }
  28.  
  29.     if (!fail) { fail = function() {}}
  30.  
  31.     if (typeof fail != "function")  {
  32.         console.log("BarcodeScanner.scan failure: failure parameter not a function")
  33.         return
  34.     }
  35.  
  36.     if (typeof success != "function") {
  37.         fail("success callback parameter must be a function")
  38.         return
  39.     }
  40.  
  41.     if ( null == options )
  42.       options = []
  43.  
  44.     return exec(successWrapper, fail, "BarcodeScanner", "scan", options)
  45. }
  46.  
  47. //-------------------------------------------------------------------
  48. BarcodeScanner.prototype.encode = function(type, data, success, fail, options) {
  49.     if (!fail) { fail = function() {}}
  50.  
  51.     if (typeof fail != "function")  {
  52.         console.log("BarcodeScanner.scan failure: failure parameter not a function")
  53.         return
  54.     }
  55.  
  56.     if (typeof success != "function") {
  57.         fail("success callback parameter must be a function")
  58.         return
  59.     }
  60.  
  61.     return exec(success, fail, "BarcodeScanner", "encode", [{type: type, data: data, options: options}])
  62. }
  63.  
  64.   var barcodescanner = new BarcodeScanner();
  65.   module.exports = barcodescanner;
  66. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement