@xiee/utils 1.6.8 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/css/faq.css +1 -1
- package/css/faq.min.css +1 -1
- package/js/faq.js +4 -4
- package/js/faq.min.js +1 -1
- package/js/ol-id.js +23 -0
- package/js/ol-id.min.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -126,6 +126,13 @@ class, so that highlight.js will not try to syntax highlight the code in it.
|
|
|
126
126
|
|
|
127
127
|
Find all section headings (`h1` - `h6`) and number them.
|
|
128
128
|
|
|
129
|
+
## ol-id.js
|
|
130
|
+
|
|
131
|
+
Add IDs of the form `li-N` to items in ordered lists, where `N` is the index of
|
|
132
|
+
a list item. This makes it possible to reference or locate a specific item on a
|
|
133
|
+
page by a hash in the URL. If you hold `Alt` and click on an item, you will get
|
|
134
|
+
the URL with the hash in the address bar of your browser.
|
|
135
|
+
|
|
129
136
|
## render-katex.js
|
|
130
137
|
|
|
131
138
|
Simply run `renderMathInElement(document.body)` to render math expression using
|
package/css/faq.css
CHANGED
package/css/faq.min.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.faq-button{cursor:pointer}.faq-list>li>:first-child{display:block;cursor:pointer;background:#fafafa;margin:-.5em;padding:.5em}.faq-list>:not(.faq-clicked)>*{display:none}.faq-button{float:right;margin-left:1em}.faq-list .anchor{display:none}.faq-list>li:hover
|
|
1
|
+
.faq-button{cursor:pointer}.faq-list>li>:first-child{display:block;cursor:pointer;background:#fafafa;margin:-.5em;padding:.5em}.faq-list>:not(.faq-clicked)>*{display:none}.faq-button{float:right;margin-left:1em}.faq-list .anchor{display:none}.faq-list>li:hover .anchor{display:inline}.faq-list>li{border:1px solid #eee;padding:.5em}
|
package/js/faq.js
CHANGED
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
|
|
30
30
|
// add anchor links after questions
|
|
31
31
|
for (let i = 0; i < lis.length; i++) {
|
|
32
|
-
let li = lis[i]
|
|
32
|
+
let li = lis[i];
|
|
33
|
+
li.id = 'faq-' + (id ? id + '-' : '') + (i + 1);
|
|
33
34
|
let p = li.firstElementChild;
|
|
34
|
-
p.
|
|
35
|
-
|
|
36
|
-
if (location.hash === '#' + hash) {
|
|
35
|
+
p.insertAdjacentHTML('beforeend', ` <span class="anchor"><a href="#${li.id}">#</a></span>`);
|
|
36
|
+
if (location.hash === '#' + li.id) {
|
|
37
37
|
li.scrollIntoView();
|
|
38
38
|
li.classList.add(cls_clicked);
|
|
39
39
|
}
|
package/js/faq.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(t=>{const
|
|
1
|
+
(t=>{const e="faq-list",n="faq-clicked";function l(l,o){const i=l.children;if(0===i.length)return;for(let t of i)if(t.childElementCount<2)return;let c=l.classList;if(c.length>0&&!c.contains(e))return;c.add(e);const s=t.createElement("span");let a=!1;s.className="faq-button",s.innerText="⊕",s.onclick=function(){a=!a,this.innerText=a?"⊖":"⊕";for(const t of l.children)t.classList.toggle(n,a)},l.before(s);for(let t=0;t<i.length;t++){let e=i[t];e.id="faq-"+(o?o+"-":"")+(t+1);let l=e.firstElementChild;l.insertAdjacentHTML("beforeend",` <span class="anchor"><a href="#${e.id}">#</a></span>`),location.hash==="#"+e.id&&(e.scrollIntoView(),e.classList.add(n)),l.onclick=function(t){e.classList.toggle(n)}}}const o=t.querySelectorAll(["div","main","section","article"].map((t=>t+":not(.footnotes) > ol")).join(","));for(let t=0;t<o.length;t++){l(o[t],o.length>1?t+1:0)}})(document);
|
package/js/ol-id.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// add ID to <ol> items so that they can be referenced via URL hashes like #li-N
|
|
2
|
+
((d) => {
|
|
3
|
+
// add IDs to top-level <ol>s
|
|
4
|
+
const ols = d.querySelectorAll(':not(li) > ol');
|
|
5
|
+
ols.forEach((ol, i) => {
|
|
6
|
+
ol.querySelectorAll(':scope > li').forEach((li, j) => {
|
|
7
|
+
if (!li.id) li.id = 'li-' + (ols.length > 1 ? i + 1 + '-' : '') + (j + 1);
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
// add IDs to all <ol>s
|
|
11
|
+
d.querySelectorAll('ol').forEach((ol, i) => {
|
|
12
|
+
let l = ol.parentNode, id, p; // p: ID prefix
|
|
13
|
+
if (l?.tagName === 'LI') id = l.id;
|
|
14
|
+
p = (id ? id : 'li-' + (i + 1)) + '-';
|
|
15
|
+
ol.querySelectorAll(':scope > li').forEach((li, j) => {
|
|
16
|
+
if (!li.id) li.id = p + (j + 1);
|
|
17
|
+
// Alt + Click => adding hash to URL
|
|
18
|
+
li.addEventListener('click', e => {
|
|
19
|
+
e.altKey && (location.hash = li.id, e.stopPropagation());
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
})(document);
|
package/js/ol-id.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(e=>{const l=e.querySelectorAll(":not(li) > ol");l.forEach(((e,o)=>{e.querySelectorAll(":scope > li").forEach(((e,t)=>{e.id||(e.id="li-"+(l.length>1?o+1+"-":"")+(t+1))}))})),e.querySelectorAll("ol").forEach(((e,l)=>{let o,t,c=e.parentNode;"LI"===c?.tagName&&(o=c.id),t=(o||"li-"+(l+1))+"-",e.querySelectorAll(":scope > li").forEach(((e,l)=>{e.id||(e.id=t+(l+1)),e.addEventListener("click",(l=>{l.altKey&&(location.hash=e.id,l.stopPropagation())}))}))}))})(document);
|