You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
NotePostApp/www/js/platform.js

153 lines
4.1 KiB
JavaScript

/*
* 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 platform_type = "";
var nw_tray = null;
var openBrowser = function (url) {
}
var setTrayMenu = function (items) {
}
function initCordova() {
platform_type = "cordova";
try {
eval('"use strict"; class foo {}');
} catch (e) {
alert("Your device's webview is out of date and won't work with this app. Please update it.");
}
// Handle back button to close things
document.addEventListener("backbutton", function (event) {
router.navigate("/home");
}, false);
document.addEventListener("deviceready", function () {
if (cordova.platformId == 'android') {
StatusBar.backgroundColorByHexString("#D32F2F");
StatusBar.styleLightContent();
}
}, false);
openBrowser = function (url) {
cordova.InAppBrowser.open(url, '_blank', 'location=yes');
}
}
function initNW() {
platform_type = "nw";
openBrowser = function (url) {
nw.Window.open(url, {
id: url
}, function (browserwin) {
// Add menubar so the user can navigate around if they click a link
var browsermenu = new nw.Menu({type: 'menubar'});
browsermenu.append(new nw.MenuItem({
label: "Back",
click: function () {
browserwin.window.history.back();
}
}));
browsermenu.append(new nw.MenuItem({
label: "Forward",
click: function () {
browserwin.window.history.forward();
}
}));
browsermenu.append(new nw.MenuItem({
label: "Home",
click: function () {
browserwin.window.location.href = url;
}
}));
browserwin.menu = browsermenu;
});
}
nw_tray = new nw.Tray({
title: 'NotePost',
icon: 'www/img/logo_64.png'
});
setTrayMenu = function (items) {
var menu = new nw.Menu();
menu.append(new nw.MenuItem({
type: 'normal',
label: 'Open NotePost',
click: function () {
nw.Window.get().show();
}
}));
menu.append(new nw.MenuItem({
type: 'normal',
label: 'New Note',
click: function () {
router.navigate("/editnote");
nw.Window.get().show();
}
}));
menu.append(new nw.MenuItem({
type: 'separator'
}));
if (items.length > 0) {
for (i in items) {
console.log(items[i]);
var label_max = 50;
var label = items[i].title;
if (label.length > label_max) {
label = label.substring(0, label_max) + "...";
}
menu.append(new nw.MenuItem({
type: 'normal',
label: label,
click: function (id) {
return function () {
editNote(id);
nw.Window.get().show();
}
}(items[i].id)
}));
;
}
menu.append(new nw.MenuItem({
type: 'separator'
}));
}
menu.append(new nw.MenuItem({
type: 'normal',
label: 'Exit NotePost',
click: function () {
nw.App.quit();
}
}));
nw_tray.menu = menu;
}
nw.Window.get().on('minimize', function () {
nw.Window.get().hide();
});
nw_tray.on('click', function () {
nw.Window.get().show();
});
setTrayMenu([]);
}
function initPlatform() {
if (typeof cordova !== 'undefined') {
initCordova();
} else if (typeof nw !== 'undefined') {
initNW();
}
}