pace-js
Advanced tools
Comparing version 1.0.2 to 1.2.3
1695
pace.js
@@ -0,935 +1,968 @@ | ||
/*! | ||
* pace.js v1.2.3 | ||
* https://github.com/CodeByZach/pace/ | ||
* Licensed MIT © HubSpot, Inc. | ||
*/ | ||
(function() { | ||
var AjaxMonitor, Bar, DocumentMonitor, ElementMonitor, ElementTracker, EventLagMonitor, Evented, Events, NoTargetError, Pace, RequestIntercept, SOURCE_KEYS, Scaler, SocketRequestTracker, XHRRequestTracker, animation, avgAmplitude, bar, cancelAnimation, cancelAnimationFrame, defaultOptions, extend, extendNative, getFromDOM, getIntercept, handlePushState, ignoreStack, init, now, options, requestAnimationFrame, result, runAnimation, scalers, shouldIgnoreURL, shouldTrack, source, sources, uniScaler, _WebSocket, _XDomainRequest, _XMLHttpRequest, _i, _intercept, _len, _pushState, _ref, _ref1, _replaceState, | ||
__slice = [].slice, | ||
__hasProp = {}.hasOwnProperty, | ||
__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; }, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
var AjaxMonitor, Bar, DocumentMonitor, ElementMonitor, ElementTracker, EventLagMonitor, Evented, Events, NoTargetError, Pace, RequestIntercept, SOURCE_KEYS, Scaler, SocketRequestTracker, XHRRequestTracker, addEventListener, animation, avgAmplitude, bar, cancelAnimation, cancelAnimationFrame, defaultOptions, extend, extendNative, getFromDOM, getIntercept, handlePushState, ignoreStack, init, now, options, requestAnimationFrame, result, runAnimation, scalers, shouldIgnoreURL, shouldTrack, source, sources, uniScaler, _WebSocket, _XDomainRequest, _XMLHttpRequest, _i, _intercept, _len, _pushState, _ref, _ref1, _replaceState, | ||
__slice = [].slice, | ||
__hasProp = {}.hasOwnProperty, | ||
__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; }, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
defaultOptions = { | ||
catchupTime: 100, | ||
initialRate: .03, | ||
minTime: 250, | ||
ghostTime: 100, | ||
maxProgressPerFrame: 20, | ||
easeFactor: 1.25, | ||
startOnPageLoad: true, | ||
restartOnPushState: true, | ||
restartOnRequestAfter: 500, | ||
target: 'body', | ||
elements: { | ||
checkInterval: 100, | ||
selectors: ['body'] | ||
}, | ||
eventLag: { | ||
minSamples: 10, | ||
sampleCount: 3, | ||
lagThreshold: 3 | ||
}, | ||
ajax: { | ||
trackMethods: ['GET'], | ||
trackWebSockets: true, | ||
ignoreURLs: [] | ||
} | ||
}; | ||
defaultOptions = { | ||
className: '', | ||
catchupTime: 100, | ||
initialRate: .03, | ||
minTime: 250, | ||
ghostTime: 100, | ||
maxProgressPerFrame: 20, | ||
easeFactor: 1.25, | ||
startOnPageLoad: true, | ||
restartOnPushState: true, | ||
restartOnRequestAfter: 500, | ||
target: 'body', | ||
elements: { | ||
checkInterval: 100, | ||
selectors: ['body'] | ||
}, | ||
eventLag: { | ||
minSamples: 10, | ||
sampleCount: 3, | ||
lagThreshold: 3 | ||
}, | ||
ajax: { | ||
trackMethods: ['GET'], | ||
trackWebSockets: true, | ||
ignoreURLs: [] | ||
} | ||
}; | ||
now = function() { | ||
var _ref; | ||
return (_ref = typeof performance !== "undefined" && performance !== null ? typeof performance.now === "function" ? performance.now() : void 0 : void 0) != null ? _ref : +(new Date); | ||
}; | ||
now = function() { | ||
var _ref; | ||
return (_ref = typeof performance !== "undefined" && performance !== null ? typeof performance.now === "function" ? performance.now() : void 0 : void 0) != null ? _ref : +(new Date); | ||
}; | ||
requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; | ||
requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; | ||
cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame; | ||
cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame; | ||
if (requestAnimationFrame == null) { | ||
requestAnimationFrame = function(fn) { | ||
return setTimeout(fn, 50); | ||
}; | ||
cancelAnimationFrame = function(id) { | ||
return clearTimeout(id); | ||
}; | ||
} | ||
addEventListener = function(obj, event, callback) { | ||
return (typeof obj.addEventListener === "function" ? obj.addEventListener(event, callback, false) : void 0) || (obj["on" + event] = callback); | ||
}; | ||
runAnimation = function(fn) { | ||
var last, tick; | ||
last = now(); | ||
tick = function() { | ||
var diff; | ||
diff = now() - last; | ||
if (diff >= 33) { | ||
last = now(); | ||
return fn(diff, function() { | ||
return requestAnimationFrame(tick); | ||
}); | ||
} else { | ||
return setTimeout(tick, 33 - diff); | ||
} | ||
}; | ||
return tick(); | ||
}; | ||
if (requestAnimationFrame == null) { | ||
requestAnimationFrame = function(fn) { | ||
return setTimeout(fn, 50); | ||
}; | ||
cancelAnimationFrame = function(id) { | ||
return clearTimeout(id); | ||
}; | ||
} | ||
result = function() { | ||
var args, key, obj; | ||
obj = arguments[0], key = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : []; | ||
if (typeof obj[key] === 'function') { | ||
return obj[key].apply(obj, args); | ||
} else { | ||
return obj[key]; | ||
} | ||
}; | ||
runAnimation = function(fn) { | ||
var last, tick; | ||
last = now(); | ||
tick = function() { | ||
var diff; | ||
diff = now() - last; | ||
if (diff >= 33) { | ||
last = now(); | ||
return fn(diff, function() { | ||
return requestAnimationFrame(tick); | ||
}); | ||
} else { | ||
return setTimeout(tick, 33 - diff); | ||
} | ||
}; | ||
return tick(); | ||
}; | ||
extend = function() { | ||
var key, out, source, sources, val, _i, _len; | ||
out = arguments[0], sources = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
for (_i = 0, _len = sources.length; _i < _len; _i++) { | ||
source = sources[_i]; | ||
if (source) { | ||
for (key in source) { | ||
if (!__hasProp.call(source, key)) continue; | ||
val = source[key]; | ||
if ((out[key] != null) && typeof out[key] === 'object' && (val != null) && typeof val === 'object') { | ||
extend(out[key], val); | ||
} else { | ||
out[key] = val; | ||
} | ||
} | ||
} | ||
} | ||
return out; | ||
}; | ||
result = function() { | ||
var args, key, obj; | ||
obj = arguments[0], key = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : []; | ||
if (typeof obj[key] === 'function') { | ||
return obj[key].apply(obj, args); | ||
} else { | ||
return obj[key]; | ||
} | ||
}; | ||
avgAmplitude = function(arr) { | ||
var count, sum, v, _i, _len; | ||
sum = count = 0; | ||
for (_i = 0, _len = arr.length; _i < _len; _i++) { | ||
v = arr[_i]; | ||
sum += Math.abs(v); | ||
count++; | ||
} | ||
return sum / count; | ||
}; | ||
extend = function() { | ||
var key, out, source, sources, val, _i, _len; | ||
out = arguments[0], sources = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
for (_i = 0, _len = sources.length; _i < _len; _i++) { | ||
source = sources[_i]; | ||
if (source) { | ||
for (key in source) { | ||
if (!__hasProp.call(source, key)) continue; | ||
val = source[key]; | ||
if ((out[key] != null) && typeof out[key] === 'object' && (val != null) && typeof val === 'object') { | ||
extend(out[key], val); | ||
} else { | ||
out[key] = val; | ||
} | ||
} | ||
} | ||
} | ||
return out; | ||
}; | ||
getFromDOM = function(key, json) { | ||
var data, e, el; | ||
if (key == null) { | ||
key = 'options'; | ||
} | ||
if (json == null) { | ||
json = true; | ||
} | ||
el = document.querySelector("[data-pace-" + key + "]"); | ||
if (!el) { | ||
return; | ||
} | ||
data = el.getAttribute("data-pace-" + key); | ||
if (!json) { | ||
return data; | ||
} | ||
try { | ||
return JSON.parse(data); | ||
} catch (_error) { | ||
e = _error; | ||
return typeof console !== "undefined" && console !== null ? console.error("Error parsing inline pace options", e) : void 0; | ||
} | ||
}; | ||
avgAmplitude = function(arr) { | ||
var count, sum, v, _i, _len; | ||
sum = count = 0; | ||
for (_i = 0, _len = arr.length; _i < _len; _i++) { | ||
v = arr[_i]; | ||
sum += Math.abs(v); | ||
count++; | ||
} | ||
return sum / count; | ||
}; | ||
Evented = (function() { | ||
function Evented() {} | ||
getFromDOM = function(key, json) { | ||
var data, e, el; | ||
if (key == null) { | ||
key = 'options'; | ||
} | ||
if (json == null) { | ||
json = true; | ||
} | ||
el = document.querySelector("[data-pace-" + key + "]"); | ||
if (!el) { | ||
return; | ||
} | ||
data = el.getAttribute("data-pace-" + key); | ||
if (!json) { | ||
return data; | ||
} | ||
try { | ||
return JSON.parse(data); | ||
} catch (_error) { | ||
e = _error; | ||
return typeof console !== "undefined" && console !== null ? console.error("Error parsing inline pace options", e) : void 0; | ||
} | ||
}; | ||
Evented.prototype.on = function(event, handler, ctx, once) { | ||
var _base; | ||
if (once == null) { | ||
once = false; | ||
} | ||
if (this.bindings == null) { | ||
this.bindings = {}; | ||
} | ||
if ((_base = this.bindings)[event] == null) { | ||
_base[event] = []; | ||
} | ||
return this.bindings[event].push({ | ||
handler: handler, | ||
ctx: ctx, | ||
once: once | ||
}); | ||
}; | ||
Evented = (function() { | ||
function Evented() {} | ||
Evented.prototype.once = function(event, handler, ctx) { | ||
return this.on(event, handler, ctx, true); | ||
}; | ||
Evented.prototype.on = function(event, handler, ctx, once) { | ||
var _base; | ||
if (once == null) { | ||
once = false; | ||
} | ||
if (this.bindings == null) { | ||
this.bindings = {}; | ||
} | ||
if ((_base = this.bindings)[event] == null) { | ||
_base[event] = []; | ||
} | ||
return this.bindings[event].push({ | ||
handler: handler, | ||
ctx: ctx, | ||
once: once | ||
}); | ||
}; | ||
Evented.prototype.off = function(event, handler) { | ||
var i, _ref, _results; | ||
if (((_ref = this.bindings) != null ? _ref[event] : void 0) == null) { | ||
return; | ||
} | ||
if (handler == null) { | ||
return delete this.bindings[event]; | ||
} else { | ||
i = 0; | ||
_results = []; | ||
while (i < this.bindings[event].length) { | ||
if (this.bindings[event][i].handler === handler) { | ||
_results.push(this.bindings[event].splice(i, 1)); | ||
} else { | ||
_results.push(i++); | ||
} | ||
} | ||
return _results; | ||
} | ||
}; | ||
Evented.prototype.once = function(event, handler, ctx) { | ||
return this.on(event, handler, ctx, true); | ||
}; | ||
Evented.prototype.trigger = function() { | ||
var args, ctx, event, handler, i, once, _ref, _ref1, _results; | ||
event = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
if ((_ref = this.bindings) != null ? _ref[event] : void 0) { | ||
i = 0; | ||
_results = []; | ||
while (i < this.bindings[event].length) { | ||
_ref1 = this.bindings[event][i], handler = _ref1.handler, ctx = _ref1.ctx, once = _ref1.once; | ||
handler.apply(ctx != null ? ctx : this, args); | ||
if (once) { | ||
_results.push(this.bindings[event].splice(i, 1)); | ||
} else { | ||
_results.push(i++); | ||
} | ||
} | ||
return _results; | ||
} | ||
}; | ||
Evented.prototype.off = function(event, handler) { | ||
var i, _ref, _results; | ||
if (((_ref = this.bindings) != null ? _ref[event] : void 0) == null) { | ||
return; | ||
} | ||
if (handler == null) { | ||
return delete this.bindings[event]; | ||
} else { | ||
i = 0; | ||
_results = []; | ||
while (i < this.bindings[event].length) { | ||
if (this.bindings[event][i].handler === handler) { | ||
_results.push(this.bindings[event].splice(i, 1)); | ||
} else { | ||
_results.push(i++); | ||
} | ||
} | ||
return _results; | ||
} | ||
}; | ||
return Evented; | ||
Evented.prototype.trigger = function() { | ||
var args, ctx, event, handler, i, once, _ref, _ref1, _results; | ||
event = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
if ((_ref = this.bindings) != null ? _ref[event] : void 0) { | ||
i = 0; | ||
_results = []; | ||
while (i < this.bindings[event].length) { | ||
_ref1 = this.bindings[event][i], handler = _ref1.handler, ctx = _ref1.ctx, once = _ref1.once; | ||
handler.apply(ctx != null ? ctx : this, args); | ||
if (once) { | ||
_results.push(this.bindings[event].splice(i, 1)); | ||
} else { | ||
_results.push(i++); | ||
} | ||
} | ||
return _results; | ||
} | ||
}; | ||
})(); | ||
return Evented; | ||
Pace = window.Pace || {}; | ||
})(); | ||
window.Pace = Pace; | ||
Pace = window.Pace || {}; | ||
extend(Pace, Evented.prototype); | ||
window.Pace = Pace; | ||
options = Pace.options = extend({}, defaultOptions, window.paceOptions, getFromDOM()); | ||
extend(Pace, Evented.prototype); | ||
_ref = ['ajax', 'document', 'eventLag', 'elements']; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
source = _ref[_i]; | ||
if (options[source] === true) { | ||
options[source] = defaultOptions[source]; | ||
} | ||
} | ||
options = Pace.options = extend({}, defaultOptions, window.paceOptions, getFromDOM()); | ||
NoTargetError = (function(_super) { | ||
__extends(NoTargetError, _super); | ||
_ref = ['ajax', 'document', 'eventLag', 'elements']; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
source = _ref[_i]; | ||
if (options[source] === true) { | ||
options[source] = defaultOptions[source]; | ||
} | ||
} | ||
function NoTargetError() { | ||
_ref1 = NoTargetError.__super__.constructor.apply(this, arguments); | ||
return _ref1; | ||
} | ||
NoTargetError = (function(_super) { | ||
__extends(NoTargetError, _super); | ||
return NoTargetError; | ||
function NoTargetError() { | ||
_ref1 = NoTargetError.__super__.constructor.apply(this, arguments); | ||
return _ref1; | ||
} | ||
})(Error); | ||
return NoTargetError; | ||
Bar = (function() { | ||
function Bar() { | ||
this.progress = 0; | ||
} | ||
})(Error); | ||
Bar.prototype.getElement = function() { | ||
var targetElement; | ||
if (this.el == null) { | ||
targetElement = document.querySelector(options.target); | ||
if (!targetElement) { | ||
throw new NoTargetError; | ||
} | ||
this.el = document.createElement('div'); | ||
this.el.className = "pace pace-active"; | ||
document.body.className = document.body.className.replace(/pace-done/g, ''); | ||
document.body.className += ' pace-running'; | ||
this.el.innerHTML = '<div class="pace-progress">\n <div class="pace-progress-inner"></div>\n</div>\n<div class="pace-activity"></div>'; | ||
if (targetElement.firstChild != null) { | ||
targetElement.insertBefore(this.el, targetElement.firstChild); | ||
} else { | ||
targetElement.appendChild(this.el); | ||
} | ||
} | ||
return this.el; | ||
}; | ||
Bar = (function() { | ||
function Bar() { | ||
this.progress = 0; | ||
} | ||
Bar.prototype.finish = function() { | ||
var el; | ||
el = this.getElement(); | ||
el.className = el.className.replace('pace-active', ''); | ||
el.className += ' pace-inactive'; | ||
document.body.className = document.body.className.replace('pace-running', ''); | ||
return document.body.className += ' pace-done'; | ||
}; | ||
Bar.prototype.getElement = function() { | ||
var targetElement; | ||
if (this.el == null) { | ||
targetElement = document.querySelector(options.target); | ||
if (!targetElement) { | ||
throw new NoTargetError; | ||
} | ||
this.el = document.createElement('div'); | ||
this.el.className = "pace pace-active"; | ||
document.body.className = document.body.className.replace(/(pace-done )|/, 'pace-running '); | ||
var _custom_class_name = (options.className !== '') ? ' '+options.className : ''; | ||
this.el.innerHTML = '<div class="pace-progress'+_custom_class_name+'">\n <div class="pace-progress-inner"></div>\n</div>\n<div class="pace-activity"></div>'; | ||
if (targetElement.firstChild != null) { | ||
targetElement.insertBefore(this.el, targetElement.firstChild); | ||
} else { | ||
targetElement.appendChild(this.el); | ||
} | ||
} | ||
return this.el; | ||
}; | ||
Bar.prototype.update = function(prog) { | ||
this.progress = prog; | ||
return this.render(); | ||
}; | ||
Bar.prototype.finish = function() { | ||
var el; | ||
el = this.getElement(); | ||
el.className = el.className.replace('pace-active', 'pace-inactive'); | ||
return document.body.className = document.body.className.replace('pace-running ', 'pace-done '); | ||
}; | ||
Bar.prototype.destroy = function() { | ||
try { | ||
this.getElement().parentNode.removeChild(this.getElement()); | ||
} catch (_error) { | ||
NoTargetError = _error; | ||
} | ||
return this.el = void 0; | ||
}; | ||
Bar.prototype.update = function(prog) { | ||
this.progress = prog; | ||
Pace.trigger('progress', prog); | ||
return this.render(); | ||
}; | ||
Bar.prototype.render = function() { | ||
var el, key, progressStr, transform, _j, _len1, _ref2; | ||
if (document.querySelector(options.target) == null) { | ||
return false; | ||
} | ||
el = this.getElement(); | ||
transform = "translate3d(" + this.progress + "%, 0, 0)"; | ||
_ref2 = ['webkitTransform', 'msTransform', 'transform']; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
key = _ref2[_j]; | ||
el.children[0].style[key] = transform; | ||
} | ||
if (!this.lastRenderedProgress || this.lastRenderedProgress | 0 !== this.progress | 0) { | ||
el.children[0].setAttribute('data-progress-text', "" + (this.progress | 0) + "%"); | ||
if (this.progress >= 100) { | ||
progressStr = '99'; | ||
} else { | ||
progressStr = this.progress < 10 ? "0" : ""; | ||
progressStr += this.progress | 0; | ||
} | ||
el.children[0].setAttribute('data-progress', "" + progressStr); | ||
} | ||
return this.lastRenderedProgress = this.progress; | ||
}; | ||
Bar.prototype.destroy = function() { | ||
try { | ||
this.getElement().parentNode.removeChild(this.getElement()); | ||
} catch (_error) { | ||
NoTargetError = _error; | ||
} | ||
return this.el = void 0; | ||
}; | ||
Bar.prototype.done = function() { | ||
return this.progress >= 100; | ||
}; | ||
Bar.prototype.render = function() { | ||
var el, key, progressStr, transform, _j, _len1, _ref2; | ||
if (document.querySelector(options.target) == null) { | ||
return false; | ||
} | ||
el = this.getElement(); | ||
transform = "translate3d(" + this.progress + "%, 0, 0)"; | ||
_ref2 = ['webkitTransform', 'msTransform', 'transform']; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
key = _ref2[_j]; | ||
el.children[0].style[key] = transform; | ||
} | ||
if (!this.lastRenderedProgress || this.lastRenderedProgress | 0 !== this.progress | 0) { | ||
el.children[0].setAttribute('data-progress-text', "" + (this.progress | 0) + "%"); | ||
if (this.progress >= 100) { | ||
progressStr = '99'; | ||
} else { | ||
progressStr = this.progress < 10 ? "0" : ""; | ||
progressStr += this.progress | 0; | ||
} | ||
el.children[0].setAttribute('data-progress', "" + progressStr); | ||
} | ||
Pace.trigger('change', this.progress); | ||
return this.lastRenderedProgress = this.progress; | ||
}; | ||
return Bar; | ||
Bar.prototype.done = function() { | ||
return this.progress >= 100; | ||
}; | ||
})(); | ||
return Bar; | ||
Events = (function() { | ||
function Events() { | ||
this.bindings = {}; | ||
} | ||
})(); | ||
Events.prototype.trigger = function(name, val) { | ||
var binding, _j, _len1, _ref2, _results; | ||
if (this.bindings[name] != null) { | ||
_ref2 = this.bindings[name]; | ||
_results = []; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
binding = _ref2[_j]; | ||
_results.push(binding.call(this, val)); | ||
} | ||
return _results; | ||
} | ||
}; | ||
Events = (function() { | ||
function Events() { | ||
this.bindings = {}; | ||
} | ||
Events.prototype.on = function(name, fn) { | ||
var _base; | ||
if ((_base = this.bindings)[name] == null) { | ||
_base[name] = []; | ||
} | ||
return this.bindings[name].push(fn); | ||
}; | ||
Events.prototype.trigger = function(name, val) { | ||
var binding, _j, _len1, _ref2, _results; | ||
if (this.bindings[name] != null) { | ||
_ref2 = this.bindings[name]; | ||
_results = []; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
binding = _ref2[_j]; | ||
_results.push(binding.call(this, val)); | ||
} | ||
return _results; | ||
} | ||
}; | ||
return Events; | ||
Events.prototype.on = function(name, fn) { | ||
var _base; | ||
if ((_base = this.bindings)[name] == null) { | ||
_base[name] = []; | ||
} | ||
return this.bindings[name].push(fn); | ||
}; | ||
})(); | ||
return Events; | ||
_XMLHttpRequest = window.XMLHttpRequest; | ||
})(); | ||
_XDomainRequest = window.XDomainRequest; | ||
_XMLHttpRequest = window.XMLHttpRequest; | ||
_WebSocket = window.WebSocket; | ||
_XDomainRequest = window.XDomainRequest; | ||
extendNative = function(to, from) { | ||
var e, key, _results; | ||
_results = []; | ||
for (key in from.prototype) { | ||
try { | ||
if ((to[key] == null) && typeof from[key] !== 'function') { | ||
if (typeof Object.defineProperty === 'function') { | ||
_results.push(Object.defineProperty(to, key, { | ||
get: function() { | ||
return from.prototype[key]; | ||
}, | ||
configurable: true, | ||
enumerable: true | ||
})); | ||
} else { | ||
_results.push(to[key] = from.prototype[key]); | ||
} | ||
} else { | ||
_results.push(void 0); | ||
} | ||
} catch (_error) { | ||
e = _error; | ||
} | ||
} | ||
return _results; | ||
}; | ||
_WebSocket = window.WebSocket; | ||
ignoreStack = []; | ||
extendNative = function(to, from) { | ||
var e, key, _results; | ||
_results = []; | ||
for (key in from.prototype) { | ||
try { | ||
if ((to[key] == null) && typeof from[key] !== 'function') { | ||
if (typeof Object.defineProperty === 'function') { | ||
_results.push(Object.defineProperty(to, key, { | ||
get: (function(key) { | ||
return function() { | ||
return from.prototype[key]; | ||
}; | ||
})(key), | ||
configurable: true, | ||
enumerable: true | ||
})); | ||
} else { | ||
_results.push(to[key] = from.prototype[key]); | ||
} | ||
} else { | ||
_results.push(void 0); | ||
} | ||
} catch (_error) { | ||
e = _error; | ||
} | ||
} | ||
return _results; | ||
}; | ||
Pace.ignore = function() { | ||
var args, fn, ret; | ||
fn = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
ignoreStack.unshift('ignore'); | ||
ret = fn.apply(null, args); | ||
ignoreStack.shift(); | ||
return ret; | ||
}; | ||
ignoreStack = []; | ||
Pace.track = function() { | ||
var args, fn, ret; | ||
fn = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
ignoreStack.unshift('track'); | ||
ret = fn.apply(null, args); | ||
ignoreStack.shift(); | ||
return ret; | ||
}; | ||
Pace.ignore = function() { | ||
var args, fn, ret; | ||
fn = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
ignoreStack.unshift('ignore'); | ||
ret = fn.apply(null, args); | ||
ignoreStack.shift(); | ||
return ret; | ||
}; | ||
shouldTrack = function(method) { | ||
var _ref2; | ||
if (method == null) { | ||
method = 'GET'; | ||
} | ||
if (ignoreStack[0] === 'track') { | ||
return 'force'; | ||
} | ||
if (!ignoreStack.length && options.ajax) { | ||
if (method === 'socket' && options.ajax.trackWebSockets) { | ||
return true; | ||
} else if (_ref2 = method.toUpperCase(), __indexOf.call(options.ajax.trackMethods, _ref2) >= 0) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
Pace.track = function() { | ||
var args, fn, ret; | ||
fn = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
ignoreStack.unshift('track'); | ||
ret = fn.apply(null, args); | ||
ignoreStack.shift(); | ||
return ret; | ||
}; | ||
RequestIntercept = (function(_super) { | ||
__extends(RequestIntercept, _super); | ||
shouldTrack = function(method) { | ||
var _ref2; | ||
if (method == null) { | ||
method = 'GET'; | ||
} | ||
if (ignoreStack[0] === 'track') { | ||
return 'force'; | ||
} | ||
if (!ignoreStack.length && options.ajax) { | ||
if (method === 'socket' && options.ajax.trackWebSockets) { | ||
return true; | ||
} else if (_ref2 = method.toUpperCase(), __indexOf.call(options.ajax.trackMethods, _ref2) >= 0) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
function RequestIntercept() { | ||
var monitorXHR, | ||
_this = this; | ||
RequestIntercept.__super__.constructor.apply(this, arguments); | ||
monitorXHR = function(req) { | ||
var _open; | ||
_open = req.open; | ||
return req.open = function(type, url, async) { | ||
if (shouldTrack(type)) { | ||
_this.trigger('request', { | ||
type: type, | ||
url: url, | ||
request: req | ||
}); | ||
} | ||
return _open.apply(req, arguments); | ||
}; | ||
}; | ||
window.XMLHttpRequest = function(flags) { | ||
var req; | ||
req = new _XMLHttpRequest(flags); | ||
monitorXHR(req); | ||
return req; | ||
}; | ||
try { | ||
extendNative(window.XMLHttpRequest, _XMLHttpRequest); | ||
} catch (_error) {} | ||
if (_XDomainRequest != null) { | ||
window.XDomainRequest = function() { | ||
var req; | ||
req = new _XDomainRequest; | ||
monitorXHR(req); | ||
return req; | ||
}; | ||
try { | ||
extendNative(window.XDomainRequest, _XDomainRequest); | ||
} catch (_error) {} | ||
} | ||
if ((_WebSocket != null) && options.ajax.trackWebSockets) { | ||
window.WebSocket = function(url, protocols) { | ||
var req; | ||
if (protocols != null) { | ||
req = new _WebSocket(url, protocols); | ||
} else { | ||
req = new _WebSocket(url); | ||
} | ||
if (shouldTrack('socket')) { | ||
_this.trigger('request', { | ||
type: 'socket', | ||
url: url, | ||
protocols: protocols, | ||
request: req | ||
}); | ||
} | ||
return req; | ||
}; | ||
try { | ||
extendNative(window.WebSocket, _WebSocket); | ||
} catch (_error) {} | ||
} | ||
} | ||
RequestIntercept = (function(_super) { | ||
__extends(RequestIntercept, _super); | ||
return RequestIntercept; | ||
function RequestIntercept() { | ||
var monitorXHR, | ||
_this = this; | ||
RequestIntercept.__super__.constructor.apply(this, arguments); | ||
monitorXHR = function(req) { | ||
var _open; | ||
_open = req.open; | ||
return req.open = function(type, url, async) { | ||
if (shouldTrack(type)) { | ||
_this.trigger('request', { | ||
type: type, | ||
url: url, | ||
request: req | ||
}); | ||
} | ||
return _open.apply(req, arguments); | ||
}; | ||
}; | ||
window.XMLHttpRequest = function(flags) { | ||
var req; | ||
req = new _XMLHttpRequest(flags); | ||
monitorXHR(req); | ||
return req; | ||
}; | ||
try { | ||
extendNative(window.XMLHttpRequest, _XMLHttpRequest); | ||
} catch (_error) {} | ||
if (_XDomainRequest != null) { | ||
window.XDomainRequest = function() { | ||
var req; | ||
req = new _XDomainRequest; | ||
monitorXHR(req); | ||
return req; | ||
}; | ||
try { | ||
extendNative(window.XDomainRequest, _XDomainRequest); | ||
} catch (_error) {} | ||
} | ||
if ((_WebSocket != null) && options.ajax.trackWebSockets) { | ||
window.WebSocket = function(url, protocols) { | ||
var req; | ||
if (protocols != null) { | ||
req = new _WebSocket(url, protocols); | ||
} else { | ||
req = new _WebSocket(url); | ||
} | ||
if (shouldTrack('socket')) { | ||
_this.trigger('request', { | ||
type: 'socket', | ||
url: url, | ||
protocols: protocols, | ||
request: req | ||
}); | ||
} | ||
return req; | ||
}; | ||
try { | ||
extendNative(window.WebSocket, _WebSocket); | ||
} catch (_error) {} | ||
} | ||
} | ||
})(Events); | ||
return RequestIntercept; | ||
_intercept = null; | ||
})(Events); | ||
getIntercept = function() { | ||
if (_intercept == null) { | ||
_intercept = new RequestIntercept; | ||
} | ||
return _intercept; | ||
}; | ||
_intercept = null; | ||
shouldIgnoreURL = function(url) { | ||
var pattern, _j, _len1, _ref2; | ||
_ref2 = options.ajax.ignoreURLs; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
pattern = _ref2[_j]; | ||
if (typeof pattern === 'string') { | ||
if (url.indexOf(pattern) !== -1) { | ||
return true; | ||
} | ||
} else { | ||
if (pattern.test(url)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}; | ||
getIntercept = function() { | ||
if (_intercept == null) { | ||
_intercept = new RequestIntercept; | ||
} | ||
return _intercept; | ||
}; | ||
getIntercept().on('request', function(_arg) { | ||
var after, args, request, type, url; | ||
type = _arg.type, request = _arg.request, url = _arg.url; | ||
if (shouldIgnoreURL(url)) { | ||
return; | ||
} | ||
if (!Pace.running && (options.restartOnRequestAfter !== false || shouldTrack(type) === 'force')) { | ||
args = arguments; | ||
after = options.restartOnRequestAfter || 0; | ||
if (typeof after === 'boolean') { | ||
after = 0; | ||
} | ||
return setTimeout(function() { | ||
var stillActive, _j, _len1, _ref2, _ref3, _results; | ||
if (type === 'socket') { | ||
stillActive = request.readyState < 2; | ||
} else { | ||
stillActive = (0 < (_ref2 = request.readyState) && _ref2 < 4); | ||
} | ||
if (stillActive) { | ||
Pace.restart(); | ||
_ref3 = Pace.sources; | ||
_results = []; | ||
for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { | ||
source = _ref3[_j]; | ||
if (source instanceof AjaxMonitor) { | ||
source.watch.apply(source, args); | ||
break; | ||
} else { | ||
_results.push(void 0); | ||
} | ||
} | ||
return _results; | ||
} | ||
}, after); | ||
} | ||
}); | ||
shouldIgnoreURL = function(url) { | ||
var pattern, _j, _len1, _ref2; | ||
_ref2 = options.ajax.ignoreURLs; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
pattern = _ref2[_j]; | ||
if (typeof pattern === 'string') { | ||
if (url.indexOf(pattern) !== -1) { | ||
return true; | ||
} | ||
} else { | ||
if (pattern.test(url)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}; | ||
AjaxMonitor = (function() { | ||
function AjaxMonitor() { | ||
var _this = this; | ||
this.elements = []; | ||
getIntercept().on('request', function() { | ||
return _this.watch.apply(_this, arguments); | ||
}); | ||
} | ||
getIntercept().on('request', function(_arg) { | ||
var after, args, request, type, url; | ||
type = _arg.type, request = _arg.request, url = _arg.url; | ||
if (shouldIgnoreURL(url)) { | ||
return; | ||
} | ||
if (!Pace.running && (options.restartOnRequestAfter !== false || shouldTrack(type) === 'force')) { | ||
args = arguments; | ||
after = options.restartOnRequestAfter || 0; | ||
if (typeof after === 'boolean') { | ||
after = 0; | ||
} | ||
return setTimeout(function() { | ||
var stillActive, _j, _len1, _ref2, _ref3, _results; | ||
if (type === 'socket') { | ||
stillActive = request.readyState < 1; | ||
} else { | ||
stillActive = (0 < (_ref2 = request.readyState) && _ref2 < 4); | ||
} | ||
if (stillActive) { | ||
Pace.restart(); | ||
_ref3 = Pace.sources; | ||
_results = []; | ||
for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { | ||
source = _ref3[_j]; | ||
if (source instanceof AjaxMonitor) { | ||
source.watch.apply(source, args); | ||
break; | ||
} else { | ||
_results.push(void 0); | ||
} | ||
} | ||
return _results; | ||
} | ||
}, after); | ||
} | ||
}); | ||
AjaxMonitor.prototype.watch = function(_arg) { | ||
var request, tracker, type, url; | ||
type = _arg.type, request = _arg.request, url = _arg.url; | ||
if (shouldIgnoreURL(url)) { | ||
return; | ||
} | ||
if (type === 'socket') { | ||
tracker = new SocketRequestTracker(request); | ||
} else { | ||
tracker = new XHRRequestTracker(request); | ||
} | ||
return this.elements.push(tracker); | ||
}; | ||
AjaxMonitor = (function() { | ||
function AjaxMonitor() { | ||
this.complete = __bind(this.complete, this); | ||
var _this = this; | ||
this.elements = []; | ||
getIntercept().on('request', function() { | ||
return _this.watch.apply(_this, arguments); | ||
}); | ||
} | ||
return AjaxMonitor; | ||
AjaxMonitor.prototype.watch = function(_arg) { | ||
var request, tracker, type, url; | ||
type = _arg.type, request = _arg.request, url = _arg.url; | ||
if (shouldIgnoreURL(url)) { | ||
return; | ||
} | ||
if (type === 'socket') { | ||
tracker = new SocketRequestTracker(request, this.complete); | ||
} else { | ||
tracker = new XHRRequestTracker(request, this.complete); | ||
} | ||
return this.elements.push(tracker); | ||
}; | ||
})(); | ||
AjaxMonitor.prototype.complete = function(tracker) { | ||
return this.elements = this.elements.filter(function(e) { | ||
return e !== tracker; | ||
}); | ||
}; | ||
XHRRequestTracker = (function() { | ||
function XHRRequestTracker(request) { | ||
var event, size, _j, _len1, _onreadystatechange, _ref2, | ||
_this = this; | ||
this.progress = 0; | ||
if (window.ProgressEvent != null) { | ||
size = null; | ||
request.addEventListener('progress', function(evt) { | ||
if (evt.lengthComputable) { | ||
return _this.progress = 100 * evt.loaded / evt.total; | ||
} else { | ||
return _this.progress = _this.progress + (100 - _this.progress) / 2; | ||
} | ||
}, false); | ||
_ref2 = ['load', 'abort', 'timeout', 'error']; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
event = _ref2[_j]; | ||
request.addEventListener(event, function() { | ||
return _this.progress = 100; | ||
}, false); | ||
} | ||
} else { | ||
_onreadystatechange = request.onreadystatechange; | ||
request.onreadystatechange = function() { | ||
var _ref3; | ||
if ((_ref3 = request.readyState) === 0 || _ref3 === 4) { | ||
_this.progress = 100; | ||
} else if (request.readyState === 3) { | ||
_this.progress = 50; | ||
} | ||
return typeof _onreadystatechange === "function" ? _onreadystatechange.apply(null, arguments) : void 0; | ||
}; | ||
} | ||
} | ||
return AjaxMonitor; | ||
return XHRRequestTracker; | ||
})(); | ||
})(); | ||
XHRRequestTracker = (function() { | ||
function XHRRequestTracker(request, completeCallback) { | ||
var event, size, _j, _len1, _onreadystatechange, _ref2, | ||
_this = this; | ||
this.progress = 0; | ||
if (window.ProgressEvent != null) { | ||
size = null; | ||
addEventListener(request, 'progress', function(evt) { | ||
if (evt.lengthComputable) { | ||
return _this.progress = 100 * evt.loaded / evt.total; | ||
} else { | ||
return _this.progress = _this.progress + (100 - _this.progress) / 2; | ||
} | ||
}, false); | ||
_ref2 = ['load', 'abort', 'timeout', 'error']; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
event = _ref2[_j]; | ||
addEventListener(request, event, function() { | ||
completeCallback(_this); | ||
return _this.progress = 100; | ||
}, false); | ||
} | ||
} else { | ||
_onreadystatechange = request.onreadystatechange; | ||
request.onreadystatechange = function() { | ||
var _ref3; | ||
if ((_ref3 = request.readyState) === 0 || _ref3 === 4) { | ||
completeCallback(_this); | ||
_this.progress = 100; | ||
} else if (request.readyState === 3) { | ||
_this.progress = 50; | ||
} | ||
return typeof _onreadystatechange === "function" ? _onreadystatechange.apply(null, arguments) : void 0; | ||
}; | ||
} | ||
} | ||
SocketRequestTracker = (function() { | ||
function SocketRequestTracker(request) { | ||
var event, _j, _len1, _ref2, | ||
_this = this; | ||
this.progress = 0; | ||
_ref2 = ['error', 'open']; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
event = _ref2[_j]; | ||
request.addEventListener(event, function() { | ||
return _this.progress = 100; | ||
}, false); | ||
} | ||
} | ||
return XHRRequestTracker; | ||
return SocketRequestTracker; | ||
})(); | ||
})(); | ||
SocketRequestTracker = (function() { | ||
function SocketRequestTracker(request, completeCallback) { | ||
var event, _j, _len1, _ref2, | ||
_this = this; | ||
this.progress = 0; | ||
_ref2 = ['error', 'open']; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
event = _ref2[_j]; | ||
addEventListener(request, event, function() { | ||
completeCallback(_this); | ||
return _this.progress = 100; | ||
}, false); | ||
} | ||
} | ||
ElementMonitor = (function() { | ||
function ElementMonitor(options) { | ||
var selector, _j, _len1, _ref2; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
this.elements = []; | ||
if (options.selectors == null) { | ||
options.selectors = []; | ||
} | ||
_ref2 = options.selectors; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
selector = _ref2[_j]; | ||
this.elements.push(new ElementTracker(selector)); | ||
} | ||
} | ||
return SocketRequestTracker; | ||
return ElementMonitor; | ||
})(); | ||
})(); | ||
ElementMonitor = (function() { | ||
function ElementMonitor(options) { | ||
var selector, _j, _len1, _ref2; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
this.complete = __bind(this.complete, this); | ||
this.elements = []; | ||
if (options.selectors == null) { | ||
options.selectors = []; | ||
} | ||
_ref2 = options.selectors; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
selector = _ref2[_j]; | ||
this.elements.push(new ElementTracker(selector, this.complete)); | ||
} | ||
} | ||
ElementTracker = (function() { | ||
function ElementTracker(selector) { | ||
this.selector = selector; | ||
this.progress = 0; | ||
this.check(); | ||
} | ||
ElementMonitor.prototype.complete = function(tracker) { | ||
return this.elements = this.elements.filter(function(e) { | ||
return e !== tracker; | ||
}); | ||
}; | ||
ElementTracker.prototype.check = function() { | ||
var _this = this; | ||
if (document.querySelector(this.selector)) { | ||
return this.done(); | ||
} else { | ||
return setTimeout((function() { | ||
return _this.check(); | ||
}), options.elements.checkInterval); | ||
} | ||
}; | ||
return ElementMonitor; | ||
ElementTracker.prototype.done = function() { | ||
return this.progress = 100; | ||
}; | ||
})(); | ||
return ElementTracker; | ||
ElementTracker = (function() { | ||
function ElementTracker(selector, completeCallback) { | ||
this.selector = selector; | ||
this.completeCallback = completeCallback; | ||
this.progress = 0; | ||
this.check(); | ||
} | ||
})(); | ||
ElementTracker.prototype.check = function() { | ||
var _this = this; | ||
if (document.querySelector(this.selector)) { | ||
return this.done(); | ||
} else { | ||
return setTimeout((function() { | ||
return _this.check(); | ||
}), options.elements.checkInterval); | ||
} | ||
}; | ||
DocumentMonitor = (function() { | ||
DocumentMonitor.prototype.states = { | ||
loading: 0, | ||
interactive: 50, | ||
complete: 100 | ||
}; | ||
ElementTracker.prototype.done = function() { | ||
this.completeCallback(this); | ||
this.completeCallback = null; | ||
return this.progress = 100; | ||
}; | ||
function DocumentMonitor() { | ||
var _onreadystatechange, _ref2, | ||
_this = this; | ||
this.progress = (_ref2 = this.states[document.readyState]) != null ? _ref2 : 100; | ||
_onreadystatechange = document.onreadystatechange; | ||
document.onreadystatechange = function() { | ||
if (_this.states[document.readyState] != null) { | ||
_this.progress = _this.states[document.readyState]; | ||
} | ||
return typeof _onreadystatechange === "function" ? _onreadystatechange.apply(null, arguments) : void 0; | ||
}; | ||
} | ||
return ElementTracker; | ||
return DocumentMonitor; | ||
})(); | ||
})(); | ||
DocumentMonitor = (function() { | ||
DocumentMonitor.prototype.states = { | ||
loading: 0, | ||
interactive: 50, | ||
complete: 100 | ||
}; | ||
EventLagMonitor = (function() { | ||
function EventLagMonitor() { | ||
var avg, interval, last, points, samples, | ||
_this = this; | ||
this.progress = 0; | ||
avg = 0; | ||
samples = []; | ||
points = 0; | ||
last = now(); | ||
interval = setInterval(function() { | ||
var diff; | ||
diff = now() - last - 50; | ||
last = now(); | ||
samples.push(diff); | ||
if (samples.length > options.eventLag.sampleCount) { | ||
samples.shift(); | ||
} | ||
avg = avgAmplitude(samples); | ||
if (++points >= options.eventLag.minSamples && avg < options.eventLag.lagThreshold) { | ||
_this.progress = 100; | ||
return clearInterval(interval); | ||
} else { | ||
return _this.progress = 100 * (3 / (avg + 3)); | ||
} | ||
}, 50); | ||
} | ||
function DocumentMonitor() { | ||
var _onreadystatechange, _ref2, | ||
_this = this; | ||
this.progress = (_ref2 = this.states[document.readyState]) != null ? _ref2 : 100; | ||
_onreadystatechange = document.onreadystatechange; | ||
document.onreadystatechange = function() { | ||
if (_this.states[document.readyState] != null) { | ||
_this.progress = _this.states[document.readyState]; | ||
} | ||
return typeof _onreadystatechange === "function" ? _onreadystatechange.apply(null, arguments) : void 0; | ||
}; | ||
} | ||
return EventLagMonitor; | ||
return DocumentMonitor; | ||
})(); | ||
})(); | ||
Scaler = (function() { | ||
function Scaler(source) { | ||
this.source = source; | ||
this.last = this.sinceLastUpdate = 0; | ||
this.rate = options.initialRate; | ||
this.catchup = 0; | ||
this.progress = this.lastProgress = 0; | ||
if (this.source != null) { | ||
this.progress = result(this.source, 'progress'); | ||
} | ||
} | ||
EventLagMonitor = (function() { | ||
function EventLagMonitor() { | ||
var avg, interval, last, points, samples, | ||
_this = this; | ||
this.progress = 0; | ||
avg = 0; | ||
samples = []; | ||
points = 0; | ||
last = now(); | ||
interval = setInterval(function() { | ||
var diff; | ||
diff = now() - last - 50; | ||
last = now(); | ||
samples.push(diff); | ||
if (samples.length > options.eventLag.sampleCount) { | ||
samples.shift(); | ||
} | ||
avg = avgAmplitude(samples); | ||
if (++points >= options.eventLag.minSamples && avg < options.eventLag.lagThreshold) { | ||
_this.progress = 100; | ||
return clearInterval(interval); | ||
} else { | ||
return _this.progress = 100 * (3 / (avg + 3)); | ||
} | ||
}, 50); | ||
} | ||
Scaler.prototype.tick = function(frameTime, val) { | ||
var scaling; | ||
if (val == null) { | ||
val = result(this.source, 'progress'); | ||
} | ||
if (val >= 100) { | ||
this.done = true; | ||
} | ||
if (val === this.last) { | ||
this.sinceLastUpdate += frameTime; | ||
} else { | ||
if (this.sinceLastUpdate) { | ||
this.rate = (val - this.last) / this.sinceLastUpdate; | ||
} | ||
this.catchup = (val - this.progress) / options.catchupTime; | ||
this.sinceLastUpdate = 0; | ||
this.last = val; | ||
} | ||
if (val > this.progress) { | ||
this.progress += this.catchup * frameTime; | ||
} | ||
scaling = 1 - Math.pow(this.progress / 100, options.easeFactor); | ||
this.progress += scaling * this.rate * frameTime; | ||
this.progress = Math.min(this.lastProgress + options.maxProgressPerFrame, this.progress); | ||
this.progress = Math.max(0, this.progress); | ||
this.progress = Math.min(100, this.progress); | ||
this.lastProgress = this.progress; | ||
return this.progress; | ||
}; | ||
return EventLagMonitor; | ||
return Scaler; | ||
})(); | ||
})(); | ||
Scaler = (function() { | ||
function Scaler(source) { | ||
this.source = source; | ||
this.last = this.sinceLastUpdate = 0; | ||
this.rate = options.initialRate; | ||
this.catchup = 0; | ||
this.progress = this.lastProgress = 0; | ||
if (this.source != null) { | ||
this.progress = result(this.source, 'progress'); | ||
} | ||
} | ||
sources = null; | ||
Scaler.prototype.tick = function(frameTime, val) { | ||
var scaling; | ||
if (val == null) { | ||
val = result(this.source, 'progress'); | ||
} | ||
if (val >= 100) { | ||
this.done = true; | ||
} | ||
if (val === this.last) { | ||
this.sinceLastUpdate += frameTime; | ||
} else { | ||
if (this.sinceLastUpdate) { | ||
this.rate = (val - this.last) / this.sinceLastUpdate; | ||
} | ||
this.catchup = (val - this.progress) / options.catchupTime; | ||
this.sinceLastUpdate = 0; | ||
this.last = val; | ||
} | ||
if (val > this.progress) { | ||
this.progress += this.catchup * frameTime; | ||
} | ||
scaling = 1 - Math.pow(this.progress / 100, options.easeFactor); | ||
this.progress += scaling * this.rate * frameTime; | ||
this.progress = Math.min(this.lastProgress + options.maxProgressPerFrame, this.progress); | ||
this.progress = Math.max(0, this.progress); | ||
this.progress = Math.min(100, this.progress); | ||
this.lastProgress = this.progress; | ||
return this.progress; | ||
}; | ||
scalers = null; | ||
return Scaler; | ||
bar = null; | ||
})(); | ||
uniScaler = null; | ||
sources = null; | ||
animation = null; | ||
scalers = null; | ||
cancelAnimation = null; | ||
bar = null; | ||
Pace.running = false; | ||
uniScaler = null; | ||
handlePushState = function() { | ||
if (options.restartOnPushState) { | ||
return Pace.restart(); | ||
} | ||
}; | ||
animation = null; | ||
if (window.history.pushState != null) { | ||
_pushState = window.history.pushState; | ||
window.history.pushState = function() { | ||
handlePushState(); | ||
return _pushState.apply(window.history, arguments); | ||
}; | ||
} | ||
cancelAnimation = null; | ||
if (window.history.replaceState != null) { | ||
_replaceState = window.history.replaceState; | ||
window.history.replaceState = function() { | ||
handlePushState(); | ||
return _replaceState.apply(window.history, arguments); | ||
}; | ||
} | ||
Pace.running = false; | ||
SOURCE_KEYS = { | ||
ajax: AjaxMonitor, | ||
elements: ElementMonitor, | ||
document: DocumentMonitor, | ||
eventLag: EventLagMonitor | ||
}; | ||
handlePushState = function() { | ||
if (options.restartOnPushState) { | ||
return Pace.restart(); | ||
} | ||
}; | ||
(init = function() { | ||
var type, _j, _k, _len1, _len2, _ref2, _ref3, _ref4; | ||
Pace.sources = sources = []; | ||
_ref2 = ['ajax', 'elements', 'document', 'eventLag']; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
type = _ref2[_j]; | ||
if (options[type] !== false) { | ||
sources.push(new SOURCE_KEYS[type](options[type])); | ||
} | ||
} | ||
_ref4 = (_ref3 = options.extraSources) != null ? _ref3 : []; | ||
for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) { | ||
source = _ref4[_k]; | ||
sources.push(new source(options)); | ||
} | ||
Pace.bar = bar = new Bar; | ||
scalers = []; | ||
return uniScaler = new Scaler; | ||
})(); | ||
if (window.history.pushState != null) { | ||
_pushState = window.history.pushState; | ||
window.history.pushState = function() { | ||
handlePushState(); | ||
return _pushState.apply(window.history, arguments); | ||
}; | ||
} | ||
Pace.stop = function() { | ||
Pace.trigger('stop'); | ||
Pace.running = false; | ||
bar.destroy(); | ||
cancelAnimation = true; | ||
if (animation != null) { | ||
if (typeof cancelAnimationFrame === "function") { | ||
cancelAnimationFrame(animation); | ||
} | ||
animation = null; | ||
} | ||
return init(); | ||
}; | ||
if (window.history.replaceState != null) { | ||
_replaceState = window.history.replaceState; | ||
window.history.replaceState = function() { | ||
handlePushState(); | ||
return _replaceState.apply(window.history, arguments); | ||
}; | ||
} | ||
Pace.restart = function() { | ||
Pace.trigger('restart'); | ||
Pace.stop(); | ||
return Pace.start(); | ||
}; | ||
SOURCE_KEYS = { | ||
ajax: AjaxMonitor, | ||
elements: ElementMonitor, | ||
document: DocumentMonitor, | ||
eventLag: EventLagMonitor | ||
}; | ||
Pace.go = function() { | ||
var start; | ||
Pace.running = true; | ||
bar.render(); | ||
start = now(); | ||
cancelAnimation = false; | ||
return animation = runAnimation(function(frameTime, enqueueNextFrame) { | ||
var avg, count, done, element, elements, i, j, remaining, scaler, scalerList, sum, _j, _k, _len1, _len2, _ref2; | ||
remaining = 100 - bar.progress; | ||
count = sum = 0; | ||
done = true; | ||
for (i = _j = 0, _len1 = sources.length; _j < _len1; i = ++_j) { | ||
source = sources[i]; | ||
scalerList = scalers[i] != null ? scalers[i] : scalers[i] = []; | ||
elements = (_ref2 = source.elements) != null ? _ref2 : [source]; | ||
for (j = _k = 0, _len2 = elements.length; _k < _len2; j = ++_k) { | ||
element = elements[j]; | ||
scaler = scalerList[j] != null ? scalerList[j] : scalerList[j] = new Scaler(element); | ||
done &= scaler.done; | ||
if (scaler.done) { | ||
continue; | ||
} | ||
count++; | ||
sum += scaler.tick(frameTime); | ||
} | ||
} | ||
avg = sum / count; | ||
bar.update(uniScaler.tick(frameTime, avg)); | ||
if (bar.done() || done || cancelAnimation) { | ||
bar.update(100); | ||
Pace.trigger('done'); | ||
return setTimeout(function() { | ||
bar.finish(); | ||
Pace.running = false; | ||
return Pace.trigger('hide'); | ||
}, Math.max(options.ghostTime, Math.max(options.minTime - (now() - start), 0))); | ||
} else { | ||
return enqueueNextFrame(); | ||
} | ||
}); | ||
}; | ||
(init = function() { | ||
var type, _j, _k, _len1, _len2, _ref2, _ref3, _ref4; | ||
Pace.sources = sources = []; | ||
_ref2 = ['ajax', 'elements', 'document', 'eventLag']; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
type = _ref2[_j]; | ||
if (options[type] !== false) { | ||
sources.push(new SOURCE_KEYS[type](options[type])); | ||
} | ||
} | ||
_ref4 = (_ref3 = options.extraSources) != null ? _ref3 : []; | ||
for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) { | ||
source = _ref4[_k]; | ||
sources.push(new source(options)); | ||
} | ||
Pace.bar = bar = new Bar; | ||
scalers = []; | ||
return uniScaler = new Scaler; | ||
})(); | ||
Pace.start = function(_options) { | ||
extend(options, _options); | ||
Pace.running = true; | ||
try { | ||
bar.render(); | ||
} catch (_error) { | ||
NoTargetError = _error; | ||
} | ||
if (!document.querySelector('.pace')) { | ||
return setTimeout(Pace.start, 50); | ||
} else { | ||
Pace.trigger('start'); | ||
return Pace.go(); | ||
} | ||
}; | ||
Pace.stop = function() { | ||
Pace.trigger('stop'); | ||
Pace.running = false; | ||
bar.destroy(); | ||
cancelAnimation = true; | ||
if (animation != null) { | ||
if (typeof cancelAnimationFrame === "function") { | ||
cancelAnimationFrame(animation); | ||
} | ||
animation = null; | ||
} | ||
return init(); | ||
}; | ||
if (typeof define === 'function' && define.amd) { | ||
define(['pace'], function() { | ||
return Pace; | ||
}); | ||
} else if (typeof exports === 'object') { | ||
module.exports = Pace; | ||
} else { | ||
if (options.startOnPageLoad) { | ||
Pace.start(); | ||
} | ||
} | ||
Pace.restart = function() { | ||
Pace.trigger('restart'); | ||
Pace.stop(); | ||
return Pace.start(); | ||
}; | ||
}).call(this); | ||
Pace.go = function() { | ||
var start; | ||
Pace.running = true; | ||
bar.render(); | ||
start = now(); | ||
cancelAnimation = false; | ||
return animation = runAnimation(function(frameTime, enqueueNextFrame) { | ||
var avg, count, done, element, elements, i, j, remaining, scaler, scalerList, sum, _j, _k, _len1, _len2, _ref2; | ||
remaining = 100 - bar.progress; | ||
count = sum = 0; | ||
done = true; | ||
for (i = _j = 0, _len1 = sources.length; _j < _len1; i = ++_j) { | ||
source = sources[i]; | ||
scalerList = scalers[i] != null ? scalers[i] : scalers[i] = []; | ||
elements = (_ref2 = source.elements) != null ? _ref2 : [source]; | ||
for (j = _k = 0, _len2 = elements.length; _k < _len2; j = ++_k) { | ||
element = elements[j]; | ||
scaler = scalerList[j] != null ? scalerList[j] : scalerList[j] = new Scaler(element); | ||
done &= scaler.done; | ||
if (scaler.done) { | ||
continue; | ||
} | ||
count++; | ||
sum += scaler.tick(frameTime); | ||
} | ||
} | ||
avg = sum / count; | ||
bar.update(uniScaler.tick(frameTime, avg)); | ||
if (bar.done() || done || cancelAnimation) { | ||
bar.update(100); | ||
Pace.trigger('done'); | ||
return setTimeout(function() { | ||
bar.finish(); | ||
Pace.running = false; | ||
return Pace.trigger('hide'); | ||
}, Math.max(options.ghostTime, Math.max(options.minTime - (now() - start), 0))); | ||
} else { | ||
return enqueueNextFrame(); | ||
} | ||
}); | ||
}; | ||
Pace.start = function(_options) { | ||
extend(options, _options); | ||
Pace.running = true; | ||
try { | ||
bar.render(); | ||
} catch (_error) { | ||
NoTargetError = _error; | ||
} | ||
if (!document.querySelector('.pace')) { | ||
return setTimeout(Pace.start, 50); | ||
} else { | ||
Pace.trigger('start'); | ||
return Pace.go(); | ||
} | ||
}; | ||
if (typeof define === 'function' && define.amd) { | ||
define(function() { | ||
return Pace; | ||
}); | ||
} else if (typeof exports === 'object') { | ||
module.exports = Pace; | ||
} else { | ||
if (options.startOnPageLoad) { | ||
Pace.start(); | ||
} | ||
} | ||
}).call(this); |
@@ -1,2 +0,6 @@ | ||
/*! pace 1.0.2 */ | ||
(function(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X=[].slice,Y={}.hasOwnProperty,Z=function(a,b){function c(){this.constructor=a}for(var d in b)Y.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},$=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};for(u={catchupTime:100,initialRate:.03,minTime:250,ghostTime:100,maxProgressPerFrame:20,easeFactor:1.25,startOnPageLoad:!0,restartOnPushState:!0,restartOnRequestAfter:500,target:"body",elements:{checkInterval:100,selectors:["body"]},eventLag:{minSamples:10,sampleCount:3,lagThreshold:3},ajax:{trackMethods:["GET"],trackWebSockets:!0,ignoreURLs:[]}},C=function(){var a;return null!=(a="undefined"!=typeof performance&&null!==performance&&"function"==typeof performance.now?performance.now():void 0)?a:+new Date},E=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,t=window.cancelAnimationFrame||window.mozCancelAnimationFrame,null==E&&(E=function(a){return setTimeout(a,50)},t=function(a){return clearTimeout(a)}),G=function(a){var b,c;return b=C(),(c=function(){var d;return d=C()-b,d>=33?(b=C(),a(d,function(){return E(c)})):setTimeout(c,33-d)})()},F=function(){var a,b,c;return c=arguments[0],b=arguments[1],a=3<=arguments.length?X.call(arguments,2):[],"function"==typeof c[b]?c[b].apply(c,a):c[b]},v=function(){var a,b,c,d,e,f,g;for(b=arguments[0],d=2<=arguments.length?X.call(arguments,1):[],f=0,g=d.length;g>f;f++)if(c=d[f])for(a in c)Y.call(c,a)&&(e=c[a],null!=b[a]&&"object"==typeof b[a]&&null!=e&&"object"==typeof e?v(b[a],e):b[a]=e);return b},q=function(a){var b,c,d,e,f;for(c=b=0,e=0,f=a.length;f>e;e++)d=a[e],c+=Math.abs(d),b++;return c/b},x=function(a,b){var c,d,e;if(null==a&&(a="options"),null==b&&(b=!0),e=document.querySelector("[data-pace-"+a+"]")){if(c=e.getAttribute("data-pace-"+a),!b)return c;try{return JSON.parse(c)}catch(f){return d=f,"undefined"!=typeof console&&null!==console?console.error("Error parsing inline pace options",d):void 0}}},g=function(){function a(){}return a.prototype.on=function(a,b,c,d){var e;return null==d&&(d=!1),null==this.bindings&&(this.bindings={}),null==(e=this.bindings)[a]&&(e[a]=[]),this.bindings[a].push({handler:b,ctx:c,once:d})},a.prototype.once=function(a,b,c){return this.on(a,b,c,!0)},a.prototype.off=function(a,b){var c,d,e;if(null!=(null!=(d=this.bindings)?d[a]:void 0)){if(null==b)return delete this.bindings[a];for(c=0,e=[];c<this.bindings[a].length;)this.bindings[a][c].handler===b?e.push(this.bindings[a].splice(c,1)):e.push(c++);return e}},a.prototype.trigger=function(){var a,b,c,d,e,f,g,h,i;if(c=arguments[0],a=2<=arguments.length?X.call(arguments,1):[],null!=(g=this.bindings)?g[c]:void 0){for(e=0,i=[];e<this.bindings[c].length;)h=this.bindings[c][e],d=h.handler,b=h.ctx,f=h.once,d.apply(null!=b?b:this,a),f?i.push(this.bindings[c].splice(e,1)):i.push(e++);return i}},a}(),j=window.Pace||{},window.Pace=j,v(j,g.prototype),D=j.options=v({},u,window.paceOptions,x()),U=["ajax","document","eventLag","elements"],Q=0,S=U.length;S>Q;Q++)K=U[Q],D[K]===!0&&(D[K]=u[K]);i=function(a){function b(){return V=b.__super__.constructor.apply(this,arguments)}return Z(b,a),b}(Error),b=function(){function a(){this.progress=0}return a.prototype.getElement=function(){var a;if(null==this.el){if(a=document.querySelector(D.target),!a)throw new i;this.el=document.createElement("div"),this.el.className="pace pace-active",document.body.className=document.body.className.replace(/pace-done/g,""),document.body.className+=" pace-running",this.el.innerHTML='<div class="pace-progress">\n <div class="pace-progress-inner"></div>\n</div>\n<div class="pace-activity"></div>',null!=a.firstChild?a.insertBefore(this.el,a.firstChild):a.appendChild(this.el)}return this.el},a.prototype.finish=function(){var a;return a=this.getElement(),a.className=a.className.replace("pace-active",""),a.className+=" pace-inactive",document.body.className=document.body.className.replace("pace-running",""),document.body.className+=" pace-done"},a.prototype.update=function(a){return this.progress=a,this.render()},a.prototype.destroy=function(){try{this.getElement().parentNode.removeChild(this.getElement())}catch(a){i=a}return this.el=void 0},a.prototype.render=function(){var a,b,c,d,e,f,g;if(null==document.querySelector(D.target))return!1;for(a=this.getElement(),d="translate3d("+this.progress+"%, 0, 0)",g=["webkitTransform","msTransform","transform"],e=0,f=g.length;f>e;e++)b=g[e],a.children[0].style[b]=d;return(!this.lastRenderedProgress||this.lastRenderedProgress|0!==this.progress|0)&&(a.children[0].setAttribute("data-progress-text",""+(0|this.progress)+"%"),this.progress>=100?c="99":(c=this.progress<10?"0":"",c+=0|this.progress),a.children[0].setAttribute("data-progress",""+c)),this.lastRenderedProgress=this.progress},a.prototype.done=function(){return this.progress>=100},a}(),h=function(){function a(){this.bindings={}}return a.prototype.trigger=function(a,b){var c,d,e,f,g;if(null!=this.bindings[a]){for(f=this.bindings[a],g=[],d=0,e=f.length;e>d;d++)c=f[d],g.push(c.call(this,b));return g}},a.prototype.on=function(a,b){var c;return null==(c=this.bindings)[a]&&(c[a]=[]),this.bindings[a].push(b)},a}(),P=window.XMLHttpRequest,O=window.XDomainRequest,N=window.WebSocket,w=function(a,b){var c,d,e;e=[];for(d in b.prototype)try{null==a[d]&&"function"!=typeof b[d]?"function"==typeof Object.defineProperty?e.push(Object.defineProperty(a,d,{get:function(){return b.prototype[d]},configurable:!0,enumerable:!0})):e.push(a[d]=b.prototype[d]):e.push(void 0)}catch(f){c=f}return e},A=[],j.ignore=function(){var a,b,c;return b=arguments[0],a=2<=arguments.length?X.call(arguments,1):[],A.unshift("ignore"),c=b.apply(null,a),A.shift(),c},j.track=function(){var a,b,c;return b=arguments[0],a=2<=arguments.length?X.call(arguments,1):[],A.unshift("track"),c=b.apply(null,a),A.shift(),c},J=function(a){var b;if(null==a&&(a="GET"),"track"===A[0])return"force";if(!A.length&&D.ajax){if("socket"===a&&D.ajax.trackWebSockets)return!0;if(b=a.toUpperCase(),$.call(D.ajax.trackMethods,b)>=0)return!0}return!1},k=function(a){function b(){var a,c=this;b.__super__.constructor.apply(this,arguments),a=function(a){var b;return b=a.open,a.open=function(d,e,f){return J(d)&&c.trigger("request",{type:d,url:e,request:a}),b.apply(a,arguments)}},window.XMLHttpRequest=function(b){var c;return c=new P(b),a(c),c};try{w(window.XMLHttpRequest,P)}catch(d){}if(null!=O){window.XDomainRequest=function(){var b;return b=new O,a(b),b};try{w(window.XDomainRequest,O)}catch(d){}}if(null!=N&&D.ajax.trackWebSockets){window.WebSocket=function(a,b){var d;return d=null!=b?new N(a,b):new N(a),J("socket")&&c.trigger("request",{type:"socket",url:a,protocols:b,request:d}),d};try{w(window.WebSocket,N)}catch(d){}}}return Z(b,a),b}(h),R=null,y=function(){return null==R&&(R=new k),R},I=function(a){var b,c,d,e;for(e=D.ajax.ignoreURLs,c=0,d=e.length;d>c;c++)if(b=e[c],"string"==typeof b){if(-1!==a.indexOf(b))return!0}else if(b.test(a))return!0;return!1},y().on("request",function(b){var c,d,e,f,g;return f=b.type,e=b.request,g=b.url,I(g)?void 0:j.running||D.restartOnRequestAfter===!1&&"force"!==J(f)?void 0:(d=arguments,c=D.restartOnRequestAfter||0,"boolean"==typeof c&&(c=0),setTimeout(function(){var b,c,g,h,i,k;if(b="socket"===f?e.readyState<2:0<(h=e.readyState)&&4>h){for(j.restart(),i=j.sources,k=[],c=0,g=i.length;g>c;c++){if(K=i[c],K instanceof a){K.watch.apply(K,d);break}k.push(void 0)}return k}},c))}),a=function(){function a(){var a=this;this.elements=[],y().on("request",function(){return a.watch.apply(a,arguments)})}return a.prototype.watch=function(a){var b,c,d,e;return d=a.type,b=a.request,e=a.url,I(e)?void 0:(c="socket"===d?new n(b):new o(b),this.elements.push(c))},a}(),o=function(){function a(a){var b,c,d,e,f,g,h=this;if(this.progress=0,null!=window.ProgressEvent)for(c=null,a.addEventListener("progress",function(a){return a.lengthComputable?h.progress=100*a.loaded/a.total:h.progress=h.progress+(100-h.progress)/2},!1),g=["load","abort","timeout","error"],d=0,e=g.length;e>d;d++)b=g[d],a.addEventListener(b,function(){return h.progress=100},!1);else f=a.onreadystatechange,a.onreadystatechange=function(){var b;return 0===(b=a.readyState)||4===b?h.progress=100:3===a.readyState&&(h.progress=50),"function"==typeof f?f.apply(null,arguments):void 0}}return a}(),n=function(){function a(a){var b,c,d,e,f=this;for(this.progress=0,e=["error","open"],c=0,d=e.length;d>c;c++)b=e[c],a.addEventListener(b,function(){return f.progress=100},!1)}return a}(),d=function(){function a(a){var b,c,d,f;for(null==a&&(a={}),this.elements=[],null==a.selectors&&(a.selectors=[]),f=a.selectors,c=0,d=f.length;d>c;c++)b=f[c],this.elements.push(new e(b))}return a}(),e=function(){function a(a){this.selector=a,this.progress=0,this.check()}return a.prototype.check=function(){var a=this;return document.querySelector(this.selector)?this.done():setTimeout(function(){return a.check()},D.elements.checkInterval)},a.prototype.done=function(){return this.progress=100},a}(),c=function(){function a(){var a,b,c=this;this.progress=null!=(b=this.states[document.readyState])?b:100,a=document.onreadystatechange,document.onreadystatechange=function(){return null!=c.states[document.readyState]&&(c.progress=c.states[document.readyState]),"function"==typeof a?a.apply(null,arguments):void 0}}return a.prototype.states={loading:0,interactive:50,complete:100},a}(),f=function(){function a(){var a,b,c,d,e,f=this;this.progress=0,a=0,e=[],d=0,c=C(),b=setInterval(function(){var g;return g=C()-c-50,c=C(),e.push(g),e.length>D.eventLag.sampleCount&&e.shift(),a=q(e),++d>=D.eventLag.minSamples&&a<D.eventLag.lagThreshold?(f.progress=100,clearInterval(b)):f.progress=100*(3/(a+3))},50)}return a}(),m=function(){function a(a){this.source=a,this.last=this.sinceLastUpdate=0,this.rate=D.initialRate,this.catchup=0,this.progress=this.lastProgress=0,null!=this.source&&(this.progress=F(this.source,"progress"))}return a.prototype.tick=function(a,b){var c;return null==b&&(b=F(this.source,"progress")),b>=100&&(this.done=!0),b===this.last?this.sinceLastUpdate+=a:(this.sinceLastUpdate&&(this.rate=(b-this.last)/this.sinceLastUpdate),this.catchup=(b-this.progress)/D.catchupTime,this.sinceLastUpdate=0,this.last=b),b>this.progress&&(this.progress+=this.catchup*a),c=1-Math.pow(this.progress/100,D.easeFactor),this.progress+=c*this.rate*a,this.progress=Math.min(this.lastProgress+D.maxProgressPerFrame,this.progress),this.progress=Math.max(0,this.progress),this.progress=Math.min(100,this.progress),this.lastProgress=this.progress,this.progress},a}(),L=null,H=null,r=null,M=null,p=null,s=null,j.running=!1,z=function(){return D.restartOnPushState?j.restart():void 0},null!=window.history.pushState&&(T=window.history.pushState,window.history.pushState=function(){return z(),T.apply(window.history,arguments)}),null!=window.history.replaceState&&(W=window.history.replaceState,window.history.replaceState=function(){return z(),W.apply(window.history,arguments)}),l={ajax:a,elements:d,document:c,eventLag:f},(B=function(){var a,c,d,e,f,g,h,i;for(j.sources=L=[],g=["ajax","elements","document","eventLag"],c=0,e=g.length;e>c;c++)a=g[c],D[a]!==!1&&L.push(new l[a](D[a]));for(i=null!=(h=D.extraSources)?h:[],d=0,f=i.length;f>d;d++)K=i[d],L.push(new K(D));return j.bar=r=new b,H=[],M=new m})(),j.stop=function(){return j.trigger("stop"),j.running=!1,r.destroy(),s=!0,null!=p&&("function"==typeof t&&t(p),p=null),B()},j.restart=function(){return j.trigger("restart"),j.stop(),j.start()},j.go=function(){var a;return j.running=!0,r.render(),a=C(),s=!1,p=G(function(b,c){var d,e,f,g,h,i,k,l,n,o,p,q,t,u,v,w;for(l=100-r.progress,e=p=0,f=!0,i=q=0,u=L.length;u>q;i=++q)for(K=L[i],o=null!=H[i]?H[i]:H[i]=[],h=null!=(w=K.elements)?w:[K],k=t=0,v=h.length;v>t;k=++t)g=h[k],n=null!=o[k]?o[k]:o[k]=new m(g),f&=n.done,n.done||(e++,p+=n.tick(b));return d=p/e,r.update(M.tick(b,d)),r.done()||f||s?(r.update(100),j.trigger("done"),setTimeout(function(){return r.finish(),j.running=!1,j.trigger("hide")},Math.max(D.ghostTime,Math.max(D.minTime-(C()-a),0)))):c()})},j.start=function(a){v(D,a),j.running=!0;try{r.render()}catch(b){i=b}return document.querySelector(".pace")?(j.trigger("start"),j.go()):setTimeout(j.start,50)},"function"==typeof define&&define.amd?define(["pace"],function(){return j}):"object"==typeof exports?module.exports=j:D.startOnPageLoad&&j.start()}).call(this); | ||
/*! | ||
* pace.js v1.2.3 | ||
* https://github.com/CodeByZach/pace/ | ||
* Licensed MIT © HubSpot, Inc. | ||
*/ | ||
(function(){function o(t,e){return function(){return t.apply(e,arguments)}}var u,c,i,n,y,t,l,v,r,s,a,e,p,w,b,h,f,d,g,m,k,S,q,x,L,P,T,R,j,O,E,M,A,C,N,_,F,U,W,X,D,H,I,z,G,B=[].slice,J={}.hasOwnProperty,K=function(t,e){for(var n in e)J.call(e,n)&&(t[n]=e[n]);function r(){this.constructor=t}return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},Q=[].indexOf||function(t){for(var e=0,n=this.length;e<n;e++)if(e in this&&this[e]===t)return e;return-1};function V(){}for(f={className:"",catchupTime:100,initialRate:.03,minTime:250,ghostTime:100,maxProgressPerFrame:20,easeFactor:1.25,startOnPageLoad:!0,restartOnPushState:!0,restartOnRequestAfter:500,target:"body",elements:{checkInterval:100,selectors:["body"]},eventLag:{minSamples:10,sampleCount:3,lagThreshold:3},ajax:{trackMethods:["GET"],trackWebSockets:!0,ignoreURLs:[]}},L=function(){var t;return null!=(t="undefined"!=typeof performance&&null!==performance&&"function"==typeof performance.now?performance.now():void 0)?t:+new Date},T=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,h=window.cancelAnimationFrame||window.mozCancelAnimationFrame,a=function(t,e,n){return("function"==typeof t.addEventListener?t.addEventListener(e,n,!1):void 0)||(t["on"+e]=n)},null==T&&(T=function(t){return setTimeout(t,50)},h=function(t){return clearTimeout(t)}),j=function(e){var n=L(),r=function(){var t=L()-n;return 33<=t?(n=L(),e(t,function(){return T(r)})):setTimeout(r,33-t)};return r()},R=function(){var t=arguments[0],e=arguments[1],n=3<=arguments.length?B.call(arguments,2):[];return"function"==typeof t[e]?t[e].apply(t,n):t[e]},d=function(){for(var t,e,n,r=arguments[0],s=2<=arguments.length?B.call(arguments,1):[],o=0,i=s.length;o<i;o++)if(e=s[o])for(t in e)J.call(e,t)&&(n=e[t],null!=r[t]&&"object"==typeof r[t]&&null!=n&&"object"==typeof n?d(r[t],n):r[t]=n);return r},p=function(t){for(var e,n,r=e=0,s=0,o=t.length;s<o;s++)n=t[s],r+=Math.abs(n),e++;return r/e},m=function(t,e){var n,r;if(null==t&&(t="options"),null==e&&(e=!0),r=document.querySelector("[data-pace-"+t+"]")){if(n=r.getAttribute("data-pace-"+t),!e)return n;try{return JSON.parse(n)}catch(t){return"undefined"!=typeof console&&null!==console?console.error("Error parsing inline pace options",t):void 0}}},V.prototype.on=function(t,e,n,r){var s;return null==r&&(r=!1),null==this.bindings&&(this.bindings={}),null==(s=this.bindings)[t]&&(s[t]=[]),this.bindings[t].push({handler:e,ctx:n,once:r})},V.prototype.once=function(t,e,n){return this.on(t,e,n,!0)},V.prototype.off=function(t,e){var n,r,s;if(null!=(null!=(r=this.bindings)?r[t]:void 0)){if(null==e)return delete this.bindings[t];for(n=0,s=[];n<this.bindings[t].length;)this.bindings[t][n].handler===e?s.push(this.bindings[t].splice(n,1)):s.push(n++);return s}},V.prototype.trigger=function(){var t,e,n,r,s,o,i=arguments[0],a=2<=arguments.length?B.call(arguments,1):[];if(null!=(r=this.bindings)&&r[i]){for(n=0,o=[];n<this.bindings[i].length;)e=(s=this.bindings[i][n]).handler,t=s.ctx,s=s.once,e.apply(null!=t?t:this,a),s?o.push(this.bindings[i].splice(n,1)):o.push(n++);return o}},G=V,y=window.Pace||{},window.Pace=y,d(y,G.prototype),P=y.options=d({},f,window.paceOptions,m()),W=0,D=(I=["ajax","document","eventLag","elements"]).length;W<D;W++)!0===P[A=I[W]]&&(P[A]=f[A]);function Y(){return Y.__super__.constructor.apply(this,arguments)}function Z(){this.progress=0}function $(){this.bindings={}}function tt(){var e,o=this;tt.__super__.constructor.apply(this,arguments),e=function(r){var s=r.open;return r.open=function(t,e,n){return M(t)&&o.trigger("request",{type:t,url:e,request:r}),s.apply(r,arguments)}},window.XMLHttpRequest=function(t){t=new U(t);return e(t),t};try{g(window.XMLHttpRequest,U)}catch(t){}if(null!=F){window.XDomainRequest=function(){var t=new F;return e(t),t};try{g(window.XDomainRequest,F)}catch(t){}}if(null!=_&&P.ajax.trackWebSockets){window.WebSocket=function(t,e){var n=null!=e?new _(t,e):new _(t);return M("socket")&&o.trigger("request",{type:"socket",url:t,protocols:e,request:n}),n};try{g(window.WebSocket,_)}catch(t){}}}function et(){this.complete=o(this.complete,this);var t=this;this.elements=[],k().on("request",function(){return t.watch.apply(t,arguments)})}function nt(t){var e,n,r,s;for(null==t&&(t={}),this.complete=o(this.complete,this),this.elements=[],null==t.selectors&&(t.selectors=[]),n=0,r=(s=t.selectors).length;n<r;n++)e=s[n],this.elements.push(new i(e,this.complete))}function rt(t,e){this.selector=t,this.completeCallback=e,this.progress=0,this.check()}function st(){var t,e,n=this;this.progress=null!=(e=this.states[document.readyState])?e:100,t=document.onreadystatechange,document.onreadystatechange=function(){return null!=n.states[document.readyState]&&(n.progress=n.states[document.readyState]),"function"==typeof t?t.apply(null,arguments):void 0}}function ot(t){this.source=t,this.last=this.sinceLastUpdate=0,this.rate=P.initialRate,this.catchup=0,this.progress=this.lastProgress=0,null!=this.source&&(this.progress=R(this.source,"progress"))}G=Error,K(Y,G),n=Y,Z.prototype.getElement=function(){var t;if(null==this.el){if(!(t=document.querySelector(P.target)))throw new n;this.el=document.createElement("div"),this.el.className="pace pace-active",document.body.className=document.body.className.replace(/(pace-done )|/,"pace-running ");var e=""!==P.className?" "+P.className:"";this.el.innerHTML='<div class="pace-progress'+e+'">\n <div class="pace-progress-inner"></div>\n</div>\n<div class="pace-activity"></div>',null!=t.firstChild?t.insertBefore(this.el,t.firstChild):t.appendChild(this.el)}return this.el},Z.prototype.finish=function(){var t=this.getElement();return t.className=t.className.replace("pace-active","pace-inactive"),document.body.className=document.body.className.replace("pace-running ","pace-done ")},Z.prototype.update=function(t){return this.progress=t,y.trigger("progress",t),this.render()},Z.prototype.destroy=function(){try{this.getElement().parentNode.removeChild(this.getElement())}catch(t){n=t}return this.el=void 0},Z.prototype.render=function(){var t,e,n,r,s,o,i;if(null==document.querySelector(P.target))return!1;for(t=this.getElement(),r="translate3d("+this.progress+"%, 0, 0)",s=0,o=(i=["webkitTransform","msTransform","transform"]).length;s<o;s++)e=i[s],t.children[0].style[e]=r;return(!this.lastRenderedProgress||this.lastRenderedProgress|0!==this.progress|0)&&(t.children[0].setAttribute("data-progress-text",(0|this.progress)+"%"),100<=this.progress?n="99":(n=this.progress<10?"0":"",n+=0|this.progress),t.children[0].setAttribute("data-progress",""+n)),y.trigger("change",this.progress),this.lastRenderedProgress=this.progress},Z.prototype.done=function(){return 100<=this.progress},c=Z,$.prototype.trigger=function(t,e){var n,r,s,o,i;if(null!=this.bindings[t]){for(i=[],r=0,s=(o=this.bindings[t]).length;r<s;r++)n=o[r],i.push(n.call(this,e));return i}},$.prototype.on=function(t,e){var n;return null==(n=this.bindings)[t]&&(n[t]=[]),this.bindings[t].push(e)},m=$,U=window.XMLHttpRequest,F=window.XDomainRequest,_=window.WebSocket,g=function(t,e){var n,r=[];for(n in e.prototype)try{null==t[n]&&"function"!=typeof e[n]?"function"==typeof Object.defineProperty?r.push(Object.defineProperty(t,n,{get:function(t){return function(){return e.prototype[t]}}(n),configurable:!0,enumerable:!0})):r.push(t[n]=e.prototype[n]):r.push(void 0)}catch(t){0}return r},q=[],y.ignore=function(){var t=arguments[0],e=2<=arguments.length?B.call(arguments,1):[];return q.unshift("ignore"),e=t.apply(null,e),q.shift(),e},y.track=function(){var t=arguments[0],e=2<=arguments.length?B.call(arguments,1):[];return q.unshift("track"),e=t.apply(null,e),q.shift(),e},M=function(t){if(null==t&&(t="GET"),"track"===q[0])return"force";if(!q.length&&P.ajax){if("socket"===t&&P.ajax.trackWebSockets)return!0;if(t=t.toUpperCase(),0<=Q.call(P.ajax.trackMethods,t))return!0}return!1},K(tt,m),t=tt,X=null,E=function(t){for(var e,n=P.ajax.ignoreURLs,r=0,s=n.length;r<s;r++)if("string"==typeof(e=n[r])){if(-1!==t.indexOf(e))return!0}else if(e.test(t))return!0;return!1},(k=function(){return null==X&&(X=new t),X})().on("request",function(t){var o,i=t.type,a=t.request,e=t.url;if(!E(e))return y.running||!1===P.restartOnRequestAfter&&"force"!==M(i)?void 0:(o=arguments,"boolean"==typeof(e=P.restartOnRequestAfter||0)&&(e=0),setTimeout(function(){var t,e,n,r,s="socket"===i?a.readyState<1:0<(s=a.readyState)&&s<4;if(s){for(y.restart(),r=[],t=0,e=(n=y.sources).length;t<e;t++){if((A=n[t])instanceof u){A.watch.apply(A,o);break}r.push(void 0)}return r}},e))}),et.prototype.watch=function(t){var e=t.type,n=t.request,t=t.url;if(!E(t))return n=new("socket"===e?r:s)(n,this.complete),this.elements.push(n)},et.prototype.complete=function(e){return this.elements=this.elements.filter(function(t){return t!==e})},u=et,s=function(e,n){var t,r,s,o,i=this;if(this.progress=0,null!=window.ProgressEvent)for(a(e,"progress",function(t){return t.lengthComputable?i.progress=100*t.loaded/t.total:i.progress=i.progress+(100-i.progress)/2}),t=0,r=(o=["load","abort","timeout","error"]).length;t<r;t++)a(e,o[t],function(){return n(i),i.progress=100});else s=e.onreadystatechange,e.onreadystatechange=function(){var t;return 0===(t=e.readyState)||4===t?(n(i),i.progress=100):3===e.readyState&&(i.progress=50),"function"==typeof s?s.apply(null,arguments):void 0}},r=function(t,e){for(var n,r=this,s=this.progress=0,o=(n=["error","open"]).length;s<o;s++)a(t,n[s],function(){return e(r),r.progress=100})},nt.prototype.complete=function(e){return this.elements=this.elements.filter(function(t){return t!==e})},G=nt,rt.prototype.check=function(){var t=this;return document.querySelector(this.selector)?this.done():setTimeout(function(){return t.check()},P.elements.checkInterval)},rt.prototype.done=function(){return this.completeCallback(this),this.completeCallback=null,this.progress=100},i=rt,st.prototype.states={loading:0,interactive:50,complete:100},K=st,m=function(){var e,n,r,s,o,i=this;this.progress=0,o=[],s=0,r=L(),n=setInterval(function(){var t=L()-r-50;return r=L(),o.push(t),o.length>P.eventLag.sampleCount&&o.shift(),e=p(o),++s>=P.eventLag.minSamples&&e<P.eventLag.lagThreshold?(i.progress=100,clearInterval(n)):i.progress=3/(e+3)*100},50)},ot.prototype.tick=function(t,e){return null==e&&(e=R(this.source,"progress")),100<=e&&(this.done=!0),e===this.last?this.sinceLastUpdate+=t:(this.sinceLastUpdate&&(this.rate=(e-this.last)/this.sinceLastUpdate),this.catchup=(e-this.progress)/P.catchupTime,this.sinceLastUpdate=0,this.last=e),e>this.progress&&(this.progress+=this.catchup*t),e=1-Math.pow(this.progress/100,P.easeFactor),this.progress+=e*this.rate*t,this.progress=Math.min(this.lastProgress+P.maxProgressPerFrame,this.progress),this.progress=Math.max(0,this.progress),this.progress=Math.min(100,this.progress),this.lastProgress=this.progress,this.progress},v=ot,b=e=N=w=O=C=null,y.running=!1,S=function(){if(P.restartOnPushState)return y.restart()},null!=window.history.pushState&&(H=window.history.pushState,window.history.pushState=function(){return S(),H.apply(window.history,arguments)}),null!=window.history.replaceState&&(z=window.history.replaceState,window.history.replaceState=function(){return S(),z.apply(window.history,arguments)}),l={ajax:u,elements:G,document:K,eventLag:m},(x=function(){var t,e,n,r,s,o,i,a;for(y.sources=C=[],e=0,r=(o=["ajax","elements","document","eventLag"]).length;e<r;e++)!1!==P[t=o[e]]&&C.push(new l[t](P[t]));for(n=0,s=(a=null!=(i=P.extraSources)?i:[]).length;n<s;n++)A=a[n],C.push(new A(P));return y.bar=w=new c,O=[],N=new v})(),y.stop=function(){return y.trigger("stop"),y.running=!1,w.destroy(),b=!0,null!=e&&("function"==typeof h&&h(e),e=null),x()},y.restart=function(){return y.trigger("restart"),y.stop(),y.start()},y.go=function(){var m;return y.running=!0,w.render(),m=L(),b=!1,e=j(function(t,e){w.progress;for(var n,r,s,o,i,a,u,c,l,p,h=a=0,f=!0,d=u=0,g=C.length;u<g;d=++u)for(A=C[d],i=null!=O[d]?O[d]:O[d]=[],s=c=0,l=(r=null!=(p=A.elements)?p:[A]).length;c<l;s=++c)o=r[s],f&=(o=null!=i[s]?i[s]:i[s]=new v(o)).done,o.done||(h++,a+=o.tick(t));return n=a/h,w.update(N.tick(t,n)),w.done()||f||b?(w.update(100),y.trigger("done"),setTimeout(function(){return w.finish(),y.running=!1,y.trigger("hide")},Math.max(P.ghostTime,Math.max(P.minTime-(L()-m),0)))):e()})},y.start=function(t){d(P,t),y.running=!0;try{w.render()}catch(t){n=t}return document.querySelector(".pace")?(y.trigger("start"),y.go()):setTimeout(y.start,50)},"function"==typeof define&&define.amd?define(function(){return y}):"object"==typeof exports?module.exports=y:P.startOnPageLoad&&y.start()}).call(this); |
{ | ||
"name": "pace-js", | ||
"version": "1.0.2", | ||
"description": "Automatic page load progress bar", | ||
"authors": [ | ||
"Zack Bloom <zackbloom@gmail.com>", | ||
"Adam Schwartz <adam.flynn.schwartz@gmail.com>" | ||
], | ||
"license": "MIT", | ||
"version": "1.2.3", | ||
"description": "Automatically add a progress bar to your site.", | ||
"main": "pace.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/HubSpot/pace.git" | ||
"url": "git+https://github.com/CodeByZach/pace.git" | ||
}, | ||
"devDependencies": { | ||
"grunt-contrib-coffee": "~0.7.0", | ||
"coffee-script": "~1.6.3", | ||
"grunt-contrib-uglify": "~0.2.4", | ||
"grunt-cli": "~0.1.9", | ||
"grunt": "~0.4.1", | ||
"grunt-contrib-watch": "~0.5.3", | ||
"color": "~0.4.4" | ||
} | ||
"keywords": [ | ||
"pace", | ||
"pace-js", | ||
"pace.js", | ||
"progress-bar", | ||
"loading-bar", | ||
"loading-indicator", | ||
"loading-animation" | ||
], | ||
"author": "CodeByZach <codebyzach@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/CodeByZach/pace/issues" | ||
}, | ||
"homepage": "https://github.com/CodeByZach/pace#readme" | ||
} |
282
README.md
@@ -1,29 +0,281 @@ | ||
pace | ||
PACE | ||
==== | ||
[![Latest Release](https://img.shields.io/github/tag/CodeByZach/pace.svg?label=version)](https://github.com/CodeByZach/pace/releases/latest) | ||
<a href="https://eager.io/app/kYKTiQjoVjQk/install?source=button"> | ||
<img src="https://install.eager.io/install-button.png" border="0" width="126"> | ||
</a> | ||
An automatic web page progress bar. | ||
Include [pace.js](https://raw.github.com/HubSpot/pace/v1.0.2/pace.min.js) and a [theme](http://github.hubspot.com/pace/docs/welcome/) of your choice to your page and you are done! | ||
### [Demo](https://codebyzach.github.io/pace/) | ||
### [Documentation](https://codebyzach.github.io/pace/docs/) | ||
We also have a [Wordpress Plugin](https://wordpress.org/plugins/pace). | ||
Include [pace.js](https://raw.github.com/CodeByZach/pace/master/pace.min.js) and the | ||
[theme](https://codebyzach.github.io/pace/) css of your choice on your page | ||
(as early as is possible), and you're done! | ||
Pace will automatically monitor your Ajax requests, event loop lag, document ready state and elements on your page to decide on the progress. | ||
Pace will automatically monitor your ajax requests, event loop lag, document | ||
ready state, and elements on your page to decide the progress. On ajax navigation | ||
it will begin again! | ||
If you use AMD or Browserify, require pace.js and call `pace.start()` as early in the loading process as is possible. | ||
### [Demo](http://github.hubspot.com/pace/docs/welcome/) | ||
Example | ||
------- | ||
### [Documentation](http://github.hubspot.com/pace/) | ||
### Example | ||
```html | ||
<head> | ||
<script src="/pace/pace.js"></script> | ||
<link href="/pace/themes/pace-theme-barber-shop.css" rel="stylesheet" /> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.3/pace.min.js"></script> | ||
<link href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.3/pace-theme-default.min.css" rel="stylesheet" /> | ||
</head> | ||
``` | ||
Configuration | ||
------------- | ||
Pace is fully automatic, no configuration is necessary to get started. | ||
If you would like to make some tweaks, here's how: | ||
You can set `window.paceOptions` before bringing in the file: | ||
```javascript | ||
paceOptions = { | ||
// Disable the 'elements' source | ||
elements: false, | ||
// Only show the progress on regular and ajax-y page navigation, | ||
// not every request | ||
restartOnRequestAfter: false | ||
} | ||
``` | ||
You can also put options on the script tag: | ||
```html | ||
<script data-pace-options='{ "ajax": false }' src='pace.js'></script> | ||
``` | ||
If you're using AMD or Browserify, you can pass your options to `start`: | ||
```javascript | ||
define(['pace'], function(pace){ | ||
pace.start({ | ||
document: false | ||
}); | ||
}); | ||
``` | ||
Themes | ||
------ | ||
Pace includes a bunch of [themes](https://codebyzach.github.io/pace/) | ||
to get you started. Just include the appropriate css file. Send us a PR with | ||
any interesting themes you create. | ||
If you have minor styling changes and don't want to extend theme css, you can add custom class names to | ||
the progress bar using the "className" option: | ||
```javascript | ||
paceOptions = { | ||
className: 'my-custom-class' | ||
} | ||
``` | ||
Collectors | ||
---------- | ||
Collectors are the bits of code which gather progress information. Pace includes four default collectors: | ||
- Ajax | ||
Monitors all ajax requests on the page | ||
- Elements | ||
Checks for the existance of specific elements on the page | ||
- Document | ||
Checks the document readyState | ||
- Event Lag | ||
Checks for event loop lag signaling that javascript is being executed | ||
They can each be configured or disabled through configuration options of the same name. | ||
```javascript | ||
paceOptions = { | ||
ajax: false, // disabled | ||
document: false, // disabled | ||
eventLag: false, // disabled | ||
elements: { | ||
selectors: ['.my-page'] | ||
} | ||
}; | ||
``` | ||
Add your own classes to `paceOptions.extraSources` to add more sources. Each source should either | ||
have a `.progress` property, or a `.elements` property which is a list of objects with | ||
`.progress` properties. Pace will automatically handle all scaling to make the progress | ||
changes look smooth to the user. | ||
Elements | ||
-------- | ||
Elements being rendered to the screen is one way for us to decide that the page has been | ||
rendered. If you would like to use that source of information (not required at all), | ||
specify one or more selectors. You can comma separate the selectors to propertly handle | ||
error states, where the progress bar should disappear, but the element we are looking for | ||
may never appear: | ||
```javascript | ||
paceOptions = { | ||
elements: { | ||
selectors: ['.timeline, .timeline-error', '.user-profile, .profile-error'] | ||
} | ||
} | ||
``` | ||
Pace will consider the elements test successful when each selector matches something. For | ||
this example, when either `.timeline` or `.timeline-error` exist, and either `.user-profile` | ||
or `.profile-error` exist. | ||
Restart Rules | ||
------------- | ||
Most users want the progress bar to automatically restart when a pushState event occurs | ||
(generally means ajax navigation is occuring). You can disable this: | ||
```javascript | ||
paceOptions = { | ||
restartOnPushState: false | ||
} | ||
``` | ||
You can also have pace restart on every ajax request which lasts longer than x ms. You'll want to | ||
disable this if you make ajax requests the user doesn't need to know about, like precaching: | ||
```javascript | ||
paceOptions = { | ||
restartOnRequestAfter: false | ||
} | ||
``` | ||
You can always trigger a restart manually by calling `Pace.restart()` | ||
See [the source](https://github.com/CodeByZach/pace/blob/master/pace.js) for a full list of options. | ||
API | ||
--- | ||
Pace exposes the following methods: | ||
- `Pace.start`: Show the progress bar and start updating. Called automatically if you don't use AMD or CommonJS. | ||
- `Pace.restart`: Show the progress bar if it's hidden and start reporting the progress from scratch. Called automatically | ||
whenever `pushState` or `replaceState` is called by default. | ||
- `Pace.stop`: Hide the progress bar and stop updating it. | ||
- `Pace.track`: Explicitly track one or more requests, see Tracking below | ||
- `Pace.ignore`: Explicitly ignore one or more requests, see Tracking below | ||
Events | ||
------ | ||
Pace fires the following events: | ||
- `start`: When pace is initially started, or as a part of a restart | ||
- `stop`: When pace is manually stopped, or as a part of a restart | ||
- `restart`: When pace is restarted (manually, or by a new AJAX request) | ||
- `done`: When pace is finished | ||
- `hide`: When the pace is hidden (can be later than `done`, based on `ghostTime` and `minTime`) | ||
You can bind onto events using the `on`, `off` and `once` methods: | ||
- `Pace.on(event, handler, [context])`: Call `handler` (optionally with context) when `event` is triggered | ||
- `Pace.off(event, [handler])`: Unbind the provided `event` and `handler` combination. | ||
- `Pace.once(event, handler, [context])`: Bind `handler` to the next (and only the next) incidence of `event` | ||
Tracking | ||
-------- | ||
By default, Pace will show any ajax requests which begin as a part of a normal or ajax-y page load, or which last longer than | ||
500ms. | ||
You can disable all ajax tracking by setting `ajax` to false: | ||
```javascript | ||
Pace.options = { | ||
ajax: false | ||
} | ||
``` | ||
You can disable ajax tracking except on page navigation by setting `restartOnRequestAfter` to false: | ||
```javascript | ||
Pace.options = { | ||
restartOnRequestAfter: false | ||
} | ||
``` | ||
You can manually disable tracking for a specific request or requests by triggering them within a `Pace.ignore` callback: | ||
```javascript | ||
Pace.ignore(function() { | ||
$.ajax(...) | ||
}); | ||
``` | ||
You can force the progress bar to be shown for a specific request by triggering them within a `Pace.track` callback: | ||
```javascript | ||
Pace.track(function() { | ||
$.ajax(...) | ||
}); | ||
``` | ||
You can also ignore URLs based on a pattern: | ||
```javascript | ||
Pace.options = { | ||
ajax: { | ||
ignoreURLs: ['some-substring', /some-regexp/] | ||
} | ||
} | ||
``` | ||
Dependencies | ||
------------ | ||
None! | ||
Support | ||
------- | ||
Pace is designed to support IE8+ (standards mode), FF 3.5+, Chrome, Safari 4+, Opera 10.5+, and all modern | ||
mobile browsers. If you run into a compatibility issue, or can make a case for supporting something else, | ||
please create an issue. | ||
Size | ||
---- | ||
pace.js is 4kb minified and gzipped. The themes vary between 0.5 and 4kb. | ||
Issues | ||
------ | ||
We have obviously not tested this on every website. If you run into an issue, or find a way the automatic | ||
detection could be better, please [create an Issue](https://github.com/CodeByZach/pace/issues/new). If you can include a test case, that's even better. | ||
Credits | ||
------- | ||
[HubSpot](http://dev.hubspot.com) | ||
Javascript by [Zack Bloom](http://twitter.com/zackbloom) | ||
CSS by [Adam Schwartz](http://twitter.com/adamfschwartz) | ||
Themes inspired by [Mary Lou](http://tympanus.net/codrops/2013/09/18/creative-loading-effects/) | ||
Project inspired by [nprogress](http://ricostacruz.com/nprogress/) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
0
0
1
282
0
816526
172
16170