@@ -143,7 +143,9 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
143
143
var SwupProgressPlugin = function ( _Plugin ) {
144
144
_inherits ( SwupProgressPlugin , _Plugin ) ;
145
145
146
- function SwupProgressPlugin ( options ) {
146
+ function SwupProgressPlugin ( ) {
147
+ var options = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
148
+
147
149
_classCallCheck ( this , SwupProgressPlugin ) ;
148
150
149
151
var _this = _possibleConstructorReturn ( this , ( SwupProgressPlugin . __proto__ || Object . getPrototypeOf ( SwupProgressPlugin ) ) . call ( this ) ) ;
@@ -191,17 +193,22 @@ var SwupProgressPlugin = function (_Plugin) {
191
193
192
194
var defaultOptions = {
193
195
className : 'swup-progress-bar' ,
194
- transition : 300 ,
195
196
delay : 300 ,
197
+ transition : undefined ,
198
+ minValue : undefined ,
199
+ initialValue : undefined ,
196
200
hideImmediately : true
197
201
} ;
198
202
199
203
_this . options = _extends ( { } , defaultOptions , options ) ;
200
204
201
205
_this . showProgressBarTimeout = null ;
206
+
202
207
_this . progressBar = new _ProgressBar2 . default ( {
203
208
className : _this . options . className ,
204
- animationDuration : _this . options . transition
209
+ animationDuration : _this . options . transition ,
210
+ minValue : _this . options . minValue ,
211
+ initialValue : _this . options . initialValue
205
212
} ) ;
206
213
return _this ;
207
214
}
@@ -295,49 +302,54 @@ var _createClass = function () { function defineProperties(target, props) { for
295
302
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
296
303
297
304
var ProgressBar = function ( ) {
298
- function ProgressBar ( _ref ) {
305
+ function ProgressBar ( ) {
299
306
var _this = this ;
300
307
301
- var _ref$className = _ref . className ,
302
- className = _ref$className === undefined ? null : _ref$className ,
308
+ var _ref = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ,
309
+ _ref$className = _ref . className ,
310
+ className = _ref$className === undefined ? 'progress-bar' : _ref$className ,
311
+ _ref$styleAttr = _ref . styleAttr ,
312
+ styleAttr = _ref$styleAttr === undefined ? 'data-progressbar-styles' : _ref$styleAttr ,
303
313
_ref$animationDuratio = _ref . animationDuration ,
304
- animationDuration = _ref$animationDuratio === undefined ? null : _ref$animationDuratio ;
314
+ animationDuration = _ref$animationDuratio === undefined ? 300 : _ref$animationDuratio ,
315
+ _ref$minValue = _ref . minValue ,
316
+ minValue = _ref$minValue === undefined ? 0.1 : _ref$minValue ,
317
+ _ref$initialValue = _ref . initialValue ,
318
+ initialValue = _ref$initialValue === undefined ? 0.25 : _ref$initialValue ,
319
+ _ref$trickleValue = _ref . trickleValue ,
320
+ trickleValue = _ref$trickleValue === undefined ? 0.03 : _ref$trickleValue ;
305
321
306
322
_classCallCheck ( this , ProgressBar ) ;
307
323
308
- this . className = 'progress-bar' ;
309
- this . animationDuration = 300 ;
310
- this . minValue = 0.1 ;
311
- this . stylesheetElement = null ;
324
+ this . styleElement = null ;
312
325
this . progressElement = null ;
313
- this . hiding = false ;
314
- this . trickleInterval = null ;
315
326
this . value = 0 ;
316
327
this . visible = false ;
328
+ this . hiding = false ;
329
+ this . trickleInterval = null ;
317
330
318
331
this . trickle = function ( ) {
319
- var advance = Math . random ( ) * 3 / 100 ;
332
+ var advance = Math . random ( ) * _this . trickleValue ;
320
333
_this . setValue ( _this . value + advance ) ;
321
334
} ;
322
335
323
- if ( className !== null ) {
324
- this . className = className ;
325
- }
326
- if ( animationDuration !== null ) {
327
- this . animationDuration = animationDuration ;
328
- }
336
+ this . className = className ;
337
+ this . styleAttr = styleAttr ;
338
+ this . animationDuration = animationDuration ;
339
+ this . minValue = minValue ;
340
+ this . initialValue = initialValue ;
341
+ this . trickleValue = trickleValue ;
329
342
330
- this . stylesheetElement = this . createStylesheetElement ( ) ;
343
+ this . styleElement = this . createStyleElement ( ) ;
331
344
this . progressElement = this . createProgressElement ( ) ;
332
- } // ms
333
-
345
+ }
334
346
335
347
_createClass ( ProgressBar , [ {
336
348
key : 'show' ,
337
349
value : function show ( ) {
338
350
if ( ! this . visible ) {
339
351
this . visible = true ;
340
- this . installStylesheetElement ( ) ;
352
+ this . installStyleElement ( ) ;
341
353
this . installProgressElement ( ) ;
342
354
this . startTrickling ( ) ;
343
355
}
@@ -360,24 +372,25 @@ var ProgressBar = function () {
360
372
} , {
361
373
key : 'setValue' ,
362
374
value : function setValue ( value ) {
363
- this . value = Math . max ( this . minValue , value ) ;
375
+ this . value = Math . min ( 1 , Math . max ( this . minValue , value ) ) ;
364
376
this . refresh ( ) ;
365
377
}
366
378
367
379
// Private
368
380
369
381
} , {
370
- key : 'installStylesheetElement ' ,
371
- value : function installStylesheetElement ( ) {
372
- document . head . insertBefore ( this . stylesheetElement , document . head . firstChild ) ;
382
+ key : 'installStyleElement ' ,
383
+ value : function installStyleElement ( ) {
384
+ document . head . insertBefore ( this . styleElement , document . head . firstChild ) ;
373
385
}
374
386
} , {
375
387
key : 'installProgressElement' ,
376
388
value : function installProgressElement ( ) {
377
- this . progressElement . style . width = '0' ;
389
+ this . progressElement . style . width = '0% ' ;
378
390
this . progressElement . style . opacity = '1' ;
379
391
document . documentElement . insertBefore ( this . progressElement , document . body ) ;
380
- this . refresh ( ) ;
392
+ this . progressElement . scrollTop = 0 ; // Force reflow to ensure initial style takes effect
393
+ this . setValue ( Math . random ( ) * this . initialValue ) ;
381
394
}
382
395
} , {
383
396
key : 'fadeProgressElement' ,
@@ -411,15 +424,15 @@ var ProgressBar = function () {
411
424
var _this3 = this ;
412
425
413
426
requestAnimationFrame ( function ( ) {
414
- _this3 . progressElement . style . width = 10 + _this3 . value * 90 + '%' ;
427
+ _this3 . progressElement . style . width = _this3 . value * 100 + '%' ;
415
428
} ) ;
416
429
}
417
430
} , {
418
- key : 'createStylesheetElement ' ,
419
- value : function createStylesheetElement ( ) {
431
+ key : 'createStyleElement ' ,
432
+ value : function createStyleElement ( ) {
420
433
var element = document . createElement ( 'style' ) ;
421
- element . setAttribute ( 'data-progressbar-styles' , '' ) ;
422
- element . textContent = this . defaultCSS ;
434
+ element . setAttribute ( this . styleAttr , '' ) ;
435
+ element . textContent = this . defaultStyles ;
423
436
return element ;
424
437
}
425
438
} , {
@@ -430,9 +443,9 @@ var ProgressBar = function () {
430
443
return element ;
431
444
}
432
445
} , {
433
- key : 'defaultCSS ' ,
446
+ key : 'defaultStyles ' ,
434
447
get : function get ( ) {
435
- return '\n .' + this . className + ' {\n position : fixed;\n display : block;\n top : 0;\n left : 0;\n height : 3px;\n background -color: black;\n z -index: 9999;\n transition :\n width ' + this . animationDuration + 'ms ease-out,\n opacity ' + this . animationDuration / 2 + 'ms ' + this . animationDuration / 2 + 'ms ease-in;\n transform : translate3d(0, 0, 0);\n }\n ' ;
448
+ return '\n\t\t .' + this . className + ' {\n\t\t\t\tposition : fixed;\n\t\t\t\tdisplay : block;\n\t\t\t\ttop : 0;\n\t\t\t\tleft : 0;\n\t\t\t\theight : 3px;\n\t\t\t\tbackground -color: black;\n\t\t\t\tz -index: 9999;\n\t\t\t\ttransition :\n\t\t\t\t\twidth ' + this . animationDuration + 'ms ease-out,\n\t\t\t\t\topacity ' + this . animationDuration / 2 + 'ms ' + this . animationDuration / 2 + 'ms ease-in;\n\t\t\t\ttransform : translate3d(0, 0, 0);\n\t\t\t }\n\t\t ' ;
436
449
}
437
450
} ] ) ;
438
451
0 commit comments