208 lines
5.6 KiB
JavaScript
Raw Normal View History

2020-10-10 19:26:30 -06:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var $$ = Dom7;
// Detect platform and run platform-specific setup code
// for Cordova, NW.js, or the browser
initPlatform();
var app = new Framework7({
root: "#app",
2021-01-22 12:06:20 -07:00
name: "Helena Express",
id: "com.netsyms.helenaexpress.app",
theme: "auto",
2020-10-10 19:26:30 -06:00
card: {
2022-01-19 15:33:40 -07:00
swipeToClose: false,
hideNavbarOnOpen: false,
2020-10-10 19:26:30 -06:00
},
popup: {
backdrop: true
},
popover: {
backdrop: true
},
touch: {
tapHold: true
},
2021-10-02 14:34:53 -06:00
init: false,
2020-10-10 19:26:30 -06:00
initOnDeviceReady: false,
routes: routes
});
2021-10-02 14:34:53 -06:00
var mainView = app.views.create('#view-main', {
2020-10-10 19:26:30 -06:00
url: "/",
2021-10-02 14:34:53 -06:00
animate: true,
loadInitialPage: false
2020-10-10 19:26:30 -06:00
});
var router = mainView.router;
function restartApplication() {
window.location = "index.html";
}
router.on("pageInit", function (pagedata) {
pagedata.$el.find('script').each(function (el) {
if ($$(this).attr('src')) {
var s = document.createElement('script');
s.src = $$(this).attr('src');
$$('head').append(s);
} else {
eval($$(this).text());
}
});
// Stop text selection from popping a system toolbar even after changing pages
if (window.getSelection) {
window.getSelection().removeAllRanges();
} else if (document.selection) {
document.selection.empty();
}
});
/**
* Perform back button behavior.
* Call this function whenever the equivalent to the Android back button is pressed.
* @returns {undefined}
*/
function handleBackButton() {
// Close sheet if it's open
2020-10-10 19:26:30 -06:00
if ($(".sheet-modal").hasClass("modal-in")) {
app.sheet.close();
} else if ($(".popup").hasClass("modal-in")) {
app.popup.close();
2020-10-10 19:26:30 -06:00
} else if ($(".searchbar-enabled")[0]) {
app.searchbar.disable();
} else if (scanningBarcode) {
return;
} else {
router.back({force: true, ignoreCache: true});
}
// Stop text selection from popping a system toolbar even after changing pages
if (window.getSelection) {
window.getSelection().removeAllRanges();
} else if (document.selection) {
document.selection.empty();
}
}
2021-05-08 17:36:34 -06:00
$(document).on("mousedown", ".hapticbtn,.input-clear-button,.button,.link", function () {
2021-05-08 17:10:23 -06:00
doHapticFeedback();
});
2020-10-10 19:26:30 -06:00
$(document).keyup(function (e) {
if (e.key === "Escape" || e.keyCode == 27) {
handleBackButton();
}
});
router.on("routeChange", function (newRoute) {
console.log("Info", "Navigating to ", newRoute.path);
trackPageView(newRoute.path, $("#view-main .page-current .navbar .navbar-inner .title").first().text());
2020-10-10 19:26:30 -06:00
});
function setAppTheme(theme) {
if (theme == "light") {
2021-10-02 16:03:33 -06:00
$("body").removeClass("theme-dark");
2021-01-22 19:17:19 -07:00
if (platform_type == "cordova" && typeof StatusBar !== 'undefined') {
StatusBar.backgroundColorByHexString("#e8f9fe");
2021-01-22 12:26:07 -07:00
StatusBar.styleDefault();
2020-10-10 19:26:30 -06:00
}
} else if (theme == "dark") {
2021-10-02 16:03:33 -06:00
$("body").addClass("theme-dark");
2021-01-22 19:17:19 -07:00
if (platform_type == "cordova" && typeof StatusBar !== 'undefined') {
StatusBar.backgroundColorByName("black");
2020-10-10 19:26:30 -06:00
StatusBar.styleLightContent();
}
}
}
function applyColorTheme() {
if (getStorage("apptheme") == "dark") {
setAppTheme("dark");
} else if (getStorage("apptheme") == "light") {
setAppTheme("light");
} else {
setAppTheme(appTheme);
}
}
/**
* Turn animations on or off.
* @param {boolean} on true for on, false for off.
* @returns {undefined}
*/
function toggleAnimations(on) {
if (on) {
$("#app").removeClass("no-animation");
} else {
$("#app").addClass("no-animation");
}
mainView.params.animate = on;
}
/**
* Turn animations on or off while considering user preferences.
* @param boolean enabled true to enable, false to disable, undefined to use animation=on/off setting.
* @returns {undefined}
*/
function setAnimations(enabled) {
if (getStorage("animation") == null) {
setStorage("animation", "auto");
}
if (typeof enabled !== "undefined") {
toggleAnimations(enabled == true);
return;
}
if (getStorage("animation") == "off") {
toggleAnimations(false);
} else if (getStorage("animation") == "on") {
toggleAnimations(true);
}
}
applyColorTheme();
setAnimations();
// Migrate from old to new account number storage key
if (inStorage("phonenumber") && !inStorage("accountnumber")) {
setStorage("accountnumber", getStorage("phonenumber"));
removeFromStorage("phonenumber");
}
var setup = (inStorage("accountnumber") && inStorage("accountkey")) || inStorage("setupskipped");
2021-10-02 14:34:53 -06:00
app.init();
2022-01-20 00:39:12 -07:00
if (getStorage("analytics") !== "false") {
try {
var _paq = window._paq = window._paq || [];
_paq.push(['enableLinkTracking']);
(function () {
var u = "https://analytics.netsyms.net/";
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setSiteId', '40']);
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.async = true;
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g, s);
})();
} catch (ex) {
// skip
}
} else {
console.log("Analytics code not loaded at user request.");
}
if (setup) {
router.navigate("/home");
} else {
router.navigate("/welcome", {
history: false,
pushState: false
});
}
2020-10-10 19:26:30 -06:00
document.title = SETTINGS.branding.apptitle;