Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- var t = function(t, e) {
- return function() {
- return t.apply(e, arguments)
- }
- },
- e = [].slice;
- namespace("OrgSync", function(r) {
- return r.CardReader = function() {
- function n(e) {
- 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) {
- return function(e) {
- if (t.isEnabled()) return t._scanner.add(e.which)
- }
- }(this)), $(document).off("keypress.OrgSyncCardReader").on("keypress.OrgSyncCardReader", function(t) {
- return function(e) {
- if (t.isEnabled() && !$(e.target).is("input, select")) return t._$cardReaderBox.focus(), t._scanner.add(e.which)
- }
- }(this))
- }
- var i, a;
- return n.instance = function(t) {
- return null != this._cardReader ? this._cardReader : this._cardReader = new r.CardReader(t)
- }, n.prototype.scan = function(t) {
- var e, r, n;
- for (r = 0, n = t.length; r < n; r++) e = t[r], this._scanner.add(e.charCodeAt(0));
- return this._scanner.add(13)
- }, n.prototype.bind = function(t, e) {
- return this._events[t] = e, this
- }, n.prototype.enable = function() {
- return this._enabled = !0, this._$cardReaderBox.focus(), this._trigger("Enabled"), this
- }, n.prototype.disable = function() {
- return this._enabled = !1, this._$cardReaderBox.blur(), this._trigger("Disabled"), this
- }, n.prototype.isEnabled = function() {
- return this._enabled
- }, n.prototype._trigger = function() {
- var t, r;
- if (r = arguments[0], t = 2 <= arguments.length ? e.call(arguments, 1) : [], this._events[r]) return this._events[r].apply(this, t)
- }, n.prototype._triggerValid = function(t) {
- return this._$cardReaderBox.val(""), this._trigger("ValidRead", t)
- }, a = function() {
- function t(t) {
- this._callback = t, this._clear()
- }
- var e;
- return e = 13, t.prototype.add = function(t) {
- return t === e ? this._executeCallback() : this._buffer += String.fromCharCode(t)
- }, t.prototype._executeCallback = function() {
- return this._callback(this._buffer), this._clear()
- }, t.prototype._clear = function() {
- return this._buffer = ""
- }, t
- }(), i = function() {
- function e(e, a) {
- this.execute = t(this.execute, this), this._matchers = [new i(e, a), new r, new n]
- }
- var r, n, i;
- return e.prototype.execute = function(t) {
- return _.find(this._matchers, function(e) {
- return e.isMatch(t)
- }).execute(t)
- }, i = function() {
- function t(t, e) {
- this._callback = e, this._extractPatternRegexp = new RegExp(t)
- }
- return t.prototype.isMatch = function(t) {
- return !!this._extractMatch(t)
- }, t.prototype.execute = function(t) {
- return this._callback(this._extractMatch(t))
- }, t.prototype._extractMatch = function(t) {
- var e;
- return null != (e = _.compact(t.match(this._extractPatternRegexp))) ? e[1] : void 0
- }, t
- }(), r = function() {
- function t() {}
- return t.prototype.isMatch = function(t) {
- return /[%;+][eE]\?/.test(t)
- }, t.prototype.execute = function(t) {
- return alert("The card did not swipe correctly. Please try again.")
- }, t
- }(), n = function() {
- function t() {}
- return t.prototype.isMatch = function(t) {
- return !0
- }, t.prototype.execute = function(t) {
- return alert("The card is not compatible with this system.")
- }, t
- }(), e
- }(), n
- }()
- })
- }).call(this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement