aboutsummaryrefslogtreecommitdiff
path: root/src/js/arching-kaos-spa-router.js
blob: 162a3167a18fbbddf94f74a4669dbd738a78f577 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Arching Kaos Single Page Application Router
 *
 * Kaotisk Hund - 2024
 *
 * @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
 *
 */
/*
 * A new feature for a new future:
 *
 * We will get `location.search` values to figure out where the visitor wants
 * to go.
 *
 * We should then replace the menu links with these ones.
 *
 * We should also modify the existing menu mechanism to show/hide depending on
 * the "route" we got from `location.search`.
 *
 */
import { menuinit, menuids } from "./ui/menu.js";

export function locationHashSetter(value)
{
    window.location.hash = value;
    locationHashOnChange();
}

export function locationHashGetter()
{
    return window.location.hash;
}

export function getWelcomeSection()
{
    return document.querySelector('#welcome-section');
}

export function getSoftError()
{
    return document.querySelector('#not-found-section');
}

export function locationHashOnChange()
{
    var route = new Object;
    route.full = locationHashGetter();
    route.args = route.full.split('/');
    route.menuid = '#'+route.args[1];
    route.subcommand = route.args[2];
    menuinit();
    if ( (locationHashGetter() !== 'undefined') && (locationHashGetter() === '') ){
        getWelcomeSection.hidden=false;
    }
    else if ( route.args[1] == "route" ) {
        getWelcomeSection.hidden=false;
        if ( route.args.length === 4 ) {
            if ( route.args[2] === "zblock" ) {
                seekZblock(route.args[3], ['search', false]);
            }
        }
    } else if ( (locationHashGetter() !== 'undefined') && ( menuids().includes(route.menuid))){
        document.querySelector(route.menuid).hidden=false;
    } else {
        getSoftError().hidden=false;
    }
}

// @license-end