pacejs_rails 0.4.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/pace.js +759 -0
- data/app/assets/stylesheets/pace-theme-barber-shop.css +72 -0
- data/app/assets/stylesheets/pace-theme-big-counter.css +35 -0
- data/app/assets/stylesheets/pace-theme-bounce.css +231 -0
- data/app/assets/stylesheets/pace-theme-center-circle.css +110 -0
- data/app/assets/stylesheets/pace-theme-corner-indicator.css +70 -0
- data/app/assets/stylesheets/pace-theme-fill-left.css +22 -0
- data/app/assets/stylesheets/pace-theme-flash.css +81 -0
- data/app/assets/stylesheets/pace-theme-flat-top.css +33 -0
- data/app/assets/stylesheets/pace-theme-mac-osx.css +84 -0
- data/app/assets/stylesheets/pace-theme-minimal.css +18 -0
- data/lib/pacejs_rails.rb +8 -0
- data/lib/pacejs_rails/version.rb +3 -0
- data/pacejs_rails.gemspec +24 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OGY4YmMxNGNiNDgxOTM0MWU1YjYyN2U0NmMxNjM5YTg1ZmFlOTQ0Yw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWJmODExZjU4YTZmOGM3MGY2MWJhMDUxNjJmYjk0ZWM2YWU5ZDExZg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGI4MzgyNjBjMTE1ODA5MjkzNzgzMDM5MTIxZDI1NTM5ZTI4MWJhZDM0NjQz
|
10
|
+
YjMwMzMxODcyNjhkNGJlZGU5MDI3MTA2YTQxZGY3OTI5NDkyNGI3NDVmZDY3
|
11
|
+
YTQzY2U1YzU2ODQzNWJmMmQ4YWRhN2MzNmJhYTVhNTRjMGQ5NWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OGFhMjc1NThhYWU2YTgwY2M0NTYxNjIyOTkwMTVkNTQ1ZmFiZTM3Y2QzOGIz
|
14
|
+
NWY0NDQ0ZjY1ZTI0NDYwYWM4NGEwNDg2NDdlZGZhOGFmNWExNDVjZmY5MzM5
|
15
|
+
NGYzMzg3ZjczMDc5N2FmZWU4NWZmNzBmZjE4M2FkY2U0NDZlNzA=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Guy Israeli
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# PacejsRails
|
2
|
+
|
3
|
+
Pace.js (Automatic web page progress bar) for Rails 3.1 and up (including 4) to work with the asset pipeline to provide versioning of the code
|
4
|
+
|
5
|
+
as seen https://github.com/HubSpot/pace
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'pacejs_rails'
|
12
|
+
|
13
|
+
|
14
|
+
Add the following directive to your Javascript manifest file (application.js):
|
15
|
+
|
16
|
+
//= require pace
|
17
|
+
|
18
|
+
In the stylesheet manifest (application.css) add a theme of your choosing:
|
19
|
+
|
20
|
+
for exmaple
|
21
|
+
|
22
|
+
*= pace-theme-big-counter
|
23
|
+
|
24
|
+
see themes here: http://github.hubspot.com/pace/docs/welcome/
|
25
|
+
|
26
|
+
themes available: https://github.com/HubSpot/pace/tree/master/themes
|
27
|
+
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install pacejs_rails
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
just install and it will monitor all ajax requests and stuff
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,759 @@
|
|
1
|
+
// Pace.js
|
2
|
+
// 0.4.15
|
3
|
+
// https://github.com/HubSpot/pace
|
4
|
+
(function() {
|
5
|
+
var AjaxMonitor, Bar, DocumentMonitor, ElementMonitor, ElementTracker, EventLagMonitor, Events, NoTargetError, RequestIntercept, SOURCE_KEYS, Scaler, SocketRequestTracker, XHRRequestTracker, animation, avgAmplitude, bar, cancelAnimation, cancelAnimationFrame, defaultOptions, extend, extendNative, getFromDOM, getIntercept, handlePushState, init, now, options, requestAnimationFrame, result, runAnimation, scalers, sources, uniScaler, _WebSocket, _XDomainRequest, _XMLHttpRequest, _intercept, _pushState, _ref, _replaceState,
|
6
|
+
__slice = [].slice,
|
7
|
+
__hasProp = {}.hasOwnProperty,
|
8
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
9
|
+
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
10
|
+
|
11
|
+
defaultOptions = {
|
12
|
+
catchupTime: 500,
|
13
|
+
initialRate: .03,
|
14
|
+
minTime: 500,
|
15
|
+
ghostTime: 250,
|
16
|
+
maxProgressPerFrame: 10,
|
17
|
+
easeFactor: 1.25,
|
18
|
+
startOnPageLoad: true,
|
19
|
+
restartOnPushState: true,
|
20
|
+
restartOnRequestAfter: 500,
|
21
|
+
target: 'body',
|
22
|
+
elements: {
|
23
|
+
checkInterval: 100,
|
24
|
+
selectors: ['body']
|
25
|
+
},
|
26
|
+
eventLag: {
|
27
|
+
minSamples: 10,
|
28
|
+
sampleCount: 3,
|
29
|
+
lagThreshold: 3
|
30
|
+
},
|
31
|
+
ajax: {
|
32
|
+
trackMethods: ['GET'],
|
33
|
+
trackWebSockets: false
|
34
|
+
}
|
35
|
+
};
|
36
|
+
|
37
|
+
now = function() {
|
38
|
+
var _ref;
|
39
|
+
return (_ref = typeof performance !== "undefined" && performance !== null ? typeof performance.now === "function" ? performance.now() : void 0 : void 0) != null ? _ref : +(new Date);
|
40
|
+
};
|
41
|
+
|
42
|
+
requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
|
43
|
+
|
44
|
+
cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame;
|
45
|
+
|
46
|
+
if (requestAnimationFrame == null) {
|
47
|
+
requestAnimationFrame = function(fn) {
|
48
|
+
return setTimeout(fn, 50);
|
49
|
+
};
|
50
|
+
cancelAnimationFrame = function(id) {
|
51
|
+
return clearTimeout(id);
|
52
|
+
};
|
53
|
+
}
|
54
|
+
|
55
|
+
runAnimation = function(fn) {
|
56
|
+
var last, tick;
|
57
|
+
last = now();
|
58
|
+
tick = function() {
|
59
|
+
var diff;
|
60
|
+
diff = now() - last;
|
61
|
+
last = now();
|
62
|
+
return fn(diff, function() {
|
63
|
+
return requestAnimationFrame(tick);
|
64
|
+
});
|
65
|
+
};
|
66
|
+
return tick();
|
67
|
+
};
|
68
|
+
|
69
|
+
result = function() {
|
70
|
+
var args, key, obj;
|
71
|
+
obj = arguments[0], key = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
72
|
+
if (typeof obj[key] === 'function') {
|
73
|
+
return obj[key].apply(obj, args);
|
74
|
+
} else {
|
75
|
+
return obj[key];
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
extend = function() {
|
80
|
+
var key, out, source, sources, val, _i, _len;
|
81
|
+
out = arguments[0], sources = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
82
|
+
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
83
|
+
source = sources[_i];
|
84
|
+
if (source) {
|
85
|
+
for (key in source) {
|
86
|
+
if (!__hasProp.call(source, key)) continue;
|
87
|
+
val = source[key];
|
88
|
+
if ((out[key] != null) && typeof out[key] === 'object' && (val != null) && typeof val === 'object') {
|
89
|
+
extend(out[key], val);
|
90
|
+
} else {
|
91
|
+
out[key] = val;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
return out;
|
97
|
+
};
|
98
|
+
|
99
|
+
avgAmplitude = function(arr) {
|
100
|
+
var count, sum, v, _i, _len;
|
101
|
+
sum = count = 0;
|
102
|
+
for (_i = 0, _len = arr.length; _i < _len; _i++) {
|
103
|
+
v = arr[_i];
|
104
|
+
sum += Math.abs(v);
|
105
|
+
count++;
|
106
|
+
}
|
107
|
+
return sum / count;
|
108
|
+
};
|
109
|
+
|
110
|
+
getFromDOM = function(key, json) {
|
111
|
+
var data, e, el;
|
112
|
+
if (key == null) {
|
113
|
+
key = 'options';
|
114
|
+
}
|
115
|
+
if (json == null) {
|
116
|
+
json = true;
|
117
|
+
}
|
118
|
+
el = document.querySelector("[data-pace-" + key + "]");
|
119
|
+
if (!el) {
|
120
|
+
return;
|
121
|
+
}
|
122
|
+
data = el.getAttribute("data-pace-" + key);
|
123
|
+
if (!json) {
|
124
|
+
return data;
|
125
|
+
}
|
126
|
+
try {
|
127
|
+
return JSON.parse(data);
|
128
|
+
} catch (_error) {
|
129
|
+
e = _error;
|
130
|
+
return typeof console !== "undefined" && console !== null ? console.error("Error parsing inline pace options", e) : void 0;
|
131
|
+
}
|
132
|
+
};
|
133
|
+
|
134
|
+
if (window.Pace == null) {
|
135
|
+
window.Pace = {};
|
136
|
+
}
|
137
|
+
|
138
|
+
options = Pace.options = extend(defaultOptions, window.paceOptions, getFromDOM());
|
139
|
+
|
140
|
+
NoTargetError = (function(_super) {
|
141
|
+
__extends(NoTargetError, _super);
|
142
|
+
|
143
|
+
function NoTargetError() {
|
144
|
+
_ref = NoTargetError.__super__.constructor.apply(this, arguments);
|
145
|
+
return _ref;
|
146
|
+
}
|
147
|
+
|
148
|
+
return NoTargetError;
|
149
|
+
|
150
|
+
})(Error);
|
151
|
+
|
152
|
+
Bar = (function() {
|
153
|
+
function Bar() {
|
154
|
+
this.progress = 0;
|
155
|
+
}
|
156
|
+
|
157
|
+
Bar.prototype.getElement = function() {
|
158
|
+
var targetElement;
|
159
|
+
if (this.el == null) {
|
160
|
+
targetElement = document.querySelector(options.target);
|
161
|
+
if (!targetElement) {
|
162
|
+
throw new NoTargetError;
|
163
|
+
}
|
164
|
+
this.el = document.createElement('div');
|
165
|
+
this.el.className = "pace pace-active";
|
166
|
+
document.body.className = document.body.className.replace('pace-done', '');
|
167
|
+
document.body.className += ' pace-running';
|
168
|
+
this.el.innerHTML = '<div class="pace-progress">\n <div class="pace-progress-inner"></div>\n</div>\n<div class="pace-activity"></div>';
|
169
|
+
if (targetElement.firstChild != null) {
|
170
|
+
targetElement.insertBefore(this.el, targetElement.firstChild);
|
171
|
+
} else {
|
172
|
+
targetElement.appendChild(this.el);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
return this.el;
|
176
|
+
};
|
177
|
+
|
178
|
+
Bar.prototype.finish = function() {
|
179
|
+
var el;
|
180
|
+
el = this.getElement();
|
181
|
+
el.className = el.className.replace('pace-active', '');
|
182
|
+
el.className += ' pace-inactive';
|
183
|
+
document.body.className = document.body.className.replace('pace-running', '');
|
184
|
+
return document.body.className += ' pace-done';
|
185
|
+
};
|
186
|
+
|
187
|
+
Bar.prototype.update = function(prog) {
|
188
|
+
this.progress = prog;
|
189
|
+
return this.render();
|
190
|
+
};
|
191
|
+
|
192
|
+
Bar.prototype.destroy = function() {
|
193
|
+
try {
|
194
|
+
this.getElement().parentNode.removeChild(this.getElement());
|
195
|
+
} catch (_error) {
|
196
|
+
NoTargetError = _error;
|
197
|
+
}
|
198
|
+
return this.el = void 0;
|
199
|
+
};
|
200
|
+
|
201
|
+
Bar.prototype.render = function() {
|
202
|
+
var el, progressStr;
|
203
|
+
if (document.querySelector(options.target) == null) {
|
204
|
+
return false;
|
205
|
+
}
|
206
|
+
el = this.getElement();
|
207
|
+
el.children[0].style.width = "" + this.progress + "%";
|
208
|
+
if (!this.lastRenderedProgress || this.lastRenderedProgress | 0 !== this.progress | 0) {
|
209
|
+
el.children[0].setAttribute('data-progress-text', "" + (this.progress | 0) + "%");
|
210
|
+
if (this.progress >= 100) {
|
211
|
+
progressStr = '99';
|
212
|
+
} else {
|
213
|
+
progressStr = this.progress < 10 ? "0" : "";
|
214
|
+
progressStr += this.progress | 0;
|
215
|
+
}
|
216
|
+
el.children[0].setAttribute('data-progress', "" + progressStr);
|
217
|
+
}
|
218
|
+
return this.lastRenderedProgress = this.progress;
|
219
|
+
};
|
220
|
+
|
221
|
+
Bar.prototype.done = function() {
|
222
|
+
return this.progress >= 100;
|
223
|
+
};
|
224
|
+
|
225
|
+
return Bar;
|
226
|
+
|
227
|
+
})();
|
228
|
+
|
229
|
+
Events = (function() {
|
230
|
+
function Events() {
|
231
|
+
this.bindings = {};
|
232
|
+
}
|
233
|
+
|
234
|
+
Events.prototype.trigger = function(name, val) {
|
235
|
+
var binding, _i, _len, _ref1, _results;
|
236
|
+
if (this.bindings[name] != null) {
|
237
|
+
_ref1 = this.bindings[name];
|
238
|
+
_results = [];
|
239
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
240
|
+
binding = _ref1[_i];
|
241
|
+
_results.push(binding.call(this, val));
|
242
|
+
}
|
243
|
+
return _results;
|
244
|
+
}
|
245
|
+
};
|
246
|
+
|
247
|
+
Events.prototype.on = function(name, fn) {
|
248
|
+
var _base;
|
249
|
+
if ((_base = this.bindings)[name] == null) {
|
250
|
+
_base[name] = [];
|
251
|
+
}
|
252
|
+
return this.bindings[name].push(fn);
|
253
|
+
};
|
254
|
+
|
255
|
+
return Events;
|
256
|
+
|
257
|
+
})();
|
258
|
+
|
259
|
+
_XMLHttpRequest = window.XMLHttpRequest;
|
260
|
+
|
261
|
+
_XDomainRequest = window.XDomainRequest;
|
262
|
+
|
263
|
+
_WebSocket = window.WebSocket;
|
264
|
+
|
265
|
+
extendNative = function(to, from) {
|
266
|
+
var e, key, val, _results;
|
267
|
+
_results = [];
|
268
|
+
for (key in from.prototype) {
|
269
|
+
try {
|
270
|
+
val = from.prototype[key];
|
271
|
+
if ((to[key] == null) && typeof val !== 'function') {
|
272
|
+
_results.push(to[key] = val);
|
273
|
+
} else {
|
274
|
+
_results.push(void 0);
|
275
|
+
}
|
276
|
+
} catch (_error) {
|
277
|
+
e = _error;
|
278
|
+
}
|
279
|
+
}
|
280
|
+
return _results;
|
281
|
+
};
|
282
|
+
|
283
|
+
RequestIntercept = (function(_super) {
|
284
|
+
__extends(RequestIntercept, _super);
|
285
|
+
|
286
|
+
function RequestIntercept() {
|
287
|
+
var monitorXHR,
|
288
|
+
_this = this;
|
289
|
+
RequestIntercept.__super__.constructor.apply(this, arguments);
|
290
|
+
monitorXHR = function(req) {
|
291
|
+
var _open;
|
292
|
+
_open = req.open;
|
293
|
+
return req.open = function(type, url, async) {
|
294
|
+
var _ref1;
|
295
|
+
if (_ref1 = (type != null ? type : 'GET').toUpperCase(), __indexOf.call(options.ajax.trackMethods, _ref1) >= 0) {
|
296
|
+
_this.trigger('request', {
|
297
|
+
type: type,
|
298
|
+
url: url,
|
299
|
+
request: req
|
300
|
+
});
|
301
|
+
}
|
302
|
+
return _open.apply(req, arguments);
|
303
|
+
};
|
304
|
+
};
|
305
|
+
window.XMLHttpRequest = function(flags) {
|
306
|
+
var req;
|
307
|
+
req = new _XMLHttpRequest(flags);
|
308
|
+
monitorXHR(req);
|
309
|
+
return req;
|
310
|
+
};
|
311
|
+
extendNative(window.XMLHttpRequest, _XMLHttpRequest);
|
312
|
+
if (_XDomainRequest != null) {
|
313
|
+
window.XDomainRequest = function() {
|
314
|
+
var req;
|
315
|
+
req = new _XDomainRequest;
|
316
|
+
monitorXHR(req);
|
317
|
+
return req;
|
318
|
+
};
|
319
|
+
extendNative(window.XDomainRequest, _XDomainRequest);
|
320
|
+
}
|
321
|
+
if ((_WebSocket != null) && options.ajax.trackWebSockets) {
|
322
|
+
window.WebSocket = function(url, protocols) {
|
323
|
+
var req;
|
324
|
+
req = new _WebSocket(url, protocols);
|
325
|
+
_this.trigger('request', {
|
326
|
+
type: 'socket',
|
327
|
+
url: url,
|
328
|
+
protocols: protocols,
|
329
|
+
request: req
|
330
|
+
});
|
331
|
+
return req;
|
332
|
+
};
|
333
|
+
extendNative(window.WebSocket, _WebSocket);
|
334
|
+
}
|
335
|
+
}
|
336
|
+
|
337
|
+
return RequestIntercept;
|
338
|
+
|
339
|
+
})(Events);
|
340
|
+
|
341
|
+
_intercept = null;
|
342
|
+
|
343
|
+
getIntercept = function() {
|
344
|
+
if (_intercept == null) {
|
345
|
+
_intercept = new RequestIntercept;
|
346
|
+
}
|
347
|
+
return _intercept;
|
348
|
+
};
|
349
|
+
|
350
|
+
if (options.restartOnRequestAfter !== false) {
|
351
|
+
getIntercept().on('request', function(_arg) {
|
352
|
+
var args, request, type;
|
353
|
+
type = _arg.type, request = _arg.request;
|
354
|
+
if (!Pace.running) {
|
355
|
+
args = arguments;
|
356
|
+
return setTimeout(function() {
|
357
|
+
var source, stillActive, _i, _len, _ref1, _ref2, _results;
|
358
|
+
if (type === 'socket') {
|
359
|
+
stillActive = request.readyState < 2;
|
360
|
+
} else {
|
361
|
+
stillActive = (0 < (_ref1 = request.readyState) && _ref1 < 4);
|
362
|
+
}
|
363
|
+
if (stillActive) {
|
364
|
+
Pace.restart();
|
365
|
+
_ref2 = Pace.sources;
|
366
|
+
_results = [];
|
367
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
368
|
+
source = _ref2[_i];
|
369
|
+
if (source instanceof AjaxMonitor) {
|
370
|
+
source.watch.apply(source, args);
|
371
|
+
break;
|
372
|
+
} else {
|
373
|
+
_results.push(void 0);
|
374
|
+
}
|
375
|
+
}
|
376
|
+
return _results;
|
377
|
+
}
|
378
|
+
}, options.restartOnRequestAfter);
|
379
|
+
}
|
380
|
+
});
|
381
|
+
}
|
382
|
+
|
383
|
+
AjaxMonitor = (function() {
|
384
|
+
function AjaxMonitor() {
|
385
|
+
var _this = this;
|
386
|
+
this.elements = [];
|
387
|
+
getIntercept().on('request', function() {
|
388
|
+
return _this.watch.apply(_this, arguments);
|
389
|
+
});
|
390
|
+
}
|
391
|
+
|
392
|
+
AjaxMonitor.prototype.watch = function(_arg) {
|
393
|
+
var request, tracker, type;
|
394
|
+
type = _arg.type, request = _arg.request;
|
395
|
+
if (type === 'socket') {
|
396
|
+
tracker = new SocketRequestTracker(request);
|
397
|
+
} else {
|
398
|
+
tracker = new XHRRequestTracker(request);
|
399
|
+
}
|
400
|
+
return this.elements.push(tracker);
|
401
|
+
};
|
402
|
+
|
403
|
+
return AjaxMonitor;
|
404
|
+
|
405
|
+
})();
|
406
|
+
|
407
|
+
XHRRequestTracker = (function() {
|
408
|
+
function XHRRequestTracker(request) {
|
409
|
+
var event, size, _i, _len, _onreadystatechange, _ref1,
|
410
|
+
_this = this;
|
411
|
+
this.progress = 0;
|
412
|
+
if (window.ProgressEvent != null) {
|
413
|
+
size = null;
|
414
|
+
request.addEventListener('progress', function(evt) {
|
415
|
+
if (evt.lengthComputable) {
|
416
|
+
return _this.progress = 100 * evt.loaded / evt.total;
|
417
|
+
} else {
|
418
|
+
return _this.progress = _this.progress + (100 - _this.progress) / 2;
|
419
|
+
}
|
420
|
+
});
|
421
|
+
_ref1 = ['load', 'abort', 'timeout', 'error'];
|
422
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
423
|
+
event = _ref1[_i];
|
424
|
+
request.addEventListener(event, function() {
|
425
|
+
return _this.progress = 100;
|
426
|
+
});
|
427
|
+
}
|
428
|
+
} else {
|
429
|
+
_onreadystatechange = request.onreadystatechange;
|
430
|
+
request.onreadystatechange = function() {
|
431
|
+
var _ref2;
|
432
|
+
if ((_ref2 = request.readyState) === 0 || _ref2 === 4) {
|
433
|
+
_this.progress = 100;
|
434
|
+
} else if (request.readyState === 3) {
|
435
|
+
_this.progress = 50;
|
436
|
+
}
|
437
|
+
return typeof _onreadystatechange === "function" ? _onreadystatechange.apply(null, arguments) : void 0;
|
438
|
+
};
|
439
|
+
}
|
440
|
+
}
|
441
|
+
|
442
|
+
return XHRRequestTracker;
|
443
|
+
|
444
|
+
})();
|
445
|
+
|
446
|
+
SocketRequestTracker = (function() {
|
447
|
+
function SocketRequestTracker(request) {
|
448
|
+
var event, _i, _len, _ref1,
|
449
|
+
_this = this;
|
450
|
+
this.progress = 0;
|
451
|
+
_ref1 = ['error', 'open'];
|
452
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
453
|
+
event = _ref1[_i];
|
454
|
+
request.addEventListener(event, function() {
|
455
|
+
return _this.progress = 100;
|
456
|
+
});
|
457
|
+
}
|
458
|
+
}
|
459
|
+
|
460
|
+
return SocketRequestTracker;
|
461
|
+
|
462
|
+
})();
|
463
|
+
|
464
|
+
ElementMonitor = (function() {
|
465
|
+
function ElementMonitor(options) {
|
466
|
+
var selector, _i, _len, _ref1;
|
467
|
+
if (options == null) {
|
468
|
+
options = {};
|
469
|
+
}
|
470
|
+
this.elements = [];
|
471
|
+
if (options.selectors == null) {
|
472
|
+
options.selectors = [];
|
473
|
+
}
|
474
|
+
_ref1 = options.selectors;
|
475
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
476
|
+
selector = _ref1[_i];
|
477
|
+
this.elements.push(new ElementTracker(selector));
|
478
|
+
}
|
479
|
+
}
|
480
|
+
|
481
|
+
return ElementMonitor;
|
482
|
+
|
483
|
+
})();
|
484
|
+
|
485
|
+
ElementTracker = (function() {
|
486
|
+
function ElementTracker(selector) {
|
487
|
+
this.selector = selector;
|
488
|
+
this.progress = 0;
|
489
|
+
this.check();
|
490
|
+
}
|
491
|
+
|
492
|
+
ElementTracker.prototype.check = function() {
|
493
|
+
var _this = this;
|
494
|
+
if (document.querySelector(this.selector)) {
|
495
|
+
return this.done();
|
496
|
+
} else {
|
497
|
+
return setTimeout((function() {
|
498
|
+
return _this.check();
|
499
|
+
}), options.elements.checkInterval);
|
500
|
+
}
|
501
|
+
};
|
502
|
+
|
503
|
+
ElementTracker.prototype.done = function() {
|
504
|
+
return this.progress = 100;
|
505
|
+
};
|
506
|
+
|
507
|
+
return ElementTracker;
|
508
|
+
|
509
|
+
})();
|
510
|
+
|
511
|
+
DocumentMonitor = (function() {
|
512
|
+
DocumentMonitor.prototype.states = {
|
513
|
+
loading: 0,
|
514
|
+
interactive: 50,
|
515
|
+
complete: 100
|
516
|
+
};
|
517
|
+
|
518
|
+
function DocumentMonitor() {
|
519
|
+
var _onreadystatechange, _ref1,
|
520
|
+
_this = this;
|
521
|
+
this.progress = (_ref1 = this.states[document.readyState]) != null ? _ref1 : 100;
|
522
|
+
_onreadystatechange = document.onreadystatechange;
|
523
|
+
document.onreadystatechange = function() {
|
524
|
+
if (_this.states[document.readyState] != null) {
|
525
|
+
_this.progress = _this.states[document.readyState];
|
526
|
+
}
|
527
|
+
return typeof _onreadystatechange === "function" ? _onreadystatechange.apply(null, arguments) : void 0;
|
528
|
+
};
|
529
|
+
}
|
530
|
+
|
531
|
+
return DocumentMonitor;
|
532
|
+
|
533
|
+
})();
|
534
|
+
|
535
|
+
EventLagMonitor = (function() {
|
536
|
+
function EventLagMonitor() {
|
537
|
+
var avg, interval, last, points, samples,
|
538
|
+
_this = this;
|
539
|
+
this.progress = 0;
|
540
|
+
avg = 0;
|
541
|
+
samples = [];
|
542
|
+
points = 0;
|
543
|
+
last = now();
|
544
|
+
interval = setInterval(function() {
|
545
|
+
var diff;
|
546
|
+
diff = now() - last - 50;
|
547
|
+
last = now();
|
548
|
+
samples.push(diff);
|
549
|
+
if (samples.length > options.eventLag.sampleCount) {
|
550
|
+
samples.shift();
|
551
|
+
}
|
552
|
+
avg = avgAmplitude(samples);
|
553
|
+
if (++points >= options.eventLag.minSamples && avg < options.eventLag.lagThreshold) {
|
554
|
+
_this.progress = 100;
|
555
|
+
return clearInterval(interval);
|
556
|
+
} else {
|
557
|
+
return _this.progress = 100 * (3 / (avg + 3));
|
558
|
+
}
|
559
|
+
}, 50);
|
560
|
+
}
|
561
|
+
|
562
|
+
return EventLagMonitor;
|
563
|
+
|
564
|
+
})();
|
565
|
+
|
566
|
+
Scaler = (function() {
|
567
|
+
function Scaler(source) {
|
568
|
+
this.source = source;
|
569
|
+
this.last = this.sinceLastUpdate = 0;
|
570
|
+
this.rate = options.initialRate;
|
571
|
+
this.catchup = 0;
|
572
|
+
this.progress = this.lastProgress = 0;
|
573
|
+
if (this.source != null) {
|
574
|
+
this.progress = result(this.source, 'progress');
|
575
|
+
}
|
576
|
+
}
|
577
|
+
|
578
|
+
Scaler.prototype.tick = function(frameTime, val) {
|
579
|
+
var scaling;
|
580
|
+
if (val == null) {
|
581
|
+
val = result(this.source, 'progress');
|
582
|
+
}
|
583
|
+
if (val >= 100) {
|
584
|
+
this.done = true;
|
585
|
+
}
|
586
|
+
if (val === this.last) {
|
587
|
+
this.sinceLastUpdate += frameTime;
|
588
|
+
} else {
|
589
|
+
if (this.sinceLastUpdate) {
|
590
|
+
this.rate = (val - this.last) / this.sinceLastUpdate;
|
591
|
+
}
|
592
|
+
this.catchup = (val - this.progress) / options.catchupTime;
|
593
|
+
this.sinceLastUpdate = 0;
|
594
|
+
this.last = val;
|
595
|
+
}
|
596
|
+
if (val > this.progress) {
|
597
|
+
this.progress += this.catchup * frameTime;
|
598
|
+
}
|
599
|
+
scaling = 1 - Math.pow(this.progress / 100, options.easeFactor);
|
600
|
+
this.progress += scaling * this.rate * frameTime;
|
601
|
+
this.progress = Math.min(this.lastProgress + options.maxProgressPerFrame, this.progress);
|
602
|
+
this.progress = Math.max(0, this.progress);
|
603
|
+
this.progress = Math.min(100, this.progress);
|
604
|
+
this.lastProgress = this.progress;
|
605
|
+
return this.progress;
|
606
|
+
};
|
607
|
+
|
608
|
+
return Scaler;
|
609
|
+
|
610
|
+
})();
|
611
|
+
|
612
|
+
sources = null;
|
613
|
+
|
614
|
+
scalers = null;
|
615
|
+
|
616
|
+
bar = null;
|
617
|
+
|
618
|
+
uniScaler = null;
|
619
|
+
|
620
|
+
animation = null;
|
621
|
+
|
622
|
+
cancelAnimation = null;
|
623
|
+
|
624
|
+
Pace.running = false;
|
625
|
+
|
626
|
+
handlePushState = function() {
|
627
|
+
if (options.restartOnPushState) {
|
628
|
+
return Pace.restart();
|
629
|
+
}
|
630
|
+
};
|
631
|
+
|
632
|
+
if (window.history.pushState != null) {
|
633
|
+
_pushState = window.history.pushState;
|
634
|
+
window.history.pushState = function() {
|
635
|
+
handlePushState();
|
636
|
+
return _pushState.apply(window.history, arguments);
|
637
|
+
};
|
638
|
+
}
|
639
|
+
|
640
|
+
if (window.history.replaceState != null) {
|
641
|
+
_replaceState = window.history.replaceState;
|
642
|
+
window.history.replaceState = function() {
|
643
|
+
handlePushState();
|
644
|
+
return _replaceState.apply(window.history, arguments);
|
645
|
+
};
|
646
|
+
}
|
647
|
+
|
648
|
+
SOURCE_KEYS = {
|
649
|
+
ajax: AjaxMonitor,
|
650
|
+
elements: ElementMonitor,
|
651
|
+
document: DocumentMonitor,
|
652
|
+
eventLag: EventLagMonitor
|
653
|
+
};
|
654
|
+
|
655
|
+
(init = function() {
|
656
|
+
var source, type, _i, _j, _len, _len1, _ref1, _ref2, _ref3;
|
657
|
+
Pace.sources = sources = [];
|
658
|
+
_ref1 = ['ajax', 'elements', 'document', 'eventLag'];
|
659
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
660
|
+
type = _ref1[_i];
|
661
|
+
if (options[type] !== false) {
|
662
|
+
sources.push(new SOURCE_KEYS[type](options[type]));
|
663
|
+
}
|
664
|
+
}
|
665
|
+
_ref3 = (_ref2 = options.extraSources) != null ? _ref2 : [];
|
666
|
+
for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
|
667
|
+
source = _ref3[_j];
|
668
|
+
sources.push(new source(options));
|
669
|
+
}
|
670
|
+
Pace.bar = bar = new Bar;
|
671
|
+
scalers = [];
|
672
|
+
return uniScaler = new Scaler;
|
673
|
+
})();
|
674
|
+
|
675
|
+
Pace.stop = function() {
|
676
|
+
Pace.running = false;
|
677
|
+
bar.destroy();
|
678
|
+
cancelAnimation = true;
|
679
|
+
if (animation != null) {
|
680
|
+
if (typeof cancelAnimationFrame === "function") {
|
681
|
+
cancelAnimationFrame(animation);
|
682
|
+
}
|
683
|
+
animation = null;
|
684
|
+
}
|
685
|
+
return init();
|
686
|
+
};
|
687
|
+
|
688
|
+
Pace.restart = function() {
|
689
|
+
Pace.stop();
|
690
|
+
return Pace.start();
|
691
|
+
};
|
692
|
+
|
693
|
+
Pace.go = function() {
|
694
|
+
Pace.running = true;
|
695
|
+
bar.render();
|
696
|
+
cancelAnimation = false;
|
697
|
+
return animation = runAnimation(function(frameTime, enqueueNextFrame) {
|
698
|
+
var avg, count, done, element, elements, i, j, remaining, scaler, scalerList, source, start, sum, _i, _j, _len, _len1, _ref1;
|
699
|
+
remaining = 100 - bar.progress;
|
700
|
+
count = sum = 0;
|
701
|
+
done = true;
|
702
|
+
for (i = _i = 0, _len = sources.length; _i < _len; i = ++_i) {
|
703
|
+
source = sources[i];
|
704
|
+
scalerList = scalers[i] != null ? scalers[i] : scalers[i] = [];
|
705
|
+
elements = (_ref1 = source.elements) != null ? _ref1 : [source];
|
706
|
+
for (j = _j = 0, _len1 = elements.length; _j < _len1; j = ++_j) {
|
707
|
+
element = elements[j];
|
708
|
+
scaler = scalerList[j] != null ? scalerList[j] : scalerList[j] = new Scaler(element);
|
709
|
+
done &= scaler.done;
|
710
|
+
if (scaler.done) {
|
711
|
+
continue;
|
712
|
+
}
|
713
|
+
count++;
|
714
|
+
sum += scaler.tick(frameTime);
|
715
|
+
}
|
716
|
+
}
|
717
|
+
avg = sum / count;
|
718
|
+
bar.update(uniScaler.tick(frameTime, avg));
|
719
|
+
start = now();
|
720
|
+
if (bar.done() || done || cancelAnimation) {
|
721
|
+
bar.update(100);
|
722
|
+
return setTimeout(function() {
|
723
|
+
bar.finish();
|
724
|
+
return Pace.running = false;
|
725
|
+
}, Math.max(options.ghostTime, Math.min(options.minTime, now() - start)));
|
726
|
+
} else {
|
727
|
+
return enqueueNextFrame();
|
728
|
+
}
|
729
|
+
});
|
730
|
+
};
|
731
|
+
|
732
|
+
Pace.start = function(_options) {
|
733
|
+
extend(options, _options);
|
734
|
+
Pace.running = true;
|
735
|
+
try {
|
736
|
+
bar.render();
|
737
|
+
} catch (_error) {
|
738
|
+
NoTargetError = _error;
|
739
|
+
}
|
740
|
+
if (!document.querySelector('.pace')) {
|
741
|
+
return setTimeout(Pace.start, 50);
|
742
|
+
} else {
|
743
|
+
return Pace.go();
|
744
|
+
}
|
745
|
+
};
|
746
|
+
|
747
|
+
if (typeof define === 'function' && define.amd) {
|
748
|
+
define(function() {
|
749
|
+
return Pace;
|
750
|
+
});
|
751
|
+
} else if (typeof exports === 'object') {
|
752
|
+
module.exports = Pace;
|
753
|
+
} else {
|
754
|
+
if (options.startOnPageLoad) {
|
755
|
+
Pace.start();
|
756
|
+
}
|
757
|
+
}
|
758
|
+
|
759
|
+
}).call(this);
|