Guest User

jQuery.fn.descendants

a guest
Feb 15th, 2014
355
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Generated by CoffeeScript 1.7.1
  2. var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
  3.  
  4. jQuery.fn.descendants = function(textNodes) {
  5.   var allowedTypes, dig, node, nodes, _i, _len;
  6.   allowedTypes = textNodes === 'all' ? [1, 3] : textNodes ? [3] : [1];
  7.   nodes = [];
  8.   dig = function(node) {
  9.     var child, _i, _len, _ref, _ref1, _results;
  10.     _ref = node.childNodes;
  11.     _results = [];
  12.     for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  13.       child = _ref[_i];
  14.       if (_ref1 = child.nodeType, __indexOf.call(allowedTypes, _ref1) >= 0) {
  15.         nodes.push(child);
  16.       }
  17.       if (child.childNodes.length) {
  18.         _results.push(dig(child));
  19.       } else {
  20.         _results.push(void 0);
  21.       }
  22.     }
  23.     return _results;
  24.   };
  25.   for (_i = 0, _len = this.length; _i < _len; _i++) {
  26.     node = this[_i];
  27.     dig(node);
  28.   }
  29.   return jQuery(nodes);
  30. };
RAW Paste Data