-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparent.js
More file actions
58 lines (52 loc) · 1.81 KB
/
Copy pathparent.js
File metadata and controls
58 lines (52 loc) · 1.81 KB
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
(function() {
function getTarget() {
var thisName = document.getElementById('thisName').value;
return encodeURI(thisName);
}
const recursiveLimit = 30;
const target = getTarget();
insertParent(target, 0, [])
/**
* 부모 문서 목록을 받아, 부모 문서들의 링크를 만들어준다.
*/
function makeHTML(plist) {
if (plist == null || plist.length < 1) {
return "";
}
var pr = "상위 문서: "
for (var i = 0; i < plist.length; i++) {
pr += `<a href="${plist[i].url}">${plist[i].title}</a>`;
if (i < plist.length - 1) {
pr += `<span> / </span>`;
}
}
return pr;
}
/**
* 재귀하며 부모 문서 정보를 가져온다.
* 모든 부모 문서를 가져오면 화면에 부모 문서 링크를 만들어 준다.
*/
function insertParent(target, recursiveCount, parentList) {
if (recursiveCount > recursiveLimit) {
return;
}
fetch(`/data/metadata/${target}.json`)
.then(response => response.json())
.then(function(data) {
if (data == null) {
return;
}
parentList.unshift(data);
if (data.parent == null) {
parentList.pop(); // this 문서가 부모 문서 목록에 나오지 않도록 제거해준다.
document.getElementById('parent-list').innerHTML = makeHTML(parentList);
return;
}
setTimeout(() => insertParent(data.parent, recursiveCount + 1, parentList), 0);
return;
})
.catch(function(error) {
console.error(error);
});
}
})();