1
- import 'intersection-observer' ;
2
1
import { css , cx , injectGlobal } from 'emotion' ;
3
2
import PropTypes from 'prop-types' ;
4
3
import React from 'react' ;
5
4
6
- import ShareBlock from '../ShareBlock' ;
7
5
import debounce from 'lodash.debounce' ;
8
6
7
+ import ShareBlock from '../ShareBlock' ;
8
+
9
+ if ( typeof window !== 'undefined' ) {
10
+ require ( 'intersection-observer' ) ;
11
+ }
12
+
9
13
injectGlobal `
10
14
body {
11
15
height : 100% ;
@@ -85,10 +89,8 @@ class ShareBlockAside extends React.Component {
85
89
86
90
componentWillUnmount ( ) {
87
91
// unobserve the targets
88
- if ( typeof window !== `undefined` ) {
89
- for ( var value of this . observerTargets ) {
90
- this . observer . unobserve ( value ) ;
91
- }
92
+ for ( var value of this . observerTargets ) {
93
+ this . observer . unobserve ( value ) ;
92
94
}
93
95
}
94
96
@@ -108,36 +110,32 @@ class ShareBlockAside extends React.Component {
108
110
} ;
109
111
110
112
setupObserver = ( ) => {
111
- if ( typeof window !== `undefined` ) {
112
- const options = { rootMargin : '0px' , threshold : [ 0.5 ] } ;
113
- this . observer = new IntersectionObserver ( this . handleIntersect , options ) ;
113
+ const options = { rootMargin : '0px' , threshold : [ 0.5 ] } ;
114
+ this . observer = new IntersectionObserver ( this . handleIntersect , options ) ;
114
115
115
- // add inline buttons to targets
116
- this . observerTargets . push ( document . querySelector ( '.rcs-buttons--inline' ) ) ;
116
+ // add inline buttons to targets
117
+ this . observerTargets . push ( document . querySelector ( '.rcs-buttons--inline' ) ) ;
117
118
118
- // add page header to targets, if selector is provided
119
- const { pageHeaderSelector } = this . props ;
120
- if ( this . props . pageHeaderSelector ) {
121
- this . observerTargets . push ( document . querySelector ( pageHeaderSelector ) ) ;
122
- }
119
+ // add page header to targets, if selector is provided
120
+ const { pageHeaderSelector } = this . props ;
121
+ if ( this . props . pageHeaderSelector ) {
122
+ this . observerTargets . push ( document . querySelector ( pageHeaderSelector ) ) ;
123
+ }
123
124
124
- // observe the targets
125
- for ( var value of this . observerTargets ) {
126
- this . observer . observe ( value ) ;
127
- }
125
+ // observe the targets
126
+ for ( var value of this . observerTargets ) {
127
+ this . observer . observe ( value ) ;
128
128
}
129
129
} ;
130
130
131
131
handleIntersect = ( entries , observer ) => {
132
- if ( typeof window !== `undefined` ) {
133
- entries . forEach ( entry => {
134
- if ( this . state . fixedButtonsTranslation ) {
135
- this . setState ( {
136
- fixedButtonsVisible : entry . intersectionRatio > 0.5 ? false : true ,
137
- } ) ;
138
- }
139
- } ) ;
140
- }
132
+ entries . forEach ( entry => {
133
+ if ( this . state . fixedButtonsTranslation ) {
134
+ this . setState ( {
135
+ fixedButtonsVisible : entry . intersectionRatio > 0.5 ? false : true ,
136
+ } ) ;
137
+ }
138
+ } ) ;
141
139
} ;
142
140
143
141
render ( ) {
0 commit comments