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

Method #initElement

tools/common/_hyperscript.iife.js:2771–2822  ·  view source on GitHub ↗
(elt, target)

Source from the content-addressed store, hash-verified

2769 delete elt._hyperscript;
2770 }
2771 #initElement(elt, target) {
2772 if (elt.closest && elt.closest(config.disableSelector)) {
2773 return;
2774 }
2775 var internalData = this.getInternalData(elt);
2776 var src = this.#getScript(elt);
2777 if (!src) return;
2778 var hash = this.#hashScript(src);
2779 if (internalData.initialized) {
2780 if (internalData.scriptHash === hash) return;
2781 this.cleanup(elt);
2782 internalData = this.getInternalData(elt);
2783 }
2784 if (!this.triggerEvent(elt, "hyperscript:before:init")) return;
2785 internalData.initialized = true;
2786 internalData.scriptHash = hash;
2787 try {
2788 var tokens = this.#tokenizer.tokenize(src);
2789 var hyperScript = this.#kernel.parseHyperScript(tokens);
2790 if (!hyperScript) return;
2791 if (hyperScript.errors?.length) {
2792 this.triggerEvent(elt, "hyperscript:parse-error", {
2793 errors: hyperScript.errors
2794 });
2795 console.error(
2796 "hyperscript: " + hyperScript.errors.length + " parse error(s) on:",
2797 elt,
2798 "\n\n" + Parser.formatErrors(hyperScript.errors)
2799 );
2800 return;
2801 }
2802 hyperScript.apply(target || elt, elt, null, this);
2803 elt.setAttribute("data-hyperscript-powered", "true");
2804 this.triggerEvent(elt, "hyperscript:after:init");
2805 setTimeout(() => {
2806 this.triggerEvent(target || elt, "load", {
2807 hyperscript: true
2808 });
2809 }, 1);
2810 } catch (e) {
2811 this.triggerEvent(elt, "exception", {
2812 error: e
2813 });
2814 console.error(
2815 "hyperscript errors were found on the following element:",
2816 elt,
2817 "\n\n",
2818 e.message,
2819 e.stack
2820 );
2821 }
2822 }
2823 #beforeProcessHooks = [];
2824 #afterProcessHooks = [];
2825 addBeforeProcessHook(fn) {

Callers 1

processNodeMethod · 0.95

Calls 10

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

Tested by

no test coverage detected