{"version":3,"file":"module.js","sources":["requirejs/components/tradeshow-ordering/magic-barcode-input/module.js"],"sourcesContent":["define([\"require\", \"exports\", \"../../component-base\", \"UI/StatusIndicator\"], function (require, exports, component_base_1, StatusIndicator_1) {\n \"use strict\";\n Object.defineProperty(exports, \"__esModule\", { value: true });\n class MagicBarcodeInput extends component_base_1.default {\n constructor(props, cd) {\n super(props, cd);\n this.isValidEntryKey = (e) => {\n //is the entry within the acceptable range of numbers, letters, symbols (but not backslash or pipe since that is our \"end symbol\")\n return ((e.which >= 48 && e.which <= 90) || (e.which >= 96 && e.which <= 111) || (e.which >= 186 && e.which <= 222) || e.which == MagicBarcodeInput.scanSuffix.which);\n };\n this.isValidKeyCode = (e) => {\n //is the entry valid for tracking entries\n return this.isValidEntryKey(e) || e.which == 32;\n };\n this.isValidEntry = () => {\n if (!this.Capture())\n return false;\n //make sure the prefix exists in the entry\n return this.indexOfPrefix() >= 0;\n };\n this.postEntry = () => {\n if (!this.Capture() || this.StatusIndicator.Is(StatusIndicator_1.Status.Loading) || !this.Activated())\n return;\n if (this.isValidEntry()) {\n this.StatusIndicator.SetStatus(StatusIndicator_1.Status.Loading);\n window.location.href = `/search/results?query=${this.sanitizedCapture()}`;\n }\n else {\n this.clear();\n }\n };\n this.indexOfPrefix = () => {\n return this.Capture().toLocaleLowerCase().indexOf(MagicBarcodeInput.scanPrefix.toLocaleLowerCase());\n };\n this.indexOfSuffix = () => {\n return this.Capture().toLocaleLowerCase().indexOf(MagicBarcodeInput.scanSuffix.key.toLocaleLowerCase());\n };\n this.sanitizedCapture = () => {\n const sanitizedCapture = this.Capture().substring(this.indexOfPrefix(), this.indexOfSuffix());\n return sanitizedCapture;\n };\n this.clear = () => {\n this.Capture(\"\");\n this.KeyCodes.removeAll();\n };\n this._el.classList.add(\"magic-scanner\");\n this.StatusIndicator = new StatusIndicator_1.StatusIndicator();\n this.Activated = ko.observable(true);\n this.Capture = ko.observable(\"\");\n this.KeyCodes = ko.observableArray([]);\n this._disposables.push(this.KeyCodes.subscribe(value => {\n if (value && value.length > 1000)\n this.clear();\n if (value.indexOf(MagicBarcodeInput.scanSuffix.which) >= 0)\n this.postEntry();\n }));\n if (this.Activated()) {\n document.addEventListener(\"keydown\", (event) => {\n if ($(\"input:focus\").length > 0) {\n return;\n }\n else {\n if (this.isValidEntryKey(event)) {\n this.Capture(`${this.Capture()}${event.key}`);\n }\n if (this.isValidKeyCode(event)) {\n this.KeyCodes.push(event.which);\n }\n }\n });\n }\n }\n }\n exports.default = MagicBarcodeInput;\n MagicBarcodeInput.scanPrefix = \"show.\";\n MagicBarcodeInput.scanSuffix = { key: \"|\", which: 220 };\n});\n//# sourceMappingURL=module.js.map"],"names":["define","require","exports","component_base_1","StatusIndicator_1","Object","defineProperty","value","MagicBarcodeInput","default","constructor","props","cd","super","this","isValidEntryKey","e","which","scanSuffix","isValidKeyCode","isValidEntry","Capture","indexOfPrefix","postEntry","StatusIndicator","Is","Status","Loading","Activated","SetStatus","window","location","href","sanitizedCapture","clear","toLocaleLowerCase","indexOf","scanPrefix","indexOfSuffix","key","substring","KeyCodes","removeAll","_el","classList","add","ko","observable","observableArray","_disposables","push","subscribe","length","document","addEventListener","$","event"],"mappings":"AAAAA,OAAO,CAAC,UAAW,UAAW,uBAAwB,sBAAuB,SAAUC,EAASC,EAASC,EAAkBC,gBAEvHC,OAAOC,eAAeJ,EAAS,aAAc,CAAEK,OAAO,UAChDC,UAA0BL,EAAiBM,QAC7CC,YAAYC,EAAOC,GACfC,MAAMF,EAAOC,GACbE,KAAKC,gBAAkB,GAEC,IAAXC,EAAEC,OAAeD,EAAEC,OAAS,IAAmB,IAAXD,EAAEC,OAAeD,EAAEC,OAAS,KAAoB,KAAXD,EAAEC,OAAgBD,EAAEC,OAAS,KAAQD,EAAEC,OAAST,EAAkBU,WAAWD,MAEnKH,KAAKK,eAAiB,GAEXL,KAAKC,gBAAgBC,IAAiB,IAAXA,EAAEC,MAExCH,KAAKM,aAAe,MACXN,KAAKO,WAG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