| 
									
										
										
										
											2018-03-27 22:42:46 -04:00
										 |  |  | import libraryLoader from "./library_loader.js"; | 
					
						
							| 
									
										
										
										
											2018-03-27 00:22:02 -04:00
										 |  |  | import noteDetailService from './note_detail.js'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const $noteDetailText = $('#note-detail-text'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let textEditor = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 21:46:38 -04:00
										 |  |  | async function show() { | 
					
						
							| 
									
										
										
										
											2018-03-27 00:22:02 -04:00
										 |  |  |     if (!textEditor) { | 
					
						
							| 
									
										
										
										
											2018-03-27 22:42:46 -04:00
										 |  |  |         await libraryLoader.requireLibrary(libraryLoader.CKEDITOR); | 
					
						
							| 
									
										
										
										
											2018-03-27 00:22:02 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         textEditor = await BalloonEditor.create($noteDetailText[0], {}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 00:21:43 +02:00
										 |  |  |         textEditor.model.document.on('change:data', noteDetailService.noteChanged); | 
					
						
							| 
									
										
										
										
											2018-03-27 00:22:02 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-12 20:03:23 -04:00
										 |  |  |     textEditor.setData(noteDetailService.getCurrentNote().content); | 
					
						
							| 
									
										
										
										
											2018-03-27 00:22:02 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $noteDetailText.show(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getContent() { | 
					
						
							|  |  |  |     let content = textEditor.getData(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // if content is only tags/whitespace (typically <p> </p>), then just make it empty
 | 
					
						
							|  |  |  |     // this is important when setting new note to code
 | 
					
						
							|  |  |  |     if (jQuery(content).text().trim() === '' && !content.includes("<img")) { | 
					
						
							|  |  |  |         content = ''; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return content; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function focus() { | 
					
						
							|  |  |  |     $noteDetailText.focus(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getEditor() { | 
					
						
							|  |  |  |     return textEditor; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default { | 
					
						
							| 
									
										
										
										
											2018-03-27 21:46:38 -04:00
										 |  |  |     show, | 
					
						
							| 
									
										
										
										
											2018-03-27 00:22:02 -04:00
										 |  |  |     getEditor, | 
					
						
							|  |  |  |     getContent, | 
					
						
							|  |  |  |     focus | 
					
						
							|  |  |  | } |