summaryrefslogtreecommitdiff
path: root/src/main.js
blob: 99c9821dd893be5f2a00b2ceb96481f5dd16ec61 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* 
    Copyright (C) 2016 Andrew Murrell

    The JavaScript code in this page is free software: you can
    redistribute it and/or modify it under the terms of the GNU
    General Public License (GNU GPL) as published by the Free Software
    Foundation, either version 3 of the License, or (at your option)
    any later version.  The code is distributed WITHOUT ANY WARRANTY;
    without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.

    As additional permission under GNU GPL version 3 section 7, you
    may distribute non-source (e.g., minimized or compacted) forms of
    that code without the copy of the GNU GPL normally required by
    section 4, provided you include this license notice and a URL
    through which recipients can access the Corresponding Source.

*/

function init() {
    /* Search Bar Handling */
    var searchbar = document.getElementById("search");
    searchbar.onfocus = function() { this.value = ""; }
    searchbar.onblur = function() {
	if (this.value == "") {
	    this.value = "Search";
	}
	clear(); initSections();
    }
    searchbar.onkeyup = clear;//function() { if (event.keycode == 13) clear };

    initSections();
    
}

function initSections() {
    addSection("Writing");
    addItem("Writing",
	    mkItem("http://365tomorrows.com/12/03/a-simple-lament/",
		   "365 Tomorrows: A Simple Lament",
		   [["FF", "Flash Fiction"]]));
    addItem("Writing",
	    mkItem("./DND/Tastavi.html",
		   "Tastavi's Backstory",
		   [["SS", "Short Story"]]));
    addItem("Writing",
	    mkItem("./DND/SpellGauntlet.txt",
		   "Spell Gauntlet: Practical Spellcasting",
		   [["FF", "Flash Fiction"],
		    ["SS", "Short Story"],
		    ["WP", "WIP"]]));
    addItem("Writing",
	    mkItem("./DND/SoP.txt",
		   "Psionic Schools for D&D",
		   [["ES", "Essay"],
		    ["HB", "Homebrew"]]));
    
    /*addItem("Writing",
	    mkItem("./DND/Psionist.html",
		   "D&D 5e Psionist Class",
		   [//["ES", "Essay"],
		    ["HB", "Homebrew"]]));*/

    addSection("Programming");
    addItem("Programming",
	    mkItem("./DND/WaterdeepBazaar/WaterdeepBazaar.html",
		   "Waterdeep Bazaar: Marketplace Generator",
		   [["DM", "DMing Resource"],
		    ["WP", "WIP"]]));

    /*addSection("Music");
    addItem("Music",
    	    mkItem("./Playlists.html",
		   "Playlists",
		   [["WP", "WIP"]]));*/
    
    //addSection("Art");

    /*addSection("Misc");
    addItem("Misc",
	    mkItem("./Reading_List.html",
		   "Reading List",
		   [["WP", "WIP"]]));*/
		  
}

function mkItem(href, title, tags) {
    return {
	href: href,
	title: title,
	tags: tags
    };
}

function addSection(name) {
    // add h2 with id 'name' there.
    var append = "<h2>" + name + "</h2>";
    // add empty table there 'name-tbl'
    append += "<table id=\"" + name + "-tbl\"></table>";
    // find 'links'
    document.getElementById("links").innerHTML += append;
}

function addItem(section, item) {
    var append = "<tr><td><a href=\"" + item.href + "\">" + item.title + "</a></td><td>";
    for (i = 0; i < item.tags.length; i++) {
	append += "<a href=\"?s=" + item.tags[i][0] + "\" class=\"tag " + item.tags[i][0] + "\">" + item.tags[i][1] + "</a>";
    }
    append += "</td></tr>";
    document.getElementById(section + "-tbl").innerHTML += append;
}

function clear() {
    document.getElementById("links").innerHTML = "";
}

onload = init;