forked from area17/twill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreviewerFrame.vue
executable file
·82 lines (74 loc) · 1.96 KB
/
PreviewerFrame.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<template>
<iframe :srcdoc="content" frameborder="0" class="previewerframe" :style="{ width: size > 0 ? size + 'px' : '' }" @load="loadPreview"></iframe>
</template>
<script>
export default {
name: 'A17previewerFrame',
props: {
size: {
type: Number,
default: 0
},
content: {
type: String,
default: ''
},
scrollPosition: {
type: Number,
default: 0
}
},
data: function () {
return {
currentScroll: this.scrollPosition
}
},
watch: {
scrollPosition: function (value) {
// scroll the iframe
this.$el.contentWindow.scrollTo(0, value)
}
},
methods: {
loadPreview: function (event) {
const self = this
// disable button and link in preview
const iframe = event.target
const buttons = iframe.contentDocument.querySelectorAll('a,button')
for (let i = 0; i < buttons.length; i++) {
buttons[i].setAttribute('disabled', 'disabled')
buttons[i].style.pointerEvents = 'none'
buttons[i].onclick = function () {
return false
}
}
iframe.contentDocument.addEventListener('scroll', function (event) {
const scrollValue = iframe.contentWindow.pageYOffset
if (scrollValue !== self.currentScroll) {
self.$emit('scrollDoc', scrollValue)
self.currentScroll = scrollValue
}
})
// move the iframe after load
this.$el.contentWindow.scrollTo(0, this.currentScroll)
}
}
}
</script>
<style lang="scss" scoped>
.previewerframe {
width: 100%;
height:100%;
margin: 0 auto;
max-width:calc(100% - 20px);
display: block;
// box-shadow:0 0px 10px rgba(0,0,0,0.8);
transform:translateX(-50%);
transition: width .3s ease;
position: absolute;
top:0;
bottom:0;
left:50%;
background:$color__background;
}
</style>