-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdard.min.js
1 lines (1 loc) · 5.3 KB
/
dard.min.js
1
function isObj(a){return typeof obj==="object"||toString.call(a).split(/\W/)[2].toLowerCase()==="object"}function isArray(b){return Array.isArray(b)||toString.call(b).split(/\W/)[2].toLowerCase()==="array"}function isFunc(a){return typeof a==="function"}function isStr(a){return typeof a==="string"?true:false}function isBool(a){return typeof a==="boolean"?true:false}function isNum(a){return typeof a==="number"?true:false}function isSet(a){return typeof a==="undefined"||a===undefined?false:true}function empty(a){var b=false;if(isStr(a)){a.length==0?b=true:b=false;if(a.length==1&&(a=="0"||a=="0")){b=true}}else{if(a===null){b=true}else{if(isNum(a)&&a==0){b=true}}}return b}function type(b,a){b.constructor.prototype=new b(a);return b.constructor}function varyArgs(a){return Array.prototype.slice.call(a)}function argsLength(a){return varyArgs(a).length}function setCss(c,b){var a,d="";if(isObj(b)){for(a in b){if(b.hasOwnProperty(a)){d+=a+":"+b[a]+";"}}c.style.cssText=d}}function toggle(b){var a=window.getComputedStyle(b,null).getPropertyValue("display");a==="none"?b.style.display="block":b.style.display="none"}function simulateClick(a){var b=document.createEvent("MouseEvents");b.initMouseEvent("click",true,true,window,0,0,0,0,0,false,false,false,false,0,null);$(a).dispatchEvent(b)}function counter(){var a=0;var b=function(c){a+=c};return{show:function(){return a},increment:function(){b(1)},reset:function(){a=0},decrement:function(){b(-1)},incrementBy:function(c){b(c)}}}function require_js_module(src){ajax({type:"GET",url:src,response:function(script){eval.apply(window,[script])},error:"ERROR: script not loaded: "+src})}function include_module(c){var a,b;if(c.keyIn("el")){a=c.el;b=str2el(c.html);if(a.hasChildNodes()){a.removeChild(a.firstChild)}a.appendChild(b);if(c.keyIn("js")){require_js_module(c.js)}}}function myObj(){self={};self.keyIn=function(a){return this.hasOwnProperty(a)?true:false};self.isTypeOf=function(a){if(a&&!isSet(a)){return"undefined"}else{if(a&&isFunc(a)&&isSet(a.prototype)){return(this instanceof a)||this.constructor.name==="Dard"?true:false}else{if(!a){return this.constructor.name.toLowerCase()}}}};self.size=function(){var d=0,a,b=this;if(typeof this=="object"){for(a in b){if(!(a in Object.prototype)){b.keyIn(a)?d++:null}}return d}};return self}function camelCase(a){return a.toLowerCase().replace(/[-_]+/g," ").replace(/[^\w\s]/g,"").replace(/ (.)/g,function(b){return b.toUpperCase()}).replace(/ /g,"")}var $=(function(){var f=[],g=window.document,h=/^#{1}[a-z0-9\-\_]+\-*$/i,e=/^\.{1}[a-z0-9\-\_\s]+$/i,a=/^<{1}[a-z]+>{1}$/i,c=/^[a-z1-6]+$/,i={},b=i.toString;Object.assign(Object.prototype,new myObj());var d=function(){var k=this;var l,m;k.extendProto=function(n){if(typeof n==="object"){Object.assign(k,n)}};k.append=function(n){if(this[0]){if(typeof n==="object"){this[0].appendChild(n)}if(isStr(n)){this[0].appendChild(str2el(n))}}};k.clone=function(){if(this[0]){return this[0].cloneNode(true)}};k.text=function(o){if(this[0]){if(isStr(o)){this[0].innerHTML=o}else{if(!o){var n=this[0].innerHTML;return n}}}};k.html=function(){if(this[0]){return this[0].outerHTML}};k.toggle=function(){if(this[0]){var n=window.getComputedStyle(this.el,null).getPropertyValue("display");n==="none"?this[0].style.display="block":this[0].style.display="none"}};k.css=function(p){var n,o="",q;if(isObj(p)&&this[0]){for(n in p){if(p.hasOwnProperty(n)){q=n.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();o+=q+":"+p[n]+";"}}this[0].style.cssText=o}};k.me=function(){if(this[0]){return this[0]}};k.on=function(o,n){if(this[0]){window.onload=this[0].addEventListener(o,n,false)}};k.empty=function(){if(this[0]){while(this[0].firstChild){this[0].removeChild(this[0].firstChild)}}};return k};function j(k,n){var o,m=this,l=varyArgs(arguments);m.constructor.prototype=new d();isNum(l[1])?o=l[1]:o=0;if(typeof k=="string"){if(h.test(k)){m[0]=g.getElementById(k.substring(1))}if(e.test(k)){m[0]=g.getElementsByClassName(k.substring(1))[o]}if(a.test(k)){m[0]=g.createElement(k.replace(/^<+|>+$/gm,""))}if(c.test(k)){m[0]=g.getElementsByTagName(k)[o]}}else{if(isObj(k)&&k.type()==="dard"){m=k}}if(m[0]){return m}}type(d);type(j);return function(){var k=varyArgs(arguments),l;if(k.length>0){isNum(k[1])?l=k[1]:l=0;return new j(k[0],l)}}}());var ajax=function(b){var a=function(){var d=new XMLHttpRequest();d.open(b.type,b.url);d.setRequestHeader("HTTP_X_REQUESTED_WITH","dard_ajax");if(b.type==="POST"&&!b.keyIn("json")){d.setRequestHeader("Content-Type","application/x-www-form-urlencoded")}if(b.keyIn("json")&&b.json===true){d.setRequestHeader("Content-Type","application/json");b.send=JSON.stringify(b.send)}if(b.type==="GET"&&b.keyIn("send")){if(isObj(b.send)){b.send=c(b.send)}}d.onreadystatechange=function(){if(d.readyState===4&&d.status===200){b.response(d.responseText)}if(d.readyState===4&&d.status!==200){if(b.keyIn("error")){b.error?console.log(b.error+d.status):""}}};b.keyIn("send")?d.send(b.send):d.send(null)};function c(d){var e="";for(var f in d){if(d.hasOwnProperty(f)){if(e.length>0){e+="&"}e+=encodeURI(f+"="+d[f])}}return e}a()};function str2el(a){var c=document.createElement("iframe");c.style.display="none";document.body.appendChild(c);c.contentDocument.open();c.contentDocument.write(a);c.contentDocument.close();var b=c.contentDocument.body.firstChild;document.body.removeChild(c);return b}function emptyEl(a){var b=$(a);while(b.firstChild){b.removeChild(b.firstChild)}};