| 
									
										
										
										
											2017-11-04 19:38:50 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 17:07:03 -04:00
										 |  |  | const link = (function() { | 
					
						
							|  |  |  |     function getNoteIdFromLink(url) { | 
					
						
							| 
									
										
										
										
											2017-11-19 08:47:22 -05:00
										 |  |  |         const noteIdMatch = /app#([A-Za-z0-9]+)$/.exec(url); | 
					
						
							| 
									
										
										
										
											2017-11-04 17:07:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (noteIdMatch === null) { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             return noteIdMatch[1]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function getNodeIdFromLabel(label) { | 
					
						
							| 
									
										
										
										
											2017-11-19 08:47:22 -05:00
										 |  |  |         const noteIdMatch = / \(([A-Za-z0-9]+)\)/.exec(label); | 
					
						
							| 
									
										
										
										
											2017-11-04 17:07:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (noteIdMatch !== null) { | 
					
						
							|  |  |  |             return noteIdMatch[1]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function createNoteLink(noteId) { | 
					
						
							|  |  |  |         const noteLink = $("<a>", { | 
					
						
							|  |  |  |             href: 'javascript:', | 
					
						
							| 
									
										
										
										
											2017-11-04 22:18:36 -04:00
										 |  |  |             text: treeUtils.getFullName(noteId) | 
					
						
							| 
									
										
										
										
											2017-11-04 17:07:03 -04:00
										 |  |  |         }).attr('action', 'note') | 
					
						
							|  |  |  |             .attr('note-id', noteId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return noteLink; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function goToInternalNote(e) { | 
					
						
							|  |  |  |         const linkEl = $(e.target); | 
					
						
							|  |  |  |         let noteId = linkEl.attr("note-id"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!noteId) { | 
					
						
							|  |  |  |             noteId = getNoteIdFromLink(linkEl.attr('href')); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (noteId) { | 
					
						
							| 
									
										
										
										
											2017-11-19 08:47:22 -05:00
										 |  |  |             noteTree.activateNode(noteId); | 
					
						
							| 
									
										
										
										
											2017-11-04 17:07:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // this is quite ugly hack, but it seems like we can't close the tooltip otherwise
 | 
					
						
							|  |  |  |             $("[role='tooltip']").remove(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (glob.activeDialog) { | 
					
						
							|  |  |  |                 try { | 
					
						
							|  |  |  |                     glob.activeDialog.dialog('close'); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 catch (e) {} | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             e.preventDefault(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // when click on link popup, in case of internal link, just go the the referenced note instead of default behavior
 | 
					
						
							|  |  |  |     // of opening the link in new window/tab
 | 
					
						
							|  |  |  |     $(document).on('click', "a[action='note']", goToInternalNote); | 
					
						
							|  |  |  |     $(document).on('click', 'div.popover-content a, div.ui-tooltip-content', goToInternalNote); | 
					
						
							|  |  |  |     $(document).on('dblclick', '.note-editable a, div.ui-tooltip-content', goToInternalNote); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |         getNodeIdFromLabel, | 
					
						
							| 
									
										
										
										
											2017-11-04 17:54:27 -04:00
										 |  |  |         getNoteIdFromLink, | 
					
						
							| 
									
										
										
										
											2017-11-04 17:07:03 -04:00
										 |  |  |         createNoteLink | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | })(); |