@xiee/utils
Advanced tools
Comparing version 1.1.0 to 1.1.1
((d) => { | ||
const cls_list = 'faq-list', cls_clicked = 'faq-clicked'; | ||
function faq(el, id) { | ||
el.classList.add(cls_list); | ||
// each child of the list must have at least 2 child elements (one question | ||
// and one answer) | ||
const lis = el.children; | ||
if (lis.length === 0) return; | ||
for (let li of lis) { | ||
if (li.childElementCount < 2) return; | ||
} | ||
let ls = el.classList; | ||
if (ls.length > 0 && !ls.contains(cls_list)) return; | ||
ls.add(cls_list); | ||
// a button to collapse/expand all FAQs | ||
const btn = d.createElement('span'); | ||
@@ -19,3 +30,3 @@ let status = false; | ||
const lis = el.children; | ||
// add anchor links after questions | ||
for (let i = 0; i < lis.length; i++) { | ||
@@ -35,3 +46,4 @@ let li = lis[i], hash = 'faq-' + (id ? id + '-' : '') + (i + 1); | ||
// ignore lists in footnotes | ||
// ignore lists in footnotes, and lists must be direct child of some | ||
// block-level elements such as <div> | ||
const ols = d.querySelectorAll(['div', 'main', 'section', 'article'].map( | ||
@@ -42,5 +54,4 @@ (x) => x + ':not(.footnotes) > ol' | ||
let ol = ols[i]; | ||
let ls = ol.classList; | ||
(ls.length === 0 || ls.contains(cls_list)) && faq(ol, ols.length > 1 ? i + 1 : 0); | ||
faq(ol, ols.length > 1 ? i + 1 : 0); | ||
} | ||
})(document); |
{ | ||
"name": "@xiee/utils", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Miscellaneous tools and utilities to manipulate HTML pages", | ||
@@ -5,0 +5,0 @@ "scripts": { |
This repo contains miscellaneous tools and utilities written in JavaScript. They | ||
are published as an NPM package | ||
[`@xiee@utils`](https://www.npmjs.com/package/@xiee/utils). You can load them | ||
[`@xiee/utils`](https://www.npmjs.com/package/@xiee/utils). You can load them | ||
via [jsdelivr.com](https://www.jsdelivr.com), e.g., | ||
``` html | ||
<script src="https://cdn.jsdelivr.net/combine/npm/@xiee/utils/js/faq.min.js" async></script> | ||
<link href="https://cdn.jsdelivr.net/combine/npm/@xiee/utils/css/faq.min.css" rel="stylesheet"></link> | ||
<script src="https://cdn.jsdelivr.net/npm/@xiee/utils/js/faq.min.js" defer></script> | ||
<link href="https://cdn.jsdelivr.net/npm/@xiee/utils/css/faq.min.css" rel="stylesheet"></link> | ||
``` | ||
@@ -81,2 +81,1 @@ | ||
the em-dash. | ||
Sorry, the diff of this file is not supported yet
11219
207
81