2019-07-22 12:44:30 +00:00
|
|
|
import { iframeResizer } from 'iframe-resizer'
|
2022-01-20 10:39:11 +00:00
|
|
|
|
2021-11-30 15:09:05 +00:00
|
|
|
import { hexToHSL } from './hexToHSL'
|
2019-10-24 12:56:57 +00:00
|
|
|
|
2019-07-22 12:44:30 +00:00
|
|
|
let script =
|
2020-04-30 15:13:45 +00:00
|
|
|
document.getElementById('script-monentreprise') ||
|
|
|
|
document.getElementById('script-simulateur-embauche'),
|
2019-07-22 12:44:30 +00:00
|
|
|
moduleName = script.dataset.module || 'simulateur-embauche',
|
2021-11-02 17:00:44 +00:00
|
|
|
couleur =
|
2021-11-30 15:09:05 +00:00
|
|
|
script.dataset.couleur &&
|
|
|
|
encodeURIComponent(
|
|
|
|
JSON.stringify(hexToHSL(script.dataset.couleur.toUpperCase()))
|
|
|
|
),
|
2019-10-24 12:56:57 +00:00
|
|
|
lang = script.dataset.lang || 'fr',
|
|
|
|
fr = lang === 'fr',
|
2018-08-10 11:04:23 +00:00
|
|
|
baseUrl =
|
2019-04-18 14:30:11 +00:00
|
|
|
script.dataset.iframeUrl ||
|
2021-12-27 10:27:57 +00:00
|
|
|
(fr ? import.meta.env.VITE_FR_BASE_URL : import.meta.env.VITE_EN_BASE_URL) +
|
2021-03-18 12:15:07 +00:00
|
|
|
'/iframes/' +
|
|
|
|
moduleName,
|
2018-04-17 14:04:54 +00:00
|
|
|
integratorUrl = encodeURIComponent(window.location.href.toString()),
|
2018-08-10 11:04:23 +00:00
|
|
|
src =
|
2019-07-22 12:44:30 +00:00
|
|
|
baseUrl +
|
|
|
|
(baseUrl.indexOf('?') !== -1 ? '&' : '?') +
|
2019-04-30 14:22:14 +00:00
|
|
|
`couleur=${couleur}&iframe&integratorUrl=${integratorUrl}&lang=${lang}`
|
2018-08-01 10:11:22 +00:00
|
|
|
|
|
|
|
const iframe = document.createElement('iframe')
|
|
|
|
const iframeAttributes = {
|
|
|
|
id: 'simulateurEmbauche',
|
|
|
|
src,
|
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])
|
|
|
|
}
|
2018-08-30 16:16:28 +00:00
|
|
|
iframeResizer(
|
|
|
|
{
|
|
|
|
interval: 0,
|
2022-01-25 17:41:44 +00:00
|
|
|
heightCalculationMethod: 'taggedElement',
|
2018-08-30 16:16:28 +00:00
|
|
|
},
|
|
|
|
iframe
|
|
|
|
)
|
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
|
|
|
}
|
2021-03-18 12:15:07 +00:00
|
|
|
const simulateurLink =
|
2021-12-27 10:27:57 +00:00
|
|
|
import.meta.env.VITE_FR_BASE_URL + moduleToSitePath[moduleName] ?? ''
|
2021-03-18 12:15:07 +00:00
|
|
|
|
2020-12-02 11:27:03 +00:00
|
|
|
const url = new URL(simulateurLink, window.location.origin)
|
|
|
|
const params = new URLSearchParams(url.search)
|
|
|
|
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>
|
|
|
|
`
|
|
|
|
|
2018-08-29 12:35:41 +00:00
|
|
|
script.parentNode.insertBefore(iframe, script)
|
2019-10-24 12:56:57 +00:00
|
|
|
script.parentNode.insertBefore(links, script)
|