pace-rails 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c71d9cd721245695de7544d6f08fa9bf9e1b8ac2
4
- data.tar.gz: c1963ed9fa0bbd18b9b27edc67950a8cea5fa88e
3
+ metadata.gz: 2b42c1ddd98c2586259ad7b48057ff5c747971af
4
+ data.tar.gz: b780bec71c9d7c9a21d0d3907d95aa20bd01e419
5
5
  SHA512:
6
- metadata.gz: 8490d8465ebb2193ad36948385d96499335e0aa5ec39830856d5ed70502fcb139da96b658dcfc19663bcdcd8721979ffc8a002b12e65c33950bf72671c8c90e8
7
- data.tar.gz: 2dc31189085cd887c9a4bc3767ebeb3a713db42937b46305b0b805859470627b5e8b78accb2410b3e49b8061824ed7c10882bcf685b1ccfc01263fb720a1ae45
6
+ metadata.gz: 841d2ff0ab9389f02aab91ee66fad478085dd266af59cdfb2d446f47145850576a55ba9a3131fd481fe4f4551bf534a64bdcdfe2be9c13f5d94545c166bf1e42
7
+ data.tar.gz: 2f357a22f095024487bef62e27cb23a494f0f627e53ebf3688ddf56fbdedc3b8906d8213802c9a2d41c883fcd84372d34ffc3d2c72572809feade0b3b0879bee
data/.gitignore CHANGED
@@ -15,3 +15,7 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+
19
+ */.DS_Store
20
+ .DS_Store
21
+ .DS_Store?
data/README.md CHANGED
@@ -5,7 +5,7 @@ Automatic web page progress bar.
5
5
  - [Demo](http://github.hubspot.com/pace/docs/welcome/)
6
6
  - [Documentation](http://github.hubspot.com/pace/)
7
7
 
8
- ## Rails 4+
8
+ ## Rails 3+ | 4+
9
9
 
10
10
  Include pace-rails in Gemfile:
11
11
 
@@ -1,5 +1,5 @@
1
1
  module Pace
2
2
  module Rails
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
data/pace-rails.gemspec CHANGED
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_dependency "railties", "~> 4.0.0"
23
+ #spec.add_dependency "railties", "~> 4.0.0"
24
24
  spec.add_dependency "jquery-rails"
25
25
  end
@@ -0,0 +1,756 @@
1
+ (function() {
2
+ 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,
3
+ __slice = [].slice,
4
+ __hasProp = {}.hasOwnProperty,
5
+ __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; },
6
+ __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; };
7
+
8
+ defaultOptions = {
9
+ catchupTime: 500,
10
+ initialRate: .03,
11
+ minTime: 500,
12
+ ghostTime: 250,
13
+ maxProgressPerFrame: 10,
14
+ easeFactor: 1.25,
15
+ startOnPageLoad: true,
16
+ restartOnPushState: true,
17
+ restartOnRequestAfter: 500,
18
+ target: 'body',
19
+ elements: {
20
+ checkInterval: 100,
21
+ selectors: ['body']
22
+ },
23
+ eventLag: {
24
+ minSamples: 10,
25
+ sampleCount: 3,
26
+ lagThreshold: 3
27
+ },
28
+ ajax: {
29
+ trackMethods: ['GET'],
30
+ trackWebSockets: false
31
+ }
32
+ };
33
+
34
+ now = function() {
35
+ var _ref;
36
+ return (_ref = typeof performance !== "undefined" && performance !== null ? typeof performance.now === "function" ? performance.now() : void 0 : void 0) != null ? _ref : +(new Date);
37
+ };
38
+
39
+ requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
40
+
41
+ cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame;
42
+
43
+ if (requestAnimationFrame == null) {
44
+ requestAnimationFrame = function(fn) {
45
+ return setTimeout(fn, 50);
46
+ };
47
+ cancelAnimationFrame = function(id) {
48
+ return clearTimeout(id);
49
+ };
50
+ }
51
+
52
+ runAnimation = function(fn) {
53
+ var last, tick;
54
+ last = now();
55
+ tick = function() {
56
+ var diff;
57
+ diff = now() - last;
58
+ last = now();
59
+ return fn(diff, function() {
60
+ return requestAnimationFrame(tick);
61
+ });
62
+ };
63
+ return tick();
64
+ };
65
+
66
+ result = function() {
67
+ var args, key, obj;
68
+ obj = arguments[0], key = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
69
+ if (typeof obj[key] === 'function') {
70
+ return obj[key].apply(obj, args);
71
+ } else {
72
+ return obj[key];
73
+ }
74
+ };
75
+
76
+ extend = function() {
77
+ var key, out, source, sources, val, _i, _len;
78
+ out = arguments[0], sources = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
79
+ for (_i = 0, _len = sources.length; _i < _len; _i++) {
80
+ source = sources[_i];
81
+ if (source) {
82
+ for (key in source) {
83
+ if (!__hasProp.call(source, key)) continue;
84
+ val = source[key];
85
+ if ((out[key] != null) && typeof out[key] === 'object' && (val != null) && typeof val === 'object') {
86
+ extend(out[key], val);
87
+ } else {
88
+ out[key] = val;
89
+ }
90
+ }
91
+ }
92
+ }
93
+ return out;
94
+ };
95
+
96
+ avgAmplitude = function(arr) {
97
+ var count, sum, v, _i, _len;
98
+ sum = count = 0;
99
+ for (_i = 0, _len = arr.length; _i < _len; _i++) {
100
+ v = arr[_i];
101
+ sum += Math.abs(v);
102
+ count++;
103
+ }
104
+ return sum / count;
105
+ };
106
+
107
+ getFromDOM = function(key, json) {
108
+ var data, e, el;
109
+ if (key == null) {
110
+ key = 'options';
111
+ }
112
+ if (json == null) {
113
+ json = true;
114
+ }
115
+ el = document.querySelector("[data-pace-" + key + "]");
116
+ if (!el) {
117
+ return;
118
+ }
119
+ data = el.getAttribute("data-pace-" + key);
120
+ if (!json) {
121
+ return data;
122
+ }
123
+ try {
124
+ return JSON.parse(data);
125
+ } catch (_error) {
126
+ e = _error;
127
+ return typeof console !== "undefined" && console !== null ? console.error("Error parsing inline pace options", e) : void 0;
128
+ }
129
+ };
130
+
131
+ if (window.Pace == null) {
132
+ window.Pace = {};
133
+ }
134
+
135
+ options = Pace.options = extend(defaultOptions, window.paceOptions, getFromDOM());
136
+
137
+ NoTargetError = (function(_super) {
138
+ __extends(NoTargetError, _super);
139
+
140
+ function NoTargetError() {
141
+ _ref = NoTargetError.__super__.constructor.apply(this, arguments);
142
+ return _ref;
143
+ }
144
+
145
+ return NoTargetError;
146
+
147
+ })(Error);
148
+
149
+ Bar = (function() {
150
+ function Bar() {
151
+ this.progress = 0;
152
+ }
153
+
154
+ Bar.prototype.getElement = function() {
155
+ var targetElement;
156
+ if (this.el == null) {
157
+ targetElement = document.querySelector(options.target);
158
+ if (!targetElement) {
159
+ throw new NoTargetError;
160
+ }
161
+ this.el = document.createElement('div');
162
+ this.el.className = "pace pace-active";
163
+ document.body.className = document.body.className.replace('pace-done', '');
164
+ document.body.className += ' pace-running';
165
+ this.el.innerHTML = '<div class="pace-progress">\n <div class="pace-progress-inner"></div>\n</div>\n<div class="pace-activity"></div>';
166
+ if (targetElement.firstChild != null) {
167
+ targetElement.insertBefore(this.el, targetElement.firstChild);
168
+ } else {
169
+ targetElement.appendChild(this.el);
170
+ }
171
+ }
172
+ return this.el;
173
+ };
174
+
175
+ Bar.prototype.finish = function() {
176
+ var el;
177
+ el = this.getElement();
178
+ el.className = el.className.replace('pace-active', '');
179
+ el.className += ' pace-inactive';
180
+ document.body.className = document.body.className.replace('pace-running', '');
181
+ return document.body.className += ' pace-done';
182
+ };
183
+
184
+ Bar.prototype.update = function(prog) {
185
+ this.progress = prog;
186
+ return this.render();
187
+ };
188
+
189
+ Bar.prototype.destroy = function() {
190
+ try {
191
+ this.getElement().parentNode.removeChild(this.getElement());
192
+ } catch (_error) {
193
+ NoTargetError = _error;
194
+ }
195
+ return this.el = void 0;
196
+ };
197
+
198
+ Bar.prototype.render = function() {
199
+ var el, progressStr;
200
+ if (document.querySelector(options.target) == null) {
201
+ return false;
202
+ }
203
+ el = this.getElement();
204
+ el.children[0].style.width = "" + this.progress + "%";
205
+ if (!this.lastRenderedProgress || this.lastRenderedProgress | 0 !== this.progress | 0) {
206
+ el.children[0].setAttribute('data-progress-text', "" + (this.progress | 0) + "%");
207
+ if (this.progress >= 100) {
208
+ progressStr = '99';
209
+ } else {
210
+ progressStr = this.progress < 10 ? "0" : "";
211
+ progressStr += this.progress | 0;
212
+ }
213
+ el.children[0].setAttribute('data-progress', "" + progressStr);
214
+ }
215
+ return this.lastRenderedProgress = this.progress;
216
+ };
217
+
218
+ Bar.prototype.done = function() {
219
+ return this.progress >= 100;
220
+ };
221
+
222
+ return Bar;
223
+
224
+ })();
225
+
226
+ Events = (function() {
227
+ function Events() {
228
+ this.bindings = {};
229
+ }
230
+
231
+ Events.prototype.trigger = function(name, val) {
232
+ var binding, _i, _len, _ref1, _results;
233
+ if (this.bindings[name] != null) {
234
+ _ref1 = this.bindings[name];
235
+ _results = [];
236
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
237
+ binding = _ref1[_i];
238
+ _results.push(binding.call(this, val));
239
+ }
240
+ return _results;
241
+ }
242
+ };
243
+
244
+ Events.prototype.on = function(name, fn) {
245
+ var _base;
246
+ if ((_base = this.bindings)[name] == null) {
247
+ _base[name] = [];
248
+ }
249
+ return this.bindings[name].push(fn);
250
+ };
251
+
252
+ return Events;
253
+
254
+ })();
255
+
256
+ _XMLHttpRequest = window.XMLHttpRequest;
257
+
258
+ _XDomainRequest = window.XDomainRequest;
259
+
260
+ _WebSocket = window.WebSocket;
261
+
262
+ extendNative = function(to, from) {
263
+ var e, key, val, _results;
264
+ _results = [];
265
+ for (key in from.prototype) {
266
+ try {
267
+ val = from.prototype[key];
268
+ if ((to[key] == null) && typeof val !== 'function') {
269
+ _results.push(to[key] = val);
270
+ } else {
271
+ _results.push(void 0);
272
+ }
273
+ } catch (_error) {
274
+ e = _error;
275
+ }
276
+ }
277
+ return _results;
278
+ };
279
+
280
+ RequestIntercept = (function(_super) {
281
+ __extends(RequestIntercept, _super);
282
+
283
+ function RequestIntercept() {
284
+ var monitorXHR,
285
+ _this = this;
286
+ RequestIntercept.__super__.constructor.apply(this, arguments);
287
+ monitorXHR = function(req) {
288
+ var _open;
289
+ _open = req.open;
290
+ return req.open = function(type, url, async) {
291
+ var _ref1;
292
+ if (_ref1 = (type != null ? type : 'GET').toUpperCase(), __indexOf.call(options.ajax.trackMethods, _ref1) >= 0) {
293
+ _this.trigger('request', {
294
+ type: type,
295
+ url: url,
296
+ request: req
297
+ });
298
+ }
299
+ return _open.apply(req, arguments);
300
+ };
301
+ };
302
+ window.XMLHttpRequest = function(flags) {
303
+ var req;
304
+ req = new _XMLHttpRequest(flags);
305
+ monitorXHR(req);
306
+ return req;
307
+ };
308
+ extendNative(window.XMLHttpRequest, _XMLHttpRequest);
309
+ if (_XDomainRequest != null) {
310
+ window.XDomainRequest = function() {
311
+ var req;
312
+ req = new _XDomainRequest;
313
+ monitorXHR(req);
314
+ return req;
315
+ };
316
+ extendNative(window.XDomainRequest, _XDomainRequest);
317
+ }
318
+ if ((_WebSocket != null) && options.ajax.trackWebSockets) {
319
+ window.WebSocket = function(url, protocols) {
320
+ var req;
321
+ req = new _WebSocket(url, protocols);
322
+ _this.trigger('request', {
323
+ type: 'socket',
324
+ url: url,
325
+ protocols: protocols,
326
+ request: req
327
+ });
328
+ return req;
329
+ };
330
+ extendNative(window.WebSocket, _WebSocket);
331
+ }
332
+ }
333
+
334
+ return RequestIntercept;
335
+
336
+ })(Events);
337
+
338
+ _intercept = null;
339
+
340
+ getIntercept = function() {
341
+ if (_intercept == null) {
342
+ _intercept = new RequestIntercept;
343
+ }
344
+ return _intercept;
345
+ };
346
+
347
+ if (options.restartOnRequestAfter !== false) {
348
+ getIntercept().on('request', function(_arg) {
349
+ var args, request, type;
350
+ type = _arg.type, request = _arg.request;
351
+ if (!Pace.running) {
352
+ args = arguments;
353
+ return setTimeout(function() {
354
+ var source, stillActive, _i, _len, _ref1, _ref2, _results;
355
+ if (type === 'socket') {
356
+ stillActive = request.readyState < 2;
357
+ } else {
358
+ stillActive = (0 < (_ref1 = request.readyState) && _ref1 < 4);
359
+ }
360
+ if (stillActive) {
361
+ Pace.restart();
362
+ _ref2 = Pace.sources;
363
+ _results = [];
364
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
365
+ source = _ref2[_i];
366
+ if (source instanceof AjaxMonitor) {
367
+ source.watch.apply(source, args);
368
+ break;
369
+ } else {
370
+ _results.push(void 0);
371
+ }
372
+ }
373
+ return _results;
374
+ }
375
+ }, options.restartOnRequestAfter);
376
+ }
377
+ });
378
+ }
379
+
380
+ AjaxMonitor = (function() {
381
+ function AjaxMonitor() {
382
+ var _this = this;
383
+ this.elements = [];
384
+ getIntercept().on('request', function() {
385
+ return _this.watch.apply(_this, arguments);
386
+ });
387
+ }
388
+
389
+ AjaxMonitor.prototype.watch = function(_arg) {
390
+ var request, tracker, type;
391
+ type = _arg.type, request = _arg.request;
392
+ if (type === 'socket') {
393
+ tracker = new SocketRequestTracker(request);
394
+ } else {
395
+ tracker = new XHRRequestTracker(request);
396
+ }
397
+ return this.elements.push(tracker);
398
+ };
399
+
400
+ return AjaxMonitor;
401
+
402
+ })();
403
+
404
+ XHRRequestTracker = (function() {
405
+ function XHRRequestTracker(request) {
406
+ var event, size, _i, _len, _onreadystatechange, _ref1,
407
+ _this = this;
408
+ this.progress = 0;
409
+ if (window.ProgressEvent != null) {
410
+ size = null;
411
+ request.addEventListener('progress', function(evt) {
412
+ if (evt.lengthComputable) {
413
+ return _this.progress = 100 * evt.loaded / evt.total;
414
+ } else {
415
+ return _this.progress = _this.progress + (100 - _this.progress) / 2;
416
+ }
417
+ });
418
+ _ref1 = ['load', 'abort', 'timeout', 'error'];
419
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
420
+ event = _ref1[_i];
421
+ request.addEventListener(event, function() {
422
+ return _this.progress = 100;
423
+ });
424
+ }
425
+ } else {
426
+ _onreadystatechange = request.onreadystatechange;
427
+ request.onreadystatechange = function() {
428
+ var _ref2;
429
+ if ((_ref2 = request.readyState) === 0 || _ref2 === 4) {
430
+ _this.progress = 100;
431
+ } else if (request.readyState === 3) {
432
+ _this.progress = 50;
433
+ }
434
+ return typeof _onreadystatechange === "function" ? _onreadystatechange.apply(null, arguments) : void 0;
435
+ };
436
+ }
437
+ }
438
+
439
+ return XHRRequestTracker;
440
+
441
+ })();
442
+
443
+ SocketRequestTracker = (function() {
444
+ function SocketRequestTracker(request) {
445
+ var event, _i, _len, _ref1,
446
+ _this = this;
447
+ this.progress = 0;
448
+ _ref1 = ['error', 'open'];
449
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
450
+ event = _ref1[_i];
451
+ request.addEventListener(event, function() {
452
+ return _this.progress = 100;
453
+ });
454
+ }
455
+ }
456
+
457
+ return SocketRequestTracker;
458
+
459
+ })();
460
+
461
+ ElementMonitor = (function() {
462
+ function ElementMonitor(options) {
463
+ var selector, _i, _len, _ref1;
464
+ if (options == null) {
465
+ options = {};
466
+ }
467
+ this.elements = [];
468
+ if (options.selectors == null) {
469
+ options.selectors = [];
470
+ }
471
+ _ref1 = options.selectors;
472
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
473
+ selector = _ref1[_i];
474
+ this.elements.push(new ElementTracker(selector));
475
+ }
476
+ }
477
+
478
+ return ElementMonitor;
479
+
480
+ })();
481
+
482
+ ElementTracker = (function() {
483
+ function ElementTracker(selector) {
484
+ this.selector = selector;
485
+ this.progress = 0;
486
+ this.check();
487
+ }
488
+
489
+ ElementTracker.prototype.check = function() {
490
+ var _this = this;
491
+ if (document.querySelector(this.selector)) {
492
+ return this.done();
493
+ } else {
494
+ return setTimeout((function() {
495
+ return _this.check();
496
+ }), options.elements.checkInterval);
497
+ }
498
+ };
499
+
500
+ ElementTracker.prototype.done = function() {
501
+ return this.progress = 100;
502
+ };
503
+
504
+ return ElementTracker;
505
+
506
+ })();
507
+
508
+ DocumentMonitor = (function() {
509
+ DocumentMonitor.prototype.states = {
510
+ loading: 0,
511
+ interactive: 50,
512
+ complete: 100
513
+ };
514
+
515
+ function DocumentMonitor() {
516
+ var _onreadystatechange, _ref1,
517
+ _this = this;
518
+ this.progress = (_ref1 = this.states[document.readyState]) != null ? _ref1 : 100;
519
+ _onreadystatechange = document.onreadystatechange;
520
+ document.onreadystatechange = function() {
521
+ if (_this.states[document.readyState] != null) {
522
+ _this.progress = _this.states[document.readyState];
523
+ }
524
+ return typeof _onreadystatechange === "function" ? _onreadystatechange.apply(null, arguments) : void 0;
525
+ };
526
+ }
527
+
528
+ return DocumentMonitor;
529
+
530
+ })();
531
+
532
+ EventLagMonitor = (function() {
533
+ function EventLagMonitor() {
534
+ var avg, interval, last, points, samples,
535
+ _this = this;
536
+ this.progress = 0;
537
+ avg = 0;
538
+ samples = [];
539
+ points = 0;
540
+ last = now();
541
+ interval = setInterval(function() {
542
+ var diff;
543
+ diff = now() - last - 50;
544
+ last = now();
545
+ samples.push(diff);
546
+ if (samples.length > options.eventLag.sampleCount) {
547
+ samples.shift();
548
+ }
549
+ avg = avgAmplitude(samples);
550
+ if (++points >= options.eventLag.minSamples && avg < options.eventLag.lagThreshold) {
551
+ _this.progress = 100;
552
+ return clearInterval(interval);
553
+ } else {
554
+ return _this.progress = 100 * (3 / (avg + 3));
555
+ }
556
+ }, 50);
557
+ }
558
+
559
+ return EventLagMonitor;
560
+
561
+ })();
562
+
563
+ Scaler = (function() {
564
+ function Scaler(source) {
565
+ this.source = source;
566
+ this.last = this.sinceLastUpdate = 0;
567
+ this.rate = options.initialRate;
568
+ this.catchup = 0;
569
+ this.progress = this.lastProgress = 0;
570
+ if (this.source != null) {
571
+ this.progress = result(this.source, 'progress');
572
+ }
573
+ }
574
+
575
+ Scaler.prototype.tick = function(frameTime, val) {
576
+ var scaling;
577
+ if (val == null) {
578
+ val = result(this.source, 'progress');
579
+ }
580
+ if (val >= 100) {
581
+ this.done = true;
582
+ }
583
+ if (val === this.last) {
584
+ this.sinceLastUpdate += frameTime;
585
+ } else {
586
+ if (this.sinceLastUpdate) {
587
+ this.rate = (val - this.last) / this.sinceLastUpdate;
588
+ }
589
+ this.catchup = (val - this.progress) / options.catchupTime;
590
+ this.sinceLastUpdate = 0;
591
+ this.last = val;
592
+ }
593
+ if (val > this.progress) {
594
+ this.progress += this.catchup * frameTime;
595
+ }
596
+ scaling = 1 - Math.pow(this.progress / 100, options.easeFactor);
597
+ this.progress += scaling * this.rate * frameTime;
598
+ this.progress = Math.min(this.lastProgress + options.maxProgressPerFrame, this.progress);
599
+ this.progress = Math.max(0, this.progress);
600
+ this.progress = Math.min(100, this.progress);
601
+ this.lastProgress = this.progress;
602
+ return this.progress;
603
+ };
604
+
605
+ return Scaler;
606
+
607
+ })();
608
+
609
+ sources = null;
610
+
611
+ scalers = null;
612
+
613
+ bar = null;
614
+
615
+ uniScaler = null;
616
+
617
+ animation = null;
618
+
619
+ cancelAnimation = null;
620
+
621
+ Pace.running = false;
622
+
623
+ handlePushState = function() {
624
+ if (options.restartOnPushState) {
625
+ return Pace.restart();
626
+ }
627
+ };
628
+
629
+ if (window.history.pushState != null) {
630
+ _pushState = window.history.pushState;
631
+ window.history.pushState = function() {
632
+ handlePushState();
633
+ return _pushState.apply(window.history, arguments);
634
+ };
635
+ }
636
+
637
+ if (window.history.replaceState != null) {
638
+ _replaceState = window.history.replaceState;
639
+ window.history.replaceState = function() {
640
+ handlePushState();
641
+ return _replaceState.apply(window.history, arguments);
642
+ };
643
+ }
644
+
645
+ SOURCE_KEYS = {
646
+ ajax: AjaxMonitor,
647
+ elements: ElementMonitor,
648
+ document: DocumentMonitor,
649
+ eventLag: EventLagMonitor
650
+ };
651
+
652
+ (init = function() {
653
+ var source, type, _i, _j, _len, _len1, _ref1, _ref2, _ref3;
654
+ Pace.sources = sources = [];
655
+ _ref1 = ['ajax', 'elements', 'document', 'eventLag'];
656
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
657
+ type = _ref1[_i];
658
+ if (options[type] !== false) {
659
+ sources.push(new SOURCE_KEYS[type](options[type]));
660
+ }
661
+ }
662
+ _ref3 = (_ref2 = options.extraSources) != null ? _ref2 : [];
663
+ for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
664
+ source = _ref3[_j];
665
+ sources.push(new source(options));
666
+ }
667
+ Pace.bar = bar = new Bar;
668
+ scalers = [];
669
+ return uniScaler = new Scaler;
670
+ })();
671
+
672
+ Pace.stop = function() {
673
+ Pace.running = false;
674
+ bar.destroy();
675
+ cancelAnimation = true;
676
+ if (animation != null) {
677
+ if (typeof cancelAnimationFrame === "function") {
678
+ cancelAnimationFrame(animation);
679
+ }
680
+ animation = null;
681
+ }
682
+ return init();
683
+ };
684
+
685
+ Pace.restart = function() {
686
+ Pace.stop();
687
+ return Pace.start();
688
+ };
689
+
690
+ Pace.go = function() {
691
+ Pace.running = true;
692
+ bar.render();
693
+ cancelAnimation = false;
694
+ return animation = runAnimation(function(frameTime, enqueueNextFrame) {
695
+ var avg, count, done, element, elements, i, j, remaining, scaler, scalerList, source, start, sum, _i, _j, _len, _len1, _ref1;
696
+ remaining = 100 - bar.progress;
697
+ count = sum = 0;
698
+ done = true;
699
+ for (i = _i = 0, _len = sources.length; _i < _len; i = ++_i) {
700
+ source = sources[i];
701
+ scalerList = scalers[i] != null ? scalers[i] : scalers[i] = [];
702
+ elements = (_ref1 = source.elements) != null ? _ref1 : [source];
703
+ for (j = _j = 0, _len1 = elements.length; _j < _len1; j = ++_j) {
704
+ element = elements[j];
705
+ scaler = scalerList[j] != null ? scalerList[j] : scalerList[j] = new Scaler(element);
706
+ done &= scaler.done;
707
+ if (scaler.done) {
708
+ continue;
709
+ }
710
+ count++;
711
+ sum += scaler.tick(frameTime);
712
+ }
713
+ }
714
+ avg = sum / count;
715
+ bar.update(uniScaler.tick(frameTime, avg));
716
+ start = now();
717
+ if (bar.done() || done || cancelAnimation) {
718
+ bar.update(100);
719
+ return setTimeout(function() {
720
+ bar.finish();
721
+ return Pace.running = false;
722
+ }, Math.max(options.ghostTime, Math.min(options.minTime, now() - start)));
723
+ } else {
724
+ return enqueueNextFrame();
725
+ }
726
+ });
727
+ };
728
+
729
+ Pace.start = function(_options) {
730
+ extend(options, _options);
731
+ Pace.running = true;
732
+ try {
733
+ bar.render();
734
+ } catch (_error) {
735
+ NoTargetError = _error;
736
+ }
737
+ if (!document.querySelector('.pace')) {
738
+ return setTimeout(Pace.start, 50);
739
+ } else {
740
+ return Pace.go();
741
+ }
742
+ };
743
+
744
+ if (typeof define === 'function' && define.amd) {
745
+ define(function() {
746
+ return Pace;
747
+ });
748
+ } else if (typeof exports === 'object') {
749
+ module.exports = Pace;
750
+ } else {
751
+ if (options.startOnPageLoad) {
752
+ Pace.start();
753
+ }
754
+ }
755
+
756
+ }).call(this);