11function LoadingBar ( color , parent ) {
2- this . meter = $ ( '<span>' , { style : 'transition: width 1s ease; width:0%;' } ) ;
2+ this . meter = $ ( '<span>' , { style : 'transition: width 0.5s ease; width:0%;' } ) ;
33 this . elem = $ ( '<div>' , { style : 'display:none' , class : 'meter animate ' + color } ) . append (
44 this . meter . append ( $ ( '<span>' ) )
55 ) ;
@@ -10,18 +10,32 @@ function LoadingBar(color, parent) {
1010 return this ;
1111}
1212
13- LoadingBar . prototype . start = function ( percentage ) {
14- percentage = percentage || 0 ;
15- this . meter . css ( 'width' , percentage + '%' ) ;
13+ LoadingBar . prototype . start = function ( progress ) {
14+ progress = progress || 5 ;
15+ this . clearTimer ( ) ;
16+ this . meter . css ( 'width' , progress + '%' ) ;
1617 this . elem . show ( ) ;
1718} ;
1819
1920LoadingBar . prototype . end = function ( ) {
20- this . elem . hide ( ) ;
21+ this . update ( 100 ) ;
2122} ;
2223
23- LoadingBar . prototype . update = function ( percentage ) {
24- this . meter . css ( 'width' , percentage + '%' ) ;
24+ LoadingBar . prototype . update = function ( progress ) {
25+ this . clearTimer ( ) ;
26+ this . meter . css ( 'width' , progress + '%' ) ;
27+ if ( progress === 100 ) {
28+ this . timer = setTimeout ( function ( ) {
29+ this . elem . hide ( ) ;
30+ } . bind ( this ) , 500 ) ;
31+ }
32+ } ;
33+
34+ LoadingBar . prototype . clearTimer = function ( ) {
35+ if ( this . timer ) {
36+ clearTimeout ( this . timer ) ;
37+ this . timer = null ;
38+ }
2539} ;
2640
2741module . exports = LoadingBar ;
0 commit comments