vendor/DocumentUp/documentup.js
function _qwery(selector, _root) {
      var r = [], ret = [], i, l, m, token, tag, els, intr, item, root = _root
        , tokens = tokenCache.g(selector) || tokenCache.s(selector, selector.split(tokenizr))
        , dividedTokens = selector.match(dividers)
  
      if (!tokens.length) return r
  
      token = (tokens = tokens.slice(0)).pop() // copy cached tokens, take the last one
      if (tokens.length && (m = tokens[tokens.length - 1].match(idOnly))) root = byId(_root, m[1])
      if (!root) return r
  
      intr = q(token)
      // collect base candidates to filter
      els = root !== _root && root.nodeType !== 9 && dividedTokens && /^[+~]$/.test(dividedTokens[dividedTokens.length - 1]) ?
        function (r) {
          while (root = root.nextSibling) {
            root.nodeType == 1 && (intr[1] ? intr[1] == root.tagName.toLowerCase() : 1) && (r[r.length] = root)
          }
          return r
        }([]) :
        root[byTag](intr[1] || '*')
      // filter elements according to the right-most part of the selector
      for (i = 0, l = els.length; i < l; i++) {
        if (item = interpret.apply(els[i], intr)) r[r.length] = item
      }
      if (!tokens.length) return r
  
      // filter further according to the rest of the selector (the left side)
      each(r, function(e) { if (ancestorMatch(e, tokens, dividedTokens)) ret[ret.length] = e })
      return ret
    }
function _qwery(selector, _root) {
      var r = [], ret = [], i, l, m, token, tag, els, intr, item, root = _root
        , tokens = tokenCache.g(selector) || tokenCache.s(selector, selector.split(tokenizr))
        , dividedTokens = selector.match(dividers)
  
      if (!tokens.length) return r
  
      token = (tokens = tokens.slice(0)).pop() // copy cached tokens, take the last one
      if (tokens.length && (m = tokens[tokens.length - 1].match(idOnly))) root = byId(_root, m[1])
      if (!root) return r
  
      intr = q(token)
      // collect base candidates to filter
      els = root !== _root && root.nodeType !== 9 && dividedTokens && /^[+~]$/.test(dividedTokens[dividedTokens.length - 1]) ?
        function (r) {
          while (root = root.nextSibling) {
            root.nodeType == 1 && (intr[1] ? intr[1] == root.tagName.toLowerCase() : 1) && (r[r.length] = root)
          }
          return r
        }([]) :
        root[byTag](intr[1] || '*')
      // filter elements according to the right-most part of the selector
      for (i = 0, l = els.length; i < l; i++) {
        if (item = interpret.apply(els[i], intr)) r[r.length] = item
      }
      if (!tokens.length) return r
  
      // filter further according to the rest of the selector (the left side)
      each(r, function(e) { if (ancestorMatch(e, tokens, dividedTokens)) ret[ret.length] = e })
      return ret
    }
function _qwery ( selector , _root ) { var r = [ ] , ret = [ ] , i , l , m , token , tag , els , intr , item , root = _root , tokens = tokenCache . g ( selector ) || tokenCache . s ( selector , selector . split ( tokenizr ) ) , dividedTokens = selector . match ( dividers ) if ( ! tokens . length ) return r token = ( tokens = tokens . slice ( 0 ) ) . pop ( ) // copy cached tokens, take the last one if ( tokens . length && ( m = tokens [ tokens . length - 1 ] . match ( idOnly ) ) ) root = byId ( _root , m [ 1 ] ) if ( ! root ) return r intr = q ( token ) // collect base candidates to filter els = root !== _root && root . nodeType !== 9 && dividedTokens && / ^[+~]$ / . test ( dividedTokens [ dividedTokens . length - 1 ] ) ? function ( r ) { while ( root = root . nextSibling ) { root . nodeType == 1 && ( intr [ 1 ] ? intr [ 1 ] == root . tagName . toLowerCase ( ) : 1 ) && ( r [ r . length ] = root ) } return r } ( [ ] ) : root [ byTag ] ( intr [ 1 ] || '*' ) // filter elements according to the right-most part of the selector for ( i = 0 , l = els . length ; i < l ; i ++ ) { if ( item = interpret . apply ( els [ i ] , intr ) ) r [ r . length ] = item } if ( ! tokens . length ) return r // filter further according to the rest of the selector (the left side) each ( r , function ( e ) { if ( ancestorMatch ( e , tokens , dividedTokens ) ) ret [ ret . length ] = e } ) return ret }
given a selector, first check for simple cases then collect all base candidate matches and filter
given a selector first check for simple cases then collect all base candidate matches and filter