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