| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | import noteDetailService from "./note_detail.js"; | 
					
						
							|  |  |  | import treeUtils from "./tree_utils.js"; | 
					
						
							|  |  |  | import linkService from "./link.js"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setupTooltip() { | 
					
						
							|  |  |  |     $(document).tooltip({ | 
					
						
							| 
									
										
										
										
											2018-07-28 17:59:55 +02:00
										 |  |  |         items: "#note-detail-wrapper a", | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |         content: function (callback) { | 
					
						
							| 
									
										
										
										
											2018-07-28 17:59:55 +02:00
										 |  |  |             let notePath = linkService.getNotePathFromLink($(this).attr("href")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (!notePath) { | 
					
						
							|  |  |  |                 notePath = $(this).attr("note-path"); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-29 18:39:10 +02:00
										 |  |  |             if (notePath) { | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |                 const noteId = treeUtils.getNoteIdFromNotePath(notePath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 16:55:20 +02:00
										 |  |  |                 noteDetailService.loadNote(noteId).then(note => { | 
					
						
							|  |  |  |                     if (!note.content.trim()) { | 
					
						
							|  |  |  |                         return; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if (note.type === 'text') { | 
					
						
							|  |  |  |                         callback(note.content); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     else if (note.type === 'code') {console.log($("<pre>").text(note.content).html()); | 
					
						
							|  |  |  |                         callback($("<pre>").text(note.content).prop('outerHTML')); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     // other types of notes don't have tooltip preview
 | 
					
						
							|  |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04: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 | 
					
						
							|  |  |  | } |