-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjcore.min.js
More file actions
2 lines (2 loc) · 4.73 KB
/
Copy pathjcore.min.js
File metadata and controls
2 lines (2 loc) · 4.73 KB
1
2
//jCore library. www.jco.re/#license
;function jCore(t,e){if(t===$.U)return this;e=e===$.U?document:e;var n=new jCore();if(typeof t=='string')n.push.apply(n,e.querySelectorAll(t));else if(t instanceof Array){n.length=0;for(var i in t)n.push(t[i])}else n.push(t);return n};$=jCore;$$=$.prototype=[];$.U=undefined;$.ajax=function(t,e,i,o){if(o===$.U){o=i;i=''};var n,h,r,s;s='content-type';n=new XMLHttpRequest();n.onreadystatechange=function(){if(n.readyState==4&&n.status==200){h=n.getResponseHeader(s);r=n.responseText;if(h.indexOf('/json')>0)r=JSON.parse(c);o(r)}};if(t)n.open('GET',e+'?'+i,1);else{n.open('POST',e,1);n.setRequestHeader(s,'application/x-www-form-urlencoded')};n.send(i)};$.post=function(t,e,n){return $.ajax(0,t,e,n)};$.get=function(t,e,n){return $.ajax(1,t,e,n)};$$.each=function(t){for(var e=0;e<this.length;e++)if(e in this)t.call(this[e])};$$.on=function(t,e){if(t!==$.U)this.each(function(){if(this.eventList===$.U)this.eventList=[];this.eventList.push(e);var n=this.eventList.length-1;this.addEventListener(t,function(t){if(this.eventList[n].call(this,t)==!1)t.preventDefault()})});return this};$$.off=function(t,e){this.each(function(){if(e!==$.U)this.removeEventListener(t,e);else for(var n=this.eventList.length-1;n>=0;n--){this.removeEventListener(t,this.eventList[n]);delete this.eventList[n]}});return this};$$.e$=function(t,e,n){if(t!==$.U)this.each(function(){this[e][n](t)});return this};$$.t$=function(t,e){if(t===$.U)return!this[0]?'':this[0][e];this.each(function(){this[e]=t});return this};$$.n$=function(t,e,n){if(e===$.U){var i=(!this[0]?'':this[0][n][t]);return i==$.U?'':i};this.each(function(){this[n][t]=e});return this};$$.css=function(t,e){if(typeof t=='object'){for(var n in t)this.n$(n,t[n],'style');return this};if(e===$.U){if(this.length<1)return'';return getComputedStyle(this[0]).getPropertyValue(t)};return this.n$(t,e,'style')};$$.html=function(t){return this.t$(t,'innerHTML')};$$.attr=function(t,e){return this.t$(e,t)};$$.data=function(t,e){return this.n$(t,e,'dataset')};$$.val=function(t){return this.t$(t,'value')};$$.toggleClass=function(t){return this.e$(t,'classList','toggle')};$$.addClass=function(t){return this.e$(t,'classList','add')};$$.removeClass=function(t){return this.e$(t,'classList','remove')};$$.remove=function(){this.each(function(){this.parentElement.removeChild(this)});return this};$$.replaceWith=function(t){if(t!==$.U)this.each(function(){if(typeof t=='string')this.innerHTML=t;else{if(t instanceof $)t=t.get(0);this.parentElement.replaceChild(t,this)}});return this};$$.show=function(){return this.css('display','block')};$$.hide=function(){return this.css('display','none')};$$.toggle=function(){this.each(function(){this.style.display=(this.style.display!='none'?'none':'')});return this};$$.get=function(t){return this[t]};$$.parent=function(){return!this[0]?'':$(this[0].parentElement)};$$.next=function(){return!this[0]?'':$(this[0].nextSibling)};$$.prev=function(){return!this[0]?'':$(this[0].prevSibling)};$$.offset=function(){return!this[0]?'':this[0].getBoundingClientRect()};$$.hasClass=function(t){return!this[0]?!1:this[0].classList.contains(t)};$$.find=function(t){return $(t,this[0])};$$.children=function(t){var n=this[0].childNodes,i=[];for(var e=0;e<n.length;e++)if($(n[e]).is(t))i.push(n[e]);return $(i)};$$.text=function(t){if(t===$.U)return!this[0]?'':this[0].innerText||this[0].textContent;return this.html(t)};$$.clone=function(){return!this[0]?new $:$(this[0].cloneNode(1))};$$.append=function(t){this.each(function(){if(typeof t=='string')this.insertAdjacentHTML('beforeend',t);else{if(t instanceof $)t=t.get(0);this.appendChild(t)}});return this};$$.is=function(t){var e=this[0],n=(e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector||e.webkitMatchesSelector);if(n===$.U)return!1;return e[n.name](t)};$$.parents=function(t){var n=[],e=this[0].parentNode;while(e){if($(e).is(t)||t===$.U)n.push(e);e=e.parentNode};return n};$$.eq=function(t){var t=(t<0)?this.length-t:t;return $(this[t])};$$.lt=function(t){var t=(t<0)?this.length-t:t,e=this.slice(0,t);return $(e)};$$.gt=function(t){var t=(t<0)?this.length-t:t,e=this.slice(t+1);return $(e)};$.prefix=function(t){var e='@-webkit-@-moz-@-o-@-ms-@-khtml-'.split('@');for(var n in e)if(document.body.style[e[n]+t]!==undefined)return e[n];return!1};$$.serialize=function(){var o=this.get(0);if(o==$.U)return'';var e,r,t,s,i,n;i=[];t=o.elements;for(e in t){if(t[e].name=='')continue;n=0;s=t[e].type;switch(t[e].nodeName){case'INPUT':if(s=='file')continue;if((s=='checkbox'||s=='radio')&&!t[e].checked)continue;n=1;break;case'BUTTON':case'TEXTAREA':n=1;break;case'SELECT':for(r in t[e].options.length)if(t[e].options[r].selected)i.push(t[e].name+'='+encodeURIComponent(t[e].options[r].value));break};if(n)i.push(t[e].name+'='+encodeURIComponent(t[e].value))};return i.join('&')};