This repository has been archived by the owner on Apr 17, 2022. It is now read-only.
forked from vaadin/vaadin-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vaadin-grid-table-outer-scroller.html
97 lines (81 loc) · 2.36 KB
/
vaadin-grid-table-outer-scroller.html
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<link rel="import" href="../polymer/polymer.html">
<dom-module id="vaadin-grid-table-outer-scroller">
<template>
<style>
:host {
display: block;
height: 100%;
width: 100%;
position: absolute;
top: 0;
box-sizing: border-box;
overflow: auto;
}
:host([passthrough]) {
pointer-events: none;
}
:host([ios]) {
pointer-events: all;
z-index: -3;
}
:host([ios][scrolling]) {
z-index: 0;
}
</style>
<slot></slot>
</template>
<script>
Polymer({
is: 'vaadin-grid-table-outer-scroller',
properties: {
scrollTarget: {
type: Object,
observer: '_scrollTargetChanged'
},
passthrough: {
type: Boolean,
reflectToAttribute: true,
value: true
}
},
listeners: {
'scroll': '_syncScrollTarget'
},
attached: function() {
this.listen(this.domHost, 'mousemove', '_onMouseMove');
// for some reason scroll bars are hidden in iOS if this style is
// added in stylesheets or before attaching.
this.style.webkitOverflowScrolling = 'touch';
},
detached: function() {
this.unlisten(this.domHost, 'mousemove', '_onMouseMove');
},
_scrollTargetChanged: function(scrollTarget, oldScrollTarget) {
if (oldScrollTarget) {
this.unlisten(oldScrollTarget, 'scroll', '_syncOuterScroller');
}
this.listen(scrollTarget, 'scroll', '_syncOuterScroller');
},
_onMouseMove: function(e) {
this.passthrough = e.offsetY <= this.clientHeight && e.offsetX <= this.clientWidth;
},
_syncOuterScroller: function() {
if (!this._syncingScrollTarget) {
this._syncingOuterScroller = true;
this.scrollTop = this.domHost._scrollTop;
this.scrollLeft = this.domHost._scrollLeft;
}
this._syncingScrollTarget = false;
},
_syncScrollTarget: function() {
if (!this._syncingOuterScroller) {
this._syncingScrollTarget = true;
this.scrollTarget.scrollTop = this.scrollTop;
this.scrollTarget.scrollLeft = this.scrollLeft;
this.domHost._scrollHandler();
}
this._syncingOuterScroller = false;
}
});
</script>
</dom-module>