This repository has been archived by the owner on Sep 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
72 lines (51 loc) · 2.11 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var IS_DEBUG_ENABLED = false;
mmir.ready(function () {
test_isNetworkAvailable();
//prepare app-module object for public export of functions etc.
mmir.app = {};
//initialize BACK-BUTTON handling:
initHistoryBackHandler();
//start app by triggering INIT event on dialog-engine:
mmir.dialog.raise('init');
//setup handler for BACK button (and for swipe-left gesture)
function initHistoryBackHandler() {
var isCordovaEnv = mmir.const.isCordovaEnv();
//generic BACK handler:
var backButtonHandler = function (event){
if(isCordovaEnv || ( ! isCordovaEnv && event.state)){
//FIX for browser-env.: to popstate-event is triggered not only when back-button is pressed in browser (however, in this case it seems, that the event.state is empty...)
if( ! isCordovaEnv && ! event.state){
event.preventDefault();
return false; /////////////////////////// EARLY EXIT ///////////////////////////////////
}
//let state-machine handle BACK event
// -> see config/statedef/dialogDescriptionSCXML.xml transition for back-event
mmir.dialog.raise('back', {
nativeBackButton : 'true'
});
}
else if(event){
event.preventDefault();
return false;
}
};
//register BACK-handler for environments and gesture:
if(isCordovaEnv){
//overwrite BACK-event for Android/cordova environment:
document.addEventListener("backbutton", backButtonHandler, true);
}
else {
//overwrite BACK-event in Browser environment:
window.addEventListener("popstate", backButtonHandler, true);
}
}
///////////////////////////////////////// TEST and DEBUG functions ////////////////////////////////////////
function test_isNetworkAvailable(){
// Check if a network connection is established.
if (mmir.util.checkNetworkConnection() == false){
alert("No network connection enabled.\nPlease enable network access.");
} else {
console.log("Network access is available.");
}
};
});