Skip to content

Commit

Permalink
Fixed bug in $() where it would only search for nodes in the first co…
Browse files Browse the repository at this point in the history
…ntext item supplied, whereas it should find child nodes in all contexts that are supplied.

Added tests.
Bumped to 0.9.11.
  • Loading branch information
hexydec committed Mar 12, 2020
1 parent 9b40916 commit 096a980
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A lightweight modular jQuery clone/alternative library built for modern browsers
![Licence](https://img.shields.io/badge/Licence-MIT-lightgrey.svg)
![Project Status](https://img.shields.io/badge/Project%20Status-Beta-yellow.svg)
![Size Minified](https://img.shields.io/badge/Size%20(Minified)-17.8kb-brightgreen.svg)
![Size Gzipped](https://img.shields.io/badge/Size%20(Gzipped)-6.48kb-brightgreen.svg)
![Size Gzipped](https://img.shields.io/badge/Size%20(Gzipped)-6.50kb-brightgreen.svg)

**This project is now in beta, make sure to test your integration with this code thoroughly before deploying**

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dabbyjs",
"version": "0.9.10",
"version": "0.9.11",
"homepage": "https://hexydec.github.io/dabby",
"author": "Will Earp <will@hexydec.com>",
"description": "A lightweight modular ES6 jQuery clone library built for modern browsers",
Expand Down
5 changes: 4 additions & 1 deletion src/core/dabby/dabby.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const $ = function dabby(selector, context) {

// if the context exists, filter
if (context.length) {
nodes = context[0].querySelectorAll(selector);
let i = context.length;
while (i--) {
nodes = Array.from(context[i].querySelectorAll(selector)).concat(nodes);
}
}

// create a single node and attach properties
Expand Down
6 changes: 6 additions & 0 deletions src/core/dabby/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@ QUnit.test("$.fn.init", function (assert) {

// empty node
assert.deepEqual($(".something-that-doesnt-exist").get(), [], "Returns empty collection when selection isn't available");

// test filtering by many nodes
test.innerHTML = '<table><tr><td>test 1</td></tr><tr><td>test 2</td></tr><tr><td>test 3</td></tr></table>';
assert.equal($("td", test.querySelectorAll("tr")).length, 3, "Can refine selection by multiple contexts sent as a node collection");
obj = $("tr", test);
assert.equal($("td", obj).length, 3, "Can refine selection by multiple contexts wrapped in a dabby object");
});

0 comments on commit 096a980

Please sign in to comment.