17
17
18
18
import Controller from './Controller' ;
19
19
import AppModel from '../model/AppModel' ;
20
- import PubSubInstance from '../libs/PubSub' ;
21
- import ToasterInstance from '../libs/Toaster' ;
22
- import DialogInstance from '../libs/Dialog' ;
23
- import RouterInstance from '../libs/Router' ;
20
+ import pubSubInstance from '../libs/PubSub' ;
21
+ import toasterInstance from '../libs/Toaster' ;
22
+ import routerInstance from '../libs/Router' ;
24
23
25
24
export default class AppController extends Controller {
26
25
27
- constructor ( ) {
28
-
26
+ constructor ( ) {
29
27
super ( ) ;
30
28
31
29
this . appModel = null ;
32
30
this . sideNavToggleButton = document . querySelector ( '.js-toggle-menu' ) ;
33
31
this . sideNav = document . querySelector ( '.js-side-nav' ) ;
34
32
this . sideNavContent = this . sideNav . querySelector ( '.js-side-nav-content' ) ;
35
- this . loadScript ( '/scripts/list.js' )
36
- this . newappshellingButton = document . querySelector ( '.js-new-appshelling-btn' ) ;
33
+ this . loadScript ( '/scripts/list.js' ) ;
34
+ this . newappshellingButton =
35
+ document . querySelector ( '.js-new-appshelling-btn' ) ;
37
36
38
37
AppModel . get ( 1 ) . then ( appModel => {
39
-
40
- RouterInstance ( ) . then ( router => {
38
+ routerInstance ( ) . then ( router => {
41
39
router . add ( '_root' ,
42
40
( data ) => this . show ( data ) ,
43
41
( ) => this . hide ( ) ) ;
@@ -58,26 +56,25 @@ export default class AppController extends Controller {
58
56
var sideNavTransform ;
59
57
var onSideNavTouchStart = ( e ) => {
60
58
touchStartX = e . touches [ 0 ] . pageX ;
61
- }
59
+ } ;
62
60
63
61
var onSideNavTouchMove = ( e ) => {
64
-
65
62
var newTouchX = e . touches [ 0 ] . pageX ;
66
63
sideNavTransform = Math . min ( 0 , newTouchX - touchStartX ) ;
67
64
68
- if ( sideNavTransform < 0 )
65
+ if ( sideNavTransform < 0 ) {
69
66
e . preventDefault ( ) ;
67
+ }
70
68
71
69
this . sideNavContent . style . transform =
72
70
'translateX(' + sideNavTransform + 'px)' ;
73
- }
71
+ } ;
74
72
75
73
var onSideNavTouchEnd = ( e ) => {
76
-
77
- if ( sideNavTransform < - 1 )
74
+ if ( sideNavTransform < - 1 ) {
78
75
this . closeSideNav ( ) ;
79
-
80
- }
76
+ }
77
+ } ;
81
78
82
79
this . sideNav . addEventListener ( 'click' , ( ) => {
83
80
this . closeSideNav ( ) ;
@@ -92,8 +89,7 @@ export default class AppController extends Controller {
92
89
// Wait for the first frame because sometimes
93
90
// window.onload fires too quickly.
94
91
requestAnimationFrame ( ( ) => {
95
-
96
- function showWaitAnimation ( e ) {
92
+ function showWaitAnimation ( e ) {
97
93
e . target . classList . add ( 'pending' ) ;
98
94
}
99
95
@@ -105,44 +101,39 @@ export default class AppController extends Controller {
105
101
} ) ;
106
102
107
103
if ( 'serviceWorker' in navigator ) {
108
-
109
104
navigator . serviceWorker . register ( '/sw.js' , {
110
105
scope : '/'
111
106
} ) . then ( function ( registration ) {
112
-
113
107
var isUpdate = false ;
114
108
115
109
// If this fires we should check if there's a new Service Worker
116
110
// waiting to be activated. If so, ask the user to force refresh.
117
- if ( registration . active )
111
+ if ( registration . active ) {
118
112
isUpdate = true ;
113
+ }
119
114
120
115
registration . onupdatefound = function ( event ) {
121
-
122
- console . log ( "A new Service Worker version has been found..." ) ;
116
+ console . log ( 'A new Service Worker version has been found...' ) ;
123
117
124
118
// If an update is found the spec says that there is a new Service
125
119
// Worker installing, so we should wait for that to complete then
126
120
// show a notification to the user.
127
- registration . installing . onstatechange = function ( event ) {
128
-
121
+ registration . installing . onstatechange = function ( stateChangEvent ) {
129
122
if ( this . state === 'installed' ) {
130
-
131
- console . log ( "Service Worker Installed." ) ;
123
+ console . log ( 'Service Worker Installed.' ) ;
132
124
133
125
if ( isUpdate ) {
134
- ToasterInstance ( ) . then ( toaster => {
126
+ toasterInstance ( ) . then ( toaster => {
135
127
toaster . toast (
136
128
'App updated. Restart for the new version.' ) ;
137
129
} ) ;
138
130
} else {
139
- ToasterInstance ( ) . then ( toaster => {
131
+ toasterInstance ( ) . then ( toaster => {
140
132
toaster . toast ( 'App ready for offline use.' ) ;
141
133
} ) ;
142
134
}
143
-
144
135
} else {
145
- console . log ( " New Service Worker state: " , this . state ) ;
136
+ console . log ( ' New Service Worker state: ' , this . state ) ;
146
137
}
147
138
} ;
148
139
} ;
@@ -154,35 +145,33 @@ export default class AppController extends Controller {
154
145
}
155
146
156
147
157
- show ( ) {
148
+ show ( ) {
158
149
this . sideNavToggleButton . tabIndex = 1 ;
159
150
this . newappshellingButton . tabIndex = 2 ;
160
151
}
161
152
162
- hide ( ) {
153
+ hide ( ) {
163
154
this . sideNavToggleButton . tabIndex = - 1 ;
164
155
this . newappshellingButton . tabIndex = - 1 ;
165
156
166
- PubSubInstance ( ) . then ( ps => {
157
+ pubSubInstance ( ) . then ( ps => {
167
158
ps . pub ( 'list-covered' ) ;
168
159
} ) ;
169
160
}
170
161
171
- toggleSideNav ( ) {
172
-
173
- if ( this . sideNav . classList . contains ( 'side-nav--visible' ) )
162
+ toggleSideNav ( ) {
163
+ if ( this . sideNav . classList . contains ( 'side-nav--visible' ) ) {
174
164
this . closeSideNav ( ) ;
175
- else
165
+ } else {
176
166
this . openSideNav ( ) ;
167
+ }
177
168
}
178
169
179
170
openSideNav ( ) {
180
-
181
171
this . sideNav . classList . add ( 'side-nav--visible' ) ;
182
172
this . sideNavToggleButton . focus ( ) ;
183
173
184
174
var onSideNavTransitionEnd = ( e ) => {
185
-
186
175
// Force the focus, otherwise touch doesn't always work.
187
176
this . sideNavContent . tabIndex = 0 ;
188
177
this . sideNavContent . focus ( ) ;
@@ -191,16 +180,14 @@ export default class AppController extends Controller {
191
180
this . sideNavContent . classList . remove ( 'side-nav__content--animatable' ) ;
192
181
this . sideNavContent . removeEventListener ( 'transitionend' ,
193
182
onSideNavTransitionEnd ) ;
194
- }
183
+ } ;
195
184
196
185
this . sideNavContent . classList . add ( 'side-nav__content--animatable' ) ;
197
186
this . sideNavContent . addEventListener ( 'transitionend' ,
198
187
onSideNavTransitionEnd ) ;
199
188
200
189
requestAnimationFrame ( ( ) => {
201
-
202
190
this . sideNavContent . style . transform = 'translateX(0px)' ;
203
-
204
191
} ) ;
205
192
}
206
193
@@ -209,6 +196,4 @@ export default class AppController extends Controller {
209
196
this . sideNavContent . classList . add ( 'side-nav__content--animatable' ) ;
210
197
this . sideNavContent . style . transform = 'translateX(-102%)' ;
211
198
}
212
-
213
-
214
199
}
0 commit comments