{ "version": 3, "sources": ["../../../Vettvangur.Frontend/src/scripts/utility/richtextApi.ts"], "sourcesContent": ["const richtextApi = {\n el: {\n sections: document.querySelectorAll('.richtext'),\n },\n\n init() {\n if (this.el.sections) {\n this.el.sections.forEach((section) => {\n const text = section.innerHTML\n const matches = text.match(/\\[(.*?)]/g)\n const words = [] as Array\n if (matches !== null) {\n matches.map((val) => {\n let word = val.replace('[', '')\n word = word.replace(']', '')\n words.push(word)\n })\n }\n if (words.length > 0) {\n this.getApiValues(words, section)\n }\n })\n }\n },\n\n getApiValues: async (words, section) => {\n const action = '/umbraco/api/data/GetKeyNumbersData'\n const method = 'GET'\n\n try {\n const req = await fetch(action, {\n method: method,\n })\n const res = await req.json()\n richtextApi.renderApiValues(words, section, res)\n } catch (error) {\n console.error('Error getting richtext api values', error)\n }\n },\n\n renderApiValues: (words, section, response) => {\n const res = response.data.returnItem\n let text = section.innerHTML\n\n if (res) {\n words.forEach((word) => {\n const selectedWord = `[${word}]`\n let wordFound = false\n res.forEach((keyNumber) => {\n if (keyNumber.key === word) {\n text = text.replace(selectedWord, keyNumber.value)\n wordFound = true\n }\n })\n if (!wordFound) {\n text = text.replace(selectedWord, word)\n }\n })\n }\n\n section.innerHTML = text\n },\n}\n\nexport default richtextApi\n"], "mappings": "gCAAA,IAAMA,EAAc,CAClB,GAAI,CACF,SAAU,SAAS,iBAAiB,WAAW,CACjD,EAEA,MAAO,CACD,KAAK,GAAG,UACV,KAAK,GAAG,SAAS,QAASC,GAAY,CAEpC,IAAMC,EADOD,EAAQ,UACA,MAAM,WAAW,EAChCE,EAAQ,CAAC,EACXD,IAAY,MACdA,EAAQ,IAAKE,GAAQ,CACnB,IAAIC,EAAOD,EAAI,QAAQ,IAAK,EAAE,EAC9BC,EAAOA,EAAK,QAAQ,IAAK,EAAE,EAC3BF,EAAM,KAAKE,CAAI,CACjB,CAAC,EAECF,EAAM,OAAS,GACjB,KAAK,aAAaA,EAAOF,CAAO,CAEpC,CAAC,CAEL,EAEA,aAAc,MAAOE,EAAOF,IAAY,CACtC,IAAMK,EAAS,sCACTC,EAAS,MAEf,GAAI,CAIF,IAAMC,EAAM,MAHA,MAAM,MAAMF,EAAQ,CAC9B,OAAQC,CACV,CAAC,GACqB,KAAK,EAC3BP,EAAY,gBAAgBG,EAAOF,EAASO,CAAG,CACjD,OAASC,EAAO,CACd,QAAQ,MAAM,oCAAqCA,CAAK,CAC1D,CACF,EAEA,gBAAiB,CAACN,EAAOF,EAASS,IAAa,CAC7C,IAAMF,EAAME,EAAS,KAAK,WACtBC,EAAOV,EAAQ,UAEfO,GACFL,EAAM,QAASE,GAAS,CACtB,IAAMO,EAAe,IAAIP,CAAI,IACzBQ,EAAY,GAChBL,EAAI,QAASM,GAAc,CACrBA,EAAU,MAAQT,IACpBM,EAAOA,EAAK,QAAQC,EAAcE,EAAU,KAAK,EACjDD,EAAY,GAEhB,CAAC,EACIA,IACHF,EAAOA,EAAK,QAAQC,EAAcP,CAAI,EAE1C,CAAC,EAGHJ,EAAQ,UAAYU,CACtB,CACF,EAEOI,EAAQf", "names": ["richtextApi", "section", "matches", "words", "val", "word", "action", "method", "res", "error", "response", "text", "selectedWord", "wordFound", "keyNumber", "richtextApi_default"] }