Files: 477a1ff6389236b919641360e1a36179dbcdce1c / volunteers / utilities.js
849 bytesRaw
1 | const _ = require('lodash') |
2 | |
3 | module.exports = {inCollection, $, $$, toggleElements} |
4 | |
5 | function inCollection (zine, param) { |
6 | // Check whether zine has collections, and if so if any match the current |
7 | // route parameter |
8 | param = decodeURI(param) |
9 | if (zine.collections) { |
10 | return zine.collections.find(collection => _.toLower(collection) === param) |
11 | } else return false |
12 | } |
13 | |
14 | function $ (el, sel = false) { |
15 | if (typeof sel === 'string') { |
16 | // (el, sel) |
17 | return el.querySelector(sel) |
18 | } |
19 | // (sel) |
20 | return document.querySelector(el) |
21 | } |
22 | |
23 | function $$ (el, sel = false) { |
24 | if (typeof sel === 'string') { |
25 | // (el, sel) |
26 | return el.querySelectorAll(sel) |
27 | } |
28 | // (sel) |
29 | return document.querySelectorAll(el) |
30 | } |
31 | |
32 | function toggleElements (elements, className) { |
33 | for (var element of elements) { |
34 | element.classList.toggle(className) |
35 | } |
36 | } |
37 |
Built with git-ssb-web