all JS functions are now inside old-school JS modules, preparation for ES6 modularization

This commit is contained in:
azivner 2018-03-24 23:58:58 -04:00
parent 001a5107dd
commit b96a1274c5
4 changed files with 261 additions and 245 deletions

View File

@ -151,16 +151,16 @@ const contextMenu = (function() {
treeChanges.deleteNodes(treeService.getSelectedNodes(true));
}
else if (ui.cmd === "exportSubTree") {
exportSubTree(node.data.noteId);
exportService.exportSubTree(node.data.noteId);
}
else if (ui.cmd === "importSubTree") {
importSubTree(node.data.noteId);
exportService.importSubTree(node.data.noteId);
}
else if (ui.cmd === "collapseSubTree") {
treeService.collapseTree(node);
}
else if (ui.cmd === "forceNoteSync") {
forceNoteSync(node.data.noteId);
syncService.forceNoteSync(node.data.noteId);
}
else if (ui.cmd === "sortAlphabetically") {
treeService.sortAlphabetically(node.data.noteId);

View File

@ -1,21 +1,22 @@
"use strict";
function exportSubTree(noteId) {
const exportService = (function () {
function exportSubTree(noteId) {
const url = utils.getHost() + "/api/export/" + noteId + "?protectedSessionId="
+ encodeURIComponent(protected_session.getProtectedSessionId());
utils.download(url);
}
}
let importNoteId;
let importNoteId;
function importSubTree(noteId) {
function importSubTree(noteId) {
importNoteId = noteId;
$("#import-upload").trigger('click');
}
}
$("#import-upload").change(async function() {
$("#import-upload").change(async function() {
const formData = new FormData();
formData.append('upload', this.files[0]);
@ -29,4 +30,10 @@ $("#import-upload").change(async function() {
});
await treeService.reload();
});
});
return {
exportSubTree,
importSubTree
};
})();

View File

@ -1,47 +1,48 @@
"use strict";
// hot keys are active also inside inputs and content editables
jQuery.hotkeys.options.filterInputAcceptingElements = false;
jQuery.hotkeys.options.filterContentEditable = false;
jQuery.hotkeys.options.filterTextInputs = false;
const initService = (function() {
// hot keys are active also inside inputs and content editables
jQuery.hotkeys.options.filterInputAcceptingElements = false;
jQuery.hotkeys.options.filterContentEditable = false;
jQuery.hotkeys.options.filterTextInputs = false;
$(document).bind('keydown', 'alt+m', e => {
$(document).bind('keydown', 'alt+m', e => {
$(".hide-toggle").toggleClass("suppressed");
e.preventDefault();
});
});
// hide (toggle) everything except for the note content for distraction free writing
$(document).bind('keydown', 'alt+t', e => {
// hide (toggle) everything except for the note content for distraction free writing
$(document).bind('keydown', 'alt+t', e => {
const date = new Date();
const dateString = utils.formatDateTime(date);
link.addTextToEditor(dateString);
e.preventDefault();
});
});
$(document).bind('keydown', 'f5', () => {
$(document).bind('keydown', 'f5', () => {
utils.reloadApp();
return false;
});
});
$(document).bind('keydown', 'ctrl+r', () => {
$(document).bind('keydown', 'ctrl+r', () => {
utils.reloadApp();
return false;
});
});
$(document).bind('keydown', 'ctrl+shift+i', () => {
$(document).bind('keydown', 'ctrl+shift+i', () => {
if (utils.isElectron()) {
require('electron').remote.getCurrentWindow().toggleDevTools();
return false;
}
});
});
$(document).bind('keydown', 'ctrl+f', () => {
$(document).bind('keydown', 'ctrl+f', () => {
if (utils.isElectron()) {
const searchInPage = require('electron-in-page-search').default;
const remote = require('electron').remote;
@ -52,27 +53,27 @@ $(document).bind('keydown', 'ctrl+f', () => {
return false;
}
});
});
$(document).bind('keydown', "ctrl+shift+up", () => {
$(document).bind('keydown', "ctrl+shift+up", () => {
const node = treeService.getCurrentNode();
node.navigate($.ui.keyCode.UP, true);
$("#note-detail").focus();
return false;
});
});
$(document).bind('keydown', "ctrl+shift+down", () => {
$(document).bind('keydown', "ctrl+shift+down", () => {
const node = treeService.getCurrentNode();
node.navigate($.ui.keyCode.DOWN, true);
$("#note-detail").focus();
return false;
});
});
$(document).bind('keydown', 'ctrl+-', () => {
$(document).bind('keydown', 'ctrl+-', () => {
if (utils.isElectron()) {
const webFrame = require('electron').webFrame;
@ -82,9 +83,9 @@ $(document).bind('keydown', 'ctrl+-', () => {
return false;
}
});
});
$(document).bind('keydown', 'ctrl+=', () => {
$(document).bind('keydown', 'ctrl+=', () => {
if (utils.isElectron()) {
const webFrame = require('electron').webFrame;
@ -92,18 +93,18 @@ $(document).bind('keydown', 'ctrl+=', () => {
return false;
}
});
});
$("#note-title").bind('keydown', 'return', () => $("#note-detail").focus());
$("#note-title").bind('keydown', 'return', () => $("#note-detail").focus());
$(window).on('beforeunload', () => {
$(window).on('beforeunload', () => {
// this makes sure that when user e.g. reloads the page or navigates away from the page, the note's content is saved
// this sends the request asynchronously and doesn't wait for result
noteEditor.saveNoteIfChanged();
});
});
// Overrides the default autocomplete filter function to search for matched on atleast 1 word in each of the input term's words
$.ui.autocomplete.filter = (array, terms) => {
// Overrides the default autocomplete filter function to search for matched on atleast 1 word in each of the input term's words
$.ui.autocomplete.filter = (array, terms) => {
if (!terms) {
return array;
}
@ -146,9 +147,9 @@ $.ui.autocomplete.filter = (array, terms) => {
console.log("Search took " + (new Date().getTime() - startDate.getTime()) + "ms");
return results;
};
};
$(document).tooltip({
$(document).tooltip({
items: "#note-detail a",
content: function(callback) {
const notePath = link.getNotePathFromLink($(this).attr("href"));
@ -173,9 +174,9 @@ $(document).tooltip({
});
});
}
});
});
window.onerror = function (msg, url, lineNo, columnNo, error) {
window.onerror = function (msg, url, lineNo, columnNo, error) {
const string = msg.toLowerCase();
let message = "Uncaught error: ";
@ -196,19 +197,19 @@ window.onerror = function (msg, url, lineNo, columnNo, error) {
messaging.logError(message);
return false;
};
};
$("#logout-button").toggle(!utils.isElectron());
$("#logout-button").toggle(!utils.isElectron());
$(document).ready(() => {
$(document).ready(() => {
server.get("script/startup").then(scriptBundles => {
for (const bundle of scriptBundles) {
utils.executeBundle(bundle);
}
});
});
});
if (utils.isElectron()) {
if (utils.isElectron()) {
require('electron').ipcRenderer.on('create-day-sub-note', async function(event, parentNoteId) {
// this might occur when day note had to be created
if (!await treeService.noteExists(parentNoteId)) {
@ -223,15 +224,15 @@ if (utils.isElectron()) {
treeService.createNote(node, node.data.noteId, 'into', node.data.isProtected);
}, 500);
});
}
}
function uploadAttachment() {
function uploadAttachment() {
$("#attachment-upload").trigger('click');
}
}
$("#upload-attachment-button").click(uploadAttachment);
$("#upload-attachment-button").click(uploadAttachment);
$("#attachment-upload").change(async function() {
$("#attachment-upload").change(async function() {
const formData = new FormData();
formData.append('upload', this.files[0]);
@ -247,4 +248,5 @@ $("#attachment-upload").change(async function() {
await treeService.reload();
await treeService.activateNode(resp.noteId);
});
});
})();

View File

@ -1,6 +1,7 @@
"use strict";
async function syncNow() {
const syncService = (function() {
async function syncNow() {
const result = await server.post('sync/now');
if (result.success) {
@ -13,12 +14,18 @@ async function syncNow() {
utils.showError("Sync failed: " + result.message);
}
}
}
$("#sync-now-button").click(syncNow);
$("#sync-now-button").click(syncNow);
async function forceNoteSync(noteId) {
async function forceNoteSync(noteId) {
const result = await server.post('sync/force-note-sync/' + noteId);
utils.showMessage("Note added to sync queue.");
}
}
return {
syncNow,
forceNoteSync
};
})();