MCPcopy Index your code
hub / github.com/bigskysoftware/_hyperscript / #initElement

Method #initElement

www/js/_hyperscript.esm.js:2782–2837  ·  view source on GitHub ↗
(elt, target)

Source from the content-addressed store, hash-verified

2780 delete elt._hyperscript;
2781 }
2782 #initElement(elt, target) {
2783 if (elt.closest && elt.closest(config.disableSelector)) {
2784 return;
2785 }
2786 var internalData = this.getInternalData(elt);
2787 var src = this.#getScript(elt);
2788 if (!src) return;
2789 var hash = this.#hashScript(src);
2790 if (internalData.initialized) {
2791 if (internalData.scriptHash === hash) {
2792 this.#resolveTemplateScopes(elt);
2793 return;
2794 }
2795 this.cleanup(elt);
2796 internalData = this.getInternalData(elt);
2797 }
2798 if (!this.triggerEvent(elt, "hyperscript:before:init")) return;
2799 internalData.initialized = true;
2800 internalData.scriptHash = hash;
2801 try {
2802 var tokens = this.#tokenizer.tokenize(src);
2803 var hyperScript = this.#kernel.parseHyperScript(tokens);
2804 if (!hyperScript) return;
2805 if (hyperScript.errors?.length) {
2806 this.triggerEvent(elt, "hyperscript:parse-error", {
2807 errors: hyperScript.errors
2808 });
2809 console.error(
2810 "hyperscript: " + hyperScript.errors.length + " parse error(s) on:",
2811 elt,
2812 "\n\n" + Parser.formatErrors(hyperScript.errors)
2813 );
2814 return;
2815 }
2816 this.#resolveTemplateScopes(elt);
2817 hyperScript.apply(target || elt, elt, null, this);
2818 elt.setAttribute("data-hyperscript-powered", "true");
2819 this.triggerEvent(elt, "hyperscript:after:init");
2820 setTimeout(() => {
2821 this.triggerEvent(target || elt, "load", {
2822 hyperscript: true
2823 });
2824 }, 1);
2825 } catch (e) {
2826 this.triggerEvent(elt, "exception", {
2827 error: e
2828 });
2829 console.error(
2830 "hyperscript errors were found on the following element:",
2831 elt,
2832 "\n\n",
2833 e.message,
2834 e.stack
2835 );
2836 }
2837 }
2838 #resolveTemplateScopes(elt) {
2839 var root = elt.closest('[data-live-template], [dom-scope="isolated"]');

Callers 1

processNodeMethod · 0.95

Calls 11

getInternalDataMethod · 0.95
#getScriptMethod · 0.95
#hashScriptMethod · 0.95
cleanupMethod · 0.95
triggerEventMethod · 0.95
setTimeoutFunction · 0.50
tokenizeMethod · 0.45
parseHyperScriptMethod · 0.45
formatErrorsMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected