{ "version": 3, "sources": ["../../../Vettvangur.Frontend/src/scripts/shared/utility/prefetch.ts"], "sourcesContent": ["const prefetch = {\r\n init() {\r\n // Event delegation used as there may be hundreds of same-site links on a page:\r\n document.body.addEventListener('mouseover', this.worker)\r\n },\r\n worker(event) {\r\n const target = event.target\r\n\r\n // Not a link? - if so exit\r\n if (target.tagName !== 'A') {\r\n return\r\n }\r\n\r\n // Read the attribute rather than the property!\r\n // - because the property is the full https:// address\r\n const href = target.getAttribute('href')\r\n\r\n // No href, or not a same-site link? - if so exit\r\n // - link attribute must start with a backslash\r\n if (!href || href.charAt(0) !== '/') {\r\n return\r\n }\r\n\r\n // Already prefetched? - if so exit\r\n const isAlreadyAdded = document.head.querySelector(`link[href=\"${href}\"]`)\r\n if (isAlreadyAdded) {\r\n return\r\n }\r\n\r\n // Is the same page? - if so exit\r\n const isSamePage = target.pathname === window.location.pathname\r\n if (isSamePage) {\r\n return\r\n }\r\n\r\n // Add prefetch link to head section\r\n const link = document.createElement('link')\r\n link.rel = 'prefetch'\r\n link.href = href\r\n document.head.appendChild(link)\r\n },\r\n}\r\n\r\nexport default prefetch\r\n"], "mappings": "gCAAA,IAAMA,EAAW,CACf,MAAO,CAEL,SAAS,KAAK,iBAAiB,YAAa,KAAK,MAAM,CACzD,EACA,OAAOC,EAAO,CACZ,IAAMC,EAASD,EAAM,OAGrB,GAAIC,EAAO,UAAY,IACrB,OAKF,IAAMC,EAAOD,EAAO,aAAa,MAAM,EAgBvC,GAZI,CAACC,GAAQA,EAAK,OAAO,CAAC,IAAM,KAKT,SAAS,KAAK,cAAc,cAAcA,KAAQ,GAMtDD,EAAO,WAAa,OAAO,SAAS,SAErD,OAIF,IAAME,EAAO,SAAS,cAAc,MAAM,EAC1CA,EAAK,IAAM,WACXA,EAAK,KAAOD,EACZ,SAAS,KAAK,YAAYC,CAAI,CAChC,CACF,EAEOC,EAAQL", "names": ["prefetch", "event", "target", "href", "link", "prefetch_default"] }