Skip to content
This repository was archived by the owner on Oct 2, 2018. It is now read-only.

Commit 42c7855

Browse files
committed
Polyfill element.closest() for older Firefox OS
1 parent 54fbfab commit 42c7855

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<script type="text/javascript" src="scripts/lib/jszip-load.js" defer></script>
3535
<script type="text/javascript" src="scripts/lib/codemirror-compressed.js" defer></script>
3636
<script type="text/javascript" src="scripts/lib/fxosrate.js" defer></script>
37+
<script type="text/javascript" src="scripts/lib/closest.js" defer></script>
3738

3839
<!-- Localization -->
3940
<meta name="defaultLanguage" content="en">

scripts/lib/closest.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(function (ELEMENT) {
2+
ELEMENT.matches = ELEMENT.matches || ELEMENT.mozMatchesSelector || ELEMENT.msMatchesSelector || ELEMENT.oMatchesSelector || ELEMENT.webkitMatchesSelector;
3+
4+
ELEMENT.closest = ELEMENT.closest || function closest(selector) {
5+
var element = this;
6+
7+
while (element) {
8+
if (element.matches(selector)) {
9+
break;
10+
}
11+
12+
element = element.parentElement;
13+
}
14+
15+
return element;
16+
};
17+
}(Element.prototype));

0 commit comments

Comments
 (0)