Skip to content

Commit 655f02c

Browse files
committed
Minor readability and formatting fixes in SidebarMobile
1 parent 5334a77 commit 655f02c

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

components/sidebar-mobile/sidebar-mobile.jsx

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@ export default class SidebarMobile extends React.Component {
1414

1515
render() {
1616
return (
17-
<nav className="sidebar-mobile" ref={ ref => this.container = ref }
17+
<nav
18+
className="sidebar-mobile"
19+
ref={ ref => this.container = ref }
1820
onTouchStart={this._handleTouchStart.bind(this)}
1921
onTouchMove={this._handleTouchMove.bind(this)}
2022
onTouchEnd={this._handleTouchEnd.bind(this)}>
21-
<div className="sidebar-mobile__toggle"
23+
24+
<div
25+
className="sidebar-mobile__toggle"
2226
onTouchStart={this._handleTouchStart.bind(this)}
2327
onTouchMove={this._handleOpenerTouchMove.bind(this)}
24-
onTouchEnd={this._handleTouchEnd.bind(this)}>
25-
</div>
28+
onTouchEnd={this._handleTouchEnd.bind(this)} />
29+
2630
<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) } />
2934

3035
{ this._getSections() }
3136
</div>
@@ -55,7 +60,7 @@ export default class SidebarMobile extends React.Component {
5560
_getSections() {
5661
return this.props.sections.map(section => (
5762
<div key={ section.url }>
58-
<h3 className="sidebar-mobile__section">{ section.title }</h3>
63+
<h3 className='sidebar-mobile__section'>{ section.title }</h3>
5964
{ this._getPages(section.pages) }
6065
</div>
6166
));
@@ -83,8 +88,7 @@ export default class SidebarMobile extends React.Component {
8388
key={ url }
8489
className={ `sidebar-mobile__page ${active ? 'sidebar-mobile__page--active' : ''}` }
8590
to={ url }
86-
onClick={ this._close.bind(this) }
87-
>
91+
onClick={ this._close.bind(this) }>
8892
{ page.title }
8993
</Link>
9094
);
@@ -124,18 +128,20 @@ export default class SidebarMobile extends React.Component {
124128
_handleTouchStart(e){
125129
initialTouchPosition.x = e.touches[0].pageX;
126130
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');
129134
}
130135

131136
_handleTouchMove(e){
132137
let xDiff = initialTouchPosition.x - e.touches[0].pageX;
133138
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) {
137143
e.preventDefault();
138-
this.container.style.transform="translateX(-"+xDiff+"px)";
144+
this.container.style.transform = `translateX(-${xDiff}px)`;
139145
lastTouchPosition.x = e.touches[0].pageX;
140146
lastTouchPosition.y = e.touches[0].pageY;
141147
}
@@ -144,25 +150,26 @@ export default class SidebarMobile extends React.Component {
144150
_handleOpenerTouchMove(e){
145151
let xDiff = e.touches[0].pageX - initialTouchPosition.x;
146152
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) {
150157
e.preventDefault();
151-
this.container.style.transform="translateX(calc(-100% + "+xDiff+"px))";
158+
this.container.style.transform = `translateX(calc(-100% + ${xDiff}px))`;
152159
lastTouchPosition.x = e.touches[0].pageX;
153160
lastTouchPosition.y = e.touches[0].pageY;
154161
}
155162
}
156163

157164
_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) {
162170
this._close();
163-
} else if(lastTouchPosition.x - initialTouchPosition.x > 100){
171+
} else if (lastTouchPosition.x - initialTouchPosition.x > 100) {
164172
this._open();
165173
}
166-
167174
}
168175
}

0 commit comments

Comments
 (0)