{ "version": 3, "sources": ["jobs-embed/src/jobs-embed.js"], "sourcesContent": ["export class AugustaJobsEmbed extends HTMLElement {\n static instance = null;\n static templatePromise = null;\n static dataPromise = null;\n static debug = false;\n static allowOverlays = false;\n static renderPromise = null;\n static callbacks = {\n themeChanged: [],\n widthChanged: [],\n render: [],\n dataLoaded: []\n };\n static host = (window.location.host.includes(\"augusta.care\") || window.location.host.includes(\"localhost\")) ? \"\" : \"https://career.augusta.care\";\n\n constructor() {\n super();\n if (this.hasAttribute('data-initialized')) return;\n this.setAttribute('data-initialized', 'true');\n this.attachShadow({ mode: 'open' });\n AugustaJobsEmbed.instance = this;\n if (AugustaJobsEmbed.debug) console.log('AugustaJobsEmbed: Constructor called');\n \n // Create content and resources containers\n this.contentContainer = document.createElement('div');\n this.resourcesContainer = document.createElement('div');\n this.shadowRoot.appendChild(this.resourcesContainer);\n this.shadowRoot.appendChild(this.contentContainer);\n }\n\n static init({ companyJobId, debug = false, allowOverlays = false } = {}) {\n AugustaJobsEmbed.companyJobId = companyJobId;\n AugustaJobsEmbed.debug = debug;\n AugustaJobsEmbed.allowOverlays = allowOverlays;\n if (this.debug) console.log('AugustaJobsEmbed: Initializing with companyJobId:', companyJobId);\n AugustaJobsEmbed.templatePromise = this.fetchTemplate();\n if (!customElements.get('augusta-jobs')) {\n customElements.define('augusta-jobs', AugustaJobsEmbed);\n }\n \n if (!AugustaJobsEmbed.allowOverlays) {\n hideIntersectingFixedElements();\n }\n }\n\n connectedCallback() {\n if (AugustaJobsEmbed.debug) console.log('AugustaJobsEmbed: Connected to DOM');\n this.loadResources();\n\n if (AugustaJobsEmbed.companyJobId) {\n AugustaJobsEmbed.dataPromise = this.fetchData();\n AugustaJobsEmbed.dataPromise.then(data => {\n AugustaJobsEmbed.triggerCallback('dataLoaded', data);\n if (data.structured_data) {\n this.insertStructuredData(data.structured_data);\n }\n });\n AugustaJobsEmbed.renderPromise = AugustaJobsEmbed.dataPromise.then(data => AugustaJobsEmbed.render(data));\n }\n }\n\n insertStructuredData(structuredData) {\n if (AugustaJobsEmbed.debug) console.log('AugustaJobsEmbed: Inserting structured data');\n\n const existingScript = document.querySelector(`script[data-augusta-job-id=\"${AugustaJobsEmbed.companyJobId}\"][type=\"application/ld+json\"]`);\n if (existingScript) {\n existingScript.remove();\n }\n\n const script = document.createElement('script');\n script.setAttribute('type', 'application/ld+json');\n script.setAttribute('data-augusta-job-id', AugustaJobsEmbed.companyJobId);\n script.textContent = JSON.stringify(structuredData, null, 4);\n document.head.appendChild(script);\n }\n\n static async fetchTemplate() {\n if (this.debug) console.log('AugustaJobsEmbed: Fetching HTML template');\n const response = await fetch(this.host + '/jobs-embed/static/augusta-jobs-template.html');\n if (!response.ok) throw new Error('Failed to fetch HTML template');\n if (this.debug) console.log('AugustaJobsEmbed: HTML template fetched successfully');\n return await response.text();\n }\n\n async fetchData() {\n if (AugustaJobsEmbed.debug) console.log('AugustaJobsEmbed: Fetching data');\n const url = `${AugustaJobsEmbed.host}/api/v1/render_jobs/${AugustaJobsEmbed.companyJobId}?currentPageUrl=${encodeURIComponent(window.location.href)}`;\n const response = await fetch(url);\n if (!response.ok) throw new Error('Failed to fetch data');\n if (AugustaJobsEmbed.debug) console.log('AugustaJobsEmbed: Data fetched successfully');\n return await response.json();\n }\n\n static async render(data) {\n if (this.debug) console.log('AugustaJobsEmbed: Rendering data', data);\n try {\n const template = await this.templatePromise;\n if (data?.jobs?.[0]) {\n data.jobs[0].hasCaregiverData = (data?.jobs?.[0]?.caregivers ?? []).length ? data.jobs[0].caregivers.some(obj => Object.values(obj).some(Boolean)) : false;\n }\n const processTemplate = new Function('data', `return \\`${template}\\`;`);\n this.instance.contentContainer.innerHTML = processTemplate(data);\n\n AugustaJobsEmbed.setWidth(data.width || 1000);\n AugustaJobsEmbed.setTheme(data.theme || \"dark-magenta\");\n\n // Emit custom event after rendering\n const event = new CustomEvent('augusta_jobs_embed_rendered', {\n bubbles: true,\n composed: true,\n detail: { shadowRoot: this.instance.shadowRoot }\n });\n document.dispatchEvent(event);\n if (this.debug) console.log('AugustaJobsEmbed: Render complete, event dispatched');\n\n // Trigger render callback\n AugustaJobsEmbed.triggerCallback('render', data);\n\n initFixedApplyButton(this.instance.contentContainer, data.theme);\n } catch (error) {\n console.error('Error rendering template:', error);\n }\n }\n\n loadResources() {\n if (AugustaJobsEmbed.debug) console.log('AugustaJobsEmbed: Loading resources');\n this.loadStyles(AugustaJobsEmbed.host + '/jobs-embed/dist/augusta-jobs.css');\n this.loadScript(AugustaJobsEmbed.host + '/jobs-embed/dist/augusta-jobs.js');\n this.loadFont();\n }\n\n loadStyles(url) {\n if (AugustaJobsEmbed.debug) console.log('AugustaJobsEmbed: Loading styles from', url);\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = url;\n this.resourcesContainer.appendChild(link);\n }\n\n loadScript(url) {\n if (AugustaJobsEmbed.debug) console.log('AugustaJobsEmbed: Loading script from', url);\n const script = document.createElement('script');\n script.type = 'module';\n script.src = url;\n this.resourcesContainer.appendChild(script);\n }\n\n loadFont() {\n if (AugustaJobsEmbed.debug) console.log('AugustaJobsEmbed: Loading font');\n const style = document.createElement('style');\n style.textContent = `\n @font-face {\n font-family: \"Roboto Slab\";\n font-style: normal;\n font-weight: 500;\n font-display: swap;\n src: url(\"${AugustaJobsEmbed.host}/jobs-embed/static/roboto-slab-500.woff2\") format(\"woff2\");\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n }\n `;\n // font needs to be available in parent page for it to be accessible in shadow DOM\n document.head.appendChild(style); \n \n }\n \n loadHomeInsteadFonts(theme) {\n // Only load these fonts if the theme is home-instead and they're not already loaded\n if (theme !== 'home-instead') return;\n \n // More robust check for already loaded fonts\n const fontsAlreadyLoaded = document.querySelector('link[href*=\"fonts.googleapis.com\"][href*=\"Instrument\"][href*=\"Jakarta\"]');\n if (fontsAlreadyLoaded) {\n if (AugustaJobsEmbed.debug) console.log('AugustaJobsEmbed: Home Instead fonts already loaded, skipping');\n return;\n }\n \n const link = document.createElement('link');\n link.rel = 'preconnect';\n link.href = 'https://fonts.googleapis.com';\n document.head.appendChild(link);\n \n const link2 = document.createElement('link');\n link2.rel = 'preconnect';\n link2.href = 'https://fonts.gstatic.com';\n link2.crossOrigin = 'anonymous';\n document.head.appendChild(link2);\n \n const fontLink = document.createElement('link');\n fontLink.rel = 'stylesheet';\n fontLink.href = 'https://fonts.googleapis.com/css2?family=Instrument+Serif&family=Plus+Jakarta+Sans:ital,wght@0,200..800;1,200..800&display=swap';\n document.head.appendChild(fontLink);\n \n if (AugustaJobsEmbed.debug) console.log('AugustaJobsEmbed: Loading Google fonts for Home Instead theme');\n }\n\n static async setTheme(theme) {\n if (this.debug) console.log('AugustaJobsEmbed: Setting theme to', theme);\n await this.renderPromise; // Wait for initial render to complete\n \n // Load Home Instead fonts if needed\n if (this.instance) {\n this.instance.loadHomeInsteadFonts(theme);\n }\n \n const jobPostsEmbed = this.instance.contentContainer.querySelector(\".job-posts-embed\");\n if (jobPostsEmbed) {\n jobPostsEmbed.dataset.theme = theme;\n AugustaJobsEmbed.triggerCallback('themeChanged', theme);\n \n // Also update the theme on any fixed-apply-button\n const fixedButton = document.querySelector('fixed-apply-button');\n if (fixedButton) {\n fixedButton.setTheme(theme);\n }\n }\n }\n\n static async setWidth(width) {\n if (this.debug) console.log('AugustaJobsEmbed: Setting width to', width);\n await this.renderPromise; // Wait for initial render to complete\n const mainContainer = this.instance.contentContainer.querySelector(\".main-container\");\n if (mainContainer) {\n mainContainer.style.maxWidth = `${width}px`;\n AugustaJobsEmbed.triggerCallback('widthChanged', width);\n }\n }\n\n static async getData() {\n if (this.debug) console.log('AugustaJobsEmbed: Getting data');\n return await this.dataPromise;\n }\n\n static on(eventName, callback) {\n if (this.callbacks[eventName]) {\n this.callbacks[eventName].push(callback);\n } else {\n console.warn(`Unknown event: ${eventName}`);\n }\n }\n\n static triggerCallback(eventName, data) {\n if (this.callbacks[eventName]) {\n this.callbacks[eventName].forEach(callback => callback(data));\n }\n }\n}\n\nclass FixedApplyButton extends HTMLElement {\n static get observedAttributes() {\n return ['data-augusta-fixed-exempt'];\n }\n\n constructor() {\n super();\n this.attachShadow({ mode: 'open' });\n \n this.resourcesContainer = document.createElement('div');\n this.contentContainer = document.createElement('div');\n \n this.shadowRoot.appendChild(this.resourcesContainer);\n this.shadowRoot.appendChild(this.contentContainer);\n\n this.loadResources();\n }\n\n connectedCallback() {\n this.setAttribute('data-augusta-fixed-exempt', 'true');\n }\n\n loadResources() {\n const hostStyles = document.createElement('style');\n hostStyles.textContent = `\n :host {\n display: none;\n position: fixed;\n top: 0;\n z-index: 2;\n }\n `;\n\n const link = document.createElement('link');\n link.rel = 'stylesheet';\n link.href = `${AugustaJobsEmbed.host}/jobs-embed/dist/augusta-jobs.css`;\n\n this.resourcesContainer.appendChild(hostStyles);\n this.resourcesContainer.appendChild(link);\n }\n\n setTheme(theme) {\n this.contentContainer.dataset.theme = theme;\n }\n\n update(jobTitle, jobApplyLink) {\n this.contentContainer.innerHTML = `\n