1/*! NProgress (c) 2013, Rico Sta. Cruz 2 * http://ricostacruz.com/nprogress */ 3 4;(function(factory) { 5 6 if (typeof module === 'function') { 7 module.exports = factory(this.jQuery || require('jquery')); 8 } else if (typeof define === 'function' && define.amd) { 9 define(['jquery'], function($) { 10 return factory($); 11 }); 12 } else { 13 this.NProgress = factory(this.jQuery); 14 } 15 16})(function($) { 17 var NProgress = {}; 18 19 NProgress.version = '0.1.2'; 20 21 var Settings = NProgress.settings = { 22 minimum: 0.08, 23 easing: 'ease', 24 positionUsing: '', 25 speed: 200, 26 trickle: true, 27 trickleRate: 0.02, 28 trickleSpeed: 800, 29 showSpinner: true, 30 template: '<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>' 31 }; 32 33 /** 34 * Updates configuration. 35 * 36 * NProgress.configure({ 37 * minimum: 0.1 38 * }); 39 */ 40 NProgress.configure = function(options) { 41 $.extend(Settings, options); 42 return this; 43 }; 44 45 /** 46 * Last number. 47 */ 48 49 NProgress.status = null; 50 51 /** 52 * Sets the progress bar status, where `n` is a number from `0.0` to `1.0`. 53 * 54 * NProgress.set(0.4); 55 * NProgress.set(1.0); 56 */ 57 58 NProgress.set = function(n) { 59 var started = NProgress.isStarted(); 60 61 n = clamp(n, Settings.minimum, 1); 62 NProgress.status = (n === 1 ? null : n); 63 64 var $progress = NProgress.render(!started), 65 $bar = $progress.find('[role="bar"]'), 66 speed = Settings.speed, 67 ease = Settings.easing; 68 69 $progress[0].offsetWidth; /* Repaint */ 70 71 $progress.queue(function(next) { 72// Set positionUsing if it hasn't already been set 73 if (Settings.positionUsing === '') Settings.positionUsing = NProgress.getPositioningCSS(); 74 75// Add transition 76 $bar.css(barPositionCSS(n, speed, ease)); 77 78 if (n === 1) { 79// Fade out 80 $progress.css({ transition: 'none', opacity: 1 }); 81 $progress[0].offsetWidth; /* Repaint */ 82 83 setTimeout(function() { 84 $progress.css({ transition: 'all '+speed+'ms linear', opacity: 0 }); 85 setTimeout(function() { 86 NProgress.remove(); 87 next(); 88 }, speed); 89 }, speed); 90 } else { 91 setTimeout(next, speed); 92 } 93 }); 94 95 return this; 96 }; 97 98 NProgress.isStarted = function() { 99 return typeof NProgress.status === 'number'; 100 }; 101 102 /** 103 * Shows the progress bar. 104 * This is the same as setting the status to 0%, except that it doesn't go backwards. 105 * 106 * NProgress.start(); 107 * 108 */ 109 NProgress.start = function() { 110 if (!NProgress.status) NProgress.set(0); 111 112 var work = function() { 113 setTimeout(function() { 114 if (!NProgress.status) return; 115 NProgress.trickle(); 116 work(); 117 }, Settings.trickleSpeed); 118 }; 119 120 if (Settings.trickle) work(); 121 122 return this; 123 }; 124 125 /** 126 * Hides the progress bar. 127 * This is the *sort of* the same as setting the status to 100%, with the 128 * difference being `done()` makes some placebo effect of some realistic motion. 129 * 130 * NProgress.done(); 131 * 132 * If `true` is passed, it will show the progress bar even if its hidden. 133 * 134 * NProgress.done(true); 135 */ 136 137 NProgress.done = function(force) { 138 if (!force && !NProgress.status) return this; 139 140 return NProgress.inc(0.3 + 0.5 * Math.random()).set(1); 141 }; 142 143 /** 144 * Increments by a random amount. 145 */ 146 147 NProgress.inc = function(amount) { 148 var n = NProgress.status; 149 150 if (!n) { 151 return NProgress.start(); 152 } else { 153 if (typeof amount !== 'number') { 154 amount = (1 - n) * clamp(Math.random() * n, 0.1, 0.95); 155 } 156 157 n = clamp(n + amount, 0, 0.994); 158 return NProgress.set(n); 159 } 160 }; 161 162 NProgress.trickle = function() { 163 return NProgress.inc(Math.random() * Settings.trickleRate); 164 }; 165 166 /** 167 * Waits for all supplied jQuery promises and 168 * increases the progress as the promises resolve. 169 * 170 * @param $promise jQUery Promise 171 */ 172 (function() { 173 var initial = 0, current = 0; 174 175 NProgress.promise = function($promise) { 176 if (!$promise || $promise.state() == "resolved") { 177 return this; 178 } 179 180 if (current == 0) { 181 NProgress.start(); 182 } 183 184 initial++; 185 current++; 186 187 $promise.always(function() { 188 current--; 189 if (current == 0) { 190 initial = 0; 191 NProgress.done(); 192 } else { 193 NProgress.set((initial - current) / initial); 194 } 195 }); 196 197 return this; 198 }; 199 200 })(); 201 202 /** 203 * (Internal) renders the progress bar markup based on the `template` 204 * setting. 205 */ 206 207 NProgress.render = function(fromStart) { 208 if (NProgress.isRendered()) return $("#nprogress"); 209 $('html').addClass('nprogress-busy'); 210 211 var $el = $("<div id='nprogress'>") 212 .html(Settings.template); 213 214 var perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0); 215 216 $el.find('[role="bar"]').css({ 217 transition: 'all 0 linear', 218 transform: 'translate3d('+perc+'%,0,0)' 219 }); 220 221 if (!Settings.showSpinner) 222 $el.find('[role="spinner"]').remove(); 223 224 $el.appendTo(document.body); 225 226 return $el; 227 }; 228 229 /** 230 * Removes the element. Opposite of render(). 231 */ 232 233 NProgress.remove = function() { 234 $('html').removeClass('nprogress-busy'); 235 $('#nprogress').remove(); 236 }; 237 238 /** 239 * Checks if the progress bar is rendered. 240 */ 241 242 NProgress.isRendered = function() { 243 return ($("#nprogress").length > 0); 244 }; 245 246 /** 247 * Determine which positioning CSS rule to use. 248 */ 249 250 NProgress.getPositioningCSS = function() { 251// Sniff on document.body.style 252 var bodyStyle = document.body.style; 253 254// Sniff prefixes 255 var vendorPrefix = ('WebkitTransform' in bodyStyle) ? 'Webkit' : 256 ('MozTransform' in bodyStyle) ? 'Moz' : 257 ('msTransform' in bodyStyle) ? 'ms' : 258 ('OTransform' in bodyStyle) ? 'O' : ''; 259 260 if (vendorPrefix + 'Perspective' in bodyStyle) { 261// Modern browsers with 3D support, e.g. Webkit, IE10 262 return 'translate3d'; 263 } else if (vendorPrefix + 'Transform' in bodyStyle) { 264// Browsers without 3D support, e.g. IE9 265 return 'translate'; 266 } else { 267 // Browsers without translate() support, e.g. IE7-8 268 return 'margin'; 269 } 270 }; 271 272 /** 273 * Helpers 274 */ 275 276 function clamp(n, min, max) { 277 if (n < min) return min; 278 if (n > max) return max; 279 return n; 280 } 281 282 /** 283 * (Internal) converts a percentage (`0..1`) to a bar translateX 284 * percentage (`-100%..0%`). 285 */ 286 287 function toBarPerc(n) { 288 return (-1 + n) * 100; 289 } 290 291 292 /** 293 * (Internal) returns the correct CSS for changing the bar's 294 * position given an n percentage, and speed and ease from Settings 295 */ 296 297 function barPositionCSS(n, speed, ease) { 298 var barCSS; 299 300 if (Settings.positionUsing === 'translate3d') { 301 barCSS = { transform: 'translate3d('+toBarPerc(n)+'%,0,0)' }; 302 } else if (Settings.positionUsing === 'translate') { 303 barCSS = { transform: 'translate('+toBarPerc(n)+'%,0)' }; 304 } else { 305 barCSS = { 'margin-left': toBarPerc(n)+'%' }; 306 } 307 308 barCSS.transition = 'all '+speed+'ms '+ease; 309 310 return barCSS; 311 } 312 313 return NProgress; 314});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.