Posted By

Piotrek290 on 08/29/09


Tagged

javascript js library code SoQ


Versions (?)

SoQ Code - full library


 / Published in: JavaScript
 

  1. // Script name: SoQ JS
  2. // Author: Nicko278 and Dealis
  3. // Lastest version: 1.4.2
  4.  
  5. eJS=$=function(a1,a2,a3){if(typeof a1=='function')$.document(a1);if(typeof a1=='string')var a1=$.nA($.init(a1,a2||0,a3||0));if(!a1.eJS){for(rx in $.e)a1[rx]=$.e[rx];a1.eJS=1;a1.now={};a1.evt={};};return a1;}
  6. $.init=function(a1,a2,a3){var all=[];var a2=a2||document;var a3=a3||'';var a1s=a1.split(/\s*\,\s*(?!\d)/i);if(a1s.length>1){for(var x=0;x<a1s.length;x++){all.push(eJSinit(a1s[x],a2,a3));};var all=merge.apply(0,all);return all.length?all.length==1?all[0]:all:null;}if(a1.replace(/\s/gi,'')=='')return a2;var a1=a1.replace(/\s+/gi,' ').replace(/^\s/,'');var el=a1.split(' ')[0].replace(/\[.*?\]/gi,'');if(el.replace(/\s/gi,'')=='+')return eJSinit(a1.slice(el.length+1),a2,'+');if(el.replace(/\s/gi,'')=='>')return eJSinit(a1.slice(el.length+1),a2,'>');var nm=el.match(/\(([\-\d\,]+)\)/);var nm=nm?nm[1].split(','):'';var co2=el.match(/\=(\d+)(\,\d+)?/i);var co=co2?co2[1]:1;var od=co2&&co2[2]?(co2[2].slice(1).num()-1)%co:co-1;var szz=a3=='+'?a2.parentNode.childNodes:a3=='>'?a2.childNodes:a2.getElementsByTagName(el.match(/^(\w+)/i)?el.match(/^(\w+)/i)[1]:'*');var el=el.replace(/^(\w+)/gi,'[tagName=$1]').replace(/\.(\w+)/gi,'[className~=$1]').replace(/\#(\w+)/gi,'[id=$1]').replace(/\([\d\-\,]\)/gi,'')+a1.slice(el.length);var els=el.match(/\[(.+?)\]/gi);var els=els||[];X:for(var x=0;x<szz.length;x++){var sz=szz[x];for(var z=0;z<els.length;z++){var elsz=els[z].slice(1,-1);var odd=elsz.match(/\!?[\~\^\$\*]?\=\=?/i);var odd=odd?odd[0]:'!=';var naz=elsz.split(odd)[0];var war=elsz.slice(naz.length+odd.length).toLowerCase();if(odd.search('==')==-1)var war=war.replace(/(\W)/gi,'\\$1');if(naz.charAt(0)=='.')var war=war.color().toHex();var szw=naz.charAt(0)=='.'?$.cur(sz,naz.slice(1)).toHex():sz[naz];var szw=szw?szw.toString().toLowerCase():'';var odz=odd.replace('!','').replace('==','=');var wrn=szw.search(RegExp(odz=='='?'^'+war+'$':odz=='~='?'(^|\\W)'+war+'(\\W|$)':odz=='^='?'^'+war:odz=='$='?war+'$':odz=='*='?war:''),'gi');if(odd.search('!')!=-1?wrn!=-1:wrn==-1)continue X;}if(a2!=sz&&sz.tagName&&(ns=$.init(a1.slice(a1.split(' ')[0].length),sz)))all.push($(ns));};var all2=nm?[]:all;if(nm)for(var x=0;x<nm.length;x++){var nma=nm[x].match(/(\-?\d+)\-(\-?\d+)/);var nma=nma?nma:[0,nm[x],nm[x]];var xx1=nma[1]<0?all.length+nma[1].num():nma[1].num();var xx2=nma[2]<0?all.length+nma[2].num():nma[2].num();var xx3=Math.min(xx1,xx2);var xx4=Math.max(xx1,xx2)+1;for(var xx=xx3;xx<xx4;xx++)if(all[xx-1])all2.push(all[xx-1]);}var all3=[];for(var x=od;x<all2.length;x+=co.num())all3.push(all2[x]);var all3=$.merge.apply(0,all3);return all3.length?all3:[];}
  7. $.extend=function(a1){for(x in a1){$.e[x]=a1[x];}};
  8. $.create=function(){return $(document.createElement());}
  9. $.load=function(a1){return $.o[a1||0];}
  10. $.nA=function(a1){return a1.length==1?a1[0]:a1;}
  11. $.merge=function(){var ret=[];for(var m=0;m<arguments.length;m++){if(arguments[m].constructor==Array){for(var mm=0;mm<arguments[m].length;mm++)ret.push(arguments[m][mm]);}else{ret.push(arguments[m]);}};return ret;}
  12. $.rcss=function(a1){var dor=['border!-width','border!-color','border!-style','margin!','padding!'];var kie=['top','right','bottom','left'];var ret='';for(var r=0;r<5;r++){var mth=a1.match(RegExp(dor[r].replace('!','')+'\s*\:\s*([^;]+)\;','i'));var mth2=a1.match(RegExp(dor[r].replace('!','')+'($|\s|\,)','i'));if(mth){for(var rr=0;rr<4;rr++)ret+=dor[r].replace('!','-'+kie[rr])+':'+mth[1].split(' ')[rr%mth[1].split(' ').length]+'; ';var a1=a1.replace(mth[0],ret);}else if(mth2){for(var rr=0;rr<4;rr++)ret+=dor[r].replace('!','-'+kie[rr])+', ';var a1=a1.replace(mth2[0],ret);}};return a1;}
  13. $.zero=function(a1,a2){return '0'.x(a2-a1.toString().length)+a1;}
  14. $.interval=function(a1,a2,a3,a4){var a4=a4||0;this.now=this.now||{};this.now[a4]=0;var arg=[];for(var x=4;x<arguments.length;x++){arg.push(arguments[x]);};arg.push(0);$.t.push([a1,a2,1,this]);$.t.push(arg);this.now[a4]=setInterval(Function('var li='+($.t.length-2)+';$.t[li+1][$.t[li+1].length-1]++;'+(a3?'if(($.t[li][2]++)=='+a3+'){clearInterval($.t[li][3].now["'+a4+'"]);delete $.t[li][3].now["'+a4+'"];};':'')+'$.t[li][0].apply($.t[li][3],$.t[li+1]);'),a2);}
  15. $.between=function(a1,a2,a3){var a3=a3||0.5;if(a1.search(/\#[0-9a-f]+/gi)!=-1||a1.search(/rgb/gi)!=-1){var a1=a1.toHex().slice(1).replace(/[0-9a-f]{2}/gi,function(a1){return $.zero(parseInt(a1,16),3);}).share(3);var a2=a2.toHex().slice(1).replace(/[0-9a-f]{2}/gi,function(a1){return $.zero(parseInt(a1,16),3);}).share(3);return '#'+$.zero((a1[0]-(a1[0]-a2[0])*a3).round().toString(16),2)+$.zero((a1[1]-(a1[1]-a2[1])*a3).round().toString(16),2)+$.zero((a1[2]-(a1[2]-a2[2])*a3).round().toString(16),2);}else if(a1.search(/\d+/gi)!=-1){return (a1.num()-((a1.num()-a2.num())*a3))+(a1.match(/[a-z\%]+/gi)?a1.match(/[a-z\%]+/gi)[0]:'');}else{return a2;}}
  16. $.cur=function(a1,a2){var ret=window.getComputedStyle?window.opera&&!a1.style[a2]&&(a2=='left'||a2=='top')?a1['client'+a2.charAt(0).toUpperCase()+a2.slice(1)]+'px':window.getComputedStyle(a1,null).getPropertyValue(a2):(a1.currentStyle[a2.camelCase()]=='auto'?(a2=='width' ? a1.offsetWidth-$.cur(a1,'padding-left').num()-$.cur(a1,'padding-right').num()-$.cur(a1,'border-left-width').num()-$.cur(a1,'border-right-width').num()+'px':a2=='height'?a1.offsetHeight-$.cur(a1,'padding-top').num()-$.cur(a1,'padding-bottom').num()-$.cur(a1,'border-top-width').num()-$.cur(a1,'border-bottom-width').num()+'px':'0px'):a1.currentStyle[a2.camelCase()]||0);if(ret=='normal')ret='0px';return ret;}
  17. $.obj=function(a1){if(typeof a1=='string'){var ret={};var spl=a1.split(/\s*\;\s*/gi);for(var x=0;x<spl.length;x++){spl2=spl[x].split(/\:\s*/gi);if(spl[x]!='')ret[spl2[0]]=spl2[1];};return ret;}else return a1;}
  18. $.each=function(a1){var th=this.constructor==Array?this:[this];var a1=typeof a1=='string'?Function(a1):a1;var len=th.length;for(var e=0;e<len;e++){var fu=a1.call(th[e],e,th);if(fu)th[e]=fu;};return th;}
  19. $.rand=function(a1,a2){return Math.round(Math.random()*(a2-a1))+a1;}
  20. $.document=function(a1){var obj=window,type='load';if(obj.addEventListener){obj.addEventListener(type,a1,false);}else if (obj.attachEvent){obj["e"+type+a1]=a1;obj[type+a1]=function(){ obj["e"+type+a1](window.event);};obj.attachEvent("on"+type, obj[type+a1]);}}
  21. $.foreach = function(a,c){for(var i=0; i<a.length; ++i)c(a[i])}
  22. $.le=0;
  23. $.t=[];
  24. $.t=[];
  25. $.o={};
  26.  
  27. $.e={
  28. on:function(a1,a2,a3){var tt=this.array();var a3=a3||'no'+($.le++);for(var y=0;y<tt.length;y++){if(window.addEventListener){var a2c=a2;tt[y].addEventListener(a1,a2c,0);}else{var a2c=Function('event','$.t['+($.t.push(a2)-1)+'].call(event.srcElement,event);');tt[y].attachEvent('on'+a1,a2c);};tt[y].evt=tt[y].evt||{};tt[y].evt[a1+'_'+a3]=a2c;};return this;},
  29. no:function(a1,a2){var tt=this.array();for(var y=0;y<tt.length;y++){var te=tt[y].event(a1);for(x in te){if(!a2||x.slice(x.split('_')[0].length+1)==a2){if(window.removeEventListener)tt[y].removeEventListener(x.split('_')[0],tt[y].evt[x],false);else tt[y].detachEvent('on'+x.split('_')[0],tt[y].evt[x]);}}};return this;},
  30. event:function(a1,a2){var ret={};var tt=this.array();if(typeof a1=='object'){for(var y=0;y<tt.length;y++)for(x in a1)tt[y].on(x.split('_')[0],a1[x],x.slice(x.split('_')[0].length+1));return this;}else for(var y=0;y<tt.length;y++)for(x in tt[y].evt)if(!a1||a1=='all'||x.split('_')[0]==a1){if(a2&&x==a1+'_'+a2){return tt[y].evt[x]}else{ret[x]=tt[y].evt[x];}}return ret;},
  31. css:function(a1){if(typeof a1=='string'&&a1.search(/\:/gi)==-1){return $.cur(this.array()[0],a1);};tt=this.array();var a1=$.obj(a1);for(var y=0;y<tt.length;y++){for(x in a1)tt[y].style[x.camelCase()]=a1[x];}return this;},
  32. anim:function(a1,a2,a3,a4,a5){var a1=$.obj($.rcss(a1));var a2=a2||1000;var a3=a3||a2/25;var a4=a4||0;var a5=typeof a5=='function'?a5:typeof a5=='string'?Function(a5):Function('');tt=this.array();var ttl=tt.length;var xx=0;for(var y=0;y<ttl;y++){for(x in a1){if(tt[y].style[x.camelCase()]!=undefined){$.interval.call(tt[y],Function("a1","a2","a3","a4","a5","a1.style."+x.camelCase()+"=$.between(a2,'"+a1[x]+"',"+(a4==0||a4==3?"Math.abs(Math.sin(Math.PI/2*(1/"+a3+")*a5)));":a4==1?"(1-Math.sin(Math.PI/2*(1-((1/"+a3+")*a5)))));":"(1/"+a3+")*"+(a4==4?"(a5%"+a3+"||1));":"a5);"))+(!xx++?"if(a5=="+a3+")$.interval.call(a1,function(a1,a2){a1.call(a2);},50,1,'an',a3,a4);":"")),a2/a3,a4==3||a4==4?0:a3,x,tt[y],$.cur(tt[y],x).color(),a5,this);}else{$.interval.call(tt[0],function(a1,a2){a1.call(a2);},a2+50,1,'anim',a5,this);}}};return this;},
  33. stop:function(a11,a111){ttt=this.array();var a11=$.rcss(a11||'');var a12=a11.split(/\s*[\,\;]\s*/gi);for(var z=0;z<a12.length;z++){for(var y=0;y<ttt.length;y++){if(ttt[y].now){for(x in ttt[y].now){if(a111?(a12[z]!=x):(!a11||a12[z]==x)){clearInterval(ttt[y].now[x]);delete ttt[y].now[x];}}}}};if(!a11)clearInterval(ttt[0].now['anim']);return this;},
  34. array:function(){return this.constructor==Array?this:[this];},
  35. remove:function(){tt=this.array();for(var y=0;y<tt.length;y++){if(tt[y].parentNode)tt[y].parentNode.removeChild(tt[y]);};return this;},
  36. next:function(a1){tt=this.array();Y:for(var y=0;y<tt.length;y++){var tns=tt[y].nextSibling;while(tns){if(tns.tagName){tt[y]=tns;break Y;}else{tns=tns.nextSibling;}};if(a1)tt[y]=0;};return $($.nA(tt));},
  37. prev:function(a1){tt=this.array();Y:for(var y=0;y<tt.length;y++){var tns=tt[y].previousSibling;while(tns){if(tns.tagName){tt[y]=tns;break Y;}else{tns=tns.previousSibling;}};if(a1)tt[y]=0;};return $($.nA(tt));},
  38. parent:function(){if(this.length)for(var y=0;y<this.length;y++){this[y]=this[y].parentNode;}else return this.parentNode;return this;},
  39. empty:function(){tt=this.array();for(var y=0;y<tt.length;y++){tt[y].innerHTML='';};return this;},
  40. inneR:function(a1,a2,a3){if(a1){var tt=this.array();for(var y=0;y<tt.length;y++){var a11=typeof a1=='function'?a1.call(tt[y],y,tt):a1;var a12=a11.constructor==Array?a11[a3?y%a11.length:y]||tt[y][a2==2?'value':'innerHTML']:a11;if(a2==1)tt[y].empty().create(document.createTextNode(a12));else if(a2==2)tt[y].value=a12;else tt[y].innerHTML=a12.replace(/^\.\.|\.\.$/gi,tt[y].innerHTML).replace(/\.(-?\d+)\./gi,function(a1,a2){return y+a2.num();})};return this;};return $($.nA(this.array().each("return this."+(a2==1?"innerHTML.replace(/\<.+?\>/gi,'')":a2==3?"value":"innerHTML"))));},
  41. html:function(a1,a2){return this.inneR(a1||0,0,a2);},
  42. tekst:function(a1,a2){return this.inneR(a1||0,1,a2);},
  43. val:function(a1,a2){return this.inneR(a1||0,2,a2);},
  44. show:function(){var tt=this.array();for(var y=0;y<tt.length;y++){tt[y].style.display='';};return this;},
  45. hide:function(){var tt=this.array();for(var y=0;y<tt.length;y++){tt[y].style.display='none';};return this;},
  46. clone:function(a1){var tt=this.array();var tt2=[];for(var y=0;y<tt.length;y++){var tt3=$(tt[y].cloneNode(1));var ttc=tt[y].child('*').array();var tt3c=tt3.child('*').array();if(!document.all){tt3.event(tt[y].evt);for(var z=0;z<ttc.length;z++)tt3c[z].event(ttc[z].evt);};tt2.push(tt3);};return $($.nA(tt2));},
  47. create:function(a1,a2,a3){if(a2){var nt=[];for(var z=0;z<a2;z++)nt=$.merge(nt,this.create(a1,0,a3));return $($.nA(nt));};var tt=this.array();var tt2=[];if(typeof a1=='string'){for(var y=0;y<tt.length;y++)tt2.push(tt[y].appendChild($(document.createElement(a1))));return $($.nA(tt2));}else{var a1=$(a1).array();for(var y=0;y<tt.length;y++)for(var x=(a3?0:y);x<(a3?a1.length:y+1);x++)tt2.push(tt[y].appendChild($(a1[x]).clone(1)));$(a1).remove();return $($.nA(tt2));}},
  48. one:function(){var tt=this.array();var tt2=[];Y:for(var y=0;y<tt.length;y++){for(var x=0;x<tt2.length;x++)if(tt[y]==tt2[x])continue Y;tt2.push(tt[y]);};return $(tt2);},
  49. to:function(a1,a2){return $(a1).create(this,0,$(a1).length?a2:1);},
  50. append:function(a1,a2){return this.create($(a1),0,this.length?a2:1);},
  51. index:function(a1){var tt=this.array();for(var y=0;y<tt.length;y++)if(tt[y]==a1)return y+1;},
  52. add:function(a1){return $($.merge(this,$(a1)));},
  53. sub:function(a1){var a1=$(a1).array();var tt=this.array();var tt2=[];Y:for(var y=0;y<tt.length;y++){for(var x=0;x<a1.length;x++){if(tt[y]==a1[x])continue Y;};tt2.push(tt[y]);};return $($.nA(tt2));},
  54. dif:function(a1){var a1=$(a1).array();var tt=this.array();var tt2=[];Y:for(var y=0;y<tt.length;y++)for(var x=0;x<a1.length;x++)if(tt[y]==a1[x])tt2.push(tt[y]);return $($.nA(tt2));},
  55. child:function(a1,a2){var tt=this.array();var tt2=[];for(var y=0;y<tt.length;y++){var tt2=$.merge(tt2,$(a1,tt[y],a2||''));};return $($.nA(tt2));},
  56. sibling:function(a1){var tt=this.array();var tt2=[];for(var y=0;y<tt.length;y++){var tt2=$.merge(tt2,$(a1,tt[y],'+'));};return $($.nA(tt2));},
  57. att:function(){var tt=this.array();var ret=[];if(arguments.length==1){for(var y=0;y<tt.length;y++)ret.push(tt[y].getAttribute(arguments[0]));return $($.nA(ret));};for(var y=0;y<tt.length;y++)for(var x=0;x<arguments.length;x+=2)tt[y].setAttribute(arguments[x],typeof arguments[x+1]=='function'?arguments[x+1].call(tt[y]):arguments[x+1]);return this;},
  58. sort:function(){var tt=this.array();var tt2=[];var all=$('*');for(var x=0;x<all.length;x++)for(var y=0;y<tt.length;y++)if(tt[y]==all[x])tt2.push($(tt[y]));return $($.nA(tt2));},
  59. slice:function(){var ret=[];for(var x=0;x<arguments.length;x+=2)ret=$.merge(ret,$(Array.prototype.slice.call(this.array(),arguments[x]||0,arguments[x+1]||this.array().length)));return $($.nA(ret));},
  60. sel:function(){var ret=[];for(var x=0;x<arguments.length;x++)if(this.array()[arguments[x]-1])ret=$.merge(ret,this.array()[arguments[x]-1]);return $($.nA(ret));},
  61. save:function(a1){return $.o[a1||0]=this;},
  62. load:function(a1){return $.o[a1||0];},
  63. move:function(a1,a2){var tt=this.array().sort();if(a1>-1)var tt=tt.reverse();var dd=a1<0?-a1:a1+1;for(var y=0;y<tt.length;y++){var elm=a2?(a2.constructor==Array?a2:[a2])[y]:tt[y];var elm2=elm;for(var x=0;x<dd;x++){var elm=$(elm)[a1<0?'prev':'next'](1);if(!elm)break;};elm2.parentNode.insertBefore(tt[y],elm||null);};return this;},
  64. len:function(){return this.array().length;},
  65. each:$.each,
  66. foreach:function(c){$.foreach(this,c);}
  67. };
  68.  
  69. Ap=Array.prototype;
  70. Sp=String.prototype;
  71. Np=Number.prototype;
  72. Fp=Function.prototype;
  73. Np.round=function(){return Math.round(this);}
  74. Sp.round=function(){return Math.round(this.num());}
  75. Np.num=function(){return this;}
  76. Sp.num=function(){return parseFloat(this);}
  77. Sp.camelCase=function(){return this.replace(/-(.)/gi,function(a1,a2){return a2.toUpperCase();});}
  78. Sp.x=function(a1,a2){return Array(a1+1).join(this+(a2||''));}
  79. Sp.toHex=function(){var th=this.toString();if(th.search(/rgb/gi)!=-1){return '#'+th.split('(')[1].split(')')[0].replace(/\d+/gi,function(a1){return a1.num()<16?'0'+a1.num().toString(16):a1.num().toString(16);}).replace(/\,|\s/gi,'');};if(th.search(/\#[0-9a-f]+/gi)!=-1){var th=th.replace(/\#/gi,'');var th2='';for(var x=0;x<th.length;x++){th2+=th.charAt(x).x(Math.round(6/th.length));};return '#'+th2.slice(0,6);};return th.color();}
  80. Sp.rep=function(a1){var ret=this.toString();for(x in a1){ret=ret.replace(RegExp(x,'gi'),a1[x]);};return ret;}
  81. Sp.color=function(){return this.rep({'transparent':'#ffffff','black':'#000000','maroon':'#800000','green':'#008000','olive':'#808000','navy':'#000080','purple':'#800080','teal':'#008080','silver':'#c0c0c0','gray':'#808080','red':'#ff0000','lime':'#00ff00','yellow':'#ffff00','blue':'#0000ff','fuchsia':'#ff00ff','aqua':'#00ffff','white':'#ffffff'});}
  82. Sp.share=function(a1){var ret=[];for(var x=0;x<this.length;x+=a1){ret.push(this.slice(x,x+a1));};return ret;}
  83. Ap.is=function(a1){for(var i=0;i<this.length;i++)if(this[i]==a1)return true;return false;};
  84. Ap.each=$.each;
  85. Fp.partial=function(){var fn=this,args=Array.prototype.slice.call(arguments);return function(){var arg=0;for(var i=0;i<args.length&&arg<arguments.length;i++)if (args[i]===undefined)args[i]=arguments[arg++];return fn.apply(this, args);};};
  86.  
  87. // MODULES
  88. $.mouse = function(e){e=e||window.Event;if(e.pageX&&e.pageY){return{x:e.pageX,y:e.pageY};}else if(e.clientX&&e.clientY){return{x:e.clientX+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft),y:e.clientY+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop)};}else{return null;}}
  89. $.selection = function(){ if(window.getSelection)return window.getSelection(); else if(document.selection)return document.selection.createRange(); }
  90. $.key = function(e){ e=window.event||e; return e.keyCode||e.which; }

Report this snippet  

You need to login to post a comment.