@@ -14,18 +14,23 @@ export default class SidebarMobile extends React.Component {
14
14
15
15
render ( ) {
16
16
return (
17
- < nav className = "sidebar-mobile" ref = { ref => this . container = ref }
17
+ < nav
18
+ className = "sidebar-mobile"
19
+ ref = { ref => this . container = ref }
18
20
onTouchStart = { this . _handleTouchStart . bind ( this ) }
19
21
onTouchMove = { this . _handleTouchMove . bind ( this ) }
20
22
onTouchEnd = { this . _handleTouchEnd . bind ( this ) } >
21
- < div className = "sidebar-mobile__toggle"
23
+
24
+ < div
25
+ className = "sidebar-mobile__toggle"
22
26
onTouchStart = { this . _handleTouchStart . bind ( this ) }
23
27
onTouchMove = { this . _handleOpenerTouchMove . bind ( this ) }
24
- onTouchEnd = { this . _handleTouchEnd . bind ( this ) } >
25
- </ div >
28
+ onTouchEnd = { this . _handleTouchEnd . bind ( this ) } / >
29
+
26
30
< div className = "sidebar-mobile__content" >
27
- < i className = "sidebar-mobile__close icon-cross"
28
- onClick = { this . _close . bind ( this ) } />
31
+ < i
32
+ className = "sidebar-mobile__close icon-cross"
33
+ onClick = { this . _close . bind ( this ) } />
29
34
30
35
{ this . _getSections ( ) }
31
36
</ div >
@@ -55,7 +60,7 @@ export default class SidebarMobile extends React.Component {
55
60
_getSections ( ) {
56
61
return this . props . sections . map ( section => (
57
62
< div key = { section . url } >
58
- < h3 className = " sidebar-mobile__section" > { section . title } </ h3 >
63
+ < h3 className = ' sidebar-mobile__section' > { section . title } </ h3 >
59
64
{ this . _getPages ( section . pages ) }
60
65
</ div >
61
66
) ) ;
@@ -83,8 +88,7 @@ export default class SidebarMobile extends React.Component {
83
88
key = { url }
84
89
className = { `sidebar-mobile__page ${ active ? 'sidebar-mobile__page--active' : '' } ` }
85
90
to = { url }
86
- onClick = { this . _close . bind ( this ) }
87
- >
91
+ onClick = { this . _close . bind ( this ) } >
88
92
{ page . title }
89
93
</ Link >
90
94
) ;
@@ -124,18 +128,20 @@ export default class SidebarMobile extends React.Component {
124
128
_handleTouchStart ( e ) {
125
129
initialTouchPosition . x = e . touches [ 0 ] . pageX ;
126
130
initialTouchPosition . y = e . touches [ 0 ] . pageY ;
127
- //for instant transform along with the touch
128
- this . container . classList . add ( "no-delay" ) ;
131
+
132
+ // For instant transform along with the touch
133
+ this . container . classList . add ( 'no-delay' ) ;
129
134
}
130
135
131
136
_handleTouchMove ( e ) {
132
137
let xDiff = initialTouchPosition . x - e . touches [ 0 ] . pageX ;
133
138
let yDiff = initialTouchPosition . y - e . touches [ 0 ] . pageY ;
134
- let factor = Math . abs ( yDiff / xDiff ) ;
135
- //factor makes sure horizontal and vertical scroll dont take place together
136
- if ( xDiff > 0 && factor < 0.8 ) {
139
+ let factor = Math . abs ( yDiff / xDiff ) ;
140
+
141
+ // Factor makes sure horizontal and vertical scroll dont take place together
142
+ if ( xDiff > 0 && factor < 0.8 ) {
137
143
e . preventDefault ( ) ;
138
- this . container . style . transform = " translateX(-" + xDiff + " px)" ;
144
+ this . container . style . transform = ` translateX(-${ xDiff } px)` ;
139
145
lastTouchPosition . x = e . touches [ 0 ] . pageX ;
140
146
lastTouchPosition . y = e . touches [ 0 ] . pageY ;
141
147
}
@@ -144,25 +150,26 @@ export default class SidebarMobile extends React.Component {
144
150
_handleOpenerTouchMove ( e ) {
145
151
let xDiff = e . touches [ 0 ] . pageX - initialTouchPosition . x ;
146
152
let yDiff = initialTouchPosition . y - e . touches [ 0 ] . pageY ;
147
- let factor = Math . abs ( yDiff / xDiff ) ;
148
- //factor makes sure horizontal and vertical scroll dont take place together
149
- if ( xDiff > 0 && xDiff < 295 && factor < 0.8 ) {
153
+ let factor = Math . abs ( yDiff / xDiff ) ;
154
+
155
+ // Factor makes sure horizontal and vertical scroll dont take place together
156
+ if ( xDiff > 0 && xDiff < 295 && factor < 0.8 ) {
150
157
e . preventDefault ( ) ;
151
- this . container . style . transform = " translateX(calc(-100% + " + xDiff + " px))" ;
158
+ this . container . style . transform = ` translateX(calc(-100% + ${ xDiff } px))` ;
152
159
lastTouchPosition . x = e . touches [ 0 ] . pageX ;
153
160
lastTouchPosition . y = e . touches [ 0 ] . pageY ;
154
161
}
155
162
}
156
163
157
164
_handleTouchEnd ( e ) {
158
- //free up all the inline styling
159
- this . container . classList . remove ( "no-delay" ) ;
160
- this . container . style = "" ;
161
- if ( initialTouchPosition . x - lastTouchPosition . x > 100 ) {
165
+ // Free up all the inline styling
166
+ this . container . classList . remove ( 'no-delay' ) ;
167
+ this . container . style = '' ;
168
+
169
+ if ( initialTouchPosition . x - lastTouchPosition . x > 100 ) {
162
170
this . _close ( ) ;
163
- } else if ( lastTouchPosition . x - initialTouchPosition . x > 100 ) {
171
+ } else if ( lastTouchPosition . x - initialTouchPosition . x > 100 ) {
164
172
this . _open ( ) ;
165
173
}
166
-
167
174
}
168
175
}
0 commit comments