hugvey/www/js/crel.min.js
Hugvey Central Command 196801d67c Timeline changes
2019-05-18 13:14:58 +02:00

30 lines
1.7 KiB
JavaScript

!function(n,e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):n.crel=e()}(this,function(){function n(a){var d,s=arguments,p=s[1],y=2,m=s.length,x=n[o];if(a=n[u](a)?a:c.createElement(a),m>1){if((!e(p,r)||n[f](p)||Array.isArray(p))&&(--y,p=null),m-y==1&&e(s[y],"string"))a.textContent=s[y];else for(;y<m;++y)null!==(d=s[y])&&l(a,d);for(var v in p)if(x[v]){var A=x[v];e(A,t)?A(a,p[v]):a[i](A,p[v])}else e(p[v],t)?a[v]=p[v]:a[i](v,p[v])}return a}var e=function(n,e){return typeof n===e},t="function",r="object",i="setAttribute",o="attrMap",f="isNode",u="isElement",c=document,a=function(n){return n instanceof Node},d=function(n){return n instanceof Element},l=function(e,t){if(Array.isArray(t))return void t.map(function(n){l(e,n)});n[f](t)||(t=c.createTextNode(t)),e.appendChild(t)};return n[o]={},n[u]=d,n[f]=a,e(Proxy,"undefined")||(n.proxy=new Proxy(n,{get:function(e,t){return!(t in n)&&(n[t]=n.bind(null,t)),n[t]}})),n});
crel.attrMap['on'] = function(element, value) {
for (var eventName in value) {
element.addEventListener(eventName, value[eventName]);
}
};
crel.attrMap['options'] = function(element, values, a, b) {
if(element.tagName != "SELECT") {
return;
}
if(Array.isArray(values)) {
for (let option of values) {
if(element.value == option) {
element.appendChild(crel('option', {'selected': 'selected'}, option));
} else {
element.appendChild(crel('option', option));
}
}
} else {
for (let option in values) {
if(element.value == option) {
element.appendChild(crel('option', {'selected': 'selected','value': option}, values[option]));
}else{
element.appendChild(crel('option', {'value': option}, values[option]));
}
}
}
};