-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Element.prototype.nextElementSibling polyfill
- Loading branch information
1 parent
653e432
commit 2dddbf9
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
polyfills/Element/prototype/nextElementSibling/config.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
aliases = [ ] | ||
dependencies = [ | ||
"Element", | ||
"Object.defineProperty" | ||
] | ||
license = "MIT" | ||
docs = "https://developer.mozilla.org/en-US/docs/Web/API/NonDocumentTypeChildNode/nextElementSibling" | ||
|
||
[browsers] | ||
android = "todo" | ||
bb = "todo" | ||
chrome = "todo" | ||
edge = "todo" | ||
edge_mob = "todo" | ||
firefox = "todo" | ||
ios_chr = "todo" | ||
ios_saf = "todo" | ||
ie = "todo" | ||
ie_mob = "todo" | ||
opera = "todo" | ||
op_mini = "todo" | ||
op_mob = "todo" | ||
safari = "todo" | ||
firefox_mob = "todo" | ||
samsung_mob = "todo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'document' in self && "nextElementSibling" in document.documentElement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Object.defineProperty(Element.prototype, "nextElementSibling", { | ||
get: function(){ | ||
var el = this.nextSibling; | ||
while (el && el.nodeType !== 1) { el = el.nextSibling; } | ||
return el; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
it("should return null if the node is the only child of its parent node", function () { | ||
var parent = document.createElement('div'), | ||
p = document.createElement('p'); | ||
parent.appendChild(p); | ||
|
||
proclaim.strictEqual(p.nextElementSibling, null); | ||
}); | ||
|
||
it("should return null if the node only has text sibling", function () { | ||
var parent = document.createElement('div'), | ||
p = document.createElement('p'); | ||
text = document.createTextNode('Hi there, how are you doing today?'); | ||
parent.appendChild(p); | ||
parent.appendChild(text); | ||
|
||
proclaim.strictEqual(p.nextElementSibling, null); | ||
}); | ||
|
||
it("should return null if the node only has comment sibling", function () { | ||
var parent = document.createElement('div'), | ||
p = document.createElement('p'); | ||
comment = document.createComment('This is a comment in the document.'); | ||
parent.appendChild(p); | ||
parent.appendChild(comment); | ||
|
||
proclaim.strictEqual(p.nextElementSibling, null); | ||
}); | ||
|
||
it("should return the first child element", function () { | ||
var parent = document.createElement('div'), | ||
h2 = document.createElement('h2'), | ||
p1 = document.createElement('p'), | ||
p2 = document.createElement('p'), | ||
p3 = document.createElement('p'), | ||
text = document.createTextNode('Hi there, how are you doing today?'), | ||
comment = document.createComment('This is a comment in the document.'); | ||
parent.appendChild(h2); | ||
parent.appendChild(text); | ||
parent.appendChild(comment); | ||
parent.appendChild(p1); | ||
parent.appendChild(p2); | ||
parent.appendChild(p3); | ||
|
||
proclaim.strictEqual(h2.nextElementSibling, p1); | ||
}); |