From 4f77a2798713e4c203f38d2890315470cbc9411d Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Fri, 10 Aug 2018 13:04:23 +0200 Subject: [PATCH] :bug: add replacewith polyfill for ie11 --- .../sites/embauche.gouv.fr/iframe-script.js | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/source/sites/embauche.gouv.fr/iframe-script.js b/source/sites/embauche.gouv.fr/iframe-script.js index 6e01c54c8..a6a8371b6 100644 --- a/source/sites/embauche.gouv.fr/iframe-script.js +++ b/source/sites/embauche.gouv.fr/iframe-script.js @@ -1,22 +1,53 @@ -import { forEachObjIndexed } from 'ramda'; +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 let script = document.getElementById('script-simulateur-embauche'), couleur = script.dataset.couleur, - baseUrl = script.dataset.iframeUrl || script.getAttribute('src').split('dist')[0], + baseUrl = + script.dataset.iframeUrl || script.getAttribute('src').split('dist')[0], integratorUrl = encodeURIComponent(window.location.href.toString()), lang = script.dataset.lang, - src = baseUrl + `?site=embauche&couleur=${couleur}&iframe&integratorUrl=${integratorUrl}&lang=${lang}` + src = + baseUrl + + `?site=embauche&couleur=${couleur}&iframe&integratorUrl=${integratorUrl}&lang=${lang}` const iframe = document.createElement('iframe') const iframeAttributes = { id: 'simulateurEmbauche', src, - style: "border: none; width: 100%; display: block; margin: 0 auto; height: 45em", - allowfullscreen : true, + style: + 'border: none; width: 100%; display: block; margin: 0 auto; height: 45em', + allowfullscreen: true, webkitallowfullscreen: true, mozallowfullscreen: true } -forEachObjIndexed((value, key) => iframe.setAttribute(key, value), iframeAttributes) - -script.replaceWith(iframe, null); +forEachObjIndexed( + (value, key) => iframe.setAttribute(key, value), + iframeAttributes +) +script.replaceWith(iframe, null)