Nevermind, don't use Babel

master
Skylar Ittner 5 years ago
parent 0415de945f
commit 8dd6a9872d

1
.gitignore vendored

@ -8,3 +8,4 @@ nbproject/private/
/www/js /www/js
/yarn-error.log /yarn-error.log
/www/yarn-error.log /www/yarn-error.log
!/www/js/

@ -1,13 +0,0 @@
const presets = [
[
"@babel/env",
{
targets: {
chrome: "33",
},
useBuiltIns: "usage",
},
],
];
module.exports = { presets };

@ -1,11 +1,10 @@
"use strict";
/* /*
* The code in this file is by StackOverflow user Juan Mendes. * The code in this file is by StackOverflow user Juan Mendes.
* License: Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0). * License: Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0).
* Source: https://stackoverflow.com/a/14966749 * Source: https://stackoverflow.com/a/14966749
*/ */
/** /**
* Creates a map out of an array be choosing what property to key by * Creates a map out of an array be choosing what property to key by
* @param {object[]} array Array that will be converted into a map * @param {object[]} array Array that will be converted into a map
@ -16,20 +15,17 @@
*/ */
function mapFromArray(array, prop) { function mapFromArray(array, prop) {
var map = {}; var map = {};
for (var i = 0; i < array.length; i++) { for (var i = 0; i < array.length; i++) {
map[ array[i][prop] ] = array[i]; map[ array[i][prop] ] = array[i];
} }
return map; return map;
} }
/** /**
* @param {object[]} o old array of notes (local copy) * @param {object[]} o old array of notes (local copy)
* @param {object[]} n new array of notes (remote copy) * @param {object[]} n new array of notes (remote copy)
* @param {object} An object with changes * @param {object} An object with changes
*/ */
function getDelta(o, n) { function getDelta(o, n) {
var delta = { var delta = {
addedRemote: [], addedRemote: [],
@ -41,39 +37,31 @@ function getDelta(o, n) {
noChange: [] noChange: []
}; };
oSane = []; oSane = [];
for (var i = 0; i < o.length; i++) { for (var i = 0; i < o.length; i++) {
if (o[i].noteid == null) { if (o[i].noteid == null) { // Note has no real `noteid`
// Note has no real `noteid`
delta.addedLocal.push(o[i]); delta.addedLocal.push(o[i]);
} else { } else {
oSane.push(o[i]); oSane.push(o[i]);
} }
} }
var local = mapFromArray(oSane, 'noteid'); var local = mapFromArray(oSane, 'noteid');
var remote = mapFromArray(n, 'noteid'); var remote = mapFromArray(n, 'noteid');
for (var id in local) { for (var id in local) {
if (!remote.hasOwnProperty(id)) { if (!remote.hasOwnProperty(id)) { // Notes that are only present locally
// Notes that are only present locally delta.addedLocal.push(local[id]);
delta.addedLocal.push(local[id]); // TODO: Figure out which notes were actually added locally and which were deleted on the server // TODO: Figure out which notes were actually added locally and which were deleted on the server
/*if (local[id].norealid) { // Note hasn't been synced to the remote yet /*if (local[id].norealid) { // Note hasn't been synced to the remote yet
delta.addedLocal.push(local[id]); delta.addedLocal.push(local[id]);
} else { // Note has been synced to remote but isn't there anymore } else { // Note has been synced to remote but isn't there anymore
delta.deletedRemote.push(local[id]); delta.deletedRemote.push(local[id]);
}*/ }*/
} else { } else { // Notes that are present on both
// Notes that are present on both if (local[id].modified > remote[id].modified) { // Local copy is newer
if (local[id].modified > remote[id].modified) {
// Local copy is newer
delta.changedLocal.push(local[id]); delta.changedLocal.push(local[id]);
} else if (local[id].modified < remote[id].modified) { } else if (local[id].modified < remote[id].modified) { // Remote copy is newer
// Remote copy is newer
delta.changedRemote.push(remote[id]); delta.changedRemote.push(remote[id]);
} else { } else { // Modified date is same, let's check content
// Modified date is same, let's check content
if (local[id].content == remote[id].content) { if (local[id].content == remote[id].content) {
delta.noChange.push(local[id]); delta.noChange.push(local[id]);
} else if (local[id].content.length > remote[id].content.length) { } else if (local[id].content.length > remote[id].content.length) {
@ -83,14 +71,13 @@ function getDelta(o, n) {
} }
} }
} }
} // Add notes that are only on the remote }
// Add notes that are only on the remote
for (var id in remote) { for (var id in remote) {
if (!local.hasOwnProperty(id)) { if (!local.hasOwnProperty(id)) {
delta.addedRemote.push(remote[id]); delta.addedRemote.push(remote[id]);
} }
} }
return delta; return delta;
} }

@ -1,10 +1,9 @@
"use strict";
/* /*
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
function saveme(callback) { function saveme(callback) {
function finishSave(note, callback) { function finishSave(note, callback) {
NOTES.fixAll(); NOTES.fixAll();
@ -15,18 +14,16 @@ function saveme(callback) {
}).open(); }).open();
$("#orig_content").val(note.content); $("#orig_content").val(note.content);
}); });
if (typeof callback == "function") { if (typeof callback == "function") {
callback(); callback();
} }
} }
var noteid = $("#note_content").data("noteid"); var noteid = $("#note_content").data("noteid");
if (noteid == "") { if (noteid == "") {
var note = { var note = {
content: $("#note_content").val(), content: $("#note_content").val(),
modified: Math.round(new Date().getTime() / 1000) modified: Math.round((new Date()).getTime() / 1000)
}; };
NOTES.add(note, function (n) { NOTES.add(note, function (n) {
$("#note_content").data("noteid", n.noteid); $("#note_content").data("noteid", n.noteid);
@ -35,7 +32,7 @@ function saveme(callback) {
} else { } else {
var note = NOTES.get(noteid); var note = NOTES.get(noteid);
note.content = $("#note_content").val(); note.content = $("#note_content").val();
note.modified = Math.round(new Date().getTime() / 1000); note.modified = Math.round((new Date()).getTime() / 1000);
NOTES.set(note); NOTES.set(note);
finishSave(note, callback); finishSave(note, callback);
} }
@ -43,18 +40,10 @@ function saveme(callback) {
function exiteditor() { function exiteditor() {
if ($("#note_content").val() == "" || $("#note_content").val() === $("#orig_content").val()) { if ($("#note_content").val() == "" || $("#note_content").val() === $("#orig_content").val()) {
router.back({ router.back({force: true, ignoreCache: true, reload: true});
force: true,
ignoreCache: true,
reload: true
});
} else { } else {
saveme(function () { saveme(function () {
router.back({ router.back({force: true, ignoreCache: true, reload: true});
force: true,
ignoreCache: true,
reload: true
});
}); });
} }
} }

@ -1,10 +1,10 @@
"use strict";
/* /*
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
$(".view-main").on("ptr:refresh", ".ptr-content", function () { $(".view-main").on("ptr:refresh", ".ptr-content", function () {
restartApplication(); restartApplication();
}); });
@ -15,15 +15,19 @@ function editNote(id) {
context: { context: {
noteid: id, noteid: id,
content: note.content, content: note.content,
notetitle: note.title notetitle: note.title,
} }
}); });
console.log("Editing " + id); console.log("Editing " + id);
} }
function favoriteNote(id) {} function favoriteNote(id) {
}
function makeList(id) {} function makeList(id) {
}
function deleteNote(id) { function deleteNote(id) {
app.dialog.confirm('Are you sure?', 'Delete Note', function () { app.dialog.confirm('Are you sure?', 'Delete Note', function () {
@ -37,14 +41,17 @@ $("#app").on("click", ".edit-note-btn", function () {
editNote($(this).data("note")); editNote($(this).data("note"));
app.popover.close(); app.popover.close();
}); });
$("#app").on("click", ".favorite-note-btn", function () { $("#app").on("click", ".favorite-note-btn", function () {
favoriteNote($(this).data("note")); favoriteNote($(this).data("note"));
app.popover.close(); app.popover.close();
}); });
$("#app").on("click", ".listify-note-btn", function () { $("#app").on("click", ".listify-note-btn", function () {
makeList($(this).data("note")); makeList($(this).data("note"));
app.popover.close(); app.popover.close();
}); });
$("#app").on("click", ".delete-note-btn", function () { $("#app").on("click", ".delete-note-btn", function () {
deleteNote($(this).data("note")); deleteNote($(this).data("note"));
app.popover.close(); app.popover.close();
@ -52,17 +59,18 @@ $("#app").on("click", ".delete-note-btn", function () {
function openNoteActionMenu(notecard) { function openNoteActionMenu(notecard) {
var noteid = notecard.data("id"); var noteid = notecard.data("id");
if (window.innerWidth < 768) { if (window.innerWidth < 768) {
var actionsheet = app.actions.create({ var actionsheet = app.actions.create({
buttons: [{ buttons: [
{
text: "Edit", text: "Edit",
bold: true, bold: true,
icon: '<i class="fas fa-edit fa-fw"></i>', icon: '<i class="fas fa-edit fa-fw"></i>',
onClick: function onClick() { onClick: function () {
editNote(noteid); editNote(noteid);
} }
}, // { },
// {
// text: "Favorite", // text: "Favorite",
// icon: '<i class="fas fa-star fa-fw"></i>', // icon: '<i class="fas fa-star fa-fw"></i>',
// onClick: function () { // onClick: function () {
@ -79,27 +87,40 @@ function openNoteActionMenu(notecard) {
{ {
text: "Delete", text: "Delete",
icon: '<i class="fas fa-trash fa-fw"></i>', icon: '<i class="fas fa-trash fa-fw"></i>',
onClick: function onClick() { onClick: function () {
deleteNote(noteid); deleteNote(noteid);
} }
}] }
]
}); });
actionsheet.open(); actionsheet.open();
return false; return false;
} else { } else {
var contextPopover = app.popover.create({ var contextPopover = app.popover.create({
targetEl: notecard.children(".menubtn"), targetEl: notecard.children(".menubtn"),
content: '<div class="popover">' + '<div class="popover-inner">' + '<div class="list">' + '<ul>' + '<li><a class="list-button item-link edit-note-btn" data-note="' + noteid + '"><i class="fas fa-edit fa-fw"></i> Edit</a></li>' + '<li><a class="list-button item-link favorite-note-btn" data-note="' + noteid + '"><i class="fas fa-star fa-fw"></i> Favorite</a></li>' + '<li><a class="list-button item-link listify-note-btn" data-note="' + noteid + '"><i class="fas fa-tasks fa-fw"></i> Make a List</a></li>' + '<li><a class="list-button item-link delete-note-btn" data-note="' + noteid + '"><i class="fas fa-trash fa-fw"></i> Delete</a></li>' + '</ul>' + '</div>' + '</div>' + '</div>' content: '<div class="popover">' +
'<div class="popover-inner">' +
'<div class="list">' +
'<ul>' +
'<li><a class="list-button item-link edit-note-btn" data-note="' + noteid + '"><i class="fas fa-edit fa-fw"></i> Edit</a></li>' +
'<li><a class="list-button item-link favorite-note-btn" data-note="' + noteid + '"><i class="fas fa-star fa-fw"></i> Favorite</a></li>' +
'<li><a class="list-button item-link listify-note-btn" data-note="' + noteid + '"><i class="fas fa-tasks fa-fw"></i> Make a List</a></li>' +
'<li><a class="list-button item-link delete-note-btn" data-note="' + noteid + '"><i class="fas fa-trash fa-fw"></i> Delete</a></li>' +
'</ul>' +
'</div>' +
'</div>' +
'</div>'
}); });
contextPopover.open(); contextPopover.open();
} }
return false; return false;
} }
$(".view-main").on("click", ".notecard .menubtn", function () { $(".view-main").on("click", ".notecard .menubtn", function () {
return openNoteActionMenu($(this).parent()); return openNoteActionMenu($(this).parent());
}); });
$(".view-main").on("contextmenu", ".notecard", function () { $(".view-main").on("contextmenu", ".notecard", function () {
return openNoteActionMenu($(this)); return openNoteActionMenu($(this));
}); });

@ -1,13 +1,9 @@
"use strict";
require("core-js/modules/es6.array.find");
require("core-js/modules/es6.regexp.to-string");
/* This Source Code Form is subject to the terms of the Mozilla Public /* 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 * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var $$ = Dom7; var $$ = Dom7;
var app = new Framework7({ var app = new Framework7({
root: "#app", root: "#app",
name: "NotePost", name: "NotePost",
@ -16,26 +12,25 @@ var app = new Framework7({
initOnDeviceReady: false, initOnDeviceReady: false,
routes: routes routes: routes
}); });
var mainView = app.views.create('.view-main', { var mainView = app.views.create('.view-main', {
url: "/" url: "/"
}); });
var router = mainView.router; var router = mainView.router;
var NOTES = null; var NOTES = null;
var OFFLINE = false; var OFFLINE = false;
/** /**
* Thanks to https://stackoverflow.com/a/13542669 * Thanks to https://stackoverflow.com/a/13542669
* @param {type} color * @param {type} color
* @param {type} percent * @param {type} percent
* @returns {String} * @returns {String}
*/ */
function shadeColor2(color, percent) { function shadeColor2(color, percent) {
var f = parseInt(color.slice(1), 16), var f = parseInt(color.slice(1), 16), t = percent < 0 ? 0 : 255, p = percent < 0 ? percent * -1 : percent, R = f >> 16, G = f >> 8 & 0x00FF, B = f & 0x0000FF;
t = percent < 0 ? 0 : 255,
p = percent < 0 ? percent * -1 : percent,
R = f >> 16,
G = f >> 8 & 0x00FF,
B = f & 0x0000FF;
return "#" + (0x1000000 + (Math.round((t - R) * p) + R) * 0x10000 + (Math.round((t - G) * p) + G) * 0x100 + (Math.round((t - B) * p) + B)).toString(16).slice(1); return "#" + (0x1000000 + (Math.round((t - R) * p) + R) * 0x10000 + (Math.round((t - G) * p) + G) * 0x100 + (Math.round((t - B) * p) + B)).toString(16).slice(1);
} }
@ -53,16 +48,17 @@ router.on("pageInit", function (pagedata) {
eval($$(this).text()); eval($$(this).text());
} }
}); });
switch (pagedata.name) { switch (pagedata.name) {
case "settings": case "settings":
updateSettingsData(); updateSettingsData();
break; break;
} }
}); // Run platform-specific setup code for Cordova or NW.js });
// Run platform-specific setup code for Cordova or NW.js
initPlatform(); initPlatform();
if (localStorage.getItem("configured") == null) { if (localStorage.getItem("configured") == null) {
// Open the setup page // Open the setup page
router.navigate("/setup/0"); router.navigate("/setup/0");

@ -1,10 +1,9 @@
"use strict";
/* /*
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
function createNotesObject(callback) { function createNotesObject(callback) {
if (localStorage.getItem("serverurl") == null) { if (localStorage.getItem("serverurl") == null) {
callback(new Notes()); callback(new Notes());
@ -15,10 +14,9 @@ function createNotesObject(callback) {
dataType: "json", dataType: "json",
cache: false, cache: false,
method: "POST", method: "POST",
beforeSend: function beforeSend(xhr) { beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa(localStorage.getItem("username") + ":" + localStorage.getItem("password"))); xhr.setRequestHeader("Authorization", "Basic " + btoa(localStorage.getItem("username") + ":" + localStorage.getItem("password")));
}, }, success: function (data) {
success: function success(data) {
if (data.status == "OK") { if (data.status == "OK") {
callback(new NotePostNotes(localStorage.getItem("serverurl"), localStorage.getItem("username"), localStorage.getItem("password"))); callback(new NotePostNotes(localStorage.getItem("serverurl"), localStorage.getItem("username"), localStorage.getItem("password")));
} else if (data.status == "ERROR") { } else if (data.status == "ERROR") {
@ -29,8 +27,7 @@ function createNotesObject(callback) {
OFFLINE = true; OFFLINE = true;
callback(new Notes()); callback(new Notes());
} }
}, }, error: function () {
error: function error() {
OFFLINE = true; OFFLINE = true;
callback(new Notes()); callback(new Notes());
} }

@ -1,20 +1,23 @@
"use strict";
/* /*
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
var platform_type = ""; var platform_type = "";
var openBrowser = function openBrowser(url) {}; var openBrowser = function (url) {
}
function initCordova() { function initCordova() {
platform_type = "cordova"; // Handle back button to close things platform_type = "cordova";
// Handle back button to close things
document.addEventListener("backbutton", function (event) { document.addEventListener("backbutton", function (event) {
router.navigate("/home"); router.navigate("/home");
}, false); }, false);
document.addEventListener("deviceready", function () { document.addEventListener("deviceready", function () {
if (cordova.platformId == 'android') { if (cordova.platformId == 'android') {
StatusBar.backgroundColorByHexString("#D32F2F"); StatusBar.backgroundColorByHexString("#D32F2F");
@ -22,43 +25,41 @@ function initCordova() {
} }
}, false); }, false);
openBrowser = function openBrowser(url) { openBrowser = function (url) {
cordova.InAppBrowser.open(url, '_blank', 'location=yes'); cordova.InAppBrowser.open(url, '_blank', 'location=yes');
}; }
} }
function initNW() { function initNW() {
platform_type = "nw"; platform_type = "nw";
openBrowser = function openBrowser(url) { openBrowser = function (url) {
nw.Window.open(url, { nw.Window.open(url, {
id: url id: url
}, function (browserwin) { }, function (browserwin) {
// Add menubar so the user can navigate around if they click a link // Add menubar so the user can navigate around if they click a link
var browsermenu = new nw.Menu({ var browsermenu = new nw.Menu({type: 'menubar'});
type: 'menubar'
});
browsermenu.append(new nw.MenuItem({ browsermenu.append(new nw.MenuItem({
label: "Back", label: "Back",
click: function click() { click: function () {
browserwin.window.history.back(); browserwin.window.history.back();
} }
})); }));
browsermenu.append(new nw.MenuItem({ browsermenu.append(new nw.MenuItem({
label: "Forward", label: "Forward",
click: function click() { click: function () {
browserwin.window.history.forward(); browserwin.window.history.forward();
} }
})); }));
browsermenu.append(new nw.MenuItem({ browsermenu.append(new nw.MenuItem({
label: "Home", label: "Home",
click: function click() { click: function () {
browserwin.window.location.href = url; browserwin.window.location.href = url;
} }
})); }));
browserwin.menu = browsermenu; browserwin.menu = browsermenu;
}); });
}; }
} }
function initPlatform() { function initPlatform() {

@ -1,16 +1,14 @@
"use strict";
require("core-js/modules/es6.regexp.replace");
require("core-js/modules/es6.string.starts-with");
/* /*
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
netsymscomurl = "https://apps.netsyms.com/notepost"; netsymscomurl = "https://apps.netsyms.com/notepost";
netsymsbizurl = "https://BIZID.netsyms.biz/notepost"; netsymsbizurl = "https://BIZID.netsyms.biz/notepost";
$('#use-security-checkbox-li').click(function () { $('#use-security-checkbox-li').click(function () {
// Event fires before the checkbox is changed, so we need to do the opposite // Event fires before the checkbox is changed, so we need to do the opposite
if ($("#use-security").prop("checked")) { if ($("#use-security").prop("checked")) {
@ -19,8 +17,8 @@ $('#use-security-checkbox-li').click(function () {
$('#protocol-select').text("http://"); $('#protocol-select').text("http://");
} }
}); });
/* Detect if the user typed "http[s]://" into the URL box and correct for it */
/* Detect if the user typed "http[s]://" into the URL box and correct for it */
$("#url").blur(function () { $("#url").blur(function () {
if ($('#url').val().toLowerCase().startsWith("https://")) { if ($('#url').val().toLowerCase().startsWith("https://")) {
$('#url').val($('#url').val().replace(/https\:\/\//ig, "")); $('#url').val($('#url').val().replace(/https\:\/\//ig, ""));
@ -32,6 +30,7 @@ $("#url").blur(function () {
$('#use-security').prop('checked', false); $('#use-security').prop('checked', false);
} }
}); });
$('#username').on("keyup", function () { $('#username').on("keyup", function () {
$('#username').val($('#username').val().toLowerCase()); $('#username').val($('#username').val().toLowerCase());
}); });
@ -45,7 +44,8 @@ function checkAndSave(url, username, password, nextcloud) {
var checkurl = url + "/api/ping"; var checkurl = url + "/api/ping";
if (nextcloud) {// TODO if (nextcloud) {
// TODO
} }
$.ajax({ $.ajax({
@ -53,26 +53,23 @@ function checkAndSave(url, username, password, nextcloud) {
dataType: "json", dataType: "json",
cache: false, cache: false,
method: "POST", method: "POST",
beforeSend: function beforeSend(xhr) { beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password)); xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
}, }, success: function (data) {
success: function success(data) {
app.preloader.hide(); app.preloader.hide();
if (data.status == "OK") { if (data.status == "OK") {
localStorage.setItem("username", username); localStorage.setItem("username", username);
localStorage.setItem("password", password); localStorage.setItem("password", password);
localStorage.setItem("serverurl", url); localStorage.setItem("serverurl", url);
localStorage.setItem("configured", true); // Restart the app to re-read the config localStorage.setItem("configured", true);
// Restart the app to re-read the config
restartApplication(); restartApplication();
} else if (data.status == "ERROR") { } else if (data.status == "ERROR") {
app.dialog.alert(data.msg, "Error"); app.dialog.alert(data.msg, "Error");
} else { } else {
app.dialog.alert("", "Error"); app.dialog.alert("", "Error");
} }
}, }, error: function () {
error: function error() {
app.preloader.hide(); app.preloader.hide();
app.dialog.alert("Could not sign in. Check your credentials and connection.", "Error"); app.dialog.alert("Could not sign in. Check your credentials and connection.", "Error");
} }
@ -81,6 +78,7 @@ function checkAndSave(url, username, password, nextcloud) {
function setupAccount() { function setupAccount() {
var type = $("#accttype").val(); var type = $("#accttype").val();
var username = $("#username").val(); var username = $("#username").val();
var password = $("#password").val(); var password = $("#password").val();
@ -88,21 +86,17 @@ function setupAccount() {
case "personal": case "personal":
checkAndSave(netsymscomurl, username, password); checkAndSave(netsymscomurl, username, password);
break; break;
case "business": case "business":
var url = netsymsbizurl.replace("BIZID", $("#bizid").val()); var url = netsymsbizurl.replace("BIZID", $("#bizid").val());
checkAndSave(url, username, password); checkAndSave(url, username, password);
break; break;
case "selfhosted": case "selfhosted":
if (/^(https?:\/\/)/.test($('#url').val())) { if (/^(https?:\/\/)/.test($('#url').val())) {
var url = $('#url').val(); var url = $('#url').val();
} else { } else {
var url = $('#protocol-select').text() + $('#url').val(); var url = $('#protocol-select').text() + $('#url').val();
} }
url = url.replace(/\/$/, ""); // Remove trailing slash url = url.replace(/\/$/, ""); // Remove trailing slash
checkAndSave(url, username, password); checkAndSave(url, username, password);
break; break;
} }

@ -1,83 +0,0 @@
/*
* The code in this file is by StackOverflow user Juan Mendes.
* License: Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0).
* Source: https://stackoverflow.com/a/14966749
*/
/**
* Creates a map out of an array be choosing what property to key by
* @param {object[]} array Array that will be converted into a map
* @param {string} prop Name of property to key by
* @return {object} The mapped array. Example:
* mapFromArray([{a:1,b:2}, {a:3,b:4}], 'a')
* returns {1: {a:1,b:2}, 3: {a:3,b:4}}
*/
function mapFromArray(array, prop) {
var map = {};
for (var i = 0; i < array.length; i++) {
map[ array[i][prop] ] = array[i];
}
return map;
}
/**
* @param {object[]} o old array of notes (local copy)
* @param {object[]} n new array of notes (remote copy)
* @param {object} An object with changes
*/
function getDelta(o, n) {
var delta = {
addedRemote: [],
addedLocal: [],
deletedRemote: [],
deletedLocal: [],
changedRemote: [],
changedLocal: [],
noChange: []
};
oSane = [];
for (var i = 0; i < o.length; i++) {
if (o[i].noteid == null) { // Note has no real `noteid`
delta.addedLocal.push(o[i]);
} else {
oSane.push(o[i]);
}
}
var local = mapFromArray(oSane, 'noteid');
var remote = mapFromArray(n, 'noteid');
for (var id in local) {
if (!remote.hasOwnProperty(id)) { // Notes that are only present locally
delta.addedLocal.push(local[id]);
// TODO: Figure out which notes were actually added locally and which were deleted on the server
/*if (local[id].norealid) { // Note hasn't been synced to the remote yet
delta.addedLocal.push(local[id]);
} else { // Note has been synced to remote but isn't there anymore
delta.deletedRemote.push(local[id]);
}*/
} else { // Notes that are present on both
if (local[id].modified > remote[id].modified) { // Local copy is newer
delta.changedLocal.push(local[id]);
} else if (local[id].modified < remote[id].modified) { // Remote copy is newer
delta.changedRemote.push(remote[id]);
} else { // Modified date is same, let's check content
if (local[id].content == remote[id].content) {
delta.noChange.push(local[id]);
} else if (local[id].content.length > remote[id].content.length) {
delta.changedLocal.push(local[id]);
} else {
delta.changedRemote.push(remote[id]);
}
}
}
}
// Add notes that are only on the remote
for (var id in remote) {
if (!local.hasOwnProperty(id)) {
delta.addedRemote.push(remote[id]);
}
}
return delta;
}

@ -1,49 +0,0 @@
/*
* 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/.
*/
function saveme(callback) {
function finishSave(note, callback) {
NOTES.fixAll();
NOTES.sync(function () {
app.toast.create({
text: 'Note saved.',
closeTimeout: 2000
}).open();
$("#orig_content").val(note.content);
});
if (typeof callback == "function") {
callback();
}
}
var noteid = $("#note_content").data("noteid");
if (noteid == "") {
var note = {
content: $("#note_content").val(),
modified: Math.round((new Date()).getTime() / 1000)
};
NOTES.add(note, function (n) {
$("#note_content").data("noteid", n.noteid);
finishSave(n, callback);
});
} else {
var note = NOTES.get(noteid);
note.content = $("#note_content").val();
note.modified = Math.round((new Date()).getTime() / 1000);
NOTES.set(note);
finishSave(note, callback);
}
}
function exiteditor() {
if ($("#note_content").val() == "" || $("#note_content").val() === $("#orig_content").val()) {
router.back({force: true, ignoreCache: true, reload: true});
} else {
saveme(function () {
router.back({force: true, ignoreCache: true, reload: true});
});
}
}

@ -1,126 +0,0 @@
/*
* 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/.
*/
$(".view-main").on("ptr:refresh", ".ptr-content", function () {
restartApplication();
});
function editNote(id) {
var note = NOTES.get(id);
router.navigate("/editnote", {
context: {
noteid: id,
content: note.content,
notetitle: note.title,
}
});
console.log("Editing " + id);
}
function favoriteNote(id) {
}
function makeList(id) {
}
function deleteNote(id) {
app.dialog.confirm('Are you sure?', 'Delete Note', function () {
NOTES.del(id, function () {
app.ptr.refresh();
});
});
}
$("#app").on("click", ".edit-note-btn", function () {
editNote($(this).data("note"));
app.popover.close();
});
$("#app").on("click", ".favorite-note-btn", function () {
favoriteNote($(this).data("note"));
app.popover.close();
});
$("#app").on("click", ".listify-note-btn", function () {
makeList($(this).data("note"));
app.popover.close();
});
$("#app").on("click", ".delete-note-btn", function () {
deleteNote($(this).data("note"));
app.popover.close();
});
function openNoteActionMenu(notecard) {
var noteid = notecard.data("id");
if (window.innerWidth < 768) {
var actionsheet = app.actions.create({
buttons: [
{
text: "Edit",
bold: true,
icon: '<i class="fas fa-edit fa-fw"></i>',
onClick: function () {
editNote(noteid);
}
},
// {
// text: "Favorite",
// icon: '<i class="fas fa-star fa-fw"></i>',
// onClick: function () {
// favoriteNote(noteid);
// }
// },
// {
// text: "Make a List",
// icon: '<i class="fas fa-tasks fa-fw"></i>',
// onClick: function () {
// makeList(noteid);
// }
// },
{
text: "Delete",
icon: '<i class="fas fa-trash fa-fw"></i>',
onClick: function () {
deleteNote(noteid);
}
}
]
});
actionsheet.open();
return false;
} else {
var contextPopover = app.popover.create({
targetEl: notecard.children(".menubtn"),
content: '<div class="popover">' +
'<div class="popover-inner">' +
'<div class="list">' +
'<ul>' +
'<li><a class="list-button item-link edit-note-btn" data-note="' + noteid + '"><i class="fas fa-edit fa-fw"></i> Edit</a></li>' +
'<li><a class="list-button item-link favorite-note-btn" data-note="' + noteid + '"><i class="fas fa-star fa-fw"></i> Favorite</a></li>' +
'<li><a class="list-button item-link listify-note-btn" data-note="' + noteid + '"><i class="fas fa-tasks fa-fw"></i> Make a List</a></li>' +
'<li><a class="list-button item-link delete-note-btn" data-note="' + noteid + '"><i class="fas fa-trash fa-fw"></i> Delete</a></li>' +
'</ul>' +
'</div>' +
'</div>' +
'</div>'
});
contextPopover.open();
}
return false;
}
$(".view-main").on("click", ".notecard .menubtn", function () {
return openNoteActionMenu($(this).parent());
});
$(".view-main").on("contextmenu", ".notecard", function () {
return openNoteActionMenu($(this));
});

@ -1,70 +0,0 @@
/* 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;
var app = new Framework7({
root: "#app",
name: "NotePost",
id: "com.netsyms.NotePostApp",
init: true,
initOnDeviceReady: false,
routes: routes
});
var mainView = app.views.create('.view-main', {
url: "/"
});
var router = mainView.router;
var NOTES = null;
var OFFLINE = false;
/**
* Thanks to https://stackoverflow.com/a/13542669
* @param {type} color
* @param {type} percent
* @returns {String}
*/
function shadeColor2(color, percent) {
var f = parseInt(color.slice(1), 16), t = percent < 0 ? 0 : 255, p = percent < 0 ? percent * -1 : percent, R = f >> 16, G = f >> 8 & 0x00FF, B = f & 0x0000FF;
return "#" + (0x1000000 + (Math.round((t - R) * p) + R) * 0x10000 + (Math.round((t - G) * p) + G) * 0x100 + (Math.round((t - B) * p) + B)).toString(16).slice(1);
}
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());
}
});
switch (pagedata.name) {
case "settings":
updateSettingsData();
break;
}
});
// Run platform-specific setup code for Cordova or NW.js
initPlatform();
if (localStorage.getItem("configured") == null) {
// Open the setup page
router.navigate("/setup/0");
} else {
createNotesObject(function (n) {
NOTES = n;
router.navigate("/home");
});
}

@ -1,36 +0,0 @@
/*
* 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/.
*/
function createNotesObject(callback) {
if (localStorage.getItem("serverurl") == null) {
callback(new Notes());
} else {
var checkurl = localStorage.getItem("serverurl") + "/api/ping";
$.ajax({
url: checkurl,
dataType: "json",
cache: false,
method: "POST",
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa(localStorage.getItem("username") + ":" + localStorage.getItem("password")));
}, success: function (data) {
if (data.status == "OK") {
callback(new NotePostNotes(localStorage.getItem("serverurl"), localStorage.getItem("username"), localStorage.getItem("password")));
} else if (data.status == "ERROR") {
app.dialog.alert(data.msg, "Error");
OFFLINE = true;
callback(new Notes());
} else {
OFFLINE = true;
callback(new Notes());
}
}, error: function () {
OFFLINE = true;
callback(new Notes());
}
});
}
}

@ -1,71 +0,0 @@
/*
* 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 openBrowser = function (url) {
}
function initCordova() {
platform_type = "cordova";
// 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;
});
}
}
function initPlatform() {
if (typeof cordova !== 'undefined') {
initCordova();
} else if (typeof nw !== 'undefined') {
initNW();
}
}

@ -1,103 +0,0 @@
/*
* 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/.
*/
netsymscomurl = "https://apps.netsyms.com/notepost";
netsymsbizurl = "https://BIZID.netsyms.biz/notepost";
$('#use-security-checkbox-li').click(function () {
// Event fires before the checkbox is changed, so we need to do the opposite
if ($("#use-security").prop("checked")) {
$('#protocol-select').text("https://");
} else {
$('#protocol-select').text("http://");
}
});
/* Detect if the user typed "http[s]://" into the URL box and correct for it */
$("#url").blur(function () {
if ($('#url').val().toLowerCase().startsWith("https://")) {
$('#url').val($('#url').val().replace(/https\:\/\//ig, ""));
$('#protocol-select').text("https://");
$('#use-security').prop('checked', true);
} else if ($('#url').val().toLowerCase().startsWith("http://")) {
$('#url').val($('#url').val().replace(/http\:\/\//ig, ""));
$('#protocol-select').text("http://");
$('#use-security').prop('checked', false);
}
});
$('#username').on("keyup", function () {
$('#username').val($('#username').val().toLowerCase());
});
function checkAndSave(url, username, password, nextcloud) {
app.preloader.show();
if (typeof nextcloud === 'undefined') {
nextcloud = false;
}
var checkurl = url + "/api/ping";
if (nextcloud) {
// TODO
}
$.ajax({
url: checkurl,
dataType: "json",
cache: false,
method: "POST",
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
}, success: function (data) {
app.preloader.hide();
if (data.status == "OK") {
localStorage.setItem("username", username);
localStorage.setItem("password", password);
localStorage.setItem("serverurl", url);
localStorage.setItem("configured", true);
// Restart the app to re-read the config
restartApplication();
} else if (data.status == "ERROR") {
app.dialog.alert(data.msg, "Error");
} else {
app.dialog.alert("", "Error");
}
}, error: function () {
app.preloader.hide();
app.dialog.alert("Could not sign in. Check your credentials and connection.", "Error");
}
});
}
function setupAccount() {
var type = $("#accttype").val();
var username = $("#username").val();
var password = $("#password").val();
switch (type) {
case "personal":
checkAndSave(netsymscomurl, username, password);
break;
case "business":
var url = netsymsbizurl.replace("BIZID", $("#bizid").val());
checkAndSave(url, username, password);
break;
case "selfhosted":
if (/^(https?:\/\/)/.test($('#url').val())) {
var url = $('#url').val();
} else {
var url = $('#protocol-select').text() + $('#url').val();
}
url = url.replace(/\/$/, ""); // Remove trailing slash
checkAndSave(url, username, password);
break;
}
}

@ -1,25 +1,16 @@
{ {
"name": "com.netsyms.NotePostApp", "name": "com.netsyms.NotePostApp",
"scripts": {
"build": "babel js_src -d js"
},
"displayName": "NotePost", "displayName": "NotePost",
"version": "1.0.0", "version": "1.0.0",
"description": "A cross-platform client app for NotePost.", "description": "A cross-platform client app for NotePost.",
"author": "Netsyms Technologies", "author": "Netsyms Technologies",
"license": "MPL-2.0", "license": "MPL-2.0",
"dependencies": { "dependencies": {
"@babel/polyfill": "^7.2.5",
"@fortawesome/fontawesome-free": "^5.6.3", "@fortawesome/fontawesome-free": "^5.6.3",
"easymde": "^2.4.2", "easymde": "^2.4.2",
"framework7": "^3.6.5", "framework7": "^3.6.5",
"jquery": "^3.3.1", "jquery": "^3.3.1",
"marked": "^0.6.0", "marked": "^0.6.0",
"shufflejs": "^5.2.1" "shufflejs": "^5.2.1"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3"
} }
} }

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save