| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | function message(str) { | 
					
						
							| 
									
										
										
										
											2017-08-21 21:31:23 -04:00
										 |  |  |     const top = $("#top-message"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-24 11:34:16 -04:00
										 |  |  |     top.fadeIn(1500).css("display","inline-block"); | 
					
						
							| 
									
										
										
										
											2017-08-21 21:31:23 -04:00
										 |  |  |     top.html(str); | 
					
						
							|  |  |  |     top.fadeOut(1500); | 
					
						
							| 
									
										
										
										
											2017-08-13 21:42:10 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function error(str) { | 
					
						
							| 
									
										
										
										
											2017-08-21 21:31:23 -04:00
										 |  |  |     const error = $("#error-message"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-24 11:34:16 -04:00
										 |  |  |     error.show().css("display","inline-block"); | 
					
						
							| 
									
										
										
										
											2017-08-21 21:31:23 -04:00
										 |  |  |     error.html(str); | 
					
						
							|  |  |  |     error.fadeOut(10000); | 
					
						
							| 
									
										
										
										
											2017-09-06 22:06:43 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-18 20:48:02 -04:00
										 |  |  | function getAutocompleteItems(noteIds) { | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  |     const autocompleteItems = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-18 20:48:02 -04:00
										 |  |  |     for (const noteId of noteIds) { | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  |         const fullName = getFullName(noteId); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-18 20:48:02 -04:00
										 |  |  |         if (fullName !== null) { | 
					
						
							|  |  |  |             autocompleteItems.push({ | 
					
						
							|  |  |  |                 value: fullName + " (" + noteId + ")", | 
					
						
							|  |  |  |                 label: fullName | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return autocompleteItems; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 22:06:43 -04:00
										 |  |  | function uint8ToBase64(u8Arr) { | 
					
						
							|  |  |  |     const CHUNK_SIZE = 0x8000; //arbitrary number
 | 
					
						
							|  |  |  |     const length = u8Arr.length; | 
					
						
							|  |  |  |     let index = 0; | 
					
						
							|  |  |  |     let result = ''; | 
					
						
							|  |  |  |     let slice; | 
					
						
							|  |  |  |     while (index < length) { | 
					
						
							|  |  |  |         slice = u8Arr.subarray(index, Math.min(index + CHUNK_SIZE, length)); | 
					
						
							|  |  |  |         result += String.fromCharCode.apply(null, slice); | 
					
						
							|  |  |  |         index += CHUNK_SIZE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return btoa(result); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function base64ToUint8Array(base64encoded) { | 
					
						
							| 
									
										
										
										
											2017-10-09 18:53:11 -04:00
										 |  |  |     return new Uint8Array(atob(base64encoded).split("").map(c => c.charCodeAt(0))); | 
					
						
							| 
									
										
										
										
											2017-09-30 22:36:14 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getDateFromTS(timestamp) { | 
					
						
							|  |  |  |     // Date accepts number of milliseconds since epoch so UTC timestamp works without any extra handling
 | 
					
						
							|  |  |  |     // see https://stackoverflow.com/questions/4631928/convert-utc-epoch-to-local-date-with-javascript
 | 
					
						
							|  |  |  |     const utcDate = new Date(timestamp * 1000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const localDate = new Date(utcDate.getTime() - utcDate.getTimezoneOffset() * 60 * 1000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return localDate; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function formatTime(date) { | 
					
						
							|  |  |  |     return (date.getHours() <= 9 ? "0" : "") + date.getHours() + ":" + (date.getMinutes() <= 9 ? "0" : "") + date.getMinutes(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function formatDate(date) { | 
					
						
							|  |  |  |     return date.getDate() + ". " + (date.getMonth() + 1) + ". " + date.getFullYear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function formatDateTime(date) { | 
					
						
							|  |  |  |     return formatDate(date) + " " + formatTime(date); | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | } |