forked from ZachisGit/ipfs-arxiv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipfs_arxiv.js
79 lines (65 loc) · 2.06 KB
/
ipfs_arxiv.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
var page_index = 1;
var page_count = 0;
var entries_per_page = 20;
window.onload = function()
{
var url_string = window.location.href;
var url = new URL(url_string);
page_index = url.searchParams.get('page');
if (page_index == null || isNaN(parseInt(page_index)) || parseInt(page_index) == "")
page_index = 1;
else
page_index = parseInt(page_index);
page_count = Math.ceil((index_json.length)/entries_per_page);
if (page_index > page_count)
page_index = 1;
display_available_pages();
display_entries();
}
function display_available_pages()
{
var page_idx = document.getElementById('page_idx');
page_idx.innerHTML = page_index;
var page_total = document.getElementById('page_total');
page_total.innerHTML = page_count;
}
function display_entries()
{
var page_start = page_index;
var page_length = entries_per_page;
if (page_index+page_length > index_json.length)
page_length = index_json.length-((page_count-1)*entries_per_page);
for (var i = page_start-1; i < page_start+page_length-1; i++)
{
var entry = get_entry_tag(index_json[i]);
document.getElementById('main').appendChild(entry);
}
document.getElementById('main').removeChild(document.getElementById('base_entry'));
}
function get_entry_tag(json_entry)
{
var tobecloned = document.getElementById('base_entry');
var clone = tobecloned.cloneNode(true);
clone.id = '';
clone.getElementsByClassName('entry_title')[0].innerHTML = json_entry['title'];
clone.getElementsByClassName('entry_summary')[0].innerHTML = json_entry['summary'];
clone.getElementsByClassName('entry_id')[0].innerHTML = json_entry['id'];
clone.getElementsByClassName('entry_download')[0].href = 'pdfs/'+json_entry['id']+'.pdf';
return clone;
}
function next_page()
{
if (page_index + 1 > page_count)
page_index = 1;
else
page_index++;
window.location.href = "index.html?page="+page_index;
}
function prev_page()
{
if (page_index - 1 <= 0)
page_index = page_count;
else
page_index--;
window.location.href = "index.html?page="+page_index;
}