45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package core
|
|
|
|
import "fmt"
|
|
|
|
const initScriptTmpl = `
|
|
try {
|
|
var __sui_data = %s;
|
|
} catch (e) { console.log('init data error:', e); }
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
try {
|
|
document.querySelectorAll("[s\\:ready]").forEach(function (element) {
|
|
const method = element.getAttribute("s:ready");
|
|
const cn = element.getAttribute("s:cn");
|
|
if (method && typeof window[cn] === "function") {
|
|
try {
|
|
window[cn](element);
|
|
} catch (e) {
|
|
const message = e.message || e || "An error occurred";
|
|
console.error(` + "`[SUI] ${cn} Error: ${message}`" + `);
|
|
}
|
|
}
|
|
});
|
|
} catch (e) {}
|
|
});
|
|
%s
|
|
`
|
|
|
|
const i118nScriptTmpl = `
|
|
function L(key) {
|
|
return key;
|
|
}
|
|
`
|
|
|
|
func bodyInjectionScript(jsonRaw string, debug bool) string {
|
|
jsPrintData := ""
|
|
if debug {
|
|
jsPrintData = `console.log(__sui_data);`
|
|
}
|
|
return fmt.Sprintf(`<script type="text/javascript">`+initScriptTmpl+`</script>`, jsonRaw, jsPrintData)
|
|
}
|
|
|
|
func headInjectionScript() string {
|
|
return fmt.Sprintf(`<script type="text/javascript">` + i118nScriptTmpl + `</script>`)
|
|
}
|