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 };

@ -40,4 +40,4 @@
<script src="routes.js"></script> <script src="routes.js"></script>
<script src="js/platform.js"></script> <script src="js/platform.js"></script>
<script src="js/main.js"></script> <script src="js/main.js"></script>

@ -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
@ -15,82 +14,70 @@
* returns {1: {a:1,b:2}, 3: {a:3,b:4}} * returns {1: {a:1,b:2}, 3: {a:3,b:4}}
*/ */
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: [],
addedLocal: [], addedLocal: [],
deletedRemote: [], deletedRemote: [],
deletedLocal: [], deletedLocal: [],
changedRemote: [], changedRemote: [],
changedLocal: [], changedLocal: [],
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) { // Note has no real `noteid`
if (o[i].noteid == null) { delta.addedLocal.push(o[i]);
// 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 { } else {
delta.changedRemote.push(remote[id]); oSane.push(o[i]);
} }
}
} }
} // Add notes that are only on the remote var local = mapFromArray(oSane, 'noteid');
var remote = mapFromArray(n, 'noteid');
for (var id in local) {
for (var id in remote) { if (!remote.hasOwnProperty(id)) { // Notes that are only present locally
if (!local.hasOwnProperty(id)) { delta.addedLocal.push(local[id]);
delta.addedRemote.push(remote[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]);
}
}
}
} }
}
return delta; // 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,60 +1,49 @@
"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 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") { function saveme(callback) {
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"); 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); finishSave(n, callback);
finishSave(n, 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); }
}
} }
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, } else {
ignoreCache: true, saveme(function () {
reload: true router.back({force: true, ignoreCache: true, reload: true});
}); });
} else { }
saveme(function () {
router.back({
force: true,
ignoreCache: true,
reload: true
});
});
}
} }

@ -1,105 +1,126 @@
"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();
}); });
function editNote(id) { function editNote(id) {
var note = NOTES.get(id); var note = NOTES.get(id);
router.navigate("/editnote", { router.navigate("/editnote", {
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 () {
NOTES.del(id, function () { NOTES.del(id, function () {
app.ptr.refresh(); app.ptr.refresh();
});
}); });
});
} }
$("#app").on("click", ".edit-note-btn", function () { $("#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();
}); });
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", // {
// icon: '<i class="fas fa-star fa-fw"></i>', // text: "Favorite",
// onClick: function () { // icon: '<i class="fas fa-star fa-fw"></i>',
// favoriteNote(noteid); // onClick: function () {
// } // favoriteNote(noteid);
// }, // }
// { // },
// text: "Make a List", // {
// icon: '<i class="fas fa-tasks fa-fw"></i>', // text: "Make a List",
// onClick: function () { // icon: '<i class="fas fa-tasks fa-fw"></i>',
// makeList(noteid); // onClick: function () {
// } // makeList(noteid);
// }, // }
{ // },
text: "Delete", {
icon: '<i class="fas fa-trash fa-fw"></i>', text: "Delete",
onClick: function onClick() { icon: '<i class="fas fa-trash fa-fw"></i>',
deleteNote(noteid); 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; 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 () { $(".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,74 +1,70 @@
"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",
id: "com.netsyms.NotePostApp", id: "com.netsyms.NotePostApp",
init: true, init: true,
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, 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);
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() { function restartApplication() {
window.location = "index.html"; window.location = "index.html";
} }
router.on("pageInit", function (pagedata) { router.on("pageInit", function (pagedata) {
pagedata.$el.find('script').each(function (el) { pagedata.$el.find('script').each(function (el) {
if ($$(this).attr('src')) { if ($$(this).attr('src')) {
var s = document.createElement('script'); var s = document.createElement('script');
s.src = $$(this).attr('src'); s.src = $$(this).attr('src');
$$('head').append(s); $$('head').append(s);
} else { } else {
eval($$(this).text()); eval($$(this).text());
}
});
switch (pagedata.name) {
case "settings":
updateSettingsData();
break;
} }
}); });
switch (pagedata.name) {
case "settings":
updateSettingsData();
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");
} else { } else {
createNotesObject(function (n) { createNotesObject(function (n) {
NOTES = n; NOTES = n;
router.navigate("/home"); router.navigate("/home");
}); });
} }

@ -1,39 +1,36 @@
"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());
} else {
var checkurl = localStorage.getItem("serverurl") + "/api/ping";
$.ajax({
url: checkurl,
dataType: "json",
cache: false,
method: "POST",
beforeSend: function beforeSend(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa(localStorage.getItem("username") + ":" + localStorage.getItem("password")));
},
success: function success(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 error() {
OFFLINE = true;
callback(new Notes()); 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,70 +1,71 @@
"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";
document.addEventListener("backbutton", function (event) { // Handle back button to close things
router.navigate("/home"); document.addEventListener("backbutton", function (event) {
}, false); router.navigate("/home");
document.addEventListener("deviceready", function () { }, false);
if (cordova.platformId == 'android') {
StatusBar.backgroundColorByHexString("#D32F2F"); document.addEventListener("deviceready", function () {
StatusBar.styleLightContent(); if (cordova.platformId == 'android') {
} StatusBar.backgroundColorByHexString("#D32F2F");
}, false); StatusBar.styleLightContent();
}
}, 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({
}); label: "Back",
browsermenu.append(new nw.MenuItem({ click: function () {
label: "Back", browserwin.window.history.back();
click: function click() { }
browserwin.window.history.back(); }));
} browsermenu.append(new nw.MenuItem({
})); label: "Forward",
browsermenu.append(new nw.MenuItem({ click: function () {
label: "Forward", browserwin.window.history.forward();
click: function click() { }
browserwin.window.history.forward(); }));
} browsermenu.append(new nw.MenuItem({
})); label: "Home",
browsermenu.append(new nw.MenuItem({ click: function () {
label: "Home", browserwin.window.location.href = url;
click: function click() { }
browserwin.window.location.href = url; }));
} browserwin.menu = browsermenu;
})); });
browserwin.menu = browsermenu; }
});
};
} }
function initPlatform() { function initPlatform() {
if (typeof cordova !== 'undefined') { if (typeof cordova !== 'undefined') {
initCordova(); initCordova();
} else if (typeof nw !== 'undefined') { } else if (typeof nw !== 'undefined') {
initNW(); initNW();
} }
} }

