2017-11-05 07:38:50 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const glob = {
|
2017-11-05 05:03:15 +08:00
|
|
|
activeDialog: null
|
|
|
|
};
|
2017-11-04 12:05:08 +08:00
|
|
|
|
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-10-10 06:53:11 +08:00
|
|
|
$(document).bind('keydown', 'alt+m', () => {
|
2017-09-23 22:18:08 +08:00
|
|
|
const toggle = $(".hide-toggle");
|
2017-10-16 08:22:18 +08:00
|
|
|
const hidden = toggle.css('visibility') === 'hidden';
|
2017-09-23 22:18:08 +08:00
|
|
|
|
2017-10-16 08:22:18 +08:00
|
|
|
toggle.css('visibility', hidden ? 'visible' : 'hidden');
|
2017-09-23 22:18:08 +08:00
|
|
|
});
|
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-10-10 06:53:11 +08:00
|
|
|
$(document).bind('keydown', 'alt+t', () => {
|
2017-08-30 11:27:28 +08:00
|
|
|
const date = new Date();
|
2017-09-27 11:23:03 +08:00
|
|
|
const dateString = formatDateTime(date);
|
2017-08-30 11:27:28 +08:00
|
|
|
|
2017-12-10 03:17:03 +08:00
|
|
|
link.addTextToEditor(dateString);
|
2017-09-04 09:34:30 +08:00
|
|
|
});
|
|
|
|
|
2017-11-17 08:43:34 +08:00
|
|
|
$(document).bind('keydown', 'f5', () => {
|
2017-11-30 12:30:35 +08:00
|
|
|
reloadApp();
|
2017-11-21 12:10:04 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).bind('keydown', 'ctrl+r', () => {
|
2017-11-30 12:30:35 +08:00
|
|
|
reloadApp();
|
2017-11-17 08:43:34 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).bind('keydown', 'ctrl+shift+i', () => {
|
|
|
|
if (isElectron()) {
|
2017-11-21 12:10:04 +08:00
|
|
|
require('electron').remote.getCurrentWindow().toggleDevTools();
|
2017-11-17 08:43:34 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-13 10:40:55 +08:00
|
|
|
|
|
|
|
$(document).bind('keydown', 'ctrl+f', () => {
|
|
|
|
if (isElectron()) {
|
|
|
|
const searchInPage = require('electron-in-page-search').default;
|
|
|
|
const remote = require('electron').remote;
|
|
|
|
|
|
|
|
const inPageSearch = searchInPage(remote.getCurrentWebContents(), { openDevToolsOfSearchWindow: true });
|
|
|
|
|
|
|
|
inPageSearch.openSearchWindow();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-10 06:53:11 +08:00
|
|
|
$(window).on('beforeunload', () => {
|
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-11-05 05:54:27 +08:00
|
|
|
noteEditor.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-10-10 06:53:11 +08:00
|
|
|
$.ui.autocomplete.filter = (array, terms) => {
|
2017-09-19 08:07:56 +08:00
|
|
|
if (!terms) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
const startDate = new Date();
|
|
|
|
|
|
|
|
const results = [];
|
|
|
|
const tokens = terms.toLowerCase().split(" ");
|
|
|
|
|
|
|
|
for (const item of array) {
|
|
|
|
let found = true;
|
2017-11-20 08:39:39 +08:00
|
|
|
const lcLabel = item.label.toLowerCase();
|
2017-09-19 08:07:56 +08:00
|
|
|
|
|
|
|
for (const token of tokens) {
|
2017-11-20 08:39:39 +08:00
|
|
|
if (lcLabel.indexOf(token) === -1) {
|
2017-09-19 08:07:56 +08:00
|
|
|
found = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
results.push(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("Search took " + (new Date().getTime() - startDate.getTime()) + "ms");
|
|
|
|
|
|
|
|
return results;
|
2017-10-12 08:37:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
$(document).tooltip({
|
2017-12-03 02:54:16 +08:00
|
|
|
items: "#note-detail a",
|
2017-10-12 08:37:27 +08:00
|
|
|
content: function(callback) {
|
2017-11-20 09:36:13 +08:00
|
|
|
const noteId = link.getNotePathFromLink($(this).attr("href"));
|
2017-10-12 08:37:27 +08:00
|
|
|
|
|
|
|
if (noteId !== null) {
|
2017-11-05 05:54:27 +08:00
|
|
|
noteEditor.loadNote(noteId).then(note => callback(note.detail.note_text));
|
2017-10-12 08:37:27 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
close: function(event, ui)
|
|
|
|
{
|
|
|
|
ui.tooltip.hover(function()
|
|
|
|
{
|
|
|
|
$(this).stop(true).fadeTo(400, 1);
|
|
|
|
},
|
|
|
|
function()
|
|
|
|
{
|
|
|
|
$(this).fadeOut('400', function()
|
|
|
|
{
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2017-10-21 11:43:20 +08:00
|
|
|
});
|
|
|
|
|
2017-11-07 11:21:11 +08:00
|
|
|
let appShown = false;
|
|
|
|
|
|
|
|
function showAppIfHidden() {
|
|
|
|
if (!appShown) {
|
|
|
|
appShown = true;
|
|
|
|
|
|
|
|
$("#container").show();
|
|
|
|
|
|
|
|
// Get a reference to the loader's div
|
|
|
|
const loaderDiv = document.getElementById("loader-wrapper");
|
|
|
|
// When the transition ends remove loader's div from display
|
|
|
|
// so that we can access the map with gestures or clicks
|
|
|
|
loaderDiv.addEventListener("transitionend", function(){
|
|
|
|
loaderDiv.style.display = "none";
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
// Kick off the CSS transition
|
|
|
|
loaderDiv.style.opacity = 0.0;
|
|
|
|
}
|
2017-12-02 11:28:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
|
|
|
const string = msg.toLowerCase();
|
|
|
|
|
|
|
|
let message = "Uncaught error: ";
|
|
|
|
|
|
|
|
if (string.indexOf("script error") > -1){
|
|
|
|
message += 'No details available';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
message += [
|
|
|
|
'Message: ' + msg,
|
|
|
|
'URL: ' + url,
|
|
|
|
'Line: ' + lineNo,
|
|
|
|
'Column: ' + columnNo,
|
|
|
|
'Error object: ' + JSON.stringify(error)
|
|
|
|
].join(' - ');
|
|
|
|
}
|
|
|
|
|
|
|
|
messaging.logError(message);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|