I got this code that works fine exept for the last else if.
If i’m in Home page, create a Toast and close app.
If and panel, or modal is open, back button closes.
But if i’m in other page than the home page Back Button not work, do nothing.
var mainView = app.views.create('.view-main');
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown(e) {
if (app.view.main.history.length == 1) {
app.toast.create({
text: 'Presione SALIR para cerrar la app.',
closeButton: true,
closeButtonText: 'Salir',
closeButtonColor: 'lime',
on: {
close: function () {
navigator.app.exitApp();
e.preventDefault();
},
}
}).open();
} else {
if ($$('.modal-in').length > 0) {
app.popup.close();
//return false;
} else if ($$('.card-opened').length > 0) {
app.card.close('.card-expandable');
} else if ($$('.panel-right').length > 0) {
app.panel.close();
} else if (app.view.main.history.length > 1){
mainView.router.back();
}
}
return true;
};