Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* _$
- * Recursive $|find
- * If you paste _$ & $ into the console of Chrome at
- * gist.github.com, you can do use
- * `$('div')[0].$('div')[0].$('div')` to return a true
- * array of about 7 divs. Advantages over jQuery are
- * consistency of API, use of raw JS types such as
- * Array, and adherance to raw web standards. Advantages
- * over DOM APIs are use of raw JS types such as Array,
- * consistency of API and a more familiar interface if
- * you're used to jQuery
- */
- function collection$(selector){ // Recursive selector matching within a collection (filter)
- var subMatches = this.filter(function(match){
- return match.matches(selector);
- });
- subMatches.$ = subMatches.find = collection$.bind(subMatches);
- return subMatches;
- }
- function node$(selector){ // Recursive selector matching within the children of a DOM node
- var matches = Array.prototype.slice.apply(this.querySelectorAll(selector));
- matches = matches.map(function(match){
- match.$ = match.find = node$.bind(match);
- return match;
- });
- matches.$ = matches.find = collection$.bind(matches);
- return matches;
- };
- function $(selector){
- return node$.bind(document)(selector);
- }
- /*
- * Retrieve all "select menus", then filter to those with class "js-language-container",
- * grab the first element within those matches, find children with tag name input,
- * then filter those inputs down to those that have a name attribute equaling
- * '[name="gist[files][][language]"'
- */
- $('div.select-menu').$('.js-language-container')[0].$('input').$('[name="gist[files][][language]"]');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement