mirror of
https://github.com/nolanlawson/pinafore
synced 2024-12-12 18:28:03 +01:00
76 lines
2.0 KiB
HTML
76 lines
2.0 KiB
HTML
<div class="container"
|
|
on:scroll="onScroll(event)"
|
|
on:fullscreen="onFullscreenChange()"
|
|
ref:node>
|
|
<slot></slot>
|
|
</div>
|
|
<script>
|
|
import { getVirtualStore } from '../_utils/virtualStoreCache'
|
|
import throttle from 'lodash/throttle'
|
|
import { isFullscreen, attachFullscreenListener, detachFullscreenListener } from '../_utils/fullscreen'
|
|
import { mark, stop } from '../_utils/marks'
|
|
import { virtualStoreCache } from '../_utils/virtualStoreCache'
|
|
|
|
const SCROLL_EVENT_DELAY = 300
|
|
|
|
export default {
|
|
oncreate() {
|
|
mark('onCreate VirtualListContainer')
|
|
let node = this.refs.node
|
|
this.store.set({
|
|
scrollTop: node.scrollTop,
|
|
scrollHeight: node.scrollHeight,
|
|
offsetHeight: node.offsetHeight
|
|
})
|
|
stop('onCreate VirtualListContainer')
|
|
},
|
|
store: () => getVirtualStore(this.get('storeKey')),
|
|
events: {
|
|
scroll(node, callback) {
|
|
const onScroll = throttle(event => {
|
|
mark('onScroll')
|
|
if (this.get('fullscreen')) {
|
|
return
|
|
}
|
|
callback(event)
|
|
stop('onScroll')
|
|
}, SCROLL_EVENT_DELAY, {
|
|
leading: true,
|
|
trailing: true
|
|
})
|
|
node.addEventListener('scroll', onScroll)
|
|
|
|
return {
|
|
teardown() {
|
|
node.removeEventListener('scroll', onScroll)
|
|
}
|
|
}
|
|
},
|
|
fullscreen(node, callback) {
|
|
const onFullscreen = (() => {
|
|
callback()
|
|
})
|
|
attachFullscreenListener(onFullscreen)
|
|
return {
|
|
teardown() {
|
|
detachFullscreenListener(onFullscreen)
|
|
}
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
onScroll(event) {
|
|
this.store.set({
|
|
scrollTop: event.target.scrollTop,
|
|
scrollHeight: event.target.scrollHeight
|
|
})
|
|
},
|
|
onFullscreenChange() {
|
|
mark('onFullscreenChange')
|
|
console.log('is fullscreen? ', isFullscreen())
|
|
this.set({ fullscreen: isFullscreen() })
|
|
stop('onFullscreenChange')
|
|
}
|
|
}
|
|
};
|
|
</script> |