Skip to content

Commit

Permalink
use forms as contexts, closes #65
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Dec 13, 2011
1 parent 69a6149 commit ca2e581
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/qwery.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
function normalizeRoot(root) {
if (!root) return doc
if (typeof root == 'string') return qwery(root)[0]
if (arrayLike(root)) return root[0]
if (!root.nodeType && arrayLike(root)) return root[0]
return root
}

Expand Down
8 changes: 6 additions & 2 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
return 'success'
}
</script>
<script src="../qwery.min.js"></script>
<script src="../src/qwery.js"></script>
<script src="../src/pseudos.js"></script>
<script type="text/javascript">
var Q = qwery.noConflict()
Expand Down Expand Up @@ -118,14 +118,18 @@ <h1>Qwery Tests</h1>
<div class="sibling-selector"></div>
</div>
</div>

<div class="parent">
<h1 class="sibling oldest"></h1>
<h2 class="sibling older"></h2>
<h3 class="sibling middle"></h3>
<h4 class="sibling younger"></h4>
<h5 class="sibling youngest"></h5>
</div>
<form>
<button></button>
<input type="text">
<input type="hidden">
</form>
</div>
<ol id="tests"></ol>
<iframe id="frame" style="width: 0; height: 0; margin-left: -1000px;"></iframe>
Expand Down
6 changes: 6 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ sink('Uniq', function (test, ok) {
})
})


sink('element-context queries', function(test, ok) {
test('relationship-first queries', 5, function() {
var pass = false
Expand Down Expand Up @@ -320,6 +321,11 @@ sink('element-context queries', function(test, ok) {
test('exclude self in match', 1, function() {
ok(Q('.order-matters', Q('#order-matters')).length == 4, 'should not include self in element-context queries')
});

// because form's have .length
test('forms can be used as contexts', 1, function() {
ok(Q('*', Q('form')[0]).length === 3, 'found 3 elements under &lt;form&gt;')
})
})

sink('tokenizer', function (test, ok) {
Expand Down

0 comments on commit ca2e581

Please sign in to comment.