-
Notifications
You must be signed in to change notification settings - Fork 0
/
BindJS.min.js
1 lines (1 loc) · 1.69 KB
/
BindJS.min.js
1
const BIND_HTML_CLASS="bind-html",BIND_VALUE_CLASS="bind-value",BIND_ATTRIBUTE_CLASS="bind-attribute",BIND_STYLE_CLASS="bind-style";var binds={};function bindValue(e,t,n){var a=binds;null!=n&&null!=n&&(a=n),Object.defineProperty(a,e,{get:()=>t.value,set:e=>{t.value=e},configurable:!0,enumerable:!0})}function bindHTML(e,t,n){var a=binds;null!=n&&null!=n&&(a=n),Object.defineProperty(a,e,{get:()=>t.innerHTML,set:e=>{t.innerHTML=e},configurable:!0,enumerable:!0})}function bindAttribute(e,t,n,a){var l=binds;null!=a&&null!=a&&(l=a),Object.defineProperty(l,e,{get:()=>t[n],set:e=>{t[n]=e},configurable:!0,enumerable:!0})}function bindStyle(e,t,n,a){var l=binds;null!=a&&null!=a&&(l=a),console.log(t.style),console.log(n),Object.defineProperty(l,e,{get:()=>t.style[n],set:e=>{t.style[n]=e,console.log(n)},configurable:!0,enumerable:!0})}function removeBind(e,t){var n=binds;null!=t&&null!=t&&(n=t),delete n[e]}function autoBind(){autoBindHTML(),autoBindValue(),autoBindAttribute(),autoBindStyle()}function autoBindHTML(){for(var e=document.getElementsByClassName(BIND_HTML_CLASS),t=0;t<e.length;t++){var n=e[t];bindHTML(n.dataset.bindHtmlVariable,n)}}function autoBindValue(){for(var e=document.getElementsByClassName(BIND_VALUE_CLASS),t=0;t<e.length;t++){var n=e[t];bindHTML(n.dataset.bindValueVariable,n)}}function autoBindAttribute(){for(var e=document.getElementsByClassName(BIND_ATTRIBUTE_CLASS),t=0;t<e.length;t++){var n=e[t];bindAttribute(n.dataset.bindAttributeVariable,n,n.dataset.bindAttributeName)}}function autoBindStyle(){for(var e=document.getElementsByClassName(BIND_STYLE_CLASS),t=0;t<e.length;t++){var n=e[t];bindStyle(n.dataset.bindStyleVariable,n,n.dataset.bindStyleName)}}window.addEventListener("load",autoBind);