{"version":3,"file":"QuickLink.js","names":["defineDs","m","ApiRequest","QuickLink","path","basePath","quickLink","prop","loaded","ready","deferred","get","key","replacements","prefix","base","segments","split","i","length","segment","console","warn","Array","Math","floor","random","keys","Object","k","val","replace","RegExp","toUpperCase","url","DS","Config","CONTEXTPREFIX","toLowerCase","method","localCacheTTL","noCache","unwrapSuccess","response","data","then","resolve","promise"],"sources":["Shared/Framework/Mithril/Scripts/Helpers/QuickLink.js"],"sourcesContent":["defineDs('Shared/Framework/Mithril/Scripts/Helpers/QuickLink', [\r\n 'Shared/Framework/Mithril/Scripts/Core/Mithril',\r\n 'Shared/Framework/Mithril/Scripts/Helpers/ApiRequest'\r\n], function (m, ApiRequest) {\r\n\r\n // Variables:\r\n var QuickLink = function (path) {\r\n var basePath = 'QuickLink';\r\n var quickLink = m.prop({});\r\n var loaded = m.prop(false);\r\n var ready = m.deferred();\r\n\r\n var get = function (key, replacements) {\r\n if (this && this.prefix) {\r\n key = this.prefix + key;\r\n }\r\n\r\n replacements = replacements || {};\r\n\r\n if (loaded()) {\r\n var base = quickLink();\r\n var segments = key.split('/');\r\n\r\n for (var i = 0; i < segments.length; i++) {\r\n var segment = segments[i];\r\n\r\n if (typeof base[segment] === 'undefined') {\r\n console.warn('QuickLink key not found: ' + key);\r\n\r\n break;\r\n }\r\n\r\n base = base[segment];\r\n }\r\n\r\n if (base instanceof Array) {\r\n base = base[Math.floor(Math.random() * base.length)];\r\n }\r\n\r\n // Replacements\r\n if (typeof base === 'string') {\r\n var keys = Object.keys(replacements);\r\n\r\n for (i = 0; i < keys.length; i++) {\r\n var k = keys[i];\r\n var val = replacements[k];\r\n\r\n base = base.replace(new RegExp('{' + k.toUpperCase() + '}', 'g'), val);\r\n }\r\n }\r\n\r\n return base || '!';\r\n }\r\n\r\n return '?';\r\n };\r\n\r\n // Initialize:\r\n var url = DS.Config.CONTEXTPREFIX + '/scapi/danskespil/navigation/' + basePath.toLowerCase() + '/get?path=' + path + '&variants=1';\r\n\r\n // ApiRequest will take care of localstorage caching and avoiding multiple request to same ressource:\r\n ApiRequest({\r\n method: 'GET',\r\n url: url,\r\n localCacheTTL: 5 * 60, // Cache 5min\r\n noCache: false, // Dont add ?noCache queryparam, as it would break 304 Not Modified headers\r\n unwrapSuccess: function (response) {\r\n return response.data[Object.keys(response.data)[0]];\r\n }\r\n }).then(function (response) {\r\n quickLink(response);\r\n loaded(true);\r\n ready.resolve();\r\n });\r\n\r\n // Public functions:\r\n return {\r\n get: get,\r\n ready: ready.promise\r\n };\r\n\r\n };\r\n\r\n return QuickLink;\r\n\r\n});\r\n"],"mappings":"AAAAA,QAAQ,CAAC,oDAAoD,EAAE,CAC7D,+CAA+C,EAC/C,qDAAqD,CACtD,EAAE,UAAUC,CAAC,EAAEC,UAAU,EAAE;EAE1B;EACA,IAAIC,SAAS,GAAG,SAAAA,CAAUC,IAAI,EAAE;IAC9B,IAAIC,QAAQ,GAAG,WAAW;IAC1B,IAAIC,SAAS,GAAGL,CAAC,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAIC,MAAM,GAAGP,CAAC,CAACM,IAAI,CAAC,KAAK,CAAC;IAC1B,IAAIE,KAAK,GAAGR,CAAC,CAACS,QAAQ,CAAC,CAAC;IAExB,IAAIC,GAAG,GAAG,SAAAA,CAAUC,GAAG,EAAEC,YAAY,EAAE;MACrC,IAAI,IAAI,IAAI,IAAI,CAACC,MAAM,EAAE;QACvBF,GAAG,GAAG,IAAI,CAACE,MAAM,GAAGF,GAAG;MACzB;MAEAC,YAAY,GAAGA,YAAY,IAAI,CAAC,CAAC;MAEjC,IAAIL,MAAM,CAAC,CAAC,EAAE;QACZ,IAAIO,IAAI,GAAGT,SAAS,CAAC,CAAC;QACtB,IAAIU,QAAQ,GAAGJ,GAAG,CAACK,KAAK,CAAC,GAAG,CAAC;QAE7B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,QAAQ,CAACG,MAAM,EAAED,CAAC,EAAE,EAA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