The magic is done here
Heyoffline.prototype.networkEvents = function(event) {
return addEvent(window, event, this[event]);
};
Which is called in attachEvents
Heyoffline.prototype.attachEvents = function() {
var event, field, _i, _j, _len, _len1, _ref, _ref1,
_this = this;
_ref = this.elements.fields;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
field = _ref[_i];
this.elementEvents(field);
}
_ref1 = this.events.network;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
event = _ref1[_j];
this.networkEvents(event); //Called here
}
return addEvent(window, 'resize', function() {
return _this.resizeOverlay();
});
};
The event, either online or offline is passed to this, the addEvent
function
addEvent
is defined as:
addEvent = function(element, event, fn, useCapture) {
if (useCapture == null) {
useCapture = false;
}
return element.addEventListener(event, fn, useCapture);
};
So really going by what I can see to use the online/offline function all you need to do is call:
//online
window.addEventListener('online', function(){alert('You are online')}, false);
//offline
window.addEventListener('offline', function(){alert('You are online')}, false);
and bobs ya uncle
Tested here as well: http://jsfiddle.net/W4EKh/
The alert comes up right after the jsfiddle one does so I am pretty certain thats how it works...
also, heres something to help out :)...
function networkListener(a, b){
var offlineF, onlineF;
if(a instanceof Function && b instanceof Function){
onlineF = a;
offlineF = b;
}else if(a instanceof Function){
if(typeof b === "string"){
if(b === "online"){
onlineF = a;
}else if(b === "offline"){
offlineF = a;
}
}else{
onlineF = a;
}
}
if(typeof onlineF !== "undefined"){
window.addEventListener('online', onlineF, false);
}
if(typeof offlineF !== "undefined"){
window.addEventListener('offline', offlineF, false);
}
}
And here you can try it out...
http://jsfiddle.net/47N6L/2/