Skip to content

Commit a1b202f

Browse files
committed
Bumped version to 0.9.7.
Updated some tests to use module format. Added more tests to getVal(). Added tests for $.fn.closest() and $.fn.parentsUntil(). Fixed bugs in $.fn.parentsUntil() where it returned the matching element, and didn't filter the nodes correctly.
1 parent 6b908d3 commit a1b202f

File tree

17 files changed

+380
-221
lines changed

17 files changed

+380
-221
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A lightweight modular jQuery clone/alternative library built for modern browsers
55
![Licence](https://img.shields.io/badge/Licence-MIT-lightgrey.svg)
66
![Project Status](https://img.shields.io/badge/Project%20Status-Beta-yellow.svg)
77
![Size Minified](https://img.shields.io/badge/Size%20(Minified)-16.6kb-brightgreen.svg)
8-
![Size Gzipped](https://img.shields.io/badge/Size%20(Gzipped)-6.07kb-brightgreen.svg)
8+
![Size Gzipped](https://img.shields.io/badge/Size%20(Gzipped)-6.09kb-brightgreen.svg)
99

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

dist/dabby.es5.js

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dabby.es5.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dabby.es5.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dabby.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! dabbyjs v0.9.6 by Will Earp - https://github.com/hexydec/dabby */
1+
/*! dabbyjs v0.9.7 by Will Earp - https://github.com/hexydec/dabby */
22

33
const $ = function dabby(selector, context) {
44

@@ -563,15 +563,20 @@ $.fn.add = function (nodes, context) {
563563
while (i--) {
564564
parent = this[i].parentNode;
565565
while (parent && parent.nodeType === Node.ELEMENT_NODE) {
566+
if (until && filterNodes(parent, selector).length) {
567+
break;
568+
}
566569
nodes.push(parent);
567-
if (!all || (until && filterNodes(parent, selector).length)) {
570+
if (!all) {
568571
break;
569-
} else {
570-
parent = parent.parentNode;
571572
}
573+
parent = parent.parentNode;
572574
}
573575
}
574-
return $(selector ? filterNodes(nodes, selector) : nodes);
576+
if (!until) {
577+
filter = selector;
578+
}
579+
return $(filter ? filterNodes(nodes, filter) : nodes);
575580
};
576581
});
577582

@@ -1373,7 +1378,7 @@ $.fn.closest = function (selector, context) {
13731378
while (i--) {
13741379
parents = [];
13751380
node = this[i];
1376-
while (node) {
1381+
while (node && node.nodeType === Node.ELEMENT_NODE) {
13771382
parents.push(node);
13781383
node = node.parentNode;
13791384
}

dist/dabby.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dabbyjs",
3-
"version": "0.9.6",
3+
"version": "0.9.7",
44
"homepage": "https://hexydec.github.io/dabby",
55
"author": "Will Earp <[email protected]>",
66
"description": "A lightweight modular jQuery clone library built for modern browsers",

src/attributes/attr/test.js

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,53 @@
11
import $ from "../../../dist/dabby.js";
22

3-
QUnit.module("Attributes");
4-
5-
QUnit.test("$.fn.attr", function (assert) {
3+
QUnit.module("Attributes", hooks => {
64
var test = document.getElementsByClassName("test")[0];
7-
test.innerHTML = '<div class="testtemp"></div>';
8-
var main = $(".testtemp"),
9-
rmain = document.getElementsByClassName("testtemp")[0],
10-
style = "padding-top: 10px;",
11-
correct = true;
12-
13-
// set and get class
14-
assert.deepEqual(main.attr("class", "testtemp testclass"), main, "Returns itself when setting class");
15-
assert.equal(rmain.className, "testtemp testclass", "Can set class");
16-
assert.equal(main.attr("class"), "testtemp testclass", "Can retrieve class");
17-
main.attr("class", "testtemp");
18-
assert.equal(main.attr("class"), "testtemp", "Can remove class");
19-
20-
// set and get style
21-
assert.deepEqual(main.attr("style", style), main, "Returns itself when setting style");
22-
assert.equal(rmain.style.cssText, style, "Can set style");
23-
assert.equal(main.attr("style"), style, "Can retrieve style");
24-
25-
// set and get attribute
26-
assert.deepEqual(main.attr("itemprop", "articleBody"), main, "Returns itself when setting property");
27-
assert.equal(rmain.getAttribute("itemprop"), "articleBody", "Can set property");
28-
assert.equal(main.attr("itemprop"), "articleBody", "Can retrieve property");
29-
main.attr("itemprop", null);
30-
assert.equal(main.attr("itemprop"), undefined, "Can remove property");
31-
32-
// set attributes using a callback
33-
test.innerHTML = '<div class="testtemp"></div><div class="testtemp"></div><div class="testtemp"></div>';
34-
main = $(".testtemp");
35-
assert.deepEqual(main.attr("data-test", function (i, el) {return "test-"+i;}), main, "Returns itself when setting attribute using callback");
36-
main.each(function (i) {
37-
if (this.getAttribute("data-test") !== "test-"+i) {
38-
correct = false;
39-
return false;
40-
}
5+
6+
hooks.before(() => {
7+
test.innerHTML = '<div class="testtemp"></div>';
8+
});
9+
10+
QUnit.test("$.fn.attr", function (assert) {
11+
var main = $(".testtemp"),
12+
rmain = document.getElementsByClassName("testtemp")[0],
13+
style = "padding-top: 10px;",
14+
correct = true;
15+
16+
// set and get class
17+
assert.deepEqual(main.attr("class", "testtemp testclass"), main, "Returns itself when setting class");
18+
assert.equal(rmain.className, "testtemp testclass", "Can set class");
19+
assert.equal(main.attr("class"), "testtemp testclass", "Can retrieve class");
20+
main.attr("class", "testtemp");
21+
assert.equal(main.attr("class"), "testtemp", "Can remove class");
22+
23+
// set and get style
24+
assert.deepEqual(main.attr("style", style), main, "Returns itself when setting style");
25+
assert.equal(rmain.style.cssText, style, "Can set style");
26+
assert.equal(main.attr("style"), style, "Can retrieve style");
27+
28+
// set and get attribute
29+
assert.deepEqual(main.attr("itemprop", "articleBody"), main, "Returns itself when setting property");
30+
assert.equal(rmain.getAttribute("itemprop"), "articleBody", "Can set property");
31+
assert.equal(main.attr("itemprop"), "articleBody", "Can retrieve property");
32+
main.attr("itemprop", null);
33+
assert.equal(main.attr("itemprop"), undefined, "Can remove property");
34+
35+
// set attributes using a callback
36+
test.innerHTML = '<div class="testtemp"></div><div class="testtemp"></div><div class="testtemp"></div>';
37+
main = $(".testtemp");
38+
assert.deepEqual(main.attr("data-test", function (i, el) {return "test-"+i;}), main, "Returns itself when setting attribute using callback");
39+
main.each(function (i) {
40+
if (this.getAttribute("data-test") !== "test-"+i) {
41+
correct = false;
42+
return false;
43+
}
44+
});
45+
assert.equal(correct, true, "Can set property with callback");
46+
47+
// reset
4148
});
42-
assert.equal(correct, true, "Can set property with callback");
4349

44-
// reset
45-
test.innerHTML = "";
50+
hooks.after(() => {
51+
test.innerHTML = "";
52+
});
4653
});

src/attributes/show-hide/test.js

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
import $ from "../../../dist/dabby.js";
22

3-
QUnit.module("Attributes");
3+
QUnit.module("Attributes", hooks => {
44

5-
QUnit.test("$.fn.show", function (assert) {
6-
var test = document.getElementsByClassName("test")[0],
7-
obj;
8-
test.innerHTML = '<div class="testtemp"><div style="display: none;"></div><div style="display: none;"></div><div style="display: none;"><div style="display: none;"></div></div><div style="display: none;"><div style="display: none;"></div></div></div>';
9-
obj = $(".testtemp div");
5+
QUnit.test("$.fn.show", function (assert) {
6+
var test = document.getElementsByClassName("test")[0],
7+
obj;
8+
test.innerHTML = '<div class="testtemp"><div style="display: none;"></div><div style="display: none;"></div><div style="display: none;"><div style="display: none;"></div></div><div style="display: none;"><div style="display: none;"></div></div></div>';
9+
obj = $(".testtemp div");
1010

11-
assert.deepEqual(obj.show(), obj, "Returns self on set");
12-
let show = 0;
13-
obj.get().forEach(item => {
14-
show += item.style.display !== "none";
11+
assert.deepEqual(obj.show(), obj, "Returns self on set");
12+
let show = 0;
13+
obj.get().forEach(item => {
14+
show += item.style.display !== "none";
15+
});
16+
assert.equal(obj.length, show, "Showed the requested elements");
1517
});
16-
assert.equal(obj.length, show, "Showed the requested elements");
17-
});
1818

19-
QUnit.test("$.fn.hide", function (assert) {
20-
var test = document.getElementsByClassName("test")[0],
21-
obj;
22-
test.innerHTML = '<div class="testtemp"><div></div><div></div><div><div></div></div><div><div></div></div></div>';
23-
obj = $(".testtemp div");
19+
QUnit.test("$.fn.hide", function (assert) {
20+
var test = document.getElementsByClassName("test")[0],
21+
obj;
22+
test.innerHTML = '<div class="testtemp"><div></div><div></div><div><div></div></div><div><div></div></div></div>';
23+
obj = $(".testtemp div");
2424

25-
assert.deepEqual(obj.hide(), obj, "Returns self on set");
26-
let hide = 0;
27-
obj.get().forEach(item => {
28-
hide += item.style.display === "none";
25+
assert.deepEqual(obj.hide(), obj, "Returns self on set");
26+
let hide = 0;
27+
obj.get().forEach(item => {
28+
hide += item.style.display === "none";
29+
});
30+
assert.equal(obj.length, hide, "Hid the requested elements");
2931
});
30-
assert.equal(obj.length, hide, "Hid the requested elements");
31-
});
3232

33-
QUnit.test("$.fn.toggle", function (assert) {
34-
var test = document.getElementsByClassName("test")[0],
35-
obj;
36-
test.innerHTML = '<div class="testtemp"><div style="display: none;"></div><div style="display: inline-block;"></div><div style="display: flex;"><div></div></div><div style="display: none;"><div style="display: none;"></div></div></div>';
37-
obj = $(".testtemp div");
33+
QUnit.test("$.fn.toggle", function (assert) {
34+
var test = document.getElementsByClassName("test")[0],
35+
obj;
36+
test.innerHTML = '<div class="testtemp"><div style="display: none;"></div><div style="display: inline-block;"></div><div style="display: flex;"><div></div></div><div style="display: none;"><div style="display: none;"></div></div></div>';
37+
obj = $(".testtemp div");
3838

39-
assert.deepEqual(obj.toggle(), obj, "Returns self on set");
40-
let show = 0, hide = 0;
41-
obj.get().forEach(item => {
42-
hide += item.style.display === "none";
43-
show += item.style.display !== "none";
39+
assert.deepEqual(obj.toggle(), obj, "Returns self on set");
40+
let show = 0, hide = 0;
41+
obj.get().forEach(item => {
42+
hide += item.style.display === "none";
43+
show += item.style.display !== "none";
44+
});
45+
assert.equal(3, show, "Showed the requested elements");
46+
assert.equal(3, hide, "Hid the requested elements");
4447
});
45-
assert.equal(3, show, "Showed the requested elements");
46-
assert.equal(3, hide, "Hid the requested elements");
4748
});

src/internal/getval/test.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
import $ from "../../../dist/dabby.js";
2-
32
import getVal from "./getval.js";
43

5-
QUnit.module("Internal");
4+
QUnit.module("Internal", hooks => {
5+
const test = document.getElementsByClassName("test")[0];
6+
7+
hooks.before(() => {
8+
test.innerHTML = '<div class="testtemp"></div><div class="testtemp2"></div><div class="testtemp3"></div>';
9+
});
10+
11+
QUnit.test("getVal", assert => {
12+
const obj = $(".test div");
13+
assert.deepEqual(getVal(obj, "test"), ["test", "test", "test"], "Can pass-through a value");
14+
assert.deepEqual(getVal(obj, function () {return $(this).attr("class");}), ["testtemp", "testtemp2", "testtemp3"], "Can use function as value");
15+
assert.deepEqual(getVal(obj, function (i, current) {return current;}, obj => obj.className), ["testtemp", "testtemp2", "testtemp3"], "Can use function as value and return original value");
16+
17+
let clone = {foo: "bar", bar: "foo"};
18+
const val = getVal(obj, clone);
19+
val.map((item, i) => {
20+
item.foo = "foo" + i;
21+
return item;
22+
});
23+
assert.deepEqual(val, [{foo: "foo0", bar: "foo"}, {foo: "foo1", bar: "foo"}, {foo: "foo2", bar: "foo"}], "Objects are cloned onto each output");
24+
assert.deepEqual(clone, {foo: "bar", bar: "foo"}, "Original object was not changed when object was copied to each val");
25+
});
626

7-
QUnit.test("getVal", function (assert) {
8-
var obj = $(".test");
9-
assert.deepEqual(getVal(obj, "test"), ["test"], "Can pass-through a value");
10-
assert.deepEqual(getVal(obj, function (i) {return this === obj[0] && !i ? "test" : false;}), ["test"], "When passing function as value, variables and context is correct");
27+
hooks.after(() => {
28+
test.innerHTML = "";
29+
});
1130
});

0 commit comments

Comments
 (0)