2017-09-10 00:06:15 +08:00
|
|
|
// hot keys are active also inside inputs and content editables
|
2017-08-22 10:04:08 +08:00
|
|
|
jQuery.hotkeys.options.filterInputAcceptingElements = true;
|
|
|
|
jQuery.hotkeys.options.filterContentEditable = true;
|
|
|
|
|
2017-09-23 22:18:08 +08:00
|
|
|
$(document).bind('keydown', 'alt+m', 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-09-10 00:06:15 +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();
|
2017-09-27 11:23:03 +08:00
|
|
|
const dateString = formatDateTime(date);
|
2017-08-30 11:27:28 +08:00
|
|
|
|
|
|
|
$('#noteDetail').summernote('insertText', dateString);
|
2017-09-04 09:34:30 +08:00
|
|
|
});
|
|
|
|
|
2017-09-05 04:03:07 +08:00
|
|
|
$(window).on('beforeunload', function(){
|
2017-09-10 00:06:15 +08:00
|
|
|
// 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
|
2017-09-05 04:03:07 +08:00
|
|
|
saveNoteIfChanged();
|
2017-09-10 23:50:17 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Overrides the default autocomplete filter function to search for matched on atleast 1 word in each of the input term's words
|
2017-09-19 08:07:56 +08:00
|
|
|
$.ui.autocomplete.filter = function (array, terms) {
|
|
|
|
if (!terms) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
const startDate = new Date();
|
|
|
|
|
|
|
|
const results = [];
|
|
|
|
const tokens = terms.toLowerCase().split(" ");
|
|
|
|
|
|
|
|
for (const item of array) {
|
|
|
|
let found = true;
|
|
|
|
const lcValue = item.value.toLowerCase();
|
|
|
|
|
|
|
|
for (const token of tokens) {
|
|
|
|
if (lcValue.indexOf(token) === -1) {
|
|
|
|
found = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
results.push(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("Search took " + (new Date().getTime() - startDate.getTime()) + "ms");
|
|
|
|
|
|
|
|
return results;
|
2017-09-10 23:50:17 +08:00
|
|
|
};
|