-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (54 loc) · 2.66 KB
/
index.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
function onSidebarOptionClick(eventObj)
{
let mappedHTMLElement = sidebarOptionToHTMLElementMap.get(eventObj.target);
let targetScrollTop = mappedHTMLElement.offsetTop;
if (mappedHTMLElement.tagName != "BLOG-POST-CARD")
{
targetScrollTop -= 8;
}
if (mappedHTMLElement != undefined)
{
window.scroll(
{
left: 0,
top: targetScrollTop,
behavior: "smooth"
}
);
}
}
function onContactMainSidebarOptionClick()
{
}
function onViewGithubRepoMainSidebarOptionClick()
{
window.open("https://github.com/S10239861-NP/Portfolio-Development-Module-Blog", "_blank");
}
let mainSidebar = document.getElementById("mainSidebar");
let blogPostCards = document.getElementsByTagName("blog-post-card");
let contactMainSidebarOption = document.getElementById("contactMainSidebarOption");
let viewGithubRepoMainSidebarOption = document.getElementById("viewGithubRepoMainSidebarOption");
let sidebarOptionToHTMLElementMap = new Map();
contactMainSidebarOption.addEventListener("click", onContactMainSidebarOptionClick);
viewGithubRepoMainSidebarOption.addEventListener("click", onViewGithubRepoMainSidebarOptionClick);
for (let currentBlogPostCardIndex = 0; currentBlogPostCardIndex < blogPostCards.length; currentBlogPostCardIndex++)
{
let currentBlogPostCard = blogPostCards.item(currentBlogPostCardIndex);
let newSidebarOption = document.createElement("a");
newSidebarOption.innerText = currentBlogPostCard.getAttribute("header");
newSidebarOption.addEventListener("click", onSidebarOptionClick);
newSidebarOption.classList.add("main-sidebar-option");
mainSidebar.insertBefore(newSidebarOption, contactMainSidebarOption);
sidebarOptionToHTMLElementMap.set(newSidebarOption, currentBlogPostCard);
let currentBlogPostCardSubHeaders = currentBlogPostCard.getElementsByTagName("h3");
for (let currentBlogPostCardSubHeaderIndex = 0; currentBlogPostCardSubHeaderIndex < currentBlogPostCardSubHeaders.length; currentBlogPostCardSubHeaderIndex++)
{
let newSidebarSubOption = document.createElement("a");
newSidebarSubOption.innerText = currentBlogPostCardSubHeaders[currentBlogPostCardSubHeaderIndex].innerText;
newSidebarSubOption.style["marginLeft"] = "10px";
newSidebarSubOption.addEventListener("click", onSidebarOptionClick);
newSidebarSubOption.classList.add("main-sidebar-option");
mainSidebar.insertBefore(newSidebarSubOption, contactMainSidebarOption);
sidebarOptionToHTMLElementMap.set(newSidebarSubOption, currentBlogPostCardSubHeaders[currentBlogPostCardSubHeaderIndex]);
}
}