2
2
* RemoteStorage connect widget
3
3
* @constructor
4
4
*
5
- * @param {object } remoteStorage - remoteStorage instance
6
- * @param {object } options - Widget options
7
- * @param {boolean } options.leaveOpen - Do not minimize widget when user clicks
8
- * outside of it (default: false)
9
- * @param {number } options.autoCloseAfter - Time after which the widget closes
10
- * automatically in ms (default: 1500)
11
- * @param {boolean } options.logging - Enable logging (default: false)
5
+ * @param {object } remoteStorage - remoteStorage instance
6
+ * @param {object } options - Widget options
7
+ * @param {boolean } options.leaveOpen - Do not minimize widget when user clicks
8
+ * outside of it (default: false)
9
+ * @param {number } options.autoCloseAfter - Time after which the widget closes
10
+ * automatically in ms (default: 1500)
11
+ * @param {boolean } options.skipInitial - Don't show the initial connect hint,
12
+ * but show sign-in screen directly instead
13
+ * (default: false)
14
+ * @param {boolean } options.logging - Enable logging (default: false)
12
15
*/
13
16
let Widget = function ( remoteStorage , options = { } ) {
14
17
this . rs = remoteStorage ;
15
18
16
- this . state = 'initial' ;
19
+ this . leaveOpen = options . leaveOpen ? options . leaveOpen : false ;
20
+ this . autoCloseAfter = options . autoCloseAfter ? options . autoCloseAfter : 1500 ;
21
+ this . skipInitial = options . skipInitial ? options . skipInitial : false ;
22
+ this . logging = options . logging ? options . logging : false ;
17
23
18
24
// true if we have remoteStorage connection's info
19
25
this . active = false ;
@@ -24,17 +30,10 @@ let Widget = function(remoteStorage, options={}) {
24
30
// widget is minimized ?
25
31
this . closed = false ;
26
32
27
- this . leaveOpen = options . leaveOpen ? options . leaveOpen : false ;
28
-
29
- this . logging = typeof options . logging === 'boolean' ? options . logging : false ;
30
-
31
- this . autoCloseAfter = options . autoCloseAfter ? options . autoCloseAfter : 1500 ;
32
-
33
33
this . lastSynced = null ;
34
34
this . lastSyncedUpdateLoop = null ;
35
35
} ;
36
36
37
-
38
37
Widget . prototype = {
39
38
40
39
log ( ...msg ) {
@@ -73,7 +72,7 @@ Widget.prototype = {
73
72
this . active = false ;
74
73
this . setOnline ( ) ;
75
74
this . setBackendClass ( ) ; // removes all backend CSS classes
76
- this . setState ( 'initial' ) ;
75
+ this . setInitialState ( ) ;
77
76
break ;
78
77
case 'connected' :
79
78
this . active = true ;
@@ -135,6 +134,20 @@ Widget.prototype = {
135
134
}
136
135
} ,
137
136
137
+
138
+ /**
139
+ * Set widget to its inital state
140
+ *
141
+ * @private
142
+ */
143
+ setInitialState ( ) {
144
+ if ( this . skipInitial ) {
145
+ this . showChooseOrSignIn ( ) ;
146
+ } else {
147
+ this . setState ( 'initial' ) ;
148
+ }
149
+ } ,
150
+
138
151
/**
139
152
* Create the widget element and add styling.
140
153
*
@@ -166,7 +179,7 @@ Widget.prototype = {
166
179
this . rsConnected = document . querySelector ( '.rs-box-connected' ) ;
167
180
this . rsSignIn = document . querySelector ( '.rs-box-sign-in' ) ;
168
181
169
- this . rsConnectedLabel = document . querySelector ( '.rs-box-connected .rs-sub-headline' )
182
+ this . rsConnectedLabel = document . querySelector ( '.rs-box-connected .rs-sub-headline' ) ;
170
183
this . rsChooseRemoteStorageButton = document . querySelector ( 'button.rs-choose-rs' ) ;
171
184
this . rsChooseDropboxButton = document . querySelector ( 'button.rs-choose-dropbox' ) ;
172
185
this . rsChooseGoogleDriveButton = document . querySelector ( 'button.rs-choose-googledrive' ) ;
@@ -234,6 +247,7 @@ Widget.prototype = {
234
247
235
248
this . setupElements ( ) ;
236
249
this . setupHandlers ( ) ;
250
+ this . setInitialState ( ) ;
237
251
} ,
238
252
239
253
setEventListeners ( ) {
@@ -343,12 +357,13 @@ Widget.prototype = {
343
357
if ( ! this . leaveOpen && this . active ) {
344
358
this . closed = true ;
345
359
this . rsWidget . classList . add ( 'rs-closed' ) ;
360
+ } else if ( this . active ) {
361
+ this . setState ( 'connected' ) ;
346
362
} else {
347
- this . setState ( this . active ? 'connected' : 'initial' ) ;
363
+ this . setInitialState ( ) ;
348
364
}
349
365
} ,
350
366
351
-
352
367
/**
353
368
* Mark the widget as offline.
354
369
*
@@ -432,7 +447,7 @@ Widget.prototype = {
432
447
} ,
433
448
434
449
updateLastSyncedOutput ( ) {
435
- if ( ! this . lastSynced ) { return } // don't do anything when we've never synced yet
450
+ if ( ! this . lastSynced ) { return ; } // don't do anything when we've never synced yet
436
451
let now = new Date ( ) ;
437
452
let secondsSinceLastSync = Math . round ( ( now . getTime ( ) - this . lastSynced . getTime ( ) ) / 1000 ) ;
438
453
let subHeadlineEl = document . querySelector ( '.rs-box-connected .rs-sub-headline' ) ;
0 commit comments