Commit 854d0c05 authored by Anton's avatar Anton

Cell detects if at least partially visible in viewport

parent 39c29d24
......@@ -23,7 +23,8 @@
props: ['cell', 'display', 'preview', 'annotation'],
data () {
return {
selected: false
selected: false,
inViewPort: false
}
},
computed: {
......@@ -42,11 +43,23 @@
}
},
mounted () {
this.onScroll()
this.$parent.$el.addEventListener('scroll', this.onScroll, false)
if (this.cellTypeName && cellTypes.hasOwnProperty(this.cellTypeName) === false) {
throw new Error('This cell type is missing: ' + this.cell.type)
}
},
beforeDestroy () {
this.$parent.$el.removeEventListener('scroll', this.onScroll)
},
methods: {
onScroll () {
const
bounds = this.$el.getBoundingClientRect(),
boundsParent = this.$parent.$el.getBoundingClientRect()
this.inViewPort = (bounds.left >= 0 && bounds.left <= boundsParent.width) ||
(bounds.right >= 0 && bounds.right <= boundsParent.width)
},
cellTypeToClassName (type) {
return 'Cell' + type.slice(0, 1).toUpperCase() + type.slice(1).replace(/[^a-z0-9]/ig, '')
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment