Permalink
Browse files

add $.contains()

  • Loading branch information...
mislav committed Oct 3, 2012
1 parent 9b46bcf commit 130cb932be993cae402045685e49336af04a2df9
Showing with 20 additions and 0 deletions.
  1. +4 −0 src/zepto.js
  2. +16 −0 test/zepto.html
View
@@ -214,6 +214,10 @@ var Zepto = (function() {
return selector === undefined ? $(nodes) : $(nodes).filter(selector)
}
+ $.contains = function(parent, node) {
+ return parent !== node && parent.contains(node)
+ }
+
function funcArg(context, arg, idx, payload) {
return isFunction(arg) ? arg.call(context, idx, payload) : arg
}
View
@@ -969,6 +969,22 @@ <h1>Zepto DOM unit tests</h1>
t.assertEqualCollection(el, el.closest('div'))
},
+ testContains: function(t){
+ var el1 = $('#li1'), el2 = $('#li2')
+
+ t.assertTrue($.contains(el1.get(0), el2.get(0)))
+ t.assertFalse($.contains(el1.get(0), $('#parents').get(0)))
+ },
+
+ testContainsOnDetached: function(t){
+ var el = $('<div><p><a></a></p></div>'),
+ para = el.children(),
+ link = para.children()
+
+ t.assertTrue($.contains(para.get(0), link.get(0)))
+ t.assertFalse($.contains(document.body, el.get(0)))
+ },
+
testParents: function(t){
var body = document.body, html = body.parentNode, container = $('#parents'),
wrapper = $('#fixtures').get(0)

0 comments on commit 130cb93

Please sign in to comment.