mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
all JS functions are now inside old-school JS modules, preparation for ES6 modularization
This commit is contained in:
parent
001a5107dd
commit
b96a1274c5
@ -151,16 +151,16 @@ const contextMenu = (function() {
|
|||||||
treeChanges.deleteNodes(treeService.getSelectedNodes(true));
|
treeChanges.deleteNodes(treeService.getSelectedNodes(true));
|
||||||
}
|
}
|
||||||
else if (ui.cmd === "exportSubTree") {
|
else if (ui.cmd === "exportSubTree") {
|
||||||
exportSubTree(node.data.noteId);
|
exportService.exportSubTree(node.data.noteId);
|
||||||
}
|
}
|
||||||
else if (ui.cmd === "importSubTree") {
|
else if (ui.cmd === "importSubTree") {
|
||||||
importSubTree(node.data.noteId);
|
exportService.importSubTree(node.data.noteId);
|
||||||
}
|
}
|
||||||
else if (ui.cmd === "collapseSubTree") {
|
else if (ui.cmd === "collapseSubTree") {
|
||||||
treeService.collapseTree(node);
|
treeService.collapseTree(node);
|
||||||
}
|
}
|
||||||
else if (ui.cmd === "forceNoteSync") {
|
else if (ui.cmd === "forceNoteSync") {
|
||||||
forceNoteSync(node.data.noteId);
|
syncService.forceNoteSync(node.data.noteId);
|
||||||
}
|
}
|
||||||
else if (ui.cmd === "sortAlphabetically") {
|
else if (ui.cmd === "sortAlphabetically") {
|
||||||
treeService.sortAlphabetically(node.data.noteId);
|
treeService.sortAlphabetically(node.data.noteId);
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function exportSubTree(noteId) {
|
const exportService = (function () {
|
||||||
|
function exportSubTree(noteId) {
|
||||||
const url = utils.getHost() + "/api/export/" + noteId + "?protectedSessionId="
|
const url = utils.getHost() + "/api/export/" + noteId + "?protectedSessionId="
|
||||||
+ encodeURIComponent(protected_session.getProtectedSessionId());
|
+ encodeURIComponent(protected_session.getProtectedSessionId());
|
||||||
|
|
||||||
utils.download(url);
|
utils.download(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
let importNoteId;
|
let importNoteId;
|
||||||
|
|
||||||
function importSubTree(noteId) {
|
function importSubTree(noteId) {
|
||||||
importNoteId = noteId;
|
importNoteId = noteId;
|
||||||
|
|
||||||
$("#import-upload").trigger('click');
|
$("#import-upload").trigger('click');
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#import-upload").change(async function() {
|
$("#import-upload").change(async function() {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('upload', this.files[0]);
|
formData.append('upload', this.files[0]);
|
||||||
|
|
||||||
@ -29,4 +30,10 @@ $("#import-upload").change(async function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await treeService.reload();
|
await treeService.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
exportSubTree,
|
||||||
|
importSubTree
|
||||||
|
};
|
||||||
|
})();
|
@ -1,47 +1,48 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// hot keys are active also inside inputs and content editables
|
const initService = (function() {
|
||||||
jQuery.hotkeys.options.filterInputAcceptingElements = false;
|
// hot keys are active also inside inputs and content editables
|
||||||
jQuery.hotkeys.options.filterContentEditable = false;
|
jQuery.hotkeys.options.filterInputAcceptingElements = false;
|
||||||
jQuery.hotkeys.options.filterTextInputs = 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");
|
$(".hide-toggle").toggleClass("suppressed");
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
// hide (toggle) everything except for the note content for distraction free writing
|
// hide (toggle) everything except for the note content for distraction free writing
|
||||||
$(document).bind('keydown', 'alt+t', e => {
|
$(document).bind('keydown', 'alt+t', e => {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const dateString = utils.formatDateTime(date);
|
const dateString = utils.formatDateTime(date);
|
||||||
|
|
||||||
link.addTextToEditor(dateString);
|
link.addTextToEditor(dateString);
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).bind('keydown', 'f5', () => {
|
$(document).bind('keydown', 'f5', () => {
|
||||||
utils.reloadApp();
|
utils.reloadApp();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).bind('keydown', 'ctrl+r', () => {
|
$(document).bind('keydown', 'ctrl+r', () => {
|
||||||
utils.reloadApp();
|
utils.reloadApp();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).bind('keydown', 'ctrl+shift+i', () => {
|
$(document).bind('keydown', 'ctrl+shift+i', () => {
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
require('electron').remote.getCurrentWindow().toggleDevTools();
|
require('electron').remote.getCurrentWindow().toggleDevTools();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).bind('keydown', 'ctrl+f', () => {
|
$(document).bind('keydown', 'ctrl+f', () => {
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
const searchInPage = require('electron-in-page-search').default;
|
const searchInPage = require('electron-in-page-search').default;
|
||||||
const remote = require('electron').remote;
|
const remote = require('electron').remote;
|
||||||
@ -52,27 +53,27 @@ $(document).bind('keydown', 'ctrl+f', () => {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).bind('keydown', "ctrl+shift+up", () => {
|
$(document).bind('keydown', "ctrl+shift+up", () => {
|
||||||
const node = treeService.getCurrentNode();
|
const node = treeService.getCurrentNode();
|
||||||
node.navigate($.ui.keyCode.UP, true);
|
node.navigate($.ui.keyCode.UP, true);
|
||||||
|
|
||||||
$("#note-detail").focus();
|
$("#note-detail").focus();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).bind('keydown', "ctrl+shift+down", () => {
|
$(document).bind('keydown', "ctrl+shift+down", () => {
|
||||||
const node = treeService.getCurrentNode();
|
const node = treeService.getCurrentNode();
|
||||||
node.navigate($.ui.keyCode.DOWN, true);
|
node.navigate($.ui.keyCode.DOWN, true);
|
||||||
|
|
||||||
$("#note-detail").focus();
|
$("#note-detail").focus();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).bind('keydown', 'ctrl+-', () => {
|
$(document).bind('keydown', 'ctrl+-', () => {
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
const webFrame = require('electron').webFrame;
|
const webFrame = require('electron').webFrame;
|
||||||
|
|
||||||
@ -82,9 +83,9 @@ $(document).bind('keydown', 'ctrl+-', () => {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).bind('keydown', 'ctrl+=', () => {
|
$(document).bind('keydown', 'ctrl+=', () => {
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
const webFrame = require('electron').webFrame;
|
const webFrame = require('electron').webFrame;
|
||||||
|
|
||||||
@ -92,18 +93,18 @@ $(document).bind('keydown', 'ctrl+=', () => {
|
|||||||
|
|
||||||
return false;
|
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 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
|
// this sends the request asynchronously and doesn't wait for result
|
||||||
noteEditor.saveNoteIfChanged();
|
noteEditor.saveNoteIfChanged();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Overrides the default autocomplete filter function to search for matched on atleast 1 word in each of the input term's words
|
// 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) => {
|
$.ui.autocomplete.filter = (array, terms) => {
|
||||||
if (!terms) {
|
if (!terms) {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
@ -146,9 +147,9 @@ $.ui.autocomplete.filter = (array, terms) => {
|
|||||||
console.log("Search took " + (new Date().getTime() - startDate.getTime()) + "ms");
|
console.log("Search took " + (new Date().getTime() - startDate.getTime()) + "ms");
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).tooltip({
|
$(document).tooltip({
|
||||||
items: "#note-detail a",
|
items: "#note-detail a",
|
||||||
content: function(callback) {
|
content: function(callback) {
|
||||||
const notePath = link.getNotePathFromLink($(this).attr("href"));
|
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();
|
const string = msg.toLowerCase();
|
||||||
|
|
||||||
let message = "Uncaught error: ";
|
let message = "Uncaught error: ";
|
||||||
@ -196,19 +197,19 @@ window.onerror = function (msg, url, lineNo, columnNo, error) {
|
|||||||
messaging.logError(message);
|
messaging.logError(message);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
$("#logout-button").toggle(!utils.isElectron());
|
$("#logout-button").toggle(!utils.isElectron());
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
server.get("script/startup").then(scriptBundles => {
|
server.get("script/startup").then(scriptBundles => {
|
||||||
for (const bundle of scriptBundles) {
|
for (const bundle of scriptBundles) {
|
||||||
utils.executeBundle(bundle);
|
utils.executeBundle(bundle);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
require('electron').ipcRenderer.on('create-day-sub-note', async function(event, parentNoteId) {
|
require('electron').ipcRenderer.on('create-day-sub-note', async function(event, parentNoteId) {
|
||||||
// this might occur when day note had to be created
|
// this might occur when day note had to be created
|
||||||
if (!await treeService.noteExists(parentNoteId)) {
|
if (!await treeService.noteExists(parentNoteId)) {
|
||||||
@ -223,15 +224,15 @@ if (utils.isElectron()) {
|
|||||||
treeService.createNote(node, node.data.noteId, 'into', node.data.isProtected);
|
treeService.createNote(node, node.data.noteId, 'into', node.data.isProtected);
|
||||||
}, 500);
|
}, 500);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadAttachment() {
|
function uploadAttachment() {
|
||||||
$("#attachment-upload").trigger('click');
|
$("#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();
|
const formData = new FormData();
|
||||||
formData.append('upload', this.files[0]);
|
formData.append('upload', this.files[0]);
|
||||||
|
|
||||||
@ -247,4 +248,5 @@ $("#attachment-upload").change(async function() {
|
|||||||
await treeService.reload();
|
await treeService.reload();
|
||||||
|
|
||||||
await treeService.activateNode(resp.noteId);
|
await treeService.activateNode(resp.noteId);
|
||||||
});
|
});
|
||||||
|
})();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
async function syncNow() {
|
const syncService = (function() {
|
||||||
|
async function syncNow() {
|
||||||
const result = await server.post('sync/now');
|
const result = await server.post('sync/now');
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
@ -13,12 +14,18 @@ async function syncNow() {
|
|||||||
|
|
||||||
utils.showError("Sync failed: " + result.message);
|
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);
|
const result = await server.post('sync/force-note-sync/' + noteId);
|
||||||
|
|
||||||
utils.showMessage("Note added to sync queue.");
|
utils.showMessage("Note added to sync queue.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
syncNow,
|
||||||
|
forceNoteSync
|
||||||
|
};
|
||||||
|
})();
|
Loading…
x
Reference in New Issue
Block a user