Debian Codegraph @

docs/assets/js/main.js

raw
1 import Alpine from 'alpinejs';
2 import { registerMagics } from './alpinejs/magics/index';
3 import { navbar, search, toc } from './alpinejs/data/index';
4 import { navStore } from './alpinejs/stores/index';
5 import persist from '@alpinejs/persist';
6 import focus from '@alpinejs/focus';
7 import * as params from '@params';
8
9 var debug = 0 ? console.log.bind(console, '[index]') : function () {};
10
11 // Set up and start Alpine.
12 (function () {
13 // Register AlpineJS plugins.
14 {
15 Alpine.plugin(focus);
16 Alpine.plugin(persist);
17 }
18 // Register AlpineJS magics and directives.
19 {
20 // Handles copy to clipboard etc.
21 registerMagics(Alpine);
22 }
23
24 // Register AlpineJS controllers.
25 {
26 // Register AlpineJS data controllers.
27 let searchConfig = {
28 index: 'hugodocs',
29 app_id: 'D1BPLZHGYQ',
30 api_key: '6df94e1e5d55d258c56f60d974d10314',
31 params: params,
32 };
33
34 Alpine.data('navbar', () => navbar(Alpine));
35 Alpine.data('search', () => search(Alpine, searchConfig));
36 Alpine.data('toc', () => toc(Alpine));
37 }
38
39 // Register AlpineJS stores.
40 {
41 Alpine.store('nav', navStore(Alpine));
42 }
43
44 // Start AlpineJS.
45 Alpine.start();
46
47 // On cross-document navigation the browser snapshots the current page for
48 // the view transition. An open overlay (e.g. the search modal) would
49 // otherwise linger in that outgoing snapshot while the page crossfades.
50 // `pageswap` runs right before the snapshot is taken, so hide such
51 // elements here to make them disappear instantly on navigation.
52 window.addEventListener('pageswap', () => {
53 document.querySelectorAll('[data-hide-on-navigate]').forEach((el) => {
54 el.classList.add('hidden');
55 });
56 });
57 })();