Created
          January 22, 2010 00:23 
        
      - 
      
- 
        Save remy/283362 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | find: function(q, context) { | |
| var ele = [], list, i, j, x; | |
| this.cache = context; | |
| // this doesn't feel quite right, we should be able to do [#foo,bar].querySelectorAll (or something) - TODO add loop | |
| if (context == undefined && this.length == 1) { | |
| return xui(q, this[0]); // results = [].slice.call(this) | |
| } else if (context == undefined && this.length > 1) { | |
| // do some sort of loop - maybe this: | |
| /* | |
| this.each(function () { | |
| ele = [].slice.call(this, xui(q, this)); | |
| }); | |
| ele = this.reduce(ele); | |
| */ | |
| } else { | |
| context = document; | |
| } | |
| // fast matching for pure ID selectors | |
| if (typeof q == string && idExpr.test(q)) { | |
| ele = [context.getElementById(q.substr(1))]; | |
| } else if (typeof q == string) { | |
| // one selector | |
| ele = [].slice.call(context.querySelectorAll(q)); | |
| } else { | |
| // an element was passed in | |
| ele = [q]; | |
| } | |
| // disabling the append style, could be a plugin: | |
| // xui.fn.add = function (q) { this.elements = this.elements.concat(this.reduce(xui(q).elements)); return this; } | |
| this.length = 0; | |
| [].push.apply(this, ele); // gotta love apply - works like a fucking charm! | |
| return this; | |
| }, | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment