2018-03-27 10:29:14 +08:00
|
|
|
import noteDetailService from "./note_detail.js";
|
|
|
|
import treeUtils from "./tree_utils.js";
|
|
|
|
import linkService from "./link.js";
|
|
|
|
|
|
|
|
function setupTooltip() {
|
|
|
|
$(document).tooltip({
|
2018-08-07 17:38:00 +08:00
|
|
|
items: "body a",
|
2018-03-27 10:29:14 +08:00
|
|
|
content: function (callback) {
|
2018-07-28 23:59:55 +08:00
|
|
|
let notePath = linkService.getNotePathFromLink($(this).attr("href"));
|
|
|
|
|
|
|
|
if (!notePath) {
|
|
|
|
notePath = $(this).attr("note-path");
|
|
|
|
}
|
2018-03-27 10:29:14 +08:00
|
|
|
|
2018-07-30 00:39:10 +08:00
|
|
|
if (notePath) {
|
2018-03-27 10:29:14 +08:00
|
|
|
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
|
|
|
|
2018-07-30 22:55:20 +08:00
|
|
|
noteDetailService.loadNote(noteId).then(note => {
|
|
|
|
if (!note.content.trim()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (note.type === 'text') {
|
|
|
|
callback(note.content);
|
|
|
|
}
|
2018-08-06 02:48:56 +08:00
|
|
|
else if (note.type === 'code') {
|
2018-07-30 22:55:20 +08:00
|
|
|
callback($("<pre>").text(note.content).prop('outerHTML'));
|
|
|
|
}
|
|
|
|
// other types of notes don't have tooltip preview
|
|
|
|
});
|
2018-03-27 10:29:14 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
close: function (event, ui) {
|
|
|
|
ui.tooltip.hover(function () {
|
|
|
|
$(this).stop(true).fadeTo(400, 1);
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
$(this).fadeOut('400', function () {
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
setupTooltip
|
|
|
|
}
|