mirror of
				https://gitlab.com/SpaccInc/SpaccDotWeb.git
				synced 2025-06-05 21:29:12 +02:00 
			
		
		
		
	[Alt] alternative function names; add RequireScript options
This commit is contained in:
		| @@ -1,4 +1,4 @@ | |||||||
| #!/bin/sh | #!/bin/sh | ||||||
| for file in ./SpaccDotWeb*.js | for file in ./SpaccDotWeb.js ./SpaccDotWeb.*.js | ||||||
| do node ./SpaccDotWeb.Build.js "BuildScriptFile('${file}')" | do node ./SpaccDotWeb.Build.js "BuildScriptFile('${file}')" | ||||||
| done | done | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| (function(){ | (function(currentScript){ | ||||||
| 	const SpaccDotWeb = {}; | 	const SpaccDotWeb = {}; | ||||||
|  |  | ||||||
| 	SpaccDotWeb.AppInit = (meta) => { | 	SpaccDotWeb.AppInit = (meta) => { | ||||||
| @@ -12,22 +12,27 @@ | |||||||
| 		localStorage[value !== undefined ? 'setItem' : 'getItem']( | 		localStorage[value !== undefined ? 'setItem' : 'getItem']( | ||||||
| 			`${prefix}/${key}`, JSON.stringify(value)) || null); | 			`${prefix}/${key}`, JSON.stringify(value)) || null); | ||||||
|  |  | ||||||
| 	SpaccDotWeb.RequireScript = (src, type) => { | 	SpaccDotWeb.requireScript = (src, params={}) => { | ||||||
| 		return (new Promise((resolve) => { | 		return (new Promise((resolve) => { | ||||||
| 			const scriptElem = document.createElement('script'); | 			const scriptElem = document.createElement('script'); | ||||||
| 			//if (type) { | 			//if (type) { | ||||||
| 			//	scriptElem.type = type; | 			//	scriptElem.type = type; | ||||||
| 			//} | 			//} | ||||||
| 			scriptElem.onload = (event) => { | 			if (params.useCurrentPath) { | ||||||
| 				resolve(event); | 				const currentPath = currentScript.src; | ||||||
| 			}; | 				if (currentPath) { | ||||||
|  | 					src = `${currentPath.split('/').slice(0, -1).join('/')}/${src}`; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			scriptElem.onload = resolve; | ||||||
| 			scriptElem.src = src; | 			scriptElem.src = src; | ||||||
| 			document.body.appendChild(scriptElem); | 			document.body.appendChild(scriptElem); | ||||||
| 		})); | 		})); | ||||||
| 	}; | 	}; | ||||||
| 	// .RequireScripts = (...) => {} | 	// .RequireScripts = (...) => {} | ||||||
|  | 	SpaccDotWeb.RequireScript = SpaccDotWeb.requireScript; | ||||||
|  |  | ||||||
| 	SpaccDotWeb.ShowModal = async (params) => { | 	SpaccDotWeb.showModal = async (params) => { | ||||||
| 	// TODO: delete dialogs from DOM after use (garbage collect)? | 	// TODO: delete dialogs from DOM after use (garbage collect)? | ||||||
| 		if (!window.HTMLDialogElement && !window.dialogPolyfill) { | 		if (!window.HTMLDialogElement && !window.dialogPolyfill) { | ||||||
| 			// TODO include in dependencies, don't load from external server | 			// TODO include in dependencies, don't load from external server | ||||||
| @@ -83,8 +88,10 @@ | |||||||
| 		modal.showModal(); | 		modal.showModal(); | ||||||
| 		return modal; | 		return modal; | ||||||
| 	}; | 	}; | ||||||
|  | 	SpaccDotWeb.ShowModal = SpaccDotWeb.showModal; | ||||||
|  |  | ||||||
| 	SpaccDotWeb.Sleep = (ms) => (new Promise((resolve) => setTimeout(resolve, ms))); | 	SpaccDotWeb.sleep = (ms) => (new Promise((resolve) => setTimeout(resolve, ms))); | ||||||
|  | 	SpaccDotWeb.Sleep = SpaccDotWeb.sleep; | ||||||
|  |  | ||||||
| 	window.SpaccDotWeb ||= SpaccDotWeb; | 	window.SpaccDotWeb ||= SpaccDotWeb; | ||||||
| })(); | })(document.currentScript); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user