made with requirebin
Created
October 27, 2017 06:40
-
-
Save samdeesh/662a9615953adb0c12aac06539a19f48 to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains hidden or 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
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | |
// Generated by CoffeeScript 1.10.0 | |
var barcodeScanListener; | |
barcodeScanListener = require('barcode-scan-listener'); | |
/* | |
Listen for scan with specified product prefix. | |
@param [Function] onScan - callback to call when scan is successful. Passes the scanned string. | |
@param [String] prefix - character prefix that appears before the scanned string (e.g. 'P%', 'C%') | |
*/ | |
module.exports = angular.module('barcodeListener', []).directive('barcodeListener', function() { | |
return { | |
restrict: 'EA', | |
scope: { | |
onScan: '=', | |
prefix: '@', | |
length: '@', | |
scanDuration: '@?' | |
}, | |
link: function(scope, element, attrs) { | |
var removeScanListener, scanDuration; | |
scanDuration = +scope.scanDuration || 50; | |
removeScanListener = barcodeScanListener.onScan({ | |
barcodePrefix: scope.prefix, | |
barcodeLength: +scope.length || void 0, | |
scanDuration: scanDuration | |
}, scope.onScan); | |
return element.on('$destroy', removeScanListener); | |
} | |
}; | |
}); | |
},{"barcode-scan-listener":2}],2:[function(require,module,exports){ | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
/* eslint-env browser */ | |
exports.default = { | |
/** | |
* Listen for scan with specified characteristics | |
* @param {String} scanCharacteristics.barcodePrefix | |
* @param {Number} [scanCharacteristics.barcodeLength] - if provided, the listener will | |
* wait for this many characters to be read before calling the handler | |
* @param {Number} [scanCharacteristics.scanDuration] | |
* @param {Function} scanHandler - called with the results of the scan | |
* @return {Function} remove this listener | |
*/ | |
onScan: function onScan() { | |
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | |
var barcodePrefix = _ref.barcodePrefix; | |
var barcodeLength = _ref.barcodeLength; | |
var scanDuration = _ref.scanDuration; | |
var scanHandler = arguments[1]; | |
if (typeof barcodePrefix !== 'string') { | |
throw new TypeError('barcodePrefix must be a string'); | |
} | |
if (barcodeLength && typeof barcodeLength !== 'number') { | |
throw new TypeError('barcodeLength must be a number'); | |
} | |
if (scanDuration && typeof scanDuration !== 'number') { | |
throw new TypeError('scanDuration must be a number'); | |
} | |
if (typeof scanHandler !== 'function') { | |
throw new TypeError('scanHandler must be a function'); | |
} | |
/** | |
* SwipeTrack calls this function, if defined, whenever a barcode is scanned | |
* within the SwipeTrack browser. See "SwipeTrack Browser JavaScript Functions" section of | |
* SwipeTrack API: http://swipetrack.net/support/faq/pdf/SwipeTrack%20API%20(v5.0.0).pdf | |
*/ | |
if (typeof window.onScanAppBarCodeData !== 'function') { | |
window.onScanAppBarCodeData = function (barcode) { | |
window.onScanAppBarCodeData.scanHandlers.forEach(function (handler) { | |
return handler(barcode); | |
}); | |
return true; | |
}; | |
window.onScanAppBarCodeData.scanHandlers = []; | |
} | |
var swipeTrackHandler = function swipeTrackHandler(barcode) { | |
if (barcode.match('^' + barcodePrefix) !== null) scanHandler(barcode.slice(barcodePrefix.length)); | |
}; | |
window.onScanAppBarCodeData.scanHandlers.push(swipeTrackHandler); | |
scanDuration = scanDuration || 50; | |
var isScanning = false; | |
var codeBuffer = ''; | |
var scannedPrefix = ''; | |
var finishScan = function finishScan() { | |
if (codeBuffer) { | |
if (!barcodeLength) scanHandler(codeBuffer);else if (codeBuffer.length >= barcodeLength) scanHandler(codeBuffer.substr(0, barcodeLength)); | |
} | |
scannedPrefix = ''; | |
codeBuffer = ''; | |
isScanning = false; | |
}; | |
var keypressHandler = function keypressHandler(e) { | |
var char = String.fromCharCode(e.which); | |
var charIndex = barcodePrefix.indexOf(char); | |
var expectedPrefix = barcodePrefix.slice(0, charIndex); | |
if (!isScanning) { | |
isScanning = true; | |
setTimeout(finishScan, scanDuration); | |
} | |
if (scannedPrefix === barcodePrefix && /[^\s]/.test(char)) { | |
codeBuffer += char; | |
} else if (scannedPrefix === expectedPrefix && char === barcodePrefix.charAt(charIndex)) { | |
scannedPrefix += char; | |
} | |
}; | |
var removeListener = function removeListener() { | |
document.removeEventListener('keypress', keypressHandler); | |
var swipeTrackHandlerIndex = window.onScanAppBarCodeData.scanHandlers.indexOf(swipeTrackHandler); | |
if (swipeTrackHandlerIndex >= 0) window.onScanAppBarCodeData.scanHandlers.splice(swipeTrackHandlerIndex, 1); | |
}; | |
document.addEventListener('keypress', keypressHandler); | |
return removeListener; | |
} | |
}; | |
module.exports = exports['default']; | |
},{}]},{},[1]) |
This file contains hidden or 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
setTimeout(function(){require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({"barcode-scan-listener":[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj};exports.default={onScan:function onScan(){var _ref=arguments.length<=0||arguments[0]===undefined?{}:arguments[0];var barcodePrefix=_ref.barcodePrefix;var barcodeValueTest=_ref.barcodeValueTest;var finishScanOnMatch=_ref.finishScanOnMatch;var scanDuration=_ref.scanDuration;var scanHandler=arguments[1];if(typeof barcodePrefix!=="string"){throw new TypeError("barcodePrefix must be a string")}if((typeof barcodeValueTest==="undefined"?"undefined":_typeof(barcodeValueTest))!=="object"||typeof barcodeValueTest.test!=="function"){throw new TypeError("barcodeValueTest must be a regular expression")}if(finishScanOnMatch!=null&&typeof finishScanOnMatch!=="boolean"){throw new TypeError("finishScanOnMatch must be a boolean")}if(scanDuration&&typeof scanDuration!=="number"){throw new TypeError("scanDuration must be a number")}if(typeof scanHandler!=="function"){throw new TypeError("scanHandler must be a function")}scanDuration=scanDuration||50;var finishScanTimeoutId=null;var prefixBuffer="";var valueBuffer="";var matchedPrefix=false;var finishScan=function finishScan(){if(matchedPrefix&&barcodeValueTest.test(valueBuffer)){scanHandler(valueBuffer)}resetScanState()};var resetScanState=function resetScanState(){finishScanTimeoutId=null;prefixBuffer="";valueBuffer="";matchedPrefix=false};var keypressHandler=function keypressHandler(e){var char=String.fromCharCode(e.which);var charIndex=barcodePrefix.indexOf(char);var expectedPrefixSlice=barcodePrefix.slice(0,charIndex);if(!finishScanTimeoutId){finishScanTimeoutId=setTimeout(finishScan,scanDuration)}if(prefixBuffer===expectedPrefixSlice&&char===barcodePrefix.charAt(charIndex)){prefixBuffer+=char}else if(matchedPrefix){valueBuffer+=char}if(prefixBuffer===barcodePrefix){matchedPrefix=true;if(finishScanOnMatch&&barcodeValueTest.test(valueBuffer)){clearTimeout(finishScanTimeoutId);finishScan()}}};var removeListener=function removeListener(){document.removeEventListener("keypress",keypressHandler)};document.addEventListener("keypress",keypressHandler);return removeListener}};module.exports=exports["default"]},{}]},{},[])(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){var barcodeScanListener;barcodeScanListener=require("barcode-scan-listener");module.exports=angular.module("barcodeListener",[]).directive("barcodeListener",function(){return{restrict:"EA",scope:{onScan:"=",prefix:"@",length:"@",scanDuration:"@?"},link:function(scope,element,attrs){var removeScanListener,scanDuration;scanDuration=+scope.scanDuration||50;removeScanListener=barcodeScanListener.onScan({barcodePrefix:scope.prefix,barcodeLength:+scope.length||void 0,scanDuration:scanDuration},scope.onScan);return element.on("$destroy",removeScanListener)}}})},{"barcode-scan-listener":2}],2:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default={onScan:function onScan(){var _ref=arguments.length<=0||arguments[0]===undefined?{}:arguments[0];var barcodePrefix=_ref.barcodePrefix;var barcodeLength=_ref.barcodeLength;var scanDuration=_ref.scanDuration;var scanHandler=arguments[1];if(typeof barcodePrefix!=="string"){throw new TypeError("barcodePrefix must be a string")}if(barcodeLength&&typeof barcodeLength!=="number"){throw new TypeError("barcodeLength must be a number")}if(scanDuration&&typeof scanDuration!=="number"){throw new TypeError("scanDuration must be a number")}if(typeof scanHandler!=="function"){throw new TypeError("scanHandler must be a function")}if(typeof window.onScanAppBarCodeData!=="function"){window.onScanAppBarCodeData=function(barcode){window.onScanAppBarCodeData.scanHandlers.forEach(function(handler){return handler(barcode)});return true};window.onScanAppBarCodeData.scanHandlers=[]}var swipeTrackHandler=function swipeTrackHandler(barcode){if(barcode.match("^"+barcodePrefix)!==null)scanHandler(barcode.slice(barcodePrefix.length))};window.onScanAppBarCodeData.scanHandlers.push(swipeTrackHandler);scanDuration=scanDuration||50;var isScanning=false;var codeBuffer="";var scannedPrefix="";var finishScan=function finishScan(){if(codeBuffer){if(!barcodeLength)scanHandler(codeBuffer);else if(codeBuffer.length>=barcodeLength)scanHandler(codeBuffer.substr(0,barcodeLength))}scannedPrefix="";codeBuffer="";isScanning=false};var keypressHandler=function keypressHandler(e){var char=String.fromCharCode(e.which);var charIndex=barcodePrefix.indexOf(char);var expectedPrefix=barcodePrefix.slice(0,charIndex);if(!isScanning){isScanning=true;setTimeout(finishScan,scanDuration)}if(scannedPrefix===barcodePrefix&&/[^\s]/.test(char)){codeBuffer+=char}else if(scannedPrefix===expectedPrefix&&char===barcodePrefix.charAt(charIndex)){scannedPrefix+=char}};var removeListener=function removeListener(){document.removeEventListener("keypress",keypressHandler);var swipeTrackHandlerIndex=window.onScanAppBarCodeData.scanHandlers.indexOf(swipeTrackHandler);if(swipeTrackHandlerIndex>=0)window.onScanAppBarCodeData.scanHandlers.splice(swipeTrackHandlerIndex,1)};document.addEventListener("keypress",keypressHandler);return removeListener}};module.exports=exports["default"]},{}]},{},[1])},0); |
This file contains hidden or 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
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"barcode-scan-listener": "2.0.3" | |
} | |
} |
This file contains hidden or 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
<!-- contents of this file will be placed inside the <body> --> |
This file contains hidden or 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
<!-- contents of this file will be placed inside the <head> --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment