Permalink
Browse files

coerce arguments to sel.matching to be arrays in the ender bridge

  • Loading branch information...
1 parent 00f62c7 commit 906ddbcaeed050ed52b370fa0e80a800ad7598f9 @amccollum committed Jun 11, 2012
Showing with 16 additions and 11 deletions.
  1. +3 −3 lib/ender.js
  2. +2 −2 lib/sel.js
  3. +2 −2 src/extras/ender.coffee
  4. +1 −1 src/sel/matching.coffee
  5. +2 −2 src/sel/sel.coffee
  6. +1 −1 src/sel/util.coffee
  7. +5 −0 src/test/ender-test.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -8,8 +8,8 @@
union: (s, r) -> $(sel.union(this, sel.sel(s, r)))
difference: (s, r) -> $(sel.difference(this, sel.sel(s, r)))
intersection: (s, r) -> $(sel.intersection(this, sel.sel(s, r)))
- matching: (s) -> $(sel.matching(this, s))
- is: (s, r) -> sel.matching(this, s, r).length > 0
+ matching: (s) -> $(sel.matching(sel.extend([], this), s))
+ is: (s) -> sel.matching(sel.extend([], this), s).length > 0
# Method synonyms (these are the names jQuery uses)
methods.and = methods.union
View
@@ -1,7 +1,7 @@
matchesSelector = html.matchesSelector or html.mozMatchesSelector or html.webkitMatchesSelector or html.msMatchesSelector
matchesDisconnected = matchesSelector and matchesSelector.call(document.createElement('div'), 'div')
- sel.matching = matching = (els, selector, roots) ->
+ sel.matching = matching = (els, selector) ->
if matchesSelector and (matchesDisconnected or els.every((el) -> el.document and el.document.nodeType != 11))
try
return els.filter((el) -> matchesSelector.call(el, selector))
View
@@ -4,7 +4,7 @@
html = document.documentElement
- extend = (a, b) ->
+ sel.extend = extend = (a, b) ->
for x in b
a.push(x)
@@ -811,7 +811,7 @@
matchesSelector = html.matchesSelector or html.mozMatchesSelector or html.webkitMatchesSelector or html.msMatchesSelector
matchesDisconnected = matchesSelector and matchesSelector.call(document.createElement('div'), 'div')
- sel.matching = matching = (els, selector, roots) ->
+ sel.matching = matching = (els, selector) ->
if matchesSelector and (matchesDisconnected or els.every((el) -> el.document and el.document.nodeType != 11))
try
return els.filter((el) -> matchesSelector.call(el, selector))
View
@@ -2,7 +2,7 @@
html = document.documentElement
- extend = (a, b) ->
+ sel.extend = extend = (a, b) ->
for x in b
a.push(x)
@@ -14,6 +14,11 @@ vows.add 'Ender Tests',
'should return the h3 third': (result) -> assert.equal result[2].tagName.toLowerCase(), 'h3'
'should return the h4 fourth': (result) -> assert.equal result[3].tagName.toLowerCase(), 'h4'
+ 'and using the .matching method':
+ topic: (els) -> els.matching('h1')
+ 'should return 1 element': (result) -> assert.equal result.length, 1
+ 'should return the h1 element': (result) -> assert.equal result[0].tagName.toLowerCase(), 'h1'
+
'and using the result as roots':
topic: (roots) -> $('.grandchild')
'we should find the grandchild': (result) -> assert.equal result[0].className, 'grandchild'

0 comments on commit 906ddbc

Please sign in to comment.