Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function responseSuccess(data) {
localStorage.setItem('_echo_' + $.mobile.activePage.attr('id'), JSON.stringify(data));
console.info('Stored '+ $.mobile.activePage.attr('id')+ ' response');
}
// Check connection
function checkConnection() {
if (navigator && navigator.network && navigator.network.connection && navigator.network.connection.type) {
var networkState = navigator.network.connection.type;
if (networkState !== Connection.NONE) {
onOnline();
} else {
onOffline();
}
// When debug only (in desktop browser)
} else {
if (navigator.onLine) {
onOnline();
} else {
onOffline();
}
$('[dsid="footer"]').text('Browser mode');
console.log('We are browser mode');
}
}
// On offline
function onOffline() {
localStorage.setItem('_isOnline', 0);
console.log('We are offline');
//$('[dsid="footer"]').text('Offline');
}
// On online
function onOnline() {
localStorage.setItem('_isOnline', 1);
console.log('We are online');
//$('[dsid="footer"]').text('Online');
}
// List service execute
function executeService(service) {
checkConnection();
var currentPage = $.mobile.activePage.attr('id');
var isOnline = localStorage.getItem('_isOnline');
var service = window[service];
if (isOnline == 1) {
console.log('Working online, sending request');
service.service.__requestOptions.echo = '';
service.execute({});
} else {
console.log('Working offline, fetching localStorage data');
service.service.__requestOptions.echo = localStorage['_echo_'+currentPage] ? localStorage['_echo_'+currentPage] : '';
service.execute();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.