trilium/static/js/init.js

50 lines
1.7 KiB
JavaScript
Raw Normal View History

$(function() {
$(window).resize(function() {
// dynamically setting height of tree and note content to match window's height
const fancyTree = $('ul.fancytree-container');
if (fancyTree.length) {
fancyTree.height($(window).height() - fancyTree.offset().top - 10);
}
const noteEditable = $('div.note-editable');
if (noteEditable.length) {
noteEditable.height($(window).height() - noteEditable.offset().top);
}
});
$(window).resize();
});
// hot keys are active also inside inputs and content editables
jQuery.hotkeys.options.filterInputAcceptingElements = true;
jQuery.hotkeys.options.filterContentEditable = true;
$(document).bind('keydown', 'alt+h', function() {
const toggle = $(".hide-toggle");
const hidden = toggle.css('display') === 'none';
toggle.css('display', hidden ? 'block' : 'none');
$("#noteDetailWrapper").css("width", hidden ? "750px" : "100%");
2017-08-23 10:40:54 +08:00
});
2017-08-29 11:10:04 +08:00
$(document).bind('keydown', 'alt+s', function() {
$("input[name=search]").focus();
2017-08-30 11:27:28 +08:00
});
// hide (toggle) everything except for the note content for distraction free writing
2017-08-30 11:27:28 +08:00
$(document).bind('keydown', 'alt+t', function() {
const date = new Date();
const dateString = date.getDate() + ". " + (date.getMonth() + 1) + ". " + date.getFullYear() + " " +
date.getHours() + ":" + date.getMinutes();
$('#noteDetail').summernote('insertText', dateString);
2017-09-04 09:34:30 +08:00
});
$(window).on('beforeunload', function(){
// 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
saveNoteIfChanged();
});