Implemented logic to detect when offline the internet and suppress Ajax calls

This commit is contained in:
Djamil Legato
2015-11-20 21:59:57 -08:00
parent 1071bf277f
commit ea2b7968e8
2 changed files with 19 additions and 1 deletions

View File

@@ -1,7 +1,19 @@
$(function(){
var root = window || {};
var root = window || {},
isOnline = typeof navigator.onLine !== 'undefined' && navigator.onLine;
window.addEventListener('online', function(){
isOnline = true;
});
window.addEventListener('offline', function(){
isOnline = false;
});
root.GravAjax = function (url, settings) {
if (!isOnline) {
toastr.error('You appear to be Offline.');
}
settings = typeof settings === 'undefined' ? typeof url === 'string' ? {} : url : settings;
settings.url = typeof settings.url === 'undefined' && typeof url === 'string' ? url : settings.url;