forked from ianfleon/seleku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seleku.min.js
1 lines (1 loc) · 2.1 KB
/
seleku.min.js
1
class SelekuClass{constructor(a){null===a?(console.log("Target tidak ditemukan."),this.elemen="Tidak ada elemen!"):this.elemen=a}style(a,b){const c=this.elemen.style;c[a]=b}css(a){let b=Object.keys(a);const c=this.elemen.style;b.forEach(function(b){c[b]=a[b]})}tambahTag(a,b){const c=document.createElement(a),d=document.createTextNode(b);c.appendChild(d);const e=this.elemen.appendChild(c);return e}tambahElemen(a){if("object"==typeof a)return this.telofObject(a);return"string"==typeof a?this.telofString(a):void 0}telofObject(a){const b=document.createElement(a.tag);let c;return null!=a.attr&&(c=Object.keys(a.attr),0<c.length&&c.forEach(c=>{b.setAttribute(c,a.attr[c])})),b.innerHTML=null==a.isi?"":a.isi,b}telofString(a){const b=a.indexOf(">"),c=a.lastIndexOf("<"),d=a.slice(1,b),e=a.slice(b+1,c),f=d.search(" ");let g;if(0>f){g=d.slice(0,b);const a=document.createElement(g),c=document.createTextNode(e);return a.appendChild(c),this.elemen.appendChild(a)}else{const b=a.indexOf(" "),c=d.slice(b),f=c.split(" ");g=d.slice(0,b-1);const h=document.createElement(g),i=document.createTextNode(e);return h.appendChild(i),f.forEach(b=>{const a=b.indexOf("="),c=b.slice(0,a),d=b.slice(a+2,b.length-1);h.setAttribute(c,d)}),this.elemen.appendChild(h)}}isi(a){return this.isi.innerHTML(a)}tambahClass(a){const b=this.elemen.classList.add(a);return b}toggleClass(a){const b=this.elemen.classList.toggle(a);return b}log(){console.log(this.elemen)}pas(a,b){return this.elemen.addEventListener(a,b)}gabung(a,b){return null==b?this.elemen.appendChild(a):a.appendChild(b)}}function $elek(a,b){if("number"==typeof b){const c=document.querySelectorAll(a)[b];if(c===void 0)console.log("SelekuJS : indeks yang anda pilih tidak ada");else return c}else if("string"==typeof b){if("semua"===b){const b=document.querySelectorAll(a);return b}if("awal"===b)return document.querySelectorAll(a)[0];if("akhir"===b){const b=document.querySelectorAll(a);return document.querySelectorAll(a)[b.length-1]}console.log("SelekuJS : Parameter tidak benar")}else{const b=document.querySelector(a);return b}}function $ku(a){const b=document.querySelector(a);return new SelekuClass(b)}