diff --git a/package.json b/package.json index f4cd60afb..931a5992d 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "focus-trap-react": "^3.1.2", "fuse.js": "^3.2.1", "i18next": "^10.0.7", + "iframe-resizer": "^3.6.1", "marked": "^0.3.17", "nearley": "^2.13.0", "ramda": "^0.25.0", diff --git a/source/sites/embauche.gouv.fr/entry.js b/source/sites/embauche.gouv.fr/entry.js index ca9564fa0..30f27216c 100644 --- a/source/sites/embauche.gouv.fr/entry.js +++ b/source/sites/embauche.gouv.fr/entry.js @@ -1,3 +1,4 @@ +import 'iframe-resizer' import React from 'react' import { render } from 'react-dom' import App from './App' diff --git a/source/sites/embauche.gouv.fr/iframe-script.js b/source/sites/embauche.gouv.fr/iframe-script.js index a6a8371b6..d73ceb033 100644 --- a/source/sites/embauche.gouv.fr/iframe-script.js +++ b/source/sites/embauche.gouv.fr/iframe-script.js @@ -1,30 +1,6 @@ -import { forEachObjIndexed } from 'ramda' -function ReplaceWith(Ele) { - 'use-strict' // For safari, and IE > 10 - var parent = this.parentNode, - i = arguments.length, - firstIsNode = +(parent && typeof Ele === 'object') - if (!parent) return - - while (i-- > firstIsNode) { - if (parent && typeof arguments[i] !== 'object') { - arguments[i] = document.createTextNode(arguments[i]) - } - if (!parent && arguments[i].parentNode) { - arguments[i].parentNode.removeChild(arguments[i]) - continue - } - parent.insertBefore(this.previousSibling, arguments[i]) - } - if (firstIsNode) parent.replaceChild(Ele, this) -} -if (!Element.prototype.replaceWith) Element.prototype.replaceWith = ReplaceWith -if (!CharacterData.prototype.replaceWith) - CharacterData.prototype.replaceWith = ReplaceWith -if (!DocumentType.prototype.replaceWith) - DocumentType.prototype.replaceWith = ReplaceWith +import { iframeResizer } from 'iframe-resizer'; let script = document.getElementById('script-simulateur-embauche'), couleur = script.dataset.couleur, baseUrl = @@ -40,14 +16,16 @@ const iframeAttributes = { id: 'simulateurEmbauche', src, style: - 'border: none; width: 100%; display: block; margin: 0 auto; height: 45em', + 'border: none; width: 100%; display: block; margin: 0 auto', allowfullscreen: true, webkitallowfullscreen: true, mozallowfullscreen: true } -forEachObjIndexed( - (value, key) => iframe.setAttribute(key, value), - iframeAttributes -) - -script.replaceWith(iframe, null) +for (var key in iframeAttributes) { + iframe.setAttribute(key, iframeAttributes[key]) +} +iframeResizer({ + interval: 0, + heightCalculationMethod: 'lowestElement' +}, iframe) +script.parentNode.insertBefore(iframe, script) diff --git a/yarn.lock b/yarn.lock index 8861a9585..f347fe581 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4049,6 +4049,10 @@ iferr@^0.1.5: version "0.1.5" resolved "https://registry.yarnpkg.com/iferr/-/iferr-0.1.5.tgz#c60eed69e6d8fdb6b3104a1fcbca1c192dc5b501" +iframe-resizer@^3.6.1: + version "3.6.1" + resolved "https://registry.yarnpkg.com/iframe-resizer/-/iframe-resizer-3.6.1.tgz#d0bc24009df6c94411382aafb040db36852d67d9" + ignore-walk@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.1.tgz#a83e62e7d272ac0e3b551aaa82831a19b69f82f8"