-
Notifications
You must be signed in to change notification settings - Fork 1
/
navigation.js
142 lines (130 loc) · 4.05 KB
/
navigation.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var current_appendix = null;
$(document).ready(function() {
$("div.interview_content").hide();
$("a.interview-link").click(function() {
$("div#" + $(this).data('iid') + " div.interview_content").show();
return false;
});
$("a.appendix").click(function() {
show_appendix($(this).data('rid'), true);
return false;
});
$("div.spoiler a.spoiler_toggle").click(function() {
$(this).parent().parent().find("div").toggle();
return false;
});
$("a.note_indicator").click(function(event) {
var x = event.pageX,
y = event.pageY;
var div = $("div.note[data-nid='" + $(this).data('nid') + "']");
div.css({top: y+20, left: x+10});
div.toggle();
return false;
});
$("body").click(function() { $("div.note").hide(); });
load_hash();
window.onhashchange = load_hash;
if(window.history && window.history.pushState) {
$(window).on('popstate', function(event) {
if(!!event.state) load_hash();
});
var url = build_hash();
if(window.history && window.history.pushState) window.history.pushState({appendix_id: current_appendix, randomData: window.Math.random()}, "", url);
}
});
function update()
{
$("a.interview-link").unbind("click");
$("a.interview-link").click(function() {
$("div#" + $(this).data('iid') + " div.interview_content").show();
return false;
});
$("a.appendix").unbind("click");
$("a.appendix").click(function() {
show_appendix($(this).data('rid'), true);
return false;
});
$("div.spoiler a.spoiler_toggle").unbind();
$("div.spoiler a.spoiler_toggle").click(function() {
$(this).parent().parent().find("div").toggle();
return false;
});
$("a.note_indicator").unbind();
$("a.note_indicator").click(function(event) {
var x = event.pageX,
y = event.pageY;
var div = $("div.note[data-nid='" + $(this).data('nid') + "']");
div.css({top: y-10, left: x+10});
div.toggle();
return false;
});
$("body").unbind();
$("body").click(function() { $("div.note").hide(); });
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
function build_hash()
{
var url = '#!';
if(current_appendix!=null)
{
url = '#!appendix=' + current_appendix;
}
return url;
}
function update_hash()
{
var url = build_hash();
if(window.history && window.history.pushState) window.history.pushState({appendix_id: current_appendix}, "", url);
else window.location.hash = url;
}
function load_hash()
{
var subject = window.location.hash.substring(window.location.hash.indexOf('!')+1);
var data = subject?JSON.parse('{"' + subject.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
function(key, value) { return key===""?value:decodeURIComponent(value) }):{};
data['appendix'] = data['appendix'] === undefined ? null : data['appendix'];
var new_appendix = current_appendix != data['appendix'];
var change = new_appendix;
current_appendix = data['appendix'];
if(change)
{
if(current_appendix != null)
{
if(new_appendix) show_appendix(current_appendix, false);
}
else
{
hide_appendix();
$('#image').show();
}
}
}
function show_appendix(id, updatehash)
{
$.ajax({
url: '/appendices/' + id + '/index.html',
type: 'GET',
cache: false, // disable when ready
success: function(data) {
current_appendix = id;
if(updatehash) update_hash();
data_object = $($.parseHTML(data, document, true));
$('#appendix .title').text(data_object.find('#title').text());
$('#appendix .text').html(data_object.find('#text').html());
$('#image').hide();
$('#appendix').show();
data_object.find('#text script').each(function(){
$.globalEval(this.innerHTML);
});
setTimeout(update, 100);
},
error: function(e) {
console.log(e.message);
}
});
}
function hide_appendix(id)
{
current_appendix = null;
$("#appendix").hide();
}