@ -1,109 +1,103 @@
"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")) {
$('#protocol-select').text("https://"); $('#protocol-select').text("https://");
} else { } else {
$('#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, ""));
$('#protocol-select').text("https://"); $('#protocol-select').text("https://");
$('#use-security').prop('checked', true); $('#use-security').prop('checked', true);
} else if ($('#url').val().toLowerCase().startsWith("http://")) { } else if ($('#url').val().toLowerCase().startsWith("http://")) {
$('#url').val($('#url').val().replace(/http\:\/\//ig, "")); $('#url').val($('#url').val().replace(/http\:\/\//ig, ""));
$('#protocol-select').text("http://"); $('#protocol-select').text("http://");
$('#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());
}); });
function checkAndSave(url, username, password, nextcloud) { function checkAndSave(url, username, password, nextcloud) {
app.preloader.show(); app.preloader.show();
if (typeof nextcloud === 'undefined') { if (typeof nextcloud === 'undefined') {
nextcloud = false; nextcloud = false;
} }
var checkurl = url + "/api/ping";
if (nextcloud) {// TODO
}
$.ajax({
url: checkurl,
dataType: "json",
cache: false,
method: "POST",
beforeSend: function beforeSend(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
},
success: function success(data) {
app.preloader.hide();
if (data.status == "OK") { var checkurl = url + "/api/ping";
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(); if (nextcloud) {
} else if (data.status == "ERROR") { // TODO
app.dialog.alert(data.msg, "Error");
} else {
app.dialog.alert("", "Error");
}
},
error: function error() {
app.preloader.hide();
app.dialog.alert("Could not sign in. Check your credentials and connection.", "Error");
} }
});
$.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() { function setupAccount() {
var type = $("#accttype").val(); var type = $("#accttype").val();
var username = $("#username").val();
var password = $("#password").val(); var username = $("#username").val();
var password = $("#password").val();
switch (type) {
case "personal": switch (type) {
checkAndSave(netsymscomurl, username, password); case "personal":
break; checkAndSave(netsymscomurl, username, password);
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
checkAndSave(url, username, password);
url = url.replace(/\/$/, ""); // Remove trailing slash break;
}
checkAndSave(url, username, password);
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": { "displayName": "NotePost",
"build": "babel js_src -d js" "version": "1.0.0",
}, "description": "A cross-platform client app for NotePost.",
"displayName": "NotePost", "author": "Netsyms Technologies",
"version": "1.0.0", "license": "MPL-2.0",
"description": "A cross-platform client app for NotePost.", "dependencies": {
"author": "Netsyms Technologies", "@fortawesome/fontawesome-free": "^5.6.3",
"license": "MPL-2.0", "easymde": "^2.4.2",
"dependencies": { "framework7": "^3.6.5",
"@babel/polyfill": "^7.2.5", "jquery": "^3.3.1",
"@fortawesome/fontawesome-free": "^5.6.3", "marked": "^0.6.0",
"easymde": "^2.4.2", "shufflejs": "^5.2.1"
"framework7": "^3.6.5", }
"jquery": "^3.3.1",
"marked": "^0.6.0",
"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