|
17 | 17 | var Settings = NProgress.settings = { |
18 | 18 | minimum: 0.08, |
19 | 19 | easing: 'ease', |
| 20 | + positionUsing: '', |
20 | 21 | speed: 200, |
21 | 22 | trickle: true, |
22 | 23 | trickleRate: 0.02, |
23 | 24 | trickleSpeed: 800, |
| 25 | + showSpinner: true, |
24 | 26 | template: '<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner"><div class="spinner-icon"></div></div>' |
25 | 27 | }; |
26 | 28 |
|
|
63 | 65 | $progress[0].offsetWidth; /* Repaint */ |
64 | 66 |
|
65 | 67 | $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)); |
70 | 73 |
|
71 | 74 | if (n === 1) { |
72 | 75 | // Fade out |
|
175 | 178 | transform: 'translate3d('+perc+'%,0,0)' |
176 | 179 | }); |
177 | 180 |
|
| 181 | + if(!Settings.showSpinner) $el.find('.spinner').hide(); |
| 182 | + |
178 | 183 | $el.appendTo(document.body); |
179 | 184 |
|
180 | 185 | return $el; |
181 | 186 | }; |
182 | 187 |
|
183 | 188 | /** |
184 | | - * (Internal) Removes the element. Opposite of render(). |
| 189 | + * Removes the element. Opposite of render(). |
185 | 190 | */ |
186 | 191 |
|
187 | 192 | NProgress.remove = function() { |
|
197 | 202 | return ($("#nprogress").length > 0); |
198 | 203 | }; |
199 | 204 |
|
| 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 | + |
200 | 230 | /** |
201 | 231 | * Helpers |
202 | 232 | */ |
|
216 | 246 | return (-1 + n) * 100; |
217 | 247 | } |
218 | 248 |
|
| 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 | + |
219 | 271 | return NProgress; |
220 | 272 | }); |
| 273 | + |
0 commit comments