109 lines
3.1 KiB
JavaScript
109 lines
3.1 KiB
JavaScript
|
|
// REQUEST HANDLING //////////////////////////////////////////////////
|
|
// note: only meant for portal/links/fields request, everything else
|
|
// does not count towards “loading”
|
|
|
|
window.activeRequests = [];
|
|
window.failedRequestCount = 0;
|
|
|
|
window.requests = function() {}
|
|
|
|
window.requests.add = function(ajax) {
|
|
window.activeRequests.push(ajax);
|
|
renderUpdateStatus();
|
|
}
|
|
|
|
window.requests.remove = function(ajax) {
|
|
window.activeRequests.splice(window.activeRequests.indexOf(ajax), 1);
|
|
renderUpdateStatus();
|
|
}
|
|
|
|
window.requests.abort = function() {
|
|
$.each(window.activeRequests, function(ind, actReq) {
|
|
if(actReq) actReq.abort();
|
|
});
|
|
|
|
window.activeRequests = [];
|
|
window.failedRequestCount = 0;
|
|
window.chat._requestOldPublicRunning = false;
|
|
window.chat._requestNewPublicRunning = false;
|
|
window.chat._requestOldFactionRunning = false;
|
|
window.chat._requestNewFactionRunning = false;
|
|
|
|
renderUpdateStatus();
|
|
}
|
|
|
|
// gives user feedback about pending operations. Draws current status
|
|
// to website.
|
|
window.renderUpdateStatus = function() {
|
|
var t = '<b>map status:</b> ';
|
|
if(mapRunsUserAction)
|
|
t += 'paused during interaction';
|
|
else if(isIdle())
|
|
t += 'Idle, not updating.';
|
|
else if(window.activeRequests.length > 0)
|
|
t += window.activeRequests.length + ' requests running.';
|
|
else
|
|
t += 'Up to date.';
|
|
|
|
if(window.failedRequestCount > 0)
|
|
t += ' ' + window.failedRequestCount + ' requests failed.'
|
|
|
|
t += '<br/><span title="not removing portals as long as you keep them in view, though">(';
|
|
var conv = ['impossible', 8,8,7,7,6,6,5,5,4,4,3,3,2,2,1];
|
|
var z = map.getZoom();
|
|
if(z >= 16)
|
|
t += 'requesting all portals';
|
|
else
|
|
t+= 'only requesting portals with level '+conv[z]+' and up';
|
|
t += ')</span>';
|
|
|
|
$('#updatestatus').html(t);
|
|
}
|
|
|
|
|
|
// sets the timer for the next auto refresh. Ensures only one timeout
|
|
// is queued. May be given 'override' in milliseconds if time should
|
|
// not be guessed automatically. Especially useful if a little delay
|
|
// is required, for example when zooming.
|
|
window.startRefreshTimeout = function(override) {
|
|
// may be required to remove 'paused during interaction' message in
|
|
// status bar
|
|
window.renderUpdateStatus();
|
|
if(refreshTimeout) clearTimeout(refreshTimeout);
|
|
var t = 0;
|
|
if(override) {
|
|
t = override;
|
|
} else {
|
|
t = REFRESH*1000;
|
|
var adj = ZOOM_LEVEL_ADJ * (18 - window.map.getZoom());
|
|
if(adj > 0) t += adj*1000;
|
|
}
|
|
var next = new Date(new Date().getTime() + t).toLocaleTimeString();
|
|
console.log('planned refresh: ' + next);
|
|
refreshTimeout = setTimeout(window.requests._callOnRefreshFunctions, t);
|
|
}
|
|
|
|
window.requests._onRefreshFunctions = [];
|
|
window.requests._callOnRefreshFunctions = function() {
|
|
startRefreshTimeout();
|
|
|
|
if(isIdle()) {
|
|
console.log('user has been idle for ' + idleTime + ' minutes. Skipping refresh.');
|
|
renderUpdateStatus();
|
|
return;
|
|
}
|
|
|
|
console.log('refreshing');
|
|
|
|
$.each(window.requests._onRefreshFunctions, function(ind, f) {
|
|
f();
|
|
});
|
|
}
|
|
|
|
|
|
// add method here to be notified of auto-refreshes
|
|
window.requests.addRefreshFunction = function(f) {
|
|
window.requests._onRefreshFunctions.push(f);
|
|
}
|