aboutsummaryrefslogtreecommitdiff
path: root/assets_src/js/lib/dom.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets_src/js/lib/dom.js')
-rw-r--r--assets_src/js/lib/dom.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/assets_src/js/lib/dom.js b/assets_src/js/lib/dom.js
index 33845af..bfbeea7 100644
--- a/assets_src/js/lib/dom.js
+++ b/assets_src/js/lib/dom.js
@@ -5,10 +5,42 @@ export function ready(fn) {
5} 5}
6 6
7export function closest(el, fn) { 7export function closest(el, fn) {
8 if (!el) {
9 return null;
10 }
8 while (el) { 11 while (el) {
9 if (fn(el)) { 12 if (fn(el)) {
10 return el; 13 return el;
11 } 14 }
12 el = el.parentNode 15 el = el.parentNode
13 } 16 }
17 return null;
18}
19
20export function next(el, fn) {
21 if (!el) {
22 return null;
23 }
24 el = el.nextSibling;
25 while (el) {
26 if (fn(el)) {
27 return el;
28 }
29 el = el.nextSibling;
30 }
31 return null;
32}
33
34export function previous(el, fn) {
35 if (!el) {
36 return null;
37 }
38 el = el.previousSibling;
39 while (el) {
40 if (fn(el)) {
41 return el;
42 }
43 el = el.previousSibling;
44 }
45 return null;
14} 46}