Advertisement
Guest User

Untitled

a guest
May 28th, 2015
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. /* _$
  2. * Recursive $|find
  3. * If you paste _$ & $ into the console of Chrome at
  4. * gist.github.com, you can do use
  5. * `$('div')[0].$('div')[0].$('div')` to return a true
  6. * array of about 7 divs. Advantages over jQuery are
  7. * consistency of API, use of raw JS types such as
  8. * Array, and adherance to raw web standards. Advantages
  9. * over DOM APIs are use of raw JS types such as Array,
  10. * consistency of API and a more familiar interface if
  11. * you're used to jQuery
  12. */
  13.  
  14. function collection$(selector){ // Recursive selector matching within a collection (filter)
  15. var subMatches = this.filter(function(match){
  16. return match.matches(selector);
  17. });
  18. subMatches.$ = subMatches.find = collection$.bind(subMatches);
  19. return subMatches;
  20. }
  21.  
  22. function node$(selector){ // Recursive selector matching within the children of a DOM node
  23. var matches = Array.prototype.slice.apply(this.querySelectorAll(selector));
  24. matches = matches.map(function(match){
  25. match.$ = match.find = node$.bind(match);
  26. return match;
  27. });
  28. matches.$ = matches.find = collection$.bind(matches);
  29. return matches;
  30. };
  31.  
  32. function $(selector){
  33. return node$.bind(document)(selector);
  34. }
  35.  
  36. /*
  37. * Retrieve all "select menus", then filter to those with class "js-language-container",
  38. * grab the first element within those matches, find children with tag name input,
  39. * then filter those inputs down to those that have a name attribute equaling
  40. * '[name="gist[files][][language]"'
  41. */
  42. $('div.select-menu').$('.js-language-container')[0].$('input').$('[name="gist[files][][language]"]');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement