improve demo resizing

This commit is contained in:
Philipp Kühn 2021-02-02 11:37:24 +01:00 committed by Hans Pagel
parent 6fb953dab8
commit 138cd75b3c
3 changed files with 32 additions and 3 deletions

View File

@ -5,7 +5,7 @@
</div>
<iframe
v-show="!isLoading"
v-resize
v-resize.quiet
:src="`/demos/${name}?${query}`"
style="background-color: transparent;"
width="100%"

View File

@ -23,8 +23,17 @@ export default function (Vue, { head }) {
Vue.use(PortalVue)
Vue.directive('resize', {
bind(el, { value = {} }) {
el.addEventListener('load', () => iframeResize(value, el))
bind: (el, { value = {} }) => {
el.addEventListener('load', () => {
iframeResize({
...value,
messageCallback(messageData) {
if (messageData.message === 'resize') {
el.iFrameResizer.resize()
}
},
}, el)
})
},
unbind(el) {
el.iFrameResizer.removeListeners()

View File

@ -23,6 +23,26 @@ export default {
],
}
},
data() {
return {
resizeObserver: null,
}
},
mounted() {
this.resizeObserver = new window.ResizeObserver(() => {
if (window.parentIFrame) {
window.parentIFrame.sendMessage('resize')
}
})
this.resizeObserver.observe(document.body)
},
beforeDestroy() {
this.resizeObserver.unobserve(document.body)
},
}
</script>