-
Notifications
You must be signed in to change notification settings - Fork 0
/
webflow-thecompass-module.min.js
1 lines (1 loc) · 1.66 KB
/
webflow-thecompass-module.min.js
1
const tc={},Ref=e=>{let t=e,r=[],l=(e,t)=>r.push({subscriber:e,bind:t}),c=e=>(r=r.filter(t=>t.subscriber!==e)).length,a=e=>{t="function"==typeof e?e(t):e,r&&r.forEach(e=>e.subscriber(t,e.bind))};return Object.freeze({get value(){return t},set value(val){a(val)},update:a,subscribe:l,unsubscribe:c})};function dfs(e){if(Array.from(e.children).length>0)Array.from(e.children).forEach(e=>{dfs(e)});else if(e.innerText){let t=e.innerText.match(/\{\{ [\w]+ \}\}/g);t&&t.forEach(t=>{let r=t.replaceAll("{","").replaceAll("}","").replaceAll(" ","");void 0===tc[r]&&(tc[r]=Ref(0)),tc[r].subscribe((l,c)=>{-1===e.innerText.indexOf(t)?e.innerText=c.innerText.replaceAll(t,tc[r].value):e.innerText=e.innerText.replaceAll(t,tc[r].value)},{innerText:e.innerText})})}e.getAttributeNames().forEach(t=>{let r=e.getAttribute(t).match(/\{\{ [\w]+ \}\}/g);r&&r.forEach(r=>{let l=r.replaceAll("{","").replaceAll("}","").replaceAll(" ","");void 0===tc[l]&&(tc[l]=Ref(0)),tc[l].subscribe((c,a)=>{-1===e.getAttribute(t).indexOf(r)?e.setAttribute(t,a.prop.replaceAll(r,tc[l].value)):e.setAttribute(t,e.getAttribute(t).replaceAll(r,tc[l].value))},{prop:e.getAttribute(t)})})})}window.addEventListener("load",()=>{dfs(document),initTC(),document.querySelectorAll("[aria-tc-onchange]").forEach(dom=>{dom.addEventListener("change",eval(dom.getAttribute("aria-tc-onchange")))}),document.querySelectorAll("[aria-tc-onclick]").forEach(dom=>{dom.addEventListener("click",eval(dom.getAttribute("aria-tc-onclick")))}),document.querySelectorAll("[aria-tc-onkeyup]").forEach(dom=>{dom.addEventListener("keyup",eval(dom.getAttribute("aria-tc-onkeyup")))})}),window.addEventListener("unload",()=>{Object.values(tc).forEach(e=>e.clear())});