Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion web/webkit/src/main/resources/toserve/lift.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
uriSuffix,
sessionId = "",
toWatch = {},
knownPromises = {};
knownPromises = {},
ajaxOnCommFailures = [],
ajaxOnCommSuccesses = [],
cometOnCommFailures = [],
cometOnCommSuccesses = [];

// default settings
settings = {
Expand Down Expand Up @@ -98,6 +102,19 @@
}
}

// Notify all functions in arr, passing any extra args
var notifyAll = function(arr) {
var args = [].slice.call(arguments, 1); // Every arg but the passed arr
for(var i = 0; i < arr.length; i++) {
try {
arr[i].apply(this, args);
} catch (e) {
settings.logError("Server communication status callback failed!");
settings.logError(e);
}
}
};

////////////////////////////////////////////////
///// Ajax /////////////////////////////////////
////////////////////////////////////////////////
Expand Down Expand Up @@ -229,6 +246,7 @@
if (aboutToSend.onSuccess) {
aboutToSend.onSuccess(data);
}
notifyAll(ajaxOnCommSuccesses);
doCycleQueueCnt++;
doAjaxCycle();
};
Expand Down Expand Up @@ -256,6 +274,7 @@
settings.ajaxOnFailure();
}
}
notifyAll(ajaxOnCommFailures, aboutToSend.data);
doCycleQueueCnt++;
doAjaxCycle();
};
Expand Down Expand Up @@ -328,11 +347,13 @@
}

function cometFailureFunc() {
notifyAll(cometOnCommFailures);
var requestCount = cometRequestCount;
setTimeout(function() { cometEntry(requestCount); }, settings.cometFailureRetryTimeout);
}

function cometSuccessFunc() {
notifyAll(cometOnCommSuccesses);
var requestCount = cometRequestCount;
setTimeout(function() { cometEntry(requestCount); }, 100);
}
Expand Down Expand Up @@ -598,6 +619,16 @@
ajaxOnSessionLost: function() {
settings.ajaxOnSessionLost();
},
// Pass a callback function to be notified when an attempt to contact the server for an ajax call fails
// The first argument to the function will be the ajax request data.
addAjaxOnCommFailure: function(callback) {
ajaxOnCommFailures.push(callback);
},
// Pass a callback function to be notified when an attempt to contact the server for an ajax call succeeds
// The first argument to the function will be the ajax request data.
addAjaxOnCommSuccess: function(callback) {
ajaxOnCommSuccesses.push(callback);
},
calcAjaxUrl: calcAjaxUrl,
registerComets: registerComets,
cometOnSessionLost: function() {
Expand All @@ -606,6 +637,14 @@
cometOnError: function(e) {
settings.cometOnError(e);
},
// Pass a callback function to be notified when an attempt to contact the server for comet fails
addCometOnCommFailure: function(callback) {
cometOnCommFailures.push(callback);
},
// Pass a callback function to be notified when an attempt to contact the server for comet succeeds
addCometOnCommSuccess: function(callback) {
cometOnCommSuccesses.push(callback);
},
unlistWatch: unlistWatch,
setToWatch: function(tw) {
toWatch = tw;
Expand Down