-
Notifications
You must be signed in to change notification settings - Fork 1
/
hypertext-timeline.js
79 lines (68 loc) · 2.14 KB
/
hypertext-timeline.js
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
$(function() {
const queryBase = "//query.wikidata.org/"
const githubBase = "//github.com/nichtich/hypertext-timeline/blob/master/"
const menu = {
"table": { sparql: null, html: null },
"timeline": { sparql: null, html: null },
"traces": { sparql: null, html: null },
"wikis": { sparql: null, html: null },
"people": { sparql: null, html: null },
"about": { html: null }
}
var selectedMenuItem = window.location.hash.substr(1)
if (!(selectedMenuItem in menu)) {
selectedMenuItem = "table"
}
function selectMenu(name) {
const item = menu[name]
selectedMenuItem = name
$("#menu li").removeClass("active")
$("#"+name).addClass("active")
if (item.html) {
$("#description").show().html(item.html)
$("#html").attr("href", githubBase + name + ".html").show()
} else {
$("#description").hide()
$("#html").hide()
}
$("#iframes iframe").hide()
$("#sparql").hide()
if (item.sparql) {
const query = encodeURIComponent(item.sparql)
var iframe = $("#iframe-"+name).show()
if (!iframe.attr("src")) {
iframe.attr("src", queryBase + "embed.html#" + query)
}
$("#sparql").attr("href", queryBase + "#" + query).show()
}
window.location.hash = name
}
Object.keys(menu).forEach(function(name) {
const item = menu[name]
var a = $('<a>').addClass("nav-link disabled")
a.text(name.charAt(0).toUpperCase() + name.slice(1))
$('<li class="nav-item">').attr('id', name).append(a).appendTo('#menu')
a.click(function(){ selectMenu(name) })
if ('sparql' in item) {
$.get(name +".sparql", function(sparql) {
item.sparql = sparql
var iframe = $("<iframe>").hide()
iframe.attr("id","iframe-"+name)
iframe.appendTo($("#iframes"))
a.removeClass("disabled")
if (name == selectedMenuItem) {
selectMenu(name)
}
}, "text")
}
if ('html' in item) {
$.get(name + ".html").done(function(html) {
item.html = html
if (name == selectedMenuItem) {
selectMenu(name)
}
a.removeClass("disabled")
})
}
})
})