-
Notifications
You must be signed in to change notification settings - Fork 0
/
go.min.js
1 lines (1 loc) · 4.91 KB
/
go.min.js
1
var gO={author:"Gabriel Conceição <[email protected]>",description:"gO library",date:"02-2014",version:"0.1",ready:function(t){var e=this;this.start(),this.wd.on("goready",function(){t(e.wd)})},start:function(t){return this.wd?!1:(this.wd=window,this._initDom(),this._initVars(),!0)},dom:{el:function(t,e){return e?this.querySelectorAll?this.querySelectorAll(t):document.querySelectorAll(t):this.querySelector?this.querySelector(t):document.querySelector(t)},atr:function(t,e){return e?(this.setAttribute(t,e),this):this.getAttribute(t)},delAtr:function(t){return t?(this.removeAttribute(t),this):!1},val:function(t){return t||""==t?(this.innerHTML=t,this):this.innerHTML},isCls:function(t){if(!this.className)return!1;if("undefined"==typeof t||""==t)return!1;for(var e=this.className.split(" "),i=0;i<e.length;i++)if(e[i]==t)return!0;return!1},cls:function(t){return"undefined"!=typeof t?""==t?this.className="":gO.dom.isCls.call(this,t)?!1:this.className=this.className+" "+t:this.className},firstCls:function(){var t=this.className.indexOf(" ");return this.className.length?-1==t?this.className:this.className.substring(0,t):!1},addCls:function(t){return t?gO.dom.isCls.call(this,t)?this:this.className?(this.className=this.className+" "+t,this):(this.className=t,this):!1},delCls:function(t){return gO.dom.isCls.call(this,t)?(this.className=this.className.replace(" "+t,"").replace(t,""),this):this},getStl:function(t,e){return t?(stlEl=window.getComputedStyle(this),stlEl?(t=stlEl[t],t?t.replace(e,""):""):""):window.getComputedStyle(this)},setStl:function(t,e){return t?"object"==typeof t?(this.style=t,this):(this.style[t]=e,this):!1},show:function(t,e){return t?e?t.insertBefore(this,t.childNodes[0]):t.appendChild(this):!1},flash:function(t){return t.parentNode.replaceChild(this,t),t},create:function(t,e){if(!t)return!1;var i=document.createElement(t);return gO.dom.cls.call(this,e),gO.dom.show(i)},parent:function(t){if(!t)return this.parentNode||!1;for(var e=this,i=0;t>=i;i++)e=e.parentNode;return e},parents:function(t){for(var e=this,i=[];"BODY"!=e.tagName;)if(e=e.parentNode,i.push(e),e===t)return{parents:i,match:!0};return i},on:function(){var t=arguments;if(t.length<2)return!1;if(2==t.length)for(var e=t[0].split(" "),i=0;i<e.length;i++)this["_on"+e[i]]=function(e){e.el=this,t[1].call(gO,e)},this.addEventListener(e[i],this["_on"+e[i]],!1);if(t.length>2)if("function"==typeof t[2])for(var n=this.el(t[0],!0),r=0;r<n.length;r++)for(var e=t[1].split(" "),i=0;i<e.length;i++)this["_on"+e[i]]=function(e){e.el=this,t[2].call(t[3]||gO,e)},n[r].addEventListener(e[i],this["_on"+e[i]],!1);else for(var e=t[0].split(" "),i=0;i<e.length;i++)this["_on"+e[i]]=function(e){e.el=this,t[1].call(t[2],e)},this.addEventListener(e[i],this["_on"+e[i]],!1);return this},off:function(t){if(!t)return!1;t=t.split(" ");for(var e=0;e<t.length;e++)this.removeEventListener(t[e],this["_on"+t[e]],!1);return this},fire:function(t,e){if(!t)return!1;var i=window.document.createEvent("CustomEvent");return i.initCustomEvent(t,!0,!0,e),this.dispatchEvent(i,e),this},tag:function(){return this.tagName},del:function(){return this.parent().removeChild(this),!0},els:{Input:{val:function(t){return t||""==t?(this.value=t,this):this.value}},Select:{val:function(t){return t?this.value=t:this.value},index:function(t){return""!=t&&t?(this.selectedIndex=t,this):this.selectedIndex}},TextArea:{val:function(t){return t||""==t?(this.value=t,this):this.value}}}},vars:{defString:{has:function(t){return this.indexOf(t)>-1},rpl:function(t,e){return this.replace(new RegExp(t,"g"),e)},"null":function(t){return!this.length},upper:function(t){if(!this.length)return!1;if(!t)return this.toUpperCase();for(var e="",i=0;t>i;i++)e+=this.charAt(i).toUpperCase();return e+=this.slice(t)},html:function(){return this.length?this.rpl("\n","<br>"):""},text:function(){return this.length?this.rpl("<br>","\n"):!0}},defArray:{order:function(t,e){var i=this[t];this[t]=this[e],this[e]=i}}},_initDom:function(){for(var t in this.dom)if("els"==t)for(var e in this.dom.els)for(var i in this.dom.els[e])window["HTML"+e+"Element"].prototype[i]=this.dom.els[e][i];else window.Element.prototype[t]=this.dom[t];window.on=this.dom.on,window.fire=this.dom.fire},_initVars:function(){for(var t in this.vars)for(var e in this.vars[t])window[t.replace("def","")].prototype[e]=this.vars[t][e]},elCreate:function(t,e){if(!t)return!1;var i=document.createElement(t);return e&&(i.className=e),i},el:function(t,e){return this.dom.el(t,e)},breakLine:function(){return"<br>"},dispach:function(t,e,i){this["_on"+t+e](this,i)},elFlash:function(t,e,i,n){if(!t||!e)return!1;if(!i)var i=500;var r=0;switch(e){case"error":var s=setInterval(function(){t.isCls("error")?t.delCls("error"):(t.addCls("error"),r++),r>=n&&(t.isCls("error")||t.addCls("error"),clearInterval(s))},i)}},width:function(){return this.wd.innerWidth},heigth:function(){return this.wd.innerHeight}};document.onreadystatechange=function(){"complete"==document.readyState&&(gO.start(),gO.wd.fire("goready"))};