Skip to content

Instantly share code, notes, and snippets.

@John-Henrique
Last active February 15, 2016 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save John-Henrique/b7ecd97147604438356d to your computer and use it in GitHub Desktop.
Save John-Henrique/b7ecd97147604438356d to your computer and use it in GitHub Desktop.
Back button handle
/**
controla os eventos online, offline, backbutton
é necessário instalar o plugin
CORDOVA-PLUGIN-DIALOGS
*/
$(function(){
document.addEventListener( 'deviceready', app_init, false );
function app_init(){
//navigator.notification.alert( 'app iniciado', false, "Aviso", 'Ok' );
document.addEventListener( 'online', app_online, false );
document.addEventListener( 'offline', app_offline, false );
document.addEventListener( 'backbutton', app_backbutton, false );
document.addEventListener( 'pause', app_pause, false );
document.addEventListener( 'resume', app_resume, false );
}
function app_offline(){
phonon.alert( 'conexão não disponivel "offline"', "Falha de conexão", false, 'Ok' );
}
function app_online(){
phonon.notif( "uhuuu, a internet voltou!", 4000, false );
}
function app_backbutton(){
if( phonon.navigator().currentPage == 'home' ){
exitAppPopup();
}else{
history.back();
}
}
function app_pause(){
//navigator.notification.alert( 'app pausado "pause"', false, "Aviso", 'Ok' );
}
function app_resume(){
//phonon.notif( "Bem vindo de volta", 4000, false );
}
function exitAppPopup() {
navigator.notification.confirm(
'Sair do app?'
, function(button){
if(button == 2){
navigator.app.exitApp();
}else if( button == 3 ){
location.replace( "https://play.google.com/store/apps/details?id=com.phonegap.concursospublicos" );
}else{
}
}
, 'Sair'
, ['Não','Sim','Avaliar']
);
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment