aboutsummaryrefslogtreecommitdiff
path: root/src/js/arching-kaos-generator.js
blob: a39a77b14131cd9971c913c66d6a9309a5327c0a (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
69
70
71
72
73
74
75
76
77
78
79
80
// Arching Kaos Generator
//
// Kaotisk Hund - 2024
//
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
//

export function makeElement(obj, attachTo)
{
    if (obj.element !== 'head' && obj.element !== 'body' && obj.element !== 'svg' && obj.element !== 'circle')
    {
        var temp = document.createElement(obj.element);
    }
    else if ( obj.element === 'svg' || obj.element === 'circle' )
    {
        var temp = document.createElementNS("http://www.w3.org/2000/svg", obj.element);
    }
    else if ( obj.id !== null && document.querySelector('#'+obj.id) )
    {
        var temp = document.querySelector('#'+obj.id);
    }
    else
    {
        var temp = document.querySelector(obj.element);
    }
    if ( obj.id !== undefined ) temp.id = obj.id;
    if ( obj.name !== undefined ) temp.name = obj.name;
    if ( obj.type !== undefined ) temp.type = obj.type;
    if ( obj.content !== undefined ) temp.content = obj.content;
    if ( obj.property !== undefined ) temp.property = obj.property;
    if ( obj.className !== undefined && obj.element !== 'svg') temp.className = obj.className;
    if ( obj.rel !== undefined ) temp.rel = obj.rel;
    if ( obj.href !== undefined ) temp.href = obj.href;
    if ( obj.style !== undefined ) temp.style = obj.style;
    if ( obj.src !== undefined ) temp.src = obj.src;
    if ( obj.as !== undefined ) temp.as = obj.as;
    if ( obj.target !== undefined ) temp.target = obj.target;
    if ( obj.onclick !== undefined ) temp.setAttribute("onclick", obj.onclick);
    if ( obj.alt !== undefined ) temp.alt = obj.alt;
    if ( obj.charset !== undefined ) temp.charset = obj.charset;
    if ( obj.value !== undefined ) temp.value = obj.value;
    if ( obj.controls !== undefined ) temp.controls = obj.controls;
    if ( obj.hidden !== undefined ) temp.hidden = obj.hidden;
    if ( obj.placeholder !== undefined ) temp.placeholder = obj.placeholder;
    if ( obj.classes !== undefined ) temp.classList = obj.classes;
    if ( obj.innerText !== undefined ) temp.innerText = obj.innerText;
    if ( obj.viewBox !== undefined ) temp.setAttribute("viewBox", obj.viewBox);
    if ( obj.cx !== undefined ) temp.setAttribute("cx", obj.cx);
    if ( obj.cy !== undefined ) temp.setAttribute("cy", obj.cy);
    if ( obj.r !== undefined ) temp.setAttribute("r", obj.r);
    if ( obj.xmlns !== undefined ) temp.setAttribute("xmlns", obj.xmlns);
    if ( obj.fill !== undefined ) temp.setAttribute("fill", obj.fill);
    if ( obj.stroke !== undefined ) temp.setAttribute("stroke", obj.stroke);
    if ( obj.strokeWidth !== undefined ) temp.setAttribute("stroke-width", obj.strokeWidth);
    if ( obj.version !== undefined ) temp.setAttribute("version", obj.version);
    if ( obj.width !== undefined ) temp.setAttribute("width", obj.width);
    if ( obj.height !== undefined ) temp.setAttribute("height", obj.height);
    if ( obj.innerHTML !== undefined && Array.isArray(obj.innerHTML) )
    {
        obj.innerHTML.forEach((value)=>{makeElement(value, temp)});
    }
    else if ( obj.innerHTML !== undefined && typeof(obj.innerHTML) === "string" )
    {
        temp.innerHTML = obj.innerHTML;
    }
    attachTo.appendChild(temp);
}

export function makeUpSite(tree, root){
    if ( tree !== undefined && Array.isArray(tree) )
    {
        for (var i = 0; i < tree.length; i++)
        {
            makeElement(tree[i], root)
        }
    }
}


// @license-end