| 
									
										
										
										
											2017-11-04 19:38:50 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 23:30:35 -05:00
										 |  |  | function reloadApp() { | 
					
						
							|  |  |  |     window.location.reload(true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-26 12:56:07 -05:00
										 |  |  | function showMessage(message) { | 
					
						
							| 
									
										
										
										
											2017-12-18 22:06:24 -05:00
										 |  |  |     console.log(now(), "message: ", message); | 
					
						
							| 
									
										
										
										
											2017-11-26 12:56:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $.notify({ | 
					
						
							|  |  |  |         // options
 | 
					
						
							|  |  |  |         message: message | 
					
						
							|  |  |  |     },{ | 
					
						
							|  |  |  |         // settings
 | 
					
						
							|  |  |  |         type: 'success', | 
					
						
							| 
									
										
										
										
											2017-11-26 17:04:18 -05:00
										 |  |  |         delay: 3000 | 
					
						
							| 
									
										
										
										
											2017-11-26 12:56:07 -05:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-08-13 21:42:10 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-12 23:47:17 -05:00
										 |  |  | function showError(message, delay = 10000) { | 
					
						
							| 
									
										
										
										
											2017-12-18 22:06:24 -05:00
										 |  |  |     console.log(now(), "error: ", message); | 
					
						
							| 
									
										
										
										
											2017-11-26 12:56:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $.notify({ | 
					
						
							|  |  |  |         // options
 | 
					
						
							|  |  |  |         message: message | 
					
						
							|  |  |  |     },{ | 
					
						
							|  |  |  |         // settings
 | 
					
						
							|  |  |  |         type: 'danger', | 
					
						
							| 
									
										
										
										
											2017-12-12 23:47:17 -05:00
										 |  |  |         delay: delay | 
					
						
							| 
									
										
										
										
											2017-11-26 12:56:07 -05:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-09-06 22:06:43 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 19:53:23 -05:00
										 |  |  | function throwError(message) { | 
					
						
							| 
									
										
										
										
											2017-12-06 20:11:45 -05:00
										 |  |  |     messaging.logError(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     throw new Error(message); | 
					
						
							| 
									
										
										
										
											2017-12-06 19:53:23 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-10 15:31:43 -05:00
										 |  |  | function parseDate(str) { | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |         return new Date(Date.parse(str)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     catch (e) { | 
					
						
							|  |  |  |         throw new Error("Can't parse date from " + str + ": " + e.stack); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-09-30 22:36:14 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 22:38:38 -05:00
										 |  |  | function padNum(num) { | 
					
						
							|  |  |  |     return (num <= 9 ? "0" : "") + num; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-30 22:36:14 -04:00
										 |  |  | function formatTime(date) { | 
					
						
							| 
									
										
										
										
											2017-12-14 22:38:38 -05:00
										 |  |  |     return padNum(date.getHours()) + ":" + padNum(date.getMinutes()); | 
					
						
							| 
									
										
										
										
											2017-09-30 22:36:14 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-18 22:06:24 -05:00
										 |  |  | function formatTimeWithSeconds(date) { | 
					
						
							|  |  |  |     return padNum(date.getHours()) + ":" + padNum(date.getMinutes()) + ":" + padNum(date.getSeconds()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-30 22:36:14 -04:00
										 |  |  | function formatDate(date) { | 
					
						
							| 
									
										
										
										
											2017-12-14 22:38:38 -05:00
										 |  |  |     return padNum(date.getDate()) + ". " + padNum(date.getMonth() + 1) + ". " + date.getFullYear(); | 
					
						
							| 
									
										
										
										
											2017-09-30 22:36:14 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-25 23:22:19 -05:00
										 |  |  | function formatDateISO(date) { | 
					
						
							|  |  |  |     return date.getFullYear() + "-" + padNum(date.getMonth() + 1) + "-" + padNum(date.getDate()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-30 22:36:14 -04:00
										 |  |  | function formatDateTime(date) { | 
					
						
							|  |  |  |     return formatDate(date) + " " + formatTime(date); | 
					
						
							| 
									
										
										
										
											2017-11-30 19:58:00 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-18 22:06:24 -05:00
										 |  |  | function now() { | 
					
						
							|  |  |  |     return formatTimeWithSeconds(new Date()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-30 19:58:00 -05:00
										 |  |  | function isElectron() { | 
					
						
							|  |  |  |     return window && window.process && window.process.type; | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function assertArguments() { | 
					
						
							|  |  |  |     for (const i in arguments) { | 
					
						
							| 
									
										
										
										
											2017-12-23 12:19:15 -05:00
										 |  |  |         if (!arguments[i]) { | 
					
						
							|  |  |  |             throwError(`Argument idx#${i} should not be falsy: ${arguments[i]}`); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function assert(expr, message) { | 
					
						
							|  |  |  |     if (!expr) { | 
					
						
							|  |  |  |         throwError(message); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-12-23 12:19:15 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function isTopLevelNode(node) { | 
					
						
							|  |  |  |     return isRootNode(node.getParent()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function isRootNode(node) { | 
					
						
							|  |  |  |     return node.key === "root_1"; | 
					
						
							| 
									
										
										
										
											2017-12-28 19:00:31 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function escapeHtml(str) { | 
					
						
							|  |  |  |     return $('<div/>').text(str).html(); | 
					
						
							| 
									
										
										
										
											2018-01-22 23:18:08 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function stopWatch(what, func) { | 
					
						
							|  |  |  |     const start = new Date(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const ret = await func(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const tookMs = new Date().getTime() - start.getTime(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     console.log(`${what} took ${tookMs}ms`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ret; | 
					
						
							| 
									
										
										
										
											2018-01-25 23:49:03 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function executeScript(script) { | 
					
						
							| 
									
										
										
										
											2018-02-18 10:47:02 -05:00
										 |  |  |     eval(script); | 
					
						
							| 
									
										
										
										
											2018-02-04 20:23:30 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function formatValueWithWhitespace(val) { | 
					
						
							| 
									
										
										
										
											2018-02-05 22:28:12 -05:00
										 |  |  |     return /[^\w_-]/.test(val) ? '"' + val + '"' : val; | 
					
						
							| 
									
										
										
										
											2018-02-04 20:23:30 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function formatAttribute(attr) { | 
					
						
							|  |  |  |     let str = "@" + formatValueWithWhitespace(attr.name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (attr.value !== "") { | 
					
						
							|  |  |  |         str += "=" + formatValueWithWhitespace(attr.value); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return str; | 
					
						
							| 
									
										
										
										
											2018-02-19 22:02:03 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const CKEDITOR = { "js": ["libraries/ckeditor/ckeditor.js"] }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const CODE_MIRROR = { | 
					
						
							|  |  |  |     js: [ | 
					
						
							|  |  |  |         "libraries/codemirror/codemirror.js", | 
					
						
							|  |  |  |         "libraries/codemirror/addon/mode/loadmode.js", | 
					
						
							|  |  |  |         "libraries/codemirror/addon/fold/xml-fold.js", | 
					
						
							|  |  |  |         "libraries/codemirror/addon/edit/matchbrackets.js", | 
					
						
							|  |  |  |         "libraries/codemirror/addon/edit/matchtags.js", | 
					
						
							|  |  |  |         "libraries/codemirror/addon/search/match-highlighter.js", | 
					
						
							| 
									
										
										
										
											2018-02-21 20:30:15 -05:00
										 |  |  |         "libraries/codemirror/mode/meta.js", | 
					
						
							| 
									
										
										
										
											2018-02-20 23:24:55 -05:00
										 |  |  |         "libraries/codemirror/addon/lint/lint.js", | 
					
						
							| 
									
										
										
										
											2018-02-21 20:30:15 -05:00
										 |  |  |         "libraries/codemirror/addon/lint/eslint.js" | 
					
						
							| 
									
										
										
										
											2018-02-20 23:24:55 -05:00
										 |  |  |     ], | 
					
						
							|  |  |  |     css: [ | 
					
						
							| 
									
										
										
										
											2018-02-21 20:30:15 -05:00
										 |  |  |         "libraries/codemirror/codemirror.css", | 
					
						
							| 
									
										
										
										
											2018-02-20 23:24:55 -05:00
										 |  |  |         "libraries/codemirror/addon/lint/lint.css" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 20:30:15 -05:00
										 |  |  | const ESLINT = { js: [ "libraries/eslint.js" ] }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-19 22:02:03 -05:00
										 |  |  | async function requireLibrary(library) { | 
					
						
							|  |  |  |     if (library.css) { | 
					
						
							|  |  |  |         library.css.map(cssUrl => requireCss(cssUrl)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (library.js) { | 
					
						
							|  |  |  |         for (const scriptUrl of library.js) { | 
					
						
							|  |  |  |             await requireScript(scriptUrl); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 20:30:15 -05:00
										 |  |  | const dynamicallyLoadedScripts = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-19 22:02:03 -05:00
										 |  |  | async function requireScript(url) { | 
					
						
							| 
									
										
										
										
											2018-02-21 20:30:15 -05:00
										 |  |  |     if (!dynamicallyLoadedScripts.includes(url)) { | 
					
						
							|  |  |  |         dynamicallyLoadedScripts.push(url); | 
					
						
							| 
									
										
										
										
											2018-02-19 22:02:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-21 20:30:15 -05:00
										 |  |  |         return await $.ajax({ | 
					
						
							| 
									
										
										
										
											2018-02-19 22:02:03 -05:00
										 |  |  |             url: url, | 
					
						
							|  |  |  |             dataType: "script", | 
					
						
							|  |  |  |             cache: true | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function requireCss(url) { | 
					
						
							|  |  |  |     const css = Array | 
					
						
							|  |  |  |         .from(document.querySelectorAll('link')) | 
					
						
							|  |  |  |         .map(scr => scr.href); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!css.includes(url)) { | 
					
						
							|  |  |  |         $('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', url)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-02-25 10:55:21 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getHost() { | 
					
						
							|  |  |  |     const url = new URL(window.location.href); | 
					
						
							|  |  |  |     return url.protocol + "//" + url.hostname + ":" + url.port; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function download(url) { | 
					
						
							|  |  |  |     if (isElectron()) { | 
					
						
							|  |  |  |         const remote = require('electron').remote; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         remote.getCurrentWebContents().downloadURL(url); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         window.location.href = url; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | } |