Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. (function() {
  2. var t = function(t, e) {
  3. return function() {
  4. return t.apply(e, arguments)
  5. }
  6. },
  7. e = [].slice;
  8. namespace("OrgSync", function(r) {
  9. return r.CardReader = function() {
  10. function n(e) {
  11. this._triggerValid = t(this._triggerValid, this), this._enabled = !1, this._events = [], this._matcher = new i(e, this._triggerValid), this._scanner = new a(this._matcher.execute), $("body").prepend('<input type="text" id="card-reader-box" tabindex="0" style="position: absolute; top: -50px;">'), this._$cardReaderBox = $("#card-reader-box"), this._$cardReaderBox.off("keypress.OrgSyncCardReader").on("keypress.OrgSyncCardReader", function(t) {
  12. return function(e) {
  13. if (t.isEnabled()) return t._scanner.add(e.which)
  14. }
  15. }(this)), $(document).off("keypress.OrgSyncCardReader").on("keypress.OrgSyncCardReader", function(t) {
  16. return function(e) {
  17. if (t.isEnabled() && !$(e.target).is("input, select")) return t._$cardReaderBox.focus(), t._scanner.add(e.which)
  18. }
  19. }(this))
  20. }
  21. var i, a;
  22. return n.instance = function(t) {
  23. return null != this._cardReader ? this._cardReader : this._cardReader = new r.CardReader(t)
  24. }, n.prototype.scan = function(t) {
  25. var e, r, n;
  26. for (r = 0, n = t.length; r < n; r++) e = t[r], this._scanner.add(e.charCodeAt(0));
  27. return this._scanner.add(13)
  28. }, n.prototype.bind = function(t, e) {
  29. return this._events[t] = e, this
  30. }, n.prototype.enable = function() {
  31. return this._enabled = !0, this._$cardReaderBox.focus(), this._trigger("Enabled"), this
  32. }, n.prototype.disable = function() {
  33. return this._enabled = !1, this._$cardReaderBox.blur(), this._trigger("Disabled"), this
  34. }, n.prototype.isEnabled = function() {
  35. return this._enabled
  36. }, n.prototype._trigger = function() {
  37. var t, r;
  38. if (r = arguments[0], t = 2 <= arguments.length ? e.call(arguments, 1) : [], this._events[r]) return this._events[r].apply(this, t)
  39. }, n.prototype._triggerValid = function(t) {
  40. return this._$cardReaderBox.val(""), this._trigger("ValidRead", t)
  41. }, a = function() {
  42. function t(t) {
  43. this._callback = t, this._clear()
  44. }
  45. var e;
  46. return e = 13, t.prototype.add = function(t) {
  47. return t === e ? this._executeCallback() : this._buffer += String.fromCharCode(t)
  48. }, t.prototype._executeCallback = function() {
  49. return this._callback(this._buffer), this._clear()
  50. }, t.prototype._clear = function() {
  51. return this._buffer = ""
  52. }, t
  53. }(), i = function() {
  54. function e(e, a) {
  55. this.execute = t(this.execute, this), this._matchers = [new i(e, a), new r, new n]
  56. }
  57. var r, n, i;
  58. return e.prototype.execute = function(t) {
  59. return _.find(this._matchers, function(e) {
  60. return e.isMatch(t)
  61. }).execute(t)
  62. }, i = function() {
  63. function t(t, e) {
  64. this._callback = e, this._extractPatternRegexp = new RegExp(t)
  65. }
  66. return t.prototype.isMatch = function(t) {
  67. return !!this._extractMatch(t)
  68. }, t.prototype.execute = function(t) {
  69. return this._callback(this._extractMatch(t))
  70. }, t.prototype._extractMatch = function(t) {
  71. var e;
  72. return null != (e = _.compact(t.match(this._extractPatternRegexp))) ? e[1] : void 0
  73. }, t
  74. }(), r = function() {
  75. function t() {}
  76. return t.prototype.isMatch = function(t) {
  77. return /[%;+][eE]\?/.test(t)
  78. }, t.prototype.execute = function(t) {
  79. return alert("The card did not swipe correctly. Please try again.")
  80. }, t
  81. }(), n = function() {
  82. function t() {}
  83. return t.prototype.isMatch = function(t) {
  84. return !0
  85. }, t.prototype.execute = function(t) {
  86. return alert("The card is not compatible with this system.")
  87. }, t
  88. }(), e
  89. }(), n
  90. }()
  91. })
  92. }).call(this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement