Skip to content

Commit 82b8cf3

Browse files
updated github pages
1 parent 5f5db90 commit 82b8cf3

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!doctype html>
22
<html>
33
<head>
4+
<title>Angular Loading Bar</title>
45
<!-- angular -->
56
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.min.js"></script>
67
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-animate.min.js"></script>
@@ -21,7 +22,7 @@
2122
<h1>Angular Loading Bar</h1>
2223
<p>An automatic loading bar using angular interceptors.<small> It works automatically, so simply include it as a dependency and it will automatically display the progress of your $http requests.</small></p>
2324
<p>
24-
<a href="https://github.com/chieffancypants/angular-loading-bar" class="btn btn-primary btn-lg">
25+
<a href="https://github.com/chieffancypants/angular-loading-bar/archive/0.0.1.zip" class="btn btn-primary btn-lg">
2526
<i class="glyphicon glyphicon-download"></i>&nbsp;&nbsp;Download
2627
</a>
2728
<a href="https://github.com/chieffancypants/angular-loading-bar" class="btn btn-default btn-lg">

src/loading-bar.js

+24-17
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Registers itself as an Angular interceptor and listens for XHR requests.
2020
*/
2121
angular.module('chieffancypants.loadingBar', [])
22-
.config(['$httpProvider', function($httpProvider) {
22+
.config(['$httpProvider', function ($httpProvider) {
2323

2424
var interceptor = ['$q', 'cfpLoadingBar', function ($q, cfpLoadingBar) {
2525

@@ -48,16 +48,13 @@ angular.module('chieffancypants.loadingBar', [])
4848
'request': function(config) {
4949
if (reqsTotal === 0) {
5050
cfpLoadingBar.start();
51-
console.log('start that shit', reqsCompleted, reqsTotal);
5251
}
5352
reqsTotal++;
54-
console.log('request', reqsCompleted, reqsTotal);
5553
return config;
5654
},
5755

5856
'response': function(response) {
5957
reqsCompleted++;
60-
console.log('set complete', reqsCompleted, reqsTotal);
6158
if (reqsCompleted === reqsTotal) {
6259
setComplete();
6360
} else {
@@ -68,7 +65,6 @@ angular.module('chieffancypants.loadingBar', [])
6865

6966
'responseError': function(rejection) {
7067
reqsCompleted++;
71-
console.log('set complete fail', reqsCompleted, reqsTotal);
7268
if (reqsCompleted === reqsTotal) {
7369
setComplete();
7470
} else {
@@ -100,17 +96,20 @@ angular.module('chieffancypants.loadingBar', [])
10096
loadingBar = loadingBarContainer.find('div').eq(0),
10197
spinner = angular.element('<div id="loading-bar-spinner"><div class="spinner-icon"></div></div>');
10298

103-
var started = false,
104-
status = 0,
105-
incTimeout;
99+
var incTimeout,
100+
started = false,
101+
status = 0;
102+
103+
var includeSpinner = this.includeSpinner;
106104

107105
/**
108106
* Inserts the loading bar element into the dom, and sets it to 1%
109107
*/
110108
function _start() {
111109
started = true;
112110
$animate.enter(loadingBarContainer, $body);
113-
if (this.includeSpinner) {
111+
112+
if (includeSpinner) {
114113
$animate.enter(spinner, $body);
115114
}
116115
_set(0.02);
@@ -139,7 +138,7 @@ angular.module('chieffancypants.loadingBar', [])
139138
}
140139

141140
/**
142-
* Increments the loading bar by a random amount between .1% and .9%
141+
* Increments the loading bar by a random amount
143142
* but slows down once it approaches 70%
144143
*/
145144
function _inc() {
@@ -149,14 +148,21 @@ angular.module('chieffancypants.loadingBar', [])
149148

150149
var rnd = 0;
151150

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;
157163
} 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;
160166
}
161167

162168
var pct = _status() + rnd;
@@ -188,6 +194,7 @@ angular.module('chieffancypants.loadingBar', [])
188194
};
189195

190196

197+
191198
}]; //
192199
}); // wtf javascript. srsly
193200
})(); //

0 commit comments

Comments
 (0)