pace_rails 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0301d0a18968cf240c42a23cceb004c1e3a090a4
4
- data.tar.gz: 159f46b0d4d956d91e9008343355e0ffde783d3d
3
+ metadata.gz: 25cfa7c3604bb6bc7e1353b2164c976727d3dcdf
4
+ data.tar.gz: f129e824a3284f9ca2bd83fab80c648a70bd8143
5
5
  SHA512:
6
- metadata.gz: df20b3cbf0ad5c149708bb156fc348e4a149b61c5ad06b889e8bd45f7e6143a28293b605e649eb2137495b5f9b1066ff9d06cfad1ed3e353a22194074228d49e
7
- data.tar.gz: 4d884cc937fac35e106b8cd199707d60839bf26ae12ba70fa9a8f0763827622d74e32261fded1106e30cb3bf08748dcfba776e72a78bd9d535ef1cd681f50855
6
+ metadata.gz: 98b3a92e52082a12702719c383894ae773045019751898dfb807df91686b56ebeab2d64f7df9b850fcc089017cd81ce9f4900280c7781250301ce269149271f8
7
+ data.tar.gz: 65a2c379c034a8a23345266a6d044773a1cbe3e24688b662c27d143caf4168a98cdd94393e35776e6b63b3fcfeec6bdc6b3b68e1e987afa7f15806db10e07b35
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # pace_rails
1
+ # pace_rails [![Gem Version](https://badge.fury.io/rb/pace_rails.png)](http://badge.fury.io/rb/pace_rails)
2
2
 
3
3
  This is basically a ruby gem for asset pipeline which include the version 0.4.3 od the awesome [Pace][Pace] library.
4
4
 
@@ -1,5 +1,5 @@
1
1
  (function() {
2
- var AjaxMonitor, Bar, DocumentMonitor, ElementMonitor, ElementTracker, EventLagMonitor, Events, RequestIntercept, SOURCE_KEYS, Scaler, SocketRequestTracker, XHRRequestTracker, animation, bar, cancelAnimation, cancelAnimationFrame, defaultOptions, extend, extendNative, firstLoad, getFromDOM, handlePushState, init, intercept, now, options, requestAnimationFrame, result, runAnimation, scalers, sources, uniScaler, _WebSocket, _XDomainRequest, _XMLHttpRequest, _pushState, _replaceState,
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
3
  __slice = [].slice,
4
4
  __hasProp = {}.hasOwnProperty,
5
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; },
@@ -14,18 +14,20 @@
14
14
  easeFactor: 1.25,
15
15
  startOnPageLoad: true,
16
16
  restartOnPushState: true,
17
- restartOnBackboneRoute: true,
17
+ restartOnRequestAfter: 500,
18
18
  target: 'body',
19
19
  elements: {
20
20
  checkInterval: 100,
21
21
  selectors: ['body']
22
22
  },
23
23
  eventLag: {
24
- minSamples: 10
24
+ minSamples: 10,
25
+ sampleCount: 3,
26
+ lagThreshold: 3
25
27
  },
26
28
  ajax: {
27
29
  trackMethods: ['GET'],
28
- trackWebSockets: true
30
+ trackWebSockets: false
29
31
  }
30
32
  };
31
33
 
@@ -91,6 +93,17 @@
91
93
  return out;
92
94
  };
