summaryrefslogtreecommitdiff
path: root/app/utils/static/next-prev-links.js
blob: 7af1b66fd5593743ff6d706519bcd66982461043 (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
function build_next_prev() {
    var url = window.location.href 
    var style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = '.np-container {padding-left: 0;} .prev, .next {display: inline-block; margin-right: .5em;} .prev:after { content: "|"; margin-left:.5em;} .prev a:before {content: "\u00AB"; margin-right: 3px;} .next a:after{content: "\u00BB"; margin-left: 3px;}';
    document.getElementsByTagName('head')[0].appendChild(style);
    var cur = Number(url.split('/')[6]);
    var base_url = url.split(cur)[0];
    var next = cur+1;
    var prev = cur-1;
    var container = document.createElement("ul");
    var next_li = document.createElement("li");
    var next_link = document.createElement("a");
    var prev_li = document.createElement("li");
    var prev_link = document.createElement("a");
    prev_li.className = "prev";
    next_li.className = "next";
    container.className = "np-container";
    next_link.href = base_url + next + "/change/";
    next_link.textContent = "Next";
    prev_link.href = base_url + prev + "/change/";
    prev_link.textContent = "Prev";
    next_li.appendChild(next_link);
    prev_li.appendChild(prev_link);
    container.appendChild(prev_li);
    container.appendChild(next_li);
    console.log(container);
    Array.from(document.getElementsByClassName('object-tools')).forEach(function(item) {
        item.parentNode.insertBefore(container, item.nextSibling);
    })
};
document.addEventListener("DOMContentLoaded", function(event) { 
    build_next_prev();
});