Skip to content

Instantly share code, notes, and snippets.

@pierr
Created December 12, 2014 15:05
Show Gist options
  • Save pierr/41cf363f51a7b81ff44a to your computer and use it in GitHub Desktop.
Save pierr/41cf363f51a7b81ff44a to your computer and use it in GitHub Desktop.
offline
/*global window, i18n*/
/**
* Enregistre l'évènement de mise à jour de l'application cache.
* @return {function}
*/
module.exports = {
initialize: function() {
window.addEventListener("load", (function() {
return window.applicationCache.addEventListener("updateready", (function() {
if (window.applicationCache.status === window.applicationCache.UPDATEREADY) {
window.applicationCache.swapCache();
alert(i18n.t('application.newVersion'));
return window.location.reload();
}
}), false);
}), false);
}
};
/*global window, navigator*/
module.exports = {
//By default the property is true.
isOnline: function() {
return true;
}
};
/**
* Check the application status.
* @return {[type]} [description]
*/
function checkStatus() {
//Publish the online property.
Backbone.Mediator.publish(module.exports.isOnline() ? 'connectivity:online' : 'connectivity:offline');
}
module.exports.checkStatus = checkStatus;
if ('onLine' in navigator) {
$(window).on('online offline', checkStatus);
checkStatus();
module.exports.isOnline = function() {
return navigator.onLine === true;
}; //On publie la ppte si elle existe.
}
module.exports = {
/**
* Initialize l'ecouteur d'évènement pour la couleur de l'icone de connexion au réseau.
* @return {function}
*/
initialize: function() {
var signalIconSelector = 'header i.fa-signal';
Backbone.Mediator.subscribe('connectivity:online', (function() {
return $(signalIconSelector).css({
color: 'white'
});
}), this);
Backbone.Mediator.subscribe('connectivity:offline', (function() {
return $(signalIconSelector).css({
color: 'red'
});
}), this);
require('../../helper/connectivity').checkStatus();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment