19
19
* Registers itself as an Angular interceptor and listens for XHR requests.
20
20
*/
21
21
angular . module ( 'chieffancypants.loadingBar' , [ ] )
22
- . config ( [ '$httpProvider' , function ( $httpProvider ) {
22
+ . config ( [ '$httpProvider' , function ( $httpProvider ) {
23
23
24
24
var interceptor = [ '$q' , 'cfpLoadingBar' , function ( $q , cfpLoadingBar ) {
25
25
@@ -48,16 +48,13 @@ angular.module('chieffancypants.loadingBar', [])
48
48
'request' : function ( config ) {
49
49
if ( reqsTotal === 0 ) {
50
50
cfpLoadingBar . start ( ) ;
51
- console . log ( 'start that shit' , reqsCompleted , reqsTotal ) ;
52
51
}
53
52
reqsTotal ++ ;
54
- console . log ( 'request' , reqsCompleted , reqsTotal ) ;
55
53
return config ;
56
54
} ,
57
55
58
56
'response' : function ( response ) {
59
57
reqsCompleted ++ ;
60
- console . log ( 'set complete' , reqsCompleted , reqsTotal ) ;
61
58
if ( reqsCompleted === reqsTotal ) {
62
59
setComplete ( ) ;
63
60
} else {
@@ -68,7 +65,6 @@ angular.module('chieffancypants.loadingBar', [])
68
65
69
66
'responseError' : function ( rejection ) {
70
67
reqsCompleted ++ ;
71
- console . log ( 'set complete fail' , reqsCompleted , reqsTotal ) ;
72
68
if ( reqsCompleted === reqsTotal ) {
73
69
setComplete ( ) ;
74
70
} else {
@@ -100,17 +96,20 @@ angular.module('chieffancypants.loadingBar', [])
100
96
loadingBar = loadingBarContainer . find ( 'div' ) . eq ( 0 ) ,
101
97
spinner = angular . element ( '<div id="loading-bar-spinner"><div class="spinner-icon"></div></div>' ) ;
102
98
103
- var started = false ,
104
- status = 0 ,
105
- incTimeout ;
99
+ var incTimeout ,
100
+ started = false ,
101
+ status = 0 ;
102
+
103
+ var includeSpinner = this . includeSpinner ;
106
104
107
105
/**
108
106
* Inserts the loading bar element into the dom, and sets it to 1%
109
107
*/
110
108
function _start ( ) {
111
109
started = true ;
112
110
$animate . enter ( loadingBarContainer , $body ) ;
113
- if ( this . includeSpinner ) {
111
+
112
+ if ( includeSpinner ) {
114
113
$animate . enter ( spinner , $body ) ;
115
114
}
116
115
_set ( 0.02 ) ;
@@ -139,7 +138,7 @@ angular.module('chieffancypants.loadingBar', [])
139
138
}
140
139
141
140
/**
142
- * Increments the loading bar by a random amount between .1% and .9%
141
+ * Increments the loading bar by a random amount
143
142
* but slows down once it approaches 70%
144
143
*/
145
144
function _inc ( ) {
@@ -149,14 +148,21 @@ angular.module('chieffancypants.loadingBar', [])
149
148
150
149
var rnd = 0 ;
151
150
152
- // TODO: do this mathmatically instead of conditionally:
153
- if ( _status ( ) >= 0.7 && _status ( ) < 0.9 ) {
154
- rnd = Math . random ( ) / 50 ;
155
- } else if ( _status ( ) >= 0.9 ) {
156
- rnd = 0.005 ;
151
+ // TODO: do this mathmatically instead of through conditions
152
+
153
+ var stat = _status ( ) ;
154
+ if ( stat >= 0 && stat < 0.25 ) {
155
+ // Start out between 3 - 6% increments
156
+ rnd = ( Math . random ( ) * ( 5 - 3 + 1 ) + 3 ) / 100 ;
157
+ } else if ( stat >= 0.25 && stat < 0.65 ) {
158
+ // increment between 0 - 3%
159
+ rnd = ( Math . random ( ) * 3 ) / 100 ;
160
+ } else if ( stat >= 0.65 && stat < 0.9 ) {
161
+ // increment between 0 - 2%
162
+ rnd = ( Math . random ( ) * 2 ) / 100 ;
157
163
} else {
158
- // TODO: Clamp min value so it starts out fast initially
159
- rnd = ( Math . random ( ) / 25 ) ;
164
+ // finally, increment it .5 %
165
+ rnd = 0.005 ;
160
166
}
161
167
162
168
var pct = _status ( ) + rnd ;
@@ -188,6 +194,7 @@ angular.module('chieffancypants.loadingBar', [])
188
194
} ;
189
195
190
196
197
+
191
198
} ] ; //
192
199
} ) ; // wtf javascript. srsly
193
200
} ) ( ) ; //
0 commit comments