|
@@ -1,37 +1,27 @@
|
|
|
import { computeEdges } from '../util/dom-geom'
|
|
import { computeEdges } from '../util/dom-geom'
|
|
|
import { removeElement, createElement, applyStyle, applyStyleProp } from '../util/dom-manip'
|
|
import { removeElement, createElement, applyStyle, applyStyleProp } from '../util/dom-manip'
|
|
|
|
|
+import { ElementScrollController } from './scroll-controller'
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
Embodies a div that has potential scrollbars
|
|
Embodies a div that has potential scrollbars
|
|
|
*/
|
|
*/
|
|
|
-export default class ScrollComponent {
|
|
|
|
|
|
|
+export default class ScrollComponent extends ElementScrollController {
|
|
|
|
|
|
|
|
- el: HTMLElement // the guaranteed outer element
|
|
|
|
|
- scrollEl: HTMLElement // the element with the scrollbars
|
|
|
|
|
overflowX: any
|
|
overflowX: any
|
|
|
overflowY: any
|
|
overflowY: any
|
|
|
|
|
|
|
|
-
|
|
|
|
|
constructor(options?) {
|
|
constructor(options?) {
|
|
|
|
|
+ super(
|
|
|
|
|
+ createElement('div', {
|
|
|
|
|
+ className: 'fc-scroller'
|
|
|
|
|
+ })
|
|
|
|
|
+ )
|
|
|
options = options || {}
|
|
options = options || {}
|
|
|
this.overflowX = options.overflowX || options.overflow || 'auto'
|
|
this.overflowX = options.overflowX || options.overflow || 'auto'
|
|
|
this.overflowY = options.overflowY || options.overflow || 'auto'
|
|
this.overflowY = options.overflowY || options.overflow || 'auto'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- render() {
|
|
|
|
|
- this.el = this.renderEl()
|
|
|
|
|
- this.applyOverflow()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- renderEl() {
|
|
|
|
|
- return this.scrollEl = createElement('div', {
|
|
|
|
|
- className: 'fc-scroller'
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
// sets to natural height, unlocks overflow
|
|
// sets to natural height, unlocks overflow
|
|
|
clear() {
|
|
clear() {
|
|
|
this.setHeight('auto')
|
|
this.setHeight('auto')
|
|
@@ -39,7 +29,7 @@ export default class ScrollComponent {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- destroy() {
|
|
|
|
|
|
|
+ removeElement() {
|
|
|
removeElement(this.el)
|
|
removeElement(this.el)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -49,7 +39,7 @@ export default class ScrollComponent {
|
|
|
|
|
|
|
|
|
|
|
|
|
applyOverflow() {
|
|
applyOverflow() {
|
|
|
- applyStyle(this.scrollEl, {
|
|
|
|
|
|
|
+ applyStyle(this.el, {
|
|
|
overflowX: this.overflowX,
|
|
overflowX: this.overflowX,
|
|
|
overflowY: this.overflowY
|
|
overflowY: this.overflowY
|
|
|
})
|
|
})
|
|
@@ -60,7 +50,6 @@ export default class ScrollComponent {
|
|
|
// Useful for preserving scrollbar widths regardless of future resizes.
|
|
// Useful for preserving scrollbar widths regardless of future resizes.
|
|
|
// Can pass in scrollbarWidths for optimization.
|
|
// Can pass in scrollbarWidths for optimization.
|
|
|
lockOverflow(scrollbarWidths) {
|
|
lockOverflow(scrollbarWidths) {
|
|
|
- let { scrollEl } = this
|
|
|
|
|
let overflowX = this.overflowX
|
|
let overflowX = this.overflowX
|
|
|
let overflowY = this.overflowY
|
|
let overflowY = this.overflowY
|
|
|
|
|
|
|
@@ -69,56 +58,28 @@ export default class ScrollComponent {
|
|
|
if (overflowX === 'auto') {
|
|
if (overflowX === 'auto') {
|
|
|
overflowX = (
|
|
overflowX = (
|
|
|
scrollbarWidths.bottom || // horizontal scrollbars?
|
|
scrollbarWidths.bottom || // horizontal scrollbars?
|
|
|
- // OR scrolling pane with massless scrollbars?
|
|
|
|
|
- scrollEl.scrollWidth - 1 > scrollEl.clientWidth
|
|
|
|
|
- // subtract 1 because of IE off-by-one issue
|
|
|
|
|
|
|
+ this.canScrollHorizontally() // OR scrolling pane with massless scrollbars?
|
|
|
) ? 'scroll' : 'hidden'
|
|
) ? 'scroll' : 'hidden'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (overflowY === 'auto') {
|
|
if (overflowY === 'auto') {
|
|
|
overflowY = (
|
|
overflowY = (
|
|
|
- scrollbarWidths.left || scrollbarWidths.right || // vertical scrollbars?
|
|
|
|
|
- // OR scrolling pane with massless scrollbars?
|
|
|
|
|
- scrollEl.scrollHeight - 1 > scrollEl.clientHeight
|
|
|
|
|
- // subtract 1 because of IE off-by-one issue
|
|
|
|
|
|
|
+ scrollbarWidths.left || scrollbarWidths.right || // horizontal scrollbars?
|
|
|
|
|
+ this.canScrollVertically() // OR scrolling pane with massless scrollbars?
|
|
|
) ? 'scroll' : 'hidden'
|
|
) ? 'scroll' : 'hidden'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- applyStyle(this.scrollEl, { overflowX, overflowY })
|
|
|
|
|
|
|
+ applyStyle(this.el, { overflowX, overflowY })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- // Getters / Setters
|
|
|
|
|
- // -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
setHeight(height) {
|
|
setHeight(height) {
|
|
|
- applyStyleProp(this.scrollEl, 'height', height)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- getScrollTop() {
|
|
|
|
|
- return this.scrollEl.scrollTop
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- setScrollTop(top) {
|
|
|
|
|
- this.scrollEl.scrollTop = top
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- getClientWidth() {
|
|
|
|
|
- return this.scrollEl.clientWidth
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- getClientHeight() {
|
|
|
|
|
- return this.scrollEl.clientHeight
|
|
|
|
|
|
|
+ applyStyleProp(this.el, 'height', height)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
getScrollbarWidths() {
|
|
getScrollbarWidths() {
|
|
|
- let edges = computeEdges(this.scrollEl)
|
|
|
|
|
|
|
+ let edges = computeEdges(this.el)
|
|
|
return {
|
|
return {
|
|
|
left: edges.scrollbarLeft,
|
|
left: edges.scrollbarLeft,
|
|
|
right: edges.scrollbarRight,
|
|
right: edges.scrollbarRight,
|