summaryrefslogtreecommitdiff
path: root/themes/default/menu.js
blob: 8107a724b481c00a90a004c281b801a3f4ebde31 (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
function main_menu(items) {
    output = "<ul>"
    for (item in items) {
	i = items[item];

	// Handle active page
        if (i["active"]) {
	    active = 'class = "active"';
        } else {
	    active = '';
	}

	// Line break labels
	label = i["label"];
	if (label.search(" ") != -1) {
	    label = label.replace(" ", "<br />");
	} else {
	    label = "&nbsp;<br />" + label;
	}

	output = output +'<li><a href="' + i["url"] + '" ' + active + '>' + label + "</a></li>";
    }
    output = output + "</ul>";
    document.write(output);
}

function render_items(items) {
    output = "<ul>";
    for (item in items) {
	i = items[item];

	// Handle active page
        if (i["active"]) {
	    active = 'class = "active"';
        } else {
	    active = '';
	}

	output = output +'<li><a href="' + i["url"] + '" ' + active + '>' + i['label'] + "</a></li>";
	if (i['subs']) {
	    output += render_items(i['subs']);
	}
    }
    output = output + "</ul>";
    return output
}

function side_menu(items) {
    if (items.length == 0) {
	return 0;
    }
    output = "<h2>Menu</h2>" + render_items(items);
    document.write(output);
}