mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-30 20:41:33 +08:00 
			
		
		
		
	hover tooltip for internal links
This commit is contained in:
		
							parent
							
								
									562a071350
								
							
						
					
					
						commit
						c4ed01128b
					
				| @ -211,6 +211,8 @@ | |||||||
|     <div id="recent-changes-dialog" title="Recent changes" style="display: none; padding: 20px;"> |     <div id="recent-changes-dialog" title="Recent changes" style="display: none; padding: 20px;"> | ||||||
|     </div> |     </div> | ||||||
| 
 | 
 | ||||||
|  |     <div id="tooltip" style="display: none;"></div> | ||||||
|  | 
 | ||||||
|     <script type="text/javascript"> |     <script type="text/javascript"> | ||||||
|       const baseApiUrl = 'api/'; |       const baseApiUrl = 'api/'; | ||||||
|     </script> |     </script> | ||||||
|  | |||||||
| @ -70,14 +70,23 @@ $(document).on('dblclick', '.note-editable a', e => { | |||||||
|     goToInternalNote(e); |     goToInternalNote(e); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | function getNoteIdFromLink(url) { | ||||||
|  |     const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(url); | ||||||
|  | 
 | ||||||
|  |     if (noteIdMatch === null) { | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         return noteIdMatch[1]; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function goToInternalNote(e, callback) { | function goToInternalNote(e, callback) { | ||||||
|     const targetUrl = $(e.target).attr("href"); |     const targetUrl = $(e.target).attr("href"); | ||||||
| 
 | 
 | ||||||
|     const noteIdMatch = /app#([A-Za-z0-9]{22})/.exec(targetUrl); |     const noteId = getNoteIdFromLink(targetUrl); | ||||||
| 
 |  | ||||||
|     if (noteIdMatch !== null) { |  | ||||||
|         const noteId = noteIdMatch[1]; |  | ||||||
| 
 | 
 | ||||||
|  |     if (noteId !== null) { | ||||||
|         getNodeByKey(noteId).setActive(); |         getNodeByKey(noteId).setActive(); | ||||||
| 
 | 
 | ||||||
|         e.preventDefault(); |         e.preventDefault(); | ||||||
|  | |||||||
| @ -106,7 +106,7 @@ function resetEncryptionSession() { | |||||||
|     globalDataKey = null; |     globalDataKey = null; | ||||||
| 
 | 
 | ||||||
|     if (globalCurrentNote.detail.encryption > 0) { |     if (globalCurrentNote.detail.encryption > 0) { | ||||||
|         loadNote(globalCurrentNote.detail.note_id); |         loadNoteToEditor(globalCurrentNote.detail.note_id); | ||||||
| 
 | 
 | ||||||
|         for (const noteId of globalAllNoteIds) { |         for (const noteId of globalAllNoteIds) { | ||||||
|             const note = getNodeByKey(noteId); |             const note = getNodeByKey(noteId); | ||||||
| @ -280,7 +280,7 @@ function encryptSubTree(noteId) { | |||||||
|         }, |         }, | ||||||
|             note => { |             note => { | ||||||
|                 if (note.detail.note_id === globalCurrentNote.detail.note_id) { |                 if (note.detail.note_id === globalCurrentNote.detail.note_id) { | ||||||
|                     loadNote(note.detail.note_id); |                     loadNoteToEditor(note.detail.note_id); | ||||||
|                 } |                 } | ||||||
|                 else { |                 else { | ||||||
|                     setTreeBasedOnEncryption(note); |                     setTreeBasedOnEncryption(note); | ||||||
| @ -307,7 +307,7 @@ function decryptSubTree(noteId) { | |||||||
|         }, |         }, | ||||||
|             note => { |             note => { | ||||||
|                 if (note.detail.note_id === globalCurrentNote.detail.note_id) { |                 if (note.detail.note_id === globalCurrentNote.detail.note_id) { | ||||||
|                     loadNote(note.detail.note_id); |                     loadNoteToEditor(note.detail.note_id); | ||||||
|                 } |                 } | ||||||
|                 else { |                 else { | ||||||
|                     setTreeBasedOnEncryption(note); |                     setTreeBasedOnEncryption(note); | ||||||
|  | |||||||
| @ -54,3 +54,30 @@ $.ui.autocomplete.filter = (array, terms) => { | |||||||
| 
 | 
 | ||||||
|     return results; |     return results; | ||||||
| }; | }; | ||||||
|  | 
 | ||||||
|  | $(document).tooltip({ | ||||||
|  |     items: ".note-editable a", | ||||||
|  |     content: function(callback) { | ||||||
|  |         const noteId = getNoteIdFromLink($(this).attr("href")); | ||||||
|  | 
 | ||||||
|  |         if (noteId !== null) { | ||||||
|  |             loadNote(noteId, note => { | ||||||
|  |                 callback(note.detail.note_text); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |     }, | ||||||
|  |     close: function(event, ui) | ||||||
|  |     { | ||||||
|  |         ui.tooltip.hover(function() | ||||||
|  |         { | ||||||
|  |             $(this).stop(true).fadeTo(400, 1); | ||||||
|  |         }, | ||||||
|  |         function() | ||||||
|  |         { | ||||||
|  |             $(this).fadeOut('400', function() | ||||||
|  |             { | ||||||
|  |                 $(this).remove(); | ||||||
|  |             }); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | }); | ||||||
| @ -191,7 +191,7 @@ function setNoteBackgroundIfEncrypted(note) { | |||||||
|     setTreeBasedOnEncryption(note); |     setTreeBasedOnEncryption(note); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function loadNote(noteId) { | function loadNoteToEditor(noteId) { | ||||||
|     $.get(baseApiUrl + 'notes/' + noteId).then(note => { |     $.get(baseApiUrl + 'notes/' + noteId).then(note => { | ||||||
|         globalCurrentNote = note; |         globalCurrentNote = note; | ||||||
| 
 | 
 | ||||||
| @ -225,8 +225,6 @@ function loadNote(noteId) { | |||||||
| 
 | 
 | ||||||
|             document.location.hash = noteId; |             document.location.hash = noteId; | ||||||
| 
 | 
 | ||||||
|             $(window).resize(); // to trigger resizing of editor
 |  | ||||||
| 
 |  | ||||||
|             addRecentNote(noteId, note.detail.note_id); |             addRecentNote(noteId, note.detail.note_id); | ||||||
| 
 | 
 | ||||||
|             noteChangeDisabled = false; |             noteChangeDisabled = false; | ||||||
| @ -235,3 +233,15 @@ function loadNote(noteId) { | |||||||
|         }); |         }); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | function loadNote(noteId, callback) { | ||||||
|  |     $.get(baseApiUrl + 'notes/' + noteId).then(note => { | ||||||
|  |         if (note.detail.encryption > 0 && !isEncryptionAvailable()) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         decryptNoteIfNecessary(note); | ||||||
|  | 
 | ||||||
|  |         callback(note); | ||||||
|  |     }); | ||||||
|  | } | ||||||
| @ -135,7 +135,7 @@ $(() => { | |||||||
|             activate: (event, data) => { |             activate: (event, data) => { | ||||||
|                 const node = data.node.data; |                 const node = data.node.data; | ||||||
| 
 | 
 | ||||||
|                 saveNoteIfChanged(() => loadNote(node.note_id)); |                 saveNoteIfChanged(() => loadNoteToEditor(node.note_id)); | ||||||
|             }, |             }, | ||||||
|             expand: (event, data) => { |             expand: (event, data) => { | ||||||
|                 setExpandedToServer(data.node.key, true); |                 setExpandedToServer(data.node.key, true); | ||||||
|  | |||||||
| @ -103,3 +103,9 @@ span.fancytree-node.encrypted.fancytree-folder > span.fancytree-icon { | |||||||
|     margin-bottom: 2px; |     margin-bottom: 2px; | ||||||
|     margin-right: 8px; |     margin-right: 8px; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | div.ui-tooltip { | ||||||
|  |     max-width: 600px; | ||||||
|  |     max-height: 600px; | ||||||
|  |     overflow: auto; | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner