Debian Codegraph @

docs/assets/js/alpinejs/data/navbar.js

raw
1 export const navbar = (Alpine) => ({
2 init: function () {
3 Alpine.bind(this.$root, this.root);
4
5 return this.$nextTick(() => {
6 let contentEl = document.querySelector('.content:not(.content--ready)');
7 if (contentEl) {
8 contentEl.classList.add('content--ready');
9 let anchorTemplate = document.getElementById('anchor-heading');
10 if (anchorTemplate) {
11 let els = contentEl.querySelectorAll('h2[id], h3[id], h4[id], h5[id], h6[id], dt[id]');
12 for (let i = 0; i < els.length; i++) {
13 let el = els[i];
14 el.classList.add('group');
15 let a = anchorTemplate.content.cloneNode(true).firstElementChild;
16 a.href = '#' + el.id;
17 el.appendChild(a);
18 }
19 }
20 }
21 });
22 },
23 root: {
24 ['@scroll.window.debounce.10ms'](event) {
25 this.$store.nav.scroll.atTop = window.scrollY < 40 ? true : false;
26 },
27 },
28 });