Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.

Commit aaa908a

Browse files
committed
Merge pull request #1 from djbender/master
updates to latest nprogress.js
2 parents 3d5a101 + 9b9099a commit aaa908a

2 files changed

Lines changed: 61 additions & 7 deletions

File tree

vendor/assets/javascripts/nprogress.js

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
var Settings = NProgress.settings = {
1818
minimum: 0.08,
1919
easing: 'ease',
20+
positionUsing: '',
2021
speed: 200,
2122
trickle: true,
2223
trickleRate: 0.02,
2324
trickleSpeed: 800,
25+
showSpinner: true,
2426
template: '<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner"><div class="spinner-icon"></div></div>'
2527
};
2628

@@ -63,10 +65,11 @@
6365
$progress[0].offsetWidth; /* Repaint */
6466

6567
$progress.queue(function(next) {
66-
$bar.css({
67-
transition: 'all '+speed+'ms '+ease,
68-
transform: 'translate3d('+toBarPerc(n)+'%,0,0)'
69-
});
68+
// Set positionUsing if it hasn't already been set
69+
if (Settings.positionUsing == '') Settings.positionUsing = NProgress.getPositioningCSS();
70+
71+
// Add transition
72+
$bar.css(barPositionCSS(n, speed, ease));
7073

7174
if (n === 1) {
7275
// Fade out
@@ -175,13 +178,15 @@
175178
transform: 'translate3d('+perc+'%,0,0)'
176179
});
177180

181+
if(!Settings.showSpinner) $el.find('.spinner').hide();
182+
178183
$el.appendTo(document.body);
179184

180185
return $el;
181186
};
182187

183188
/**
184-
* (Internal) Removes the element. Opposite of render().
189+
* Removes the element. Opposite of render().
185190
*/
186191

187192
NProgress.remove = function() {
@@ -197,6 +202,31 @@
197202
return ($("#nprogress").length > 0);
198203
};
199204

205+
/**
206+
* Determine which positioning CSS rule to use.
207+
*/
208+
NProgress.getPositioningCSS = function() {
209+
// Sniff on document.body.style
210+
var bodyStyle = document.body.style;
211+
212+
// Sniff prefixes
213+
var vendorPrefix = ('WebkitTransform' in bodyStyle) ? 'Webkit' :
214+
('MozTransform' in bodyStyle) ? 'Moz' :
215+
('msTransform' in bodyStyle) ? 'ms' :
216+
('OTransform' in bodyStyle) ? 'O' : '';
217+
218+
if (vendorPrefix + 'Perspective' in bodyStyle) {
219+
// Modern browsers with 3D support, e.g. Webkit, IE10
220+
return 'translate3d';
221+
} else if (vendorPrefix + 'Transform' in bodyStyle) {
222+
// Browsers without 3D support, e.g. IE9
223+
return 'translate';
224+
} else {
225+
// Browsers without translate() support, e.g. IE7-8
226+
return 'margin';
227+
}
228+
}
229+
200230
/**
201231
* Helpers
202232
*/
@@ -216,5 +246,28 @@
216246
return (-1 + n) * 100;
217247
}
218248

249+
250+
/**
251+
* (Internal) returns the correct CSS for changing the bar's
252+
* position given an n percentage, and speed and ease from Settings
253+
*/
254+
255+
function barPositionCSS(n, speed, ease) {
256+
var barCSS;
257+
258+
if (Settings.positionUsing == 'translate3d') {
259+
barCSS = { transform: 'translate3d('+toBarPerc(n)+'%,0,0)' };
260+
} else if (Settings.positionUsing == 'translate') {
261+
barCSS = { transform: 'translate('+toBarPerc(n)+'%,0)' };
262+
} else {
263+
barCSS = { 'margin-left': toBarPerc(n)+'%' };
264+
}
265+
266+
barCSS.transition = 'all '+speed+'ms '+ease;
267+
268+
return barCSS;
269+
}
270+
219271
return NProgress;
220272
});
273+
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
$(function() {
2-
$(document).on('page:fetch', function() { NProgress.start(); });
3-
$(document).on('page:load', function() { NProgress.done(); });
2+
$(document).on('page:fetch', function() { NProgress.start(); });
3+
$(document).on('page:change', function() { NProgress.done(); });
4+
$(document).on('page:restore', function() { NProgress.remove(); });
45
});

0 commit comments

Comments
 (0)