mirror of https://github.com/ColorlibHQ/AdminLTE
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
947 lines
26 KiB
947 lines
26 KiB
9 years ago
|
(function() {
|
||
6 years ago
|
var AjaxMonitor, Bar, DocumentMonitor, ElementMonitor, ElementTracker, EventLagMonitor, Evented, Events, NoTargetError, Pace, RequestIntercept, SOURCE_KEYS, Scaler, SocketRequestTracker, XHRRequestTracker, _WebSocket, _XDomainRequest, _XMLHttpRequest, _intercept, _pushState, _replaceState, animation, avgAmplitude, bar, cancelAnimation, cancelAnimationFrame, defaultOptions, extend, extendNative, getFromDOM, getIntercept, handlePushState, ignoreStack, init, k, len, now, options, ref, requestAnimationFrame, result, runAnimation, scalers, shouldIgnoreURL, shouldTrack, source, sources, uniScaler,
|
||
|
slice = [].slice,
|
||
|
hasProp = {}.hasOwnProperty,
|
||
|
extend1 = 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; };
|
||
9 years ago
|
|
||
|
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: []
|
||
|
}
|
||
|
};
|
||
|
|
||
|
now = function() {
|
||
6 years ago
|
var ref;
|
||
|
return (ref = typeof performance !== "undefined" && performance !== null ? typeof performance.now === "function" ? performance.now() : void 0 : void 0) != null ? ref : +(new Date);
|
||
9 years ago
|
};
|
||
|
|
||
|
requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
|
||
|
|
||
|
cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame;
|
||
|
|
||
|
if (requestAnimationFrame == null) {
|
||
|
requestAnimationFrame = function(fn) {
|
||
|
return setTimeout(fn, 50);
|
||
|
};
|
||
|
cancelAnimationFrame = function(id) {
|
||
|
return clearTimeout(id);
|
||
|
};
|
||
|
}
|
||
|
|
||
|
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();
|
||
|
};
|
||
|
|
||
|
result = function() {
|
||
|
var args, key, obj;
|
||
6 years ago
|
obj = arguments[0], key = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
|
||
9 years ago
|
if (typeof obj[key] === 'function') {
|
||
|
return obj[key].apply(obj, args);
|
||
|
} else {
|
||
|
return obj[key];
|
||
|
}
|
||
|
};
|
||
|
|
||
|
extend = function() {
|
||
6 years ago
|
var k, key, len, out, source, sources, val;
|
||
|
out = arguments[0], sources = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||
|
for (k = 0, len = sources.length; k < len; k++) {
|
||
|
source = sources[k];
|
||
9 years ago
|
if (source) {
|
||
|
for (key in source) {
|
||
6 years ago
|
if (!hasProp.call(source, key)) continue;
|
||
9 years ago
|
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;
|
||
|
};
|
||
|
|
||
|
avgAmplitude = function(arr) {
|
||
6 years ago
|
var count, k, len, sum, v;
|
||
9 years ago
|
sum = count = 0;
|
||
6 years ago
|
for (k = 0, len = arr.length; k < len; k++) {
|
||
|
v = arr[k];
|
||
9 years ago
|
sum += Math.abs(v);
|
||
|
count++;
|
||
|
}
|
||
|
return sum / count;
|
||
|
};
|
||
|
|
||
|
getFromDOM = function(key, json) {
|
||
6 years ago
|
var data, e, el, error;
|
||
9 years ago
|
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);
|
||
6 years ago
|
} catch (error) {
|
||
|
e = error;
|
||
9 years ago
|
return typeof console !== "undefined" && console !== null ? console.error("Error parsing inline pace options", e) : void 0;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
Evented = (function() {
|
||
|
function Evented() {}
|
||
|
|
||
|
Evented.prototype.on = function(event, handler, ctx, once) {
|
||
6 years ago
|
var base;
|
||
9 years ago
|
if (once == null) {
|
||
|
once = false;
|
||
|
}
|
||
|
if (this.bindings == null) {
|
||
|
this.bindings = {};
|
||
|
}
|
||
6 years ago
|
if ((base = this.bindings)[event] == null) {
|
||
|
base[event] = [];
|
||
9 years ago
|
}
|
||
|
return this.bindings[event].push({
|
||
|
handler: handler,
|
||
|
ctx: ctx,
|
||
|
once: once
|
||
|
});
|
||
|
};
|
||
|
|
||
|
Evented.prototype.once = function(event, handler, ctx) {
|
||
|
return this.on(event, handler, ctx, true);
|
||
|
};
|
||
|
|
||
|
Evented.prototype.off = function(event, handler) {
|
||
6 years ago
|
var i, ref, results;
|
||
|
if (((ref = this.bindings) != null ? ref[event] : void 0) == null) {
|
||
9 years ago
|
return;
|
||
|
}
|
||
|
if (handler == null) {
|
||
|
return delete this.bindings[event];
|
||
|
} else {
|
||
|
i = 0;
|
||
6 years ago
|
results = [];
|
||
9 years ago
|
while (i < this.bindings[event].length) {
|
||
|
if (this.bindings[event][i].handler === handler) {
|
||
6 years ago
|
results.push(this.bindings[event].splice(i, 1));
|
||
9 years ago
|
} else {
|
||
6 years ago
|
results.push(i++);
|
||
9 years ago
|
}
|
||
|
}
|
||
6 years ago
|
return results;
|
||
9 years ago
|
}
|
||
|
};
|
||
|
|
||
|
Evented.prototype.trigger = function() {
|
||
6 years ago
|
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) {
|
||
9 years ago
|
i = 0;
|
||
6 years ago
|
results = [];
|
||
9 years ago
|
while (i < this.bindings[event].length) {
|
||
6 years ago
|
ref1 = this.bindings[event][i], handler = ref1.handler, ctx = ref1.ctx, once = ref1.once;
|
||
9 years ago
|
handler.apply(ctx != null ? ctx : this, args);
|
||
|
if (once) {
|
||
6 years ago
|
results.push(this.bindings[event].splice(i, 1));
|
||
9 years ago
|
} else {
|
||
6 years ago
|
results.push(i++);
|
||
9 years ago
|
}
|
||
|
}
|
||
6 years ago
|
return results;
|
||
9 years ago
|
}
|
||
|
};
|
||
|
|
||
|
return Evented;
|
||
|
|
||
|
})();
|
||
|
|
||
|
Pace = window.Pace || {};
|
||
|
|
||
|
window.Pace = Pace;
|
||
|
|
||
|
extend(Pace, Evented.prototype);
|
||
|
|
||
|
options = Pace.options = extend({}, defaultOptions, window.paceOptions, getFromDOM());
|
||
|
|
||
6 years ago
|
ref = ['ajax', 'document', 'eventLag', 'elements'];
|
||
|
for (k = 0, len = ref.length; k < len; k++) {
|
||
|
source = ref[k];
|
||
9 years ago
|
if (options[source] === true) {
|
||
|
options[source] = defaultOptions[source];
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
NoTargetError = (function(superClass) {
|
||
|
extend1(NoTargetError, superClass);
|
||
9 years ago
|
|
||
|
function NoTargetError() {
|
||
6 years ago
|
return NoTargetError.__super__.constructor.apply(this, arguments);
|
||
9 years ago
|
}
|
||
|
|
||
|
return NoTargetError;
|
||
|
|
||
|
})(Error);
|
||
|
|
||
|
Bar = (function() {
|
||
|
function Bar() {
|
||
|
this.progress = 0;
|
||
|
}
|
||
|
|
||
|
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');
|
||
6 years ago
|
this.el.classList.add('pace');
|
||
|
this.el.classList.add('pace-active');
|
||
|
document.body.classList.remove('pace-done');
|
||
|
document.body.classList.add('pace-running');
|
||
9 years ago
|
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.prototype.finish = function() {
|
||
|
var el;
|
||
|
el = this.getElement();
|
||
6 years ago
|
el.classList.remove('pace-active');
|
||
|
el.classList.add('pace-inactive');
|
||
|
document.body.classList.remove('pace-running');
|
||
|
return document.body.classList.add('pace-done');
|
||
9 years ago
|
};
|
||
|
|
||
|
Bar.prototype.update = function(prog) {
|
||
|
this.progress = prog;
|
||
|
return this.render();
|
||
|
};
|
||
|
|
||
|
Bar.prototype.destroy = function() {
|
||
6 years ago
|
var error;
|
||
9 years ago
|
try {
|
||
|
this.getElement().parentNode.removeChild(this.getElement());
|
||
6 years ago
|
} catch (error) {
|
||
|
NoTargetError = error;
|
||
9 years ago
|
}
|
||
|
return this.el = void 0;
|
||
|
};
|
||
|
|
||
|
Bar.prototype.render = function() {
|
||
6 years ago
|
var el, key, l, len1, progressStr, ref1, transform;
|
||
9 years ago
|
if (document.querySelector(options.target) == null) {
|
||
|
return false;
|
||
|
}
|
||
|
el = this.getElement();
|
||
|
transform = "translate3d(" + this.progress + "%, 0, 0)";
|
||
6 years ago
|
ref1 = ['webkitTransform', 'msTransform', 'transform'];
|
||
|
for (l = 0, len1 = ref1.length; l < len1; l++) {
|
||
|
key = ref1[l];
|
||
9 years ago
|
el.children[0].style[key] = transform;
|
||
|
}
|
||
|
if (!this.lastRenderedProgress || this.lastRenderedProgress | 0 !== this.progress | 0) {
|
||
6 years ago
|
el.children[0].setAttribute('data-progress-text', (this.progress | 0) + "%");
|
||
9 years ago
|
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.done = function() {
|
||
|
return this.progress >= 100;
|
||
|
};
|
||
|
|
||
|
return Bar;
|
||
|
|
||
|
})();
|
||
|
|
||
|
Events = (function() {
|
||
|
function Events() {
|
||
|
this.bindings = {};
|
||
|
}
|
||
|
|
||
|
Events.prototype.trigger = function(name, val) {
|
||
6 years ago
|
var binding, l, len1, ref1, results;
|
||
9 years ago
|
if (this.bindings[name] != null) {
|
||
6 years ago
|
ref1 = this.bindings[name];
|
||
|
results = [];
|
||
|
for (l = 0, len1 = ref1.length; l < len1; l++) {
|
||
|
binding = ref1[l];
|
||
|
results.push(binding.call(this, val));
|
||
9 years ago
|
}
|
||
6 years ago
|
return results;
|
||
9 years ago
|
}
|
||
|
};
|
||
|
|
||
|
Events.prototype.on = function(name, fn) {
|
||
6 years ago
|
var base;
|
||
|
if ((base = this.bindings)[name] == null) {
|
||
|
base[name] = [];
|
||
9 years ago
|
}
|
||
|
return this.bindings[name].push(fn);
|
||
|
};
|
||
|
|
||
|
return Events;
|
||
|
|
||
|
})();
|
||
|
|
||
|
_XMLHttpRequest = window.XMLHttpRequest;
|
||
|
|
||
|
_XDomainRequest = window.XDomainRequest;
|
||
|
|
||
|
_WebSocket = window.WebSocket;
|
||
|
|
||
|
extendNative = function(to, from) {
|
||
6 years ago
|
var e, error, key, results;
|
||
|
results = [];
|
||
9 years ago
|
for (key in from.prototype) {
|
||
|
try {
|
||
|
if ((to[key] == null) && typeof from[key] !== 'function') {
|
||
|
if (typeof Object.defineProperty === 'function') {
|
||
6 years ago
|
results.push(Object.defineProperty(to, key, {
|
||
9 years ago
|
get: function() {
|
||
|
return from.prototype[key];
|
||
|
},
|
||
|
configurable: true,
|
||
|
enumerable: true
|
||
|
}));
|
||
|
} else {
|
||
6 years ago
|
results.push(to[key] = from.prototype[key]);
|
||
9 years ago
|
}
|
||
|
} else {
|
||
6 years ago
|
results.push(void 0);
|
||
9 years ago
|
}
|
||
6 years ago
|
} catch (error) {
|
||
|
e = error;
|
||
9 years ago
|
}
|
||
|
}
|
||
6 years ago
|
return results;
|
||
9 years ago
|
};
|
||
|
|
||
|
ignoreStack = [];
|
||
|
|
||
|
Pace.ignore = function() {
|
||
|
var args, fn, ret;
|
||
6 years ago
|
fn = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||
9 years ago
|
ignoreStack.unshift('ignore');
|
||
|
ret = fn.apply(null, args);
|
||
|
ignoreStack.shift();
|
||
|
return ret;
|
||
|
};
|
||
|
|
||
|
Pace.track = function() {
|
||
|
var args, fn, ret;
|
||
6 years ago
|
fn = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||
9 years ago
|
ignoreStack.unshift('track');
|
||
|
ret = fn.apply(null, args);
|
||
|
ignoreStack.shift();
|
||
|
return ret;
|
||
|
};
|
||
|
|
||
|
shouldTrack = function(method) {
|
||
6 years ago
|
var ref1;
|
||
9 years ago
|
if (method == null) {
|
||
|
method = 'GET';
|
||
|
}
|
||
|
if (ignoreStack[0] === 'track') {
|
||
|
return 'force';
|
||
|
}
|
||
|
if (!ignoreStack.length && options.ajax) {
|
||
|
if (method === 'socket' && options.ajax.trackWebSockets) {
|
||
|
return true;
|
||
6 years ago
|
} else if (ref1 = method.toUpperCase(), indexOf.call(options.ajax.trackMethods, ref1) >= 0) {
|
||
9 years ago
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
};
|
||
|
|
||
6 years ago
|
RequestIntercept = (function(superClass) {
|
||
|
extend1(RequestIntercept, superClass);
|
||
9 years ago
|
|
||
|
function RequestIntercept() {
|
||
6 years ago
|
var monitorXHR;
|
||
9 years ago
|
RequestIntercept.__super__.constructor.apply(this, arguments);
|
||
6 years ago
|
monitorXHR = (function(_this) {
|
||
|
return 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);
|
||
|
};
|
||
9 years ago
|
};
|
||
6 years ago
|
})(this);
|
||
9 years ago
|
window.XMLHttpRequest = function(flags) {
|
||
|
var req;
|
||
|
req = new _XMLHttpRequest(flags);
|
||
|
monitorXHR(req);
|
||
|
return req;
|
||
|
};
|
||
|
try {
|
||
|
extendNative(window.XMLHttpRequest, _XMLHttpRequest);
|
||
6 years ago
|
} catch (undefined) {}
|
||
9 years ago
|
if (_XDomainRequest != null) {
|
||
|
window.XDomainRequest = function() {
|
||
|
var req;
|
||
|
req = new _XDomainRequest;
|
||
|
monitorXHR(req);
|
||
|
return req;
|
||
|
};
|
||
|
try {
|
||
|
extendNative(window.XDomainRequest, _XDomainRequest);
|
||
6 years ago
|
} catch (undefined) {}
|
||
9 years ago
|
}
|
||
|
if ((_WebSocket != null) && options.ajax.trackWebSockets) {
|
||
6 years ago
|
window.WebSocket = (function(_this) {
|
||
|
return 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;
|
||
|
};
|
||
|
})(this);
|
||
9 years ago
|
try {
|
||
|
extendNative(window.WebSocket, _WebSocket);
|
||
6 years ago
|
} catch (undefined) {}
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
return RequestIntercept;
|
||
|
|
||
|
})(Events);
|
||
|
|
||
|
_intercept = null;
|
||
|
|
||
|
getIntercept = function() {
|
||
|
if (_intercept == null) {
|
||
|
_intercept = new RequestIntercept;
|
||
|
}
|
||
|
return _intercept;
|
||
|
};
|
||
|
|
||
|
shouldIgnoreURL = function(url) {
|
||
6 years ago
|
var l, len1, pattern, ref1;
|
||
|
ref1 = options.ajax.ignoreURLs;
|
||
|
for (l = 0, len1 = ref1.length; l < len1; l++) {
|
||
|
pattern = ref1[l];
|
||
9 years ago
|
if (typeof pattern === 'string') {
|
||
|
if (url.indexOf(pattern) !== -1) {
|
||
|
return true;
|
||
|
}
|
||
|
} else {
|
||
|
if (pattern.test(url)) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
};
|
||
|
|
||
6 years ago
|
getIntercept().on('request', function(arg) {
|
||
9 years ago
|
var after, args, request, type, url;
|
||
6 years ago
|
type = arg.type, request = arg.request, url = arg.url;
|
||
9 years ago
|
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() {
|
||
6 years ago
|
var l, len1, ref1, ref2, results, stillActive;
|
||
9 years ago
|
if (type === 'socket') {
|
||
|
stillActive = request.readyState < 2;
|
||
|
} else {
|
||
6 years ago
|
stillActive = (0 < (ref1 = request.readyState) && ref1 < 4);
|
||
9 years ago
|
}
|
||
|
if (stillActive) {
|
||
|
Pace.restart();
|
||
6 years ago
|
ref2 = Pace.sources;
|
||
|
results = [];
|
||
|
for (l = 0, len1 = ref2.length; l < len1; l++) {
|
||
|
source = ref2[l];
|
||
9 years ago
|
if (source instanceof AjaxMonitor) {
|
||
|
source.watch.apply(source, args);
|
||
|
break;
|
||
|
} else {
|
||
6 years ago
|
results.push(void 0);
|
||
9 years ago
|
}
|
||
|
}
|
||
6 years ago
|
return results;
|
||
9 years ago
|
}
|
||
|
}, after);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
AjaxMonitor = (function() {
|
||
|
function AjaxMonitor() {
|
||
|
this.elements = [];
|
||
6 years ago
|
getIntercept().on('request', (function(_this) {
|
||
|
return function() {
|
||
|
return _this.watch.apply(_this, arguments);
|
||
|
};
|
||
|
})(this));
|
||
9 years ago
|
}
|
||
|
|
||
6 years ago
|
AjaxMonitor.prototype.watch = function(arg) {
|
||
9 years ago
|
var request, tracker, type, url;
|
||
6 years ago
|
type = arg.type, request = arg.request, url = arg.url;
|
||
9 years ago
|
if (shouldIgnoreURL(url)) {
|
||
|
return;
|
||
|
}
|
||
|
if (type === 'socket') {
|
||
|
tracker = new SocketRequestTracker(request);
|
||
|
} else {
|
||
|
tracker = new XHRRequestTracker(request);
|
||
|
}
|
||
|
return this.elements.push(tracker);
|
||
|
};
|
||
|
|
||
|
return AjaxMonitor;
|
||
|
|
||
|
})();
|
||
|
|
||
|
XHRRequestTracker = (function() {
|
||
|
function XHRRequestTracker(request) {
|
||
6 years ago
|
var _onreadystatechange, event, l, len1, ref1, size;
|
||
9 years ago
|
this.progress = 0;
|
||
|
if (window.ProgressEvent != null) {
|
||
|
size = null;
|
||
6 years ago
|
request.addEventListener('progress', (function(_this) {
|
||
|
return function(evt) {
|
||
|
if (evt.lengthComputable) {
|
||
|
return _this.progress = 100 * evt.loaded / evt.total;
|
||
|
} else {
|
||
|
return _this.progress = _this.progress + (100 - _this.progress) / 2;
|
||
|
}
|
||
|
};
|
||
|
})(this), false);
|
||
|
ref1 = ['load', 'abort', 'timeout', 'error'];
|
||
|
for (l = 0, len1 = ref1.length; l < len1; l++) {
|
||
|
event = ref1[l];
|
||
|
request.addEventListener(event, (function(_this) {
|
||
|
return function() {
|
||
|
return _this.progress = 100;
|
||
|
};
|
||
|
})(this), false);
|
||
9 years ago
|
}
|
||
|
} else {
|
||
|
_onreadystatechange = request.onreadystatechange;
|
||
6 years ago
|
request.onreadystatechange = (function(_this) {
|
||
|
return function() {
|
||
|
var ref2;
|
||
|
if ((ref2 = request.readyState) === 0 || ref2 === 4) {
|
||
|
_this.progress = 100;
|
||
|
} else if (request.readyState === 3) {
|
||
|
_this.progress = 50;
|
||
|
}
|
||
|
return typeof _onreadystatechange === "function" ? _onreadystatechange.apply(null, arguments) : void 0;
|
||
|
};
|
||
|
})(this);
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
return XHRRequestTracker;
|
||
|
|
||
|
})();
|
||
|
|
||
|
SocketRequestTracker = (function() {
|
||
|
function SocketRequestTracker(request) {
|
||
6 years ago
|
var event, l, len1, ref1;
|
||
9 years ago
|
this.progress = 0;
|
||
6 years ago
|
ref1 = ['error', 'open'];
|
||
|
for (l = 0, len1 = ref1.length; l < len1; l++) {
|
||
|
event = ref1[l];
|
||
|
request.addEventListener(event, (function(_this) {
|
||
|
return function() {
|
||
|
return _this.progress = 100;
|
||
|
};
|
||
|
})(this), false);
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
return SocketRequestTracker;
|
||
|
|
||
|
})();
|
||
|
|
||
|
ElementMonitor = (function() {
|
||
|
function ElementMonitor(options) {
|
||
6 years ago
|
var l, len1, ref1, selector;
|
||
9 years ago
|
if (options == null) {
|
||
|
options = {};
|
||
|
}
|
||
|
this.elements = [];
|
||
|
if (options.selectors == null) {
|
||
|
options.selectors = [];
|
||
|
}
|
||
6 years ago
|
ref1 = options.selectors;
|
||
|
for (l = 0, len1 = ref1.length; l < len1; l++) {
|
||
|
selector = ref1[l];
|
||
9 years ago
|
this.elements.push(new ElementTracker(selector));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return ElementMonitor;
|
||
|
|
||
|
})();
|
||
|
|
||
|
ElementTracker = (function() {
|
||
6 years ago
|
function ElementTracker(selector1) {
|
||
|
this.selector = selector1;
|
||
9 years ago
|
this.progress = 0;
|
||
|
this.check();
|
||
|
}
|
||
|
|
||
|
ElementTracker.prototype.check = function() {
|
||
|
if (document.querySelector(this.selector)) {
|
||
|
return this.done();
|
||
|
} else {
|
||
6 years ago
|
return setTimeout(((function(_this) {
|
||
|
return function() {
|
||
|
return _this.check();
|
||
|
};
|
||
|
})(this)), options.elements.checkInterval);
|
||
9 years ago
|
}
|
||
|
};
|
||
|
|
||
|
ElementTracker.prototype.done = function() {
|
||
|
return this.progress = 100;
|
||
|
};
|
||
|
|
||
|
return ElementTracker;
|
||
|
|
||
|
})();
|
||
|
|
||
|
DocumentMonitor = (function() {
|
||
|
DocumentMonitor.prototype.states = {
|
||
|
loading: 0,
|
||
|
interactive: 50,
|
||
|
complete: 100
|
||
|
};
|
||
|
|
||
|
function DocumentMonitor() {
|
||
6 years ago
|
var _onreadystatechange, ref1;
|
||
|
this.progress = (ref1 = this.states[document.readyState]) != null ? ref1 : 100;
|
||
9 years ago
|
_onreadystatechange = document.onreadystatechange;
|
||
6 years ago
|
document.onreadystatechange = (function(_this) {
|
||
|
return function() {
|
||
|
if (_this.states[document.readyState] != null) {
|
||
|
_this.progress = _this.states[document.readyState];
|
||
|
}
|
||
|
return typeof _onreadystatechange === "function" ? _onreadystatechange.apply(null, arguments) : void 0;
|
||
|
};
|
||
|
})(this);
|
||
9 years ago
|
}
|
||
|
|
||
|
return DocumentMonitor;
|
||
|
|
||
|
})();
|
||
|
|
||
|
EventLagMonitor = (function() {
|
||
|
function EventLagMonitor() {
|
||
6 years ago
|
var avg, interval, last, points, samples;
|
||
9 years ago
|
this.progress = 0;
|
||
|
avg = 0;
|
||
|
samples = [];
|
||
|
points = 0;
|
||
|
last = now();
|
||
6 years ago
|
interval = setInterval((function(_this) {
|
||
|
return 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));
|
||
|
}
|
||
|
};
|
||
|
})(this), 50);
|
||
9 years ago
|
}
|
||
|
|
||
|
return EventLagMonitor;
|
||
|
|
||
|
})();
|
||
|
|
||
|
Scaler = (function() {
|
||
6 years ago
|
function Scaler(source1) {
|
||
|
this.source = source1;
|
||
9 years ago
|
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');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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 Scaler;
|
||
|
|
||
|
})();
|
||
|
|
||
|
sources = null;
|
||
|
|
||
|
scalers = null;
|
||
|
|
||
|
bar = null;
|
||
|
|
||
|
uniScaler = null;
|
||
|
|
||
|
animation = null;
|
||
|
|
||
|
cancelAnimation = null;
|
||
|
|
||
|
Pace.running = false;
|
||
|
|
||
|
handlePushState = function() {
|
||
|
if (options.restartOnPushState) {
|
||
|
return Pace.restart();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
if (window.history.pushState != null) {
|
||
|
_pushState = window.history.pushState;
|
||
|
window.history.pushState = function() {
|
||
|
handlePushState();
|
||
|
return _pushState.apply(window.history, arguments);
|
||
|
};
|
||
|
}
|
||
|
|
||
|
if (window.history.replaceState != null) {
|
||
|
_replaceState = window.history.replaceState;
|
||
|
window.history.replaceState = function() {
|
||
|
handlePushState();
|
||
|
return _replaceState.apply(window.history, arguments);
|
||
|
};
|
||
|
}
|
||
|
|
||
|
SOURCE_KEYS = {
|
||
|
ajax: AjaxMonitor,
|
||
|
elements: ElementMonitor,
|
||
|
document: DocumentMonitor,
|
||
|
eventLag: EventLagMonitor
|
||
|
};
|
||
|
|
||
|
(init = function() {
|
||
6 years ago
|
var l, len1, len2, m, ref1, ref2, ref3, type;
|
||
9 years ago
|
Pace.sources = sources = [];
|
||
6 years ago
|
ref1 = ['ajax', 'elements', 'document', 'eventLag'];
|
||
|
for (l = 0, len1 = ref1.length; l < len1; l++) {
|
||
|
type = ref1[l];
|
||
9 years ago
|
if (options[type] !== false) {
|
||
|
sources.push(new SOURCE_KEYS[type](options[type]));
|
||
|
}
|
||
|
}
|
||
6 years ago
|
ref3 = (ref2 = options.extraSources) != null ? ref2 : [];
|
||
|
for (m = 0, len2 = ref3.length; m < len2; m++) {
|
||
|
source = ref3[m];
|
||
9 years ago
|
sources.push(new source(options));
|
||
|
}
|
||
|
Pace.bar = bar = new Bar;
|
||
|
scalers = [];
|
||
|
return uniScaler = new Scaler;
|
||
|
})();
|
||
|
|
||
|
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();
|
||
|
};
|
||
|
|
||
|
Pace.restart = function() {
|
||
|
Pace.trigger('restart');
|
||
|
Pace.stop();
|
||
|
return Pace.start();
|
||
|
};
|
||
|
|
||
|
Pace.go = function() {
|
||
|
var start;
|
||
|
Pace.running = true;
|
||
|
bar.render();
|
||
|
start = now();
|
||
|
cancelAnimation = false;
|
||
|
return animation = runAnimation(function(frameTime, enqueueNextFrame) {
|
||
6 years ago
|
var avg, count, done, element, elements, i, j, l, len1, len2, m, ref1, remaining, scaler, scalerList, sum;
|
||
9 years ago
|
remaining = 100 - bar.progress;
|
||
|
count = sum = 0;
|
||
|
done = true;
|
||
6 years ago
|
for (i = l = 0, len1 = sources.length; l < len1; i = ++l) {
|
||
9 years ago
|
source = sources[i];
|
||
|
scalerList = scalers[i] != null ? scalers[i] : scalers[i] = [];
|
||
6 years ago
|
elements = (ref1 = source.elements) != null ? ref1 : [source];
|
||
|
for (j = m = 0, len2 = elements.length; m < len2; j = ++m) {
|
||
9 years ago
|
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) {
|
||
6 years ago
|
var error;
|
||
9 years ago
|
extend(options, _options);
|
||
|
Pace.running = true;
|
||
|
try {
|
||
|
bar.render();
|
||
6 years ago
|
} catch (error) {
|
||
|
NoTargetError = error;
|
||
9 years ago
|
}
|
||
|
if (!document.querySelector('.pace')) {
|
||
|
return setTimeout(Pace.start, 50);
|
||
|
} else {
|
||
|
Pace.trigger('start');
|
||
|
return Pace.go();
|
||
|
}
|
||
|
};
|
||
|
|
||
6 years ago
|
if (typeof exports === 'object') {
|
||
9 years ago
|
module.exports = Pace;
|
||
6 years ago
|
}
|
||
|
|
||
|
if (options.startOnPageLoad) {
|
||
|
Pace.start();
|
||
9 years ago
|
}
|
||
|
|
||
|
}).call(this);
|