Allow custom styles to be passed to embedded iframe (#1522)
* Allow custom styles to be passed to embedded iframe * Changelogpull/1523/head
parent
05a89ab130
commit
7d37208d52
@ -1 +1,16 @@
|
||||
import 'iframe-resizer/js/iframeResizer.contentWindow'
|
||||
|
||||
window.iFrameResizer = {
|
||||
onMessage: function(msg) {
|
||||
if (msg.type === 'load-custom-styles') {
|
||||
addCustomStyles(msg.opts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addCustomStyles(opts) {
|
||||
var style = document.createElement('style');
|
||||
style.innerHTML = opts.styles
|
||||
|
||||
document.head.appendChild(style);
|
||||
}
|
||||
|
||||
@ -1,3 +1,20 @@
|
||||
import iframeResize from 'iframe-resizer/js/iframeResizer'
|
||||
|
||||
iframeResize({heightCalculationMethod: 'taggedElement'}, '[plausible-embed]')
|
||||
var iframes = iframeResize({
|
||||
heightCalculationMethod: 'taggedElement',
|
||||
onInit: onInit
|
||||
}, '[plausible-embed]')
|
||||
|
||||
function onInit() {
|
||||
var iframe = iframes[0]
|
||||
var styles = iframe.getAttribute('styles')
|
||||
|
||||
if (styles) {
|
||||
iframe.iFrameResizer.sendMessage({
|
||||
type: 'load-custom-styles',
|
||||
opts: {
|
||||
styles: styles
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue