142
St
startsInvasion / files
startsInvasion / libs / node_modules / qwery / src / pseudos.js
1.1 KB
1!function () { 2 function children(node) { 3 var i, nodes = node.childNodes, r = [], l; 4 for (i = 0, l = nodes.length; i < l; i++) { 5 var item = nodes[i]; 6 nodes[i].nodeType == 1 && r.push(nodes[i]); 7 } 8 return r; 9 } 10 qwery.pseudos['last-child'] = function (el, p, childs) { 11 return el.parentNode && (p = el.parentNode) && (childs = children(p)) && childs[childs.length - 1] == el; 12 }; 13 14 qwery.pseudos['first-child'] = function (el, p) { 15 return el.parentNode && (p = el.parentNode) && (childs = children(p)) && childs[0] == el; 16 }; 17 18 qwery.pseudos['nth-child'] = function (el, val, p) { 19 if (!val || !(p = el.parentNode)) return false; 20 var childs = children(p), i, l; 21 if (isFinite(val)) { 22 return childs[val - 1] == el; 23 } else if (val == 'odd') { 24 for (i = 0, l = childs.length;i < l; i = i + 2) { 25 if (el == childs[i]) return true; 26 } 27 } else if (val == 'even') { 28 for (i = 1, l = childs.length;i < l; i = i + 2) { 29 if (el == childs[i]) return true; 30 } 31 } 32 return false; 33 }; 34}();