{ "version": 3, "sources": ["../../../../../Carbon/Carbon.FileLoader/Resources/Private/Assets/EventListener.ts", "../../Private/Fusion/Main.ts"], "sourcesContent": ["function eventListener(name: string, callback: Function, once = true) {\n if (typeof name !== 'string' || typeof callback !== 'function') {\n throw new Error('eventListener: name must be a string and callback must be a function');\n }\n document.addEventListener(name, (event) => callback(event), { once });\n}\n\nexport { eventListener as default, eventListener };\n", "import eventListener from \"Packages/Carbon/Carbon.FileLoader/Resources/Private/Assets/EventListener\";\n\neventListener(\"zammad:init\", () => {\n Alpine.data(\"zammad\", function (baseUrl: string, title: string, open: boolean) {\n return {\n open: !!open,\n name: \"\",\n email: \"\",\n body: \"\",\n agreement: false,\n fingerprint: \"\",\n token: \"\",\n ticketnumber: \"\",\n loading: false,\n failed: false,\n online: this.$persist(false).using(sessionStorage).as(\"zammad-online\"),\n error: {\n name: false,\n email: false,\n body: false,\n agreement: false,\n },\n authentificate() {\n if (!this.open || (this.token && this.fingerprint)) {\n return;\n }\n this.fingerprint = createFingerprint();\n fetch(`https://${baseUrl}/api/v1/form_config`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n fingerprint: this.fingerprint,\n }),\n })\n .then((response) => {\n if (!response.ok) {\n throw new Error(\"Network response was not ok\");\n }\n return response.json();\n })\n .then((data) => {\n this.token = data.token;\n })\n .catch((error) => {\n this.setFailed(error);\n });\n },\n init() {\n if (!baseUrl) {\n this.online = false;\n return;\n }\n if (this.online) {\n this.authentificate();\n } else {\n isSiteOnline(`https://${baseUrl}`, (online) => {\n this.online = online;\n if (online) {\n this.authentificate();\n } else {\n console.warn(`Helpdesk (${baseUrl}) is not reachable`);\n }\n });\n }\n\n this.$watch(\"open\", () => {\n this.authentificate();\n });\n },\n form: {\n \"x-id\"() {\n return [\"name\", \"email\", \"body\", \"files\"];\n },\n \"x-show\"() {\n return !this.ticketnumber;\n },\n \"x-on:submit.prevent\"(event) {\n this.failed = false;\n let hasError = false;\n if (!this.name) {\n hasError = true;\n this.error.name = true;\n }\n if (!this.body) {\n hasError = true;\n this.error.body = true;\n }\n if (!this.email) {\n hasError = true;\n this.error.email = true;\n }\n if (!this.agreement) {\n hasError = true;\n this.error.agreement = true;\n }\n if (hasError) {\n return;\n }\n\n const body = new FormData(event.target);\n body.append(\"fingerprint\", this.fingerprint);\n body.append(\"agreement\", \"on\");\n body.append(\"token\", this.token);\n body.append(\"title\", title.replaceAll(\"%s\", window.location.hostname));\n\n fetch(`https://${baseUrl}/api/v1/form_submit`, {\n method: \"POST\",\n body,\n })\n .then((response) => {\n if (!response.ok) {\n throw new Error(\"Network response was not ok\");\n }\n return response.json();\n })\n .then((data) => {\n this.loading = false;\n this.ticketnumber = data?.ticket?.number;\n })\n .catch((error) => {\n this.setFailed(error);\n });\n },\n },\n setFailed(error) {\n console.error(error);\n this.loading = false;\n this.failed = true;\n },\n };\n });\n});\n\nfunction createFingerprint() {\n const canvas = document.createElement(\"canvas\");\n const ctx = canvas.getContext(\"2d\");\n const txt = \"https://zammad.com\";\n ctx.textBaseline = \"top\";\n ctx.font = \"12px 'Arial'\";\n ctx.textBaseline = \"alphabetic\";\n ctx.fillStyle = \"#f60\";\n ctx.fillRect(125, 1, 62, 20);\n ctx.fillStyle = \"#069\";\n ctx.fillText(txt, 2, 15);\n ctx.fillStyle = \"rgba(100, 200, 0, 0.7)\";\n ctx.fillText(txt, 4, 17);\n return canvas.toDataURL();\n}\n\nfunction isSiteOnline(url, callback) {\n // try to load favicon\n const timer = setTimeout(() => {\n // timeout after 5 seconds\n callback(false);\n }, 5000);\n\n const img = document.createElement(\"img\");\n img.onload = () => {\n clearTimeout(timer);\n callback(true);\n };\n\n img.onerror = () => {\n clearTimeout(timer);\n callback(false);\n };\n\n img.src = url + \"/favicon.ico\";\n}\n"], "mappings": "MAAA,SAASA,EAAcC,EAAcC,EAAoBC,EAAO,GAAM,CAClE,GAAI,OAAOF,GAAS,UAAY,OAAOC,GAAa,WAChD,MAAM,IAAI,M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3BA,EAAI,UAAY,OAChBA,EAAI,SAASC,EAAK,EAAG,EAAE,EACvBD,EAAI,UAAY,yBAChBA,EAAI,SAASC,EAAK,EAAG,EAAE,EAChBF,EAAO,UAAU,CAC5B,CAEA,SAASL,EAAaQ,EAAKC,EAAU,CAEjC,IAAMC,EAAQ,WAAW,IAAM,CAE3BD,EAAS,EAAK,CAClB,EAAG,GAAI,EAEDE,EAAM,SAAS,cAAc,KAAK,EACxCA,EAAI,OAAS,IAAM,CACf,aAAaD,CAAK,EAClBD,EAAS,EAAI,CACjB,EAEAE,EAAI,QAAU,IAAM,CAChB,aAAaD,CAAK,EAClBD,EAAS,EAAK,CAClB,EAEAE,EAAI,IAAMH,EAAM,cACpB", "names": ["eventListener", "name", "callback", "once", "event", "eventListener", "baseUrl", "title", "open", "createFingerprint", "response", "data", "error", "isSiteOnline", "online", "event", "hasError", "body", "canvas", "ctx", "txt", "url", "callback", "timer", "img"] }