@@ -33,41 +33,51 @@ export default class ScrollSync extends Component {
3333 }
3434 }
3535
36- panes = [ ]
36+ panes = { }
3737
38- registerPane = ( node ) => {
39- if ( ! this . findPane ( node ) ) {
40- this . addEvents ( node )
41- this . panes . push ( node )
38+ registerPane = ( node , group ) => {
39+ if ( ! this . panes [ group ] ) {
40+ this . panes [ group ] = [ ]
41+ }
42+
43+ if ( ! this . findPane ( node , group ) ) {
44+ this . addEvents ( node , group )
45+ this . panes [ group ] . push ( node )
4246 }
4347 }
4448
45- unregisterPane = ( node ) => {
46- if ( this . findPane ( node ) ) {
49+ unregisterPane = ( node , group ) => {
50+ if ( this . findPane ( node , group ) ) {
4751 this . removeEvents ( node )
48- this . panes . splice ( this . panes . indexOf ( node ) , 1 )
52+ this . panes [ group ] . splice ( this . panes [ group ] . indexOf ( node ) , 1 )
4953 }
5054 }
5155
52- addEvents = ( node ) => {
56+ addEvents = ( node , group ) => {
5357 /* For some reason element.addEventListener doesnt work with document.body */
54- node . onscroll = this . handlePaneScroll . bind ( this , node ) // eslint-disable-line
58+ node . onscroll = this . handlePaneScroll . bind ( this , node , group ) // eslint-disable-line
5559 }
5660
5761 removeEvents = ( node ) => {
5862 /* For some reason element.removeEventListener doesnt work with document.body */
5963 node . onscroll = null // eslint-disable-line
6064 }
6165
62- findPane = node => this . panes . find ( pane => pane === node )
66+ findPane = ( node , group ) => {
67+ if ( ! this . panes [ group ] ) {
68+ return false
69+ }
70+
71+ return this . panes [ group ] . find ( pane => pane === node )
72+ }
6373
64- handlePaneScroll = ( node ) => {
74+ handlePaneScroll = ( node , group ) => {
6575 window . requestAnimationFrame ( ( ) => {
66- this . syncScrollPositions ( node )
76+ this . syncScrollPositions ( node , group )
6777 } )
6878 }
6979
70- syncScrollPositions = ( scrolledPane ) => {
80+ syncScrollPositions = ( scrolledPane , group ) => {
7181 const {
7282 scrollTop,
7383 scrollHeight,
@@ -82,11 +92,11 @@ export default class ScrollSync extends Component {
8292
8393 const { proportional, vertical, horizontal } = this . props
8494
85- this . panes . forEach ( ( pane ) => {
95+ this . panes [ group ] . forEach ( ( pane ) => {
8696 /* For all panes beside the currently scrolling one */
8797 if ( scrolledPane !== pane ) {
8898 /* Remove event listeners from the node that we'll manipulate */
89- this . removeEvents ( pane )
99+ this . removeEvents ( pane , group )
90100 /* Calculate the actual pane height */
91101 const paneHeight = pane . scrollHeight - clientHeight
92102 const paneWidth = pane . scrollWidth - clientWidth
@@ -99,7 +109,7 @@ export default class ScrollSync extends Component {
99109 }
100110 /* Re-attach event listeners after we're done scrolling */
101111 window . requestAnimationFrame ( ( ) => {
102- this . addEvents ( pane )
112+ this . addEvents ( pane , group )
103113 } )
104114 }
105115 } )
0 commit comments