93
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
+
94
107
  getFromDOM = function(key, json) {
95
108
  var data, e, el;
96
109
  if (key == null) {
@@ -121,6 +134,18 @@
121
134
 
122
135
  options = Pace.options = extend(defaultOptions, window.paceOptions, getFromDOM());
123
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
+
124
149
  Bar = (function() {
125
150
  function Bar() {
126
151
  this.progress = 0;
@@ -129,10 +154,13 @@
129
154
  Bar.prototype.getElement = function() {
130
155
  var targetElement;
131
156
  if (this.el == null) {
157
+ targetElement = document.querySelector(options.target);
158
+ if (!targetElement) {
159
+ throw new NoTargetError;
160
+ }
132
161
  this.el = document.createElement('div');
133
162
  this.el.className = "pace pace-active";
134
163
  this.el.innerHTML = '<div class="pace-progress">\n <div class="pace-progress-inner"></div>\n</div>\n<div class="pace-activity"></div>';
135
- targetElement = document.querySelector(options.target);
136
164
  if (targetElement.firstChild != null) {
137
165
  targetElement.insertBefore(this.el, targetElement.firstChild);
138
166
  } else {
@@ -167,14 +195,14 @@
167
195
  el = this.getElement();
168
196
  el.children[0].style.width = "" + this.progress + "%";
169
197
  if (!this.lastRenderedProgress || this.lastRenderedProgress | 0 !== this.progress | 0) {
170
- el.setAttribute('data-progress-text', "" + (this.progress | 0) + "%");
198
+ el.children[0].setAttribute('data-progress-text', "" + (this.progress | 0) + "%");
171
199
  if (this.progress >= 100) {
172
200
  progressStr = '99';
173
201
  } else {
174
202
  progressStr = this.progress < 10 ? "0" : "";
175
203
  progressStr += this.progress | 0;
176
204
  }
177
- el.setAttribute('data-progress', "" + progressStr);
205
+ el.children[0].setAttribute('data-progress', "" + progressStr);
178
206
  }
179
207
  return this.lastRenderedProgress = this.progress;
180
208
  };
@@ -193,12 +221,12 @@
193
221
  }
194
222
 
195
223
  Events.prototype.trigger = function(name, val) {
196
- var binding, _i, _len, _ref, _results;
224
+ var binding, _i, _len, _ref1, _results;
197
225
  if (this.bindings[name] != null) {
198
- _ref = this.bindings[name];
226
+ _ref1 = this.bindings[name];
199
227
  _results = [];
200
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
201
- binding = _ref[_i];
228
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
229
+ binding = _ref1[_i];
202
230
  _results.push(binding.call(this, val));
203
231
  }
204
232
  return _results;
@@ -252,8 +280,8 @@
252
280
  var _open;
253
281
  _open = req.open;
254
282
  return req.open = function(type, url, async) {
255
- var _ref;
256
- if (_ref = (type != null ? type : 'GET').toUpperCase(), __indexOf.call(options.ajax.trackMethods, _ref) >= 0) {
283
+ var _ref1;
284
+ if (_ref1 = (type != null ? type : 'GET').toUpperCase(), __indexOf.call(options.ajax.trackMethods, _ref1) >= 0) {
257
285
  _this.trigger('request', {
258
286
  type: type,
259
287
  url: url,
@@ -299,13 +327,53 @@
299
327
 
300
328
  })(Events);
301
329
 
302
- intercept = new RequestIntercept;
330
+ _intercept = null;
331
+
332
+ getIntercept = function() {
333
+ if (_intercept == null) {
334
+ _intercept = new RequestIntercept;
335
+ }
336
+ return _intercept;
337
+ };
338
+
339
+ if (options.restartOnRequestAfter !== false) {
340
+ getIntercept().on('request', function(_arg) {
341
+ var args, request, type;
342
+ type = _arg.type, request = _arg.request;
343
+ if (!Pace.running) {
344
+ args = arguments;
345
+ return setTimeout(function() {
346
+ var source, stillActive, _i, _len, _ref1, _ref2, _results;
347
+ if (type === 'socket') {
348
+ stillActive = request.readyState < 2;
349
+ } else {
350
+ stillActive = (0 < (_ref1 = request.readyState) && _ref1 < 4);
351
+ }
352
+ if (stillActive) {
353
+ Pace.restart();
354
+ _ref2 = Pace.sources;
355
+ _results = [];
356
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
357
+ source = _ref2[_i];
358
+ if (source instanceof AjaxMonitor) {
359
+ source.watch.apply(source, args);
360
+ break;
361
+ } else {
362
+ _results.push(void 0);
363
+ }
364
+ }
365
+ return _results;
366
+ }
367
+ }, options.restartOnRequestAfter);
368
+ }
369
+ });
370
+ }
303
371
 
304
372
  AjaxMonitor = (function() {
305
373
  function AjaxMonitor() {
306
374
  var _this = this;
307
375
  this.elements = [];
308
- intercept.on('request', function() {
376
+ getIntercept().on('request', function() {
309
377
  return _this.watch.apply(_this, arguments);
310
378
  });
311
379
  }
@@ -327,7 +395,7 @@
327
395
 
328
396
  XHRRequestTracker = (function() {
329
397
  function XHRRequestTracker(request) {
330
- var event, size, _i, _len, _onreadystatechange, _ref,
398
+ var event, size, _i, _len, _onreadystatechange, _ref1,
331
399
  _this = this;
332
400
  this.progress = 0;
333
401
  if (window.ProgressEvent != null) {
@@ -339,9 +407,9 @@
339
407
  return _this.progress = _this.progress + (100 - _this.progress) / 2;
340
408
  }
341
409
  });
342
- _ref = ['load', 'abort', 'timeout', 'error'];
343
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
344
- event = _ref[_i];
410
+ _ref1 = ['load', 'abort', 'timeout', 'error'];
411
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
412
+ event = _ref1[_i];
345
413
  request.addEventListener(event, function() {
346
414
  return _this.progress = 100;
347
415
  });
@@ -349,8 +417,8 @@
349
417
  } else {
350
418
  _onreadystatechange = request.onreadystatechange;
351
419
  request.onreadystatechange = function() {
352
- var _ref1;
353
- if ((_ref1 = request.readyState) === 0 || _ref1 === 4) {
420
+ var _ref2;
421
+ if ((_ref2 = request.readyState) === 0 || _ref2 === 4) {
354
422
  _this.progress = 100;
355
423
  } else if (request.readyState === 3) {
356
424
  _this.progress = 50;
@@ -366,12 +434,12 @@
366
434
 
367
435
  SocketRequestTracker = (function() {
368
436
  function SocketRequestTracker(request) {
369
- var event, _i, _len, _ref,
437
+ var event, _i, _len, _ref1,
370
438
  _this = this;
371
439
  this.progress = 0;
372
- _ref = ['error', 'open'];
373
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
374
- event = _ref[_i];
440
+ _ref1 = ['error', 'open'];
441
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
442
+ event = _ref1[_i];
375
443
  request.addEventListener(event, function() {
376
444
  return _this.progress = 100;
377
445
  });
@@ -384,7 +452,7 @@
384
452
 
385
453
  ElementMonitor = (function() {
386
454
  function ElementMonitor(options) {
387
- var selector, _i, _len, _ref;
455
+ var selector, _i, _len, _ref1;
388
456
  if (options == null) {
389
457
  options = {};
390
458
  }
@@ -392,9 +460,9 @@
392
460
  if (options.selectors == null) {
393
461
  options.selectors = [];
394
462
  }
395
- _ref = options.selectors;
396
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
397
- selector = _ref[_i];
463
+ _ref1 = options.selectors;
464
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
465
+ selector = _ref1[_i];
398
466
  this.elements.push(new ElementTracker(selector));
399
467
  }
400
468
  }
@@ -437,9 +505,9 @@
437
505
  };
438
506
 
439
507
  function DocumentMonitor() {
440
- var _onreadystatechange, _ref,
508
+ var _onreadystatechange, _ref1,
441
509
  _this = this;
442
- this.progress = (_ref = this.states[document.readyState]) != null ? _ref : 100;
510
+ this.progress = (_ref1 = this.states[document.readyState]) != null ? _ref1 : 100;
443
511
  _onreadystatechange = document.onreadystatechange;
444
512
  document.onreadystatechange = function() {
445
513
  if (_this.states[document.readyState] != null) {
@@ -455,21 +523,28 @@
455
523
 
456
524
  EventLagMonitor = (function() {
457
525
  function EventLagMonitor() {
458
- var avg, last, points,
526
+ var avg, interval, last, points, samples,
459
527
  _this = this;
460
528
  this.progress = 0;
461
529
  avg = 0;
530
+ samples = [];
462
531
  points = 0;
463
532
  last = now();
464
- setInterval(function() {
533
+ interval = setInterval(function() {
465
534
  var diff;
466
535
  diff = now() - last - 50;
467
536
  last = now();
468
- avg = avg + (diff - avg) / 15;
469
- if (points++ > options.eventLag.minSamples && Math.abs(avg) < 3) {
470
- avg = 0;
537
+ samples.push(diff);
538
+ if (samples.length > options.eventLag.sampleCount) {
539
+ samples.shift();
540
+ }
541
+ avg = avgAmplitude(samples);
542
+ if (++points >= options.eventLag.minSamples && avg < options.eventLag.lagThreshold) {
543
+ _this.progress = 100;
544
+ return clearInterval(interval);
545
+ } else {
546
+ return _this.progress = 100 * (3 / (avg + 3));
471
547
  }
472
- return _this.progress = 100 * (3 / (avg + 3));
473
548
  }, 50);
474
549
  }
475
550
 
@@ -535,6 +610,8 @@
535
610
 
536
611
  cancelAnimation = null;
537
612
 
613
+ Pace.running = false;
614
+
538
615
  handlePushState = function() {
539
616
  if (options.restartOnPushState) {
540
617
  return Pace.restart();
@@ -557,40 +634,6 @@
557
634
  };
558
635
  }
559
636
 
560
- firstLoad = true;
561
-
562
- if (options.restartOnBackboneRoute) {
563
- setTimeout(function() {
564
- if (window.Backbone == null) {
565
- return;
566
- }
567
- return Backbone.history.on('route', function(router, name) {
568
- var routeName, rule, _i, _len, _results;
569
- if (!(rule = options.restartOnBackboneRoute)) {
570
- return;
571
- }
572
- if (firstLoad) {
573
- firstLoad = false;
574
- return;
575
- }
576
- if (typeof rule === 'object') {
577
- _results = [];
578
- for (_i = 0, _len = rule.length; _i < _len; _i++) {
579
- routeName = rule[_i];
580
- if (!(routeName === name)) {
581
- continue;
582
- }
583
- Pace.restart();
584
- break;
585
- }
586
- return _results;
587
- } else {
588
- return Pace.restart();
589
- }
590
- });
591
- }, 0);
592
- }
593
-
594
637
  SOURCE_KEYS = {
595
638
  ajax: AjaxMonitor,
596
639
  elements: ElementMonitor,
@@ -599,18 +642,18 @@
599
642
  };
600
643
 
601
644
  (init = function() {
602
- var source, type, _i, _j, _len, _len1, _ref, _ref1, _ref2;
645
+ var source, type, _i, _j, _len, _len1, _ref1, _ref2, _ref3;
603
646
  Pace.sources = sources = [];
604
- _ref = ['ajax', 'elements', 'document', 'eventLag'];
605
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
606
- type = _ref[_i];
647
+ _ref1 = ['ajax', 'elements', 'document', 'eventLag'];
648
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
649
+ type = _ref1[_i];
607
650
  if (options[type] !== false) {
608
651
  sources.push(new SOURCE_KEYS[type](options[type]));
609
652
  }
610
653
  }
611
- _ref2 = (_ref1 = options.extraSources) != null ? _ref1 : [];
612
- for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
613
- source = _ref2[_j];
654
+ _ref3 = (_ref2 = options.extraSources) != null ? _ref2 : [];
655
+ for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
656
+ source = _ref3[_j];
614
657
  sources.push(new source(options));
615
658
  }
616
659
  Pace.bar = bar = new Bar;
@@ -619,6 +662,7 @@
619
662
  })();
620
663
 
621
664
  Pace.stop = function() {
665
+ Pace.running = false;
622
666
  bar.destroy();
623
667
  cancelAnimation = true;
624
668
  if (animation != null) {
@@ -636,17 +680,18 @@
636
680
  };
637
681
 
638
682
  Pace.go = function() {
683
+ Pace.running = true;
639
684
  bar.render();
640
685
  cancelAnimation = false;
641
686
  return animation = runAnimation(function(frameTime, enqueueNextFrame) {
642
- var avg, count, done, element, elements, i, j, remaining, scaler, scalerList, source, start, sum, _i, _j, _len, _len1, _ref;
687
+ var avg, count, done, element, elements, i, j, remaining, scaler, scalerList, source, start, sum, _i, _j, _len, _len1, _ref1;
643
688
  remaining = 100 - bar.progress;
644
689
  count = sum = 0;
645
690
  done = true;
646
691
  for (i = _i = 0, _len = sources.length; _i < _len; i = ++_i) {
647
692
  source = sources[i];
648
693
  scalerList = scalers[i] != null ? scalers[i] : scalers[i] = [];
649
- elements = (_ref = source.elements) != null ? _ref : [source];
694
+ elements = (_ref1 = source.elements) != null ? _ref1 : [source];
650
695
  for (j = _j = 0, _len1 = elements.length; _j < _len1; j = ++_j) {
651
696
  element = elements[j];
652
697
  scaler = scalerList[j] != null ? scalerList[j] : scalerList[j] = new Scaler(element);
@@ -664,7 +709,8 @@
664
709
  if (bar.done() || done || cancelAnimation) {
665
710
  bar.update(100);
666
711
  return setTimeout(function() {
667
- return bar.finish();
712
+ bar.finish();
713
+ return Pace.running = false;
668
714
  }, Math.max(options.ghostTime, Math.min(options.minTime, now() - start)));
669
715
  } else {
670
716
  return enqueueNextFrame();
@@ -674,7 +720,12 @@
674
720
 
675
721
  Pace.start = function(_options) {
676
722
  extend(options, _options);
677
- bar.render();
723
+ Pace.running = true;
724
+ try {
725
+ bar.render();
726
+ } catch (_error) {
727
+ NoTargetError = _error;
728
+ }
678
729
  if (!document.querySelector('.pace')) {
679
730
  return setTimeout(Pace.start, 50);
680
731
  } else {
@@ -7,6 +7,10 @@
7
7
  user-select: none;
8
8
  }
9
9
 
10
+ .pace.pace-inactive .pace-progress {
11
+ display: none;
12
+ }
13
+
10
14
  .pace .pace-progress {
11
15
  position: fixed;
12
16
  z-index: 2000;
@@ -21,7 +25,7 @@
21
25
  position: absolute;
22
26
  top: 0;
23
27
  right: .5rem;
24
- content: attr(data-progress);
28
+ content: attr(data-progress-text);
25
29
  font-family: "Helvetica Neue", sans-serif;
26
30
  font-weight: 100;
27
31
  font-size: 5rem;
@@ -1,3 +1,3 @@
1
1
  module PaceRails
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pace_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - arvind-naidu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-25 00:00:00.000000000 Z
11
+ date: 2013-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,15 +79,15 @@ files:
79
79
  - README.md
80
80
  - Rakefile
81
81
  - app/assets/javascripts/pace/pace.js
82
- - app/assets/stylesheets/pace/barber-shop.css
83
- - app/assets/stylesheets/pace/big-counter.css
84
- - app/assets/stylesheets/pace/bounce.css
85
- - app/assets/stylesheets/pace/corner-indicator.css
86
- - app/assets/stylesheets/pace/fill-left.css
87
- - app/assets/stylesheets/pace/flash.css
88
- - app/assets/stylesheets/pace/flat-top.css
89
- - app/assets/stylesheets/pace/mac-osx.css
90
- - app/assets/stylesheets/pace/minimal.css
82
+ - app/assets/stylesheets/pace/pace-theme-barber-shop.css
83
+ - app/assets/stylesheets/pace/pace-theme-big-counter.css
84
+ - app/assets/stylesheets/pace/pace-theme-bounce.css
85
+ - app/assets/stylesheets/pace/pace-theme-corner-indicator.css
86
+ - app/assets/stylesheets/pace/pace-theme-fill-left.css
87
+ - app/assets/stylesheets/pace/pace-theme-flash.css
88
+ - app/assets/stylesheets/pace/pace-theme-flat-top.css
89
+ - app/assets/stylesheets/pace/pace-theme-mac-osx.css
90
+ - app/assets/stylesheets/pace/pace-theme-minimal.css
91
91
  - lib/pace_rails.rb
92
92
  - lib/pace_rails/version.rb
93
93
  - pace_rails.gemspec
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  requirements: []
113
113
  rubyforge_project:
114
- rubygems_version: 2.1.4
114
+ rubygems_version: 2.0.3
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: Automatic page load progress bar