2021-11-30 15:09:05 +00:00
|
|
|
import { hexToHSL } from './hexToHSL'
|
2019-10-24 12:56:57 +00:00
|
|
|
|
2022-03-24 16:06:41 +00:00
|
|
|
const script = document.currentScript
|
|
|
|
const moduleName = script.dataset.module || 'simulateur-embauche'
|
2022-03-24 15:23:37 +00:00
|
|
|
const couleur =
|
|
|
|
script.dataset.couleur &&
|
|
|
|
encodeURIComponent(
|
|
|
|
JSON.stringify(hexToHSL(script.dataset.couleur.toUpperCase()))
|
2022-03-24 16:06:41 +00:00
|
|
|
)
|
2022-03-24 15:23:37 +00:00
|
|
|
|
2022-03-24 16:06:41 +00:00
|
|
|
const lang = script.dataset.lang || 'fr'
|
2022-03-24 15:23:37 +00:00
|
|
|
|
|
|
|
const src = new URL(
|
2022-03-24 16:06:41 +00:00
|
|
|
(lang === 'fr'
|
|
|
|
? import.meta.env.VITE_FR_BASE_URL
|
|
|
|
: import.meta.env.VITE_EN_BASE_URL) +
|
|
|
|
'/iframes/' +
|
|
|
|
moduleName
|
|
|
|
)
|
2022-03-24 15:23:37 +00:00
|
|
|
|
|
|
|
src.searchParams.set('iframe', true)
|
2022-03-24 16:06:41 +00:00
|
|
|
src.searchParams.set(
|
|
|
|
'integratorUrl',
|
|
|
|
encodeURIComponent(window.location.href.toString())
|
|
|
|
)
|
2022-03-24 15:23:37 +00:00
|
|
|
src.searchParams.set('lang', lang)
|
|
|
|
if (couleur) {
|
|
|
|
src.searchParams.set('couleur', couleur)
|
|
|
|
}
|
|
|
|
|
2018-08-01 10:11:22 +00:00
|
|
|
const iframe = document.createElement('iframe')
|
|
|
|
const iframeAttributes = {
|
|
|
|
id: 'simulateurEmbauche',
|
2022-03-24 15:23:37 +00:00
|
|
|
src: src.toString(),
|
2021-12-07 14:35:30 +00:00
|
|
|
style: 'border: none; width: 100%; display: block; height: 700px',
|
2021-05-11 11:27:35 +00:00
|
|
|
allow: 'clipboard-write',
|
2018-08-10 11:04:23 +00:00
|
|
|
allowfullscreen: true,
|
2018-08-01 10:11:22 +00:00
|
|
|
webkitallowfullscreen: true,
|
2020-12-01 09:17:27 +00:00
|
|
|
mozallowfullscreen: true,
|
2018-08-01 10:11:22 +00:00
|
|
|
}
|
2018-08-29 12:35:41 +00:00
|
|
|
for (var key in iframeAttributes) {
|
|
|
|
iframe.setAttribute(key, iframeAttributes[key])
|
|
|
|
}
|
2019-10-24 12:56:57 +00:00
|
|
|
|
|
|
|
const links = document.createElement('div')
|
|
|
|
const moduleToSitePath = {
|
|
|
|
'simulateur-embauche': '/simulateurs/salarié',
|
|
|
|
'simulateur-autoentrepreneur': '/simulateurs/auto-entrepreneur',
|
|
|
|
'simulateur-independant': '/simulateurs/indépendant',
|
2020-12-01 09:17:27 +00:00
|
|
|
'simulateur-dirigeantsasu': '/simulateurs/dirigeant-sasu',
|
2019-10-24 12:56:57 +00:00
|
|
|
}
|
2022-03-24 15:23:37 +00:00
|
|
|
|
2021-03-18 12:15:07 +00:00
|
|
|
const simulateurLink =
|
2022-03-24 15:23:37 +00:00
|
|
|
import.meta.env.VITE_FR_BASE_URL + (moduleToSitePath[moduleName] ?? '/')
|
2022-02-08 15:37:43 +00:00
|
|
|
|
2022-01-28 09:20:54 +00:00
|
|
|
const url = new URL(simulateurLink)
|
2022-02-08 15:37:43 +00:00
|
|
|
|
2020-12-02 11:27:03 +00:00
|
|
|
const params = new URLSearchParams(url.search)
|
2022-02-08 15:37:43 +00:00
|
|
|
|
2020-12-02 11:27:03 +00:00
|
|
|
params.append('utm_source', 'iframe')
|
|
|
|
params.append('utm_medium', 'iframe')
|
|
|
|
params.append('utm_campaign', 'newtext')
|
|
|
|
url.search = params.toString()
|
|
|
|
const simulateurURL = url.toString()
|
2022-01-20 10:39:11 +00:00
|
|
|
|
2019-10-24 12:56:57 +00:00
|
|
|
links.innerHTML = `
|
2020-10-08 12:22:43 +00:00
|
|
|
<div style="text-align: center; margin-bottom: 2rem; font-size: 80%">
|
2021-12-27 10:27:57 +00:00
|
|
|
Retrouvez ce simulateur et bien d'autres sur
|
2020-12-02 11:27:03 +00:00
|
|
|
<a href="${simulateurURL}">
|
2021-11-30 16:31:20 +00:00
|
|
|
mon-entreprise.urssaf.fr
|
2021-12-27 10:27:57 +00:00
|
|
|
</a>
|
2019-10-24 12:56:57 +00:00
|
|
|
</div>
|
|
|
|
`
|
|
|
|
|
2022-02-14 09:31:57 +00:00
|
|
|
script.before(iframe)
|
|
|
|
script.before(links)
|
2022-02-08 15:37:43 +00:00
|
|
|
|
|
|
|
window.addEventListener('message', function (evt) {
|
|
|
|
if (evt.data.kind === 'resize-height') {
|
|
|
|
iframe.style.height = evt.data.value + 'px'
|
|
|
|
}
|
2022-03-22 09:58:29 +00:00
|
|
|
if (evt.data.kind === 'get-offset') {
|
|
|
|
const iframePosition = iframe.getBoundingClientRect()
|
|
|
|
iframe.contentWindow?.postMessage(
|
|
|
|
{ kind: 'offset', value: Math.max(iframePosition.top * -1, 0) },
|
|
|
|
'*'
|
|
|
|
)
|
|
|
|
}
|
2022-02-08 15:37:43 +00:00
|
|
|
})
|