Posted By

Piotrek290 on 09/11/09


Tagged


Versions (?)

jQuery algorythm


 / Published in: JavaScript
 

  1. function $(a1,a11){
  2. var aR=[],aT={Id:/\#(\w*)/,ClassName:/\.(\w*)/},Lp=/\:(last|(\d*))/,Ld=0;
  3. for(i in a1.split(' ')){
  4. var a2=a1.split(' ')[i],aO=(!aR.length?document.body:aR[Ld]).getElementsByTagName(a2.match(/\w*/)[0]||'*'),Ld=Lp.exec(a2)?(Lp.exec(a2)[1]=='last'?aO.length-1:Lp.exec(a2)[1]-1):0;var aR=[];
  5.  
  6. aJ:for(j=0;j<aO.length;j++){
  7. for(k in aT){if(aT[k].exec(a2)?aT[k].exec(a2)[1]!=aO[j][k.charAt(0).toLowerCase()+k.slice(1)]:0)continue aJ;}
  8. aR.push(aO[j]);
  9. }
  10. };
  11. if(Lp.exec(a2)&&Lp.exec(a2)[1])return aR[Lp.exec(a2)[1]=='last'?aR.length-1:Lp.exec(a2)[1]-1];
  12. return aR.length?(aR.length==1&&!a11?aR[0]:aR):undefined;
  13. }

Report this snippet  

You need to login to post a comment.