git ssb

0+

Zach! / dat-zine-library



Tree: 477a1ff6389236b919641360e1a36179dbcdce1c

Files: 477a1ff6389236b919641360e1a36179dbcdce1c / volunteers / utilities.js

849 bytesRaw
1const _ = require('lodash')
2
3module.exports = {inCollection, $, $$, toggleElements}
4
5function 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
14function $ (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
23function $$ (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
32function toggleElements (elements, className) {
33 for (var element of elements) {
34 element.classList.toggle(className)
35 }
36}
37

Built with git-ssb-web