-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.js
123 lines (107 loc) · 2.69 KB
/
blog.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
let workPackages = (function () {
pub = {};
const openModalButtons = document.querySelectorAll("[data-modal-target]");
const closeModalButtons = document.querySelectorAll("[data-close-button]");
const overlay = $("#overlay");
function openModal(modal) {
if (modal == null) return;
modal.classList.add("active");
overlay.classList.add("active");
}
function closeModal(modal) {
if (modal == null) return;
modal.classList.remove("active");
overlay.classList.remove("active");
}
makePkg = (title, desc, author, thumbnail, content) => {
return `
<div
id="w-node-_25b018ff-bb9d-73f0-90a0-85096636098a-b3e0a829"
style="cursor: pointer"
class="blog-card"
>
<div class="cards-image-mask">
<img
src="${thumbnail}"
alt=""
class="cards-image"
/>
</div>
<h3 class="card-title">${title}</h3>
<div class="blog_body" style="display: none;">
</div>
<p>
${desc}
</p>
</div>
`;
};
displayPkgs = (pkgs) => {
pkgs.forEach((post) => {
let title = post.title;
let desc = post.desc;
let author = post.author;
let thumbnail = post.thumbnail;
let mdfile = post.content_md;
let htmlfile = post.content_html;
//console.log(htmlfile);
//$.get(htmlfile, (data) => {
//console.log("DATA:");
//console.log(data);
//});
$(".cards-grid-container").append(
makePkg(title, desc, author, thumbnail, htmlfile)
);
});
};
pub.setup = () => {
$.ajax({
type: "GET",
url: "blog.json",
data: {
get_param: "value",
},
dataType: "json",
async: false,
success: function (data) {
let posts = [];
posts = data.posts;
displayPkgs(posts);
},
error: () => {
alert("Could not load blog post data.");
},
});
openModalButtons.forEach((button) => {
button.addEventListener("click", () => {
const modal = document.querySelector(
button.dataset.modalTarget
);
openModal(modal);
});
});
overlay.on("click", () => {
const modals = document.querySelectorAll(".modal.active");
modals.forEach((modal) => {
closeModal(modal);
});
});
closeModalButtons.forEach((button) => {
button.addEventListener("click", () => {
const modal = button.closest(".modal");
closeModal(modal);
});
});
$(".blog-card").on("click", (event) => {
// TODO: Get modal to display blogpost
let title = $(event.currentTarget).find("h3")[0].innerHTML;
let body = $(event.currentTarget).find("p")[0].innerHTML;
console.log(title);
$(".title")[0].innerHTML = title;
$(".modal-body")[0].innerHTML = body;
$("#open-button").click();
});
};
return pub;
})();
$(document).ready(pub.setup);