UNPKG

quasar-framework

Version:

Build responsive SPA, SSR, PWA, Hybrid Mobile Apps and Electron apps, all simultaneously using the same codebase

117 lines (113 loc) 2.56 kB
import QScrollObservable from '../observables/QScrollObservable.js' import QResizeObservable from '../observables/QResizeObservable.js' import QWindowResizeObservable from '../observables/QWindowResizeObservable.js' import { onSSR } from '../../plugins/platform.js' export default { name: 'QLayout', provide () { return { layout: this } }, props: { view: { type: String, default: 'hhh lpr fff', validator: v => /^(h|l)h(h|r) lpr (f|l)f(f|r)$/.test(v.toLowerCase()) } }, data () { return { height: onSSR ? 0 : window.innerHeight, width: onSSR ? 0 : window.innerWidth, header: { size: 0, offset: 0, space: false }, right: { size: 300, offset: 0, space: false }, footer: { size: 0, offset: 0, space: false }, left: { size: 300, offset: 0, space: false }, scrollHeight: 0, scroll: { position: 0, direction: 'down' } } }, computed: { rows () { const rows = this.view.toLowerCase().split(' ') return { top: rows[0].split(''), middle: rows[1].split(''), bottom: rows[2].split('') } } }, created () { this.instances = { header: null, right: null, footer: null, left: null } }, render (h) { return h('div', { staticClass: 'q-layout' }, [ h(QScrollObservable, { on: { scroll: this.__onPageScroll } }), h(QResizeObservable, { on: { resize: this.__onLayoutResize } }), h(QWindowResizeObservable, { on: { resize: this.__onWindowResize } }), this.$slots.default ]) }, methods: { __animate () { if (this.timer) { clearTimeout(this.timer) } else { document.body.classList.add('q-layout-animate') } this.timer = setTimeout(() => { document.body.classList.remove('q-layout-animate') this.timer = null }, 150) }, __onPageScroll (data) { this.scroll = data this.$emit('scroll', data) }, __onLayoutResize () { this.scrollHeight = this.$el.scrollHeight this.$emit('scrollHeight', this.scrollHeight) }, __onWindowResize ({ height, width }) { if (this.height !== height) { this.height = height } if (this.width !== width) { this.width = width } this.$emit('resize', { height, width }) } } }