-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathscript.js
More file actions
175 lines (128 loc) · 5.66 KB
/
Copy pathscript.js
File metadata and controls
175 lines (128 loc) · 5.66 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import books from "./DataBase/Data.js";
// new books section
const newBooksCarouselItem1 = document.getElementById("newBooksCarouselItem1");
const newBooksCarouselItem2 = document.getElementById("newBooksCarouselItem2");
const newBooksCarouselItem3 = document.getElementById("newBooksCarouselItem3");
const newestBookFiltred1 = books().filter(book => book.date <= 4);
const newestBookFiltred2 = books().filter(book => book.date <= 8 && book.date > 4);
const newestBookFiltred3 = books().filter(book => book.date <= 12 && book.date > 8);
function cartCreator(book) {
return `<div class="bookCon col-lg-3 col-sm-6">
<div class="thumb-wrapper">
<div class="img-box">
<img src="${book.cover}" class="img-fluid" alt="book img">
</div>
<div class="thumb-content">
<h4 class="book-name">${book.name}</h4>
${book.stars}
<p class="item-price"><strike>${book.lastPrice || ""}</strike><b>$${book.price}</b></p>
<button class="btn addToCart-btn btn-outline-danger"> Add to Cart <i class="bi bi-bag"></i></button>
</div>
</div>
</div>`
}
newestBookFiltred1.forEach(book => {
newBooksCarouselItem1.innerHTML += (cartCreator(book));
})
newestBookFiltred2.forEach(book => {
newBooksCarouselItem2.innerHTML += (cartCreator(book));
})
newestBookFiltred3.forEach(book => {
newBooksCarouselItem3.innerHTML += (cartCreator(book));
})
// best books section
const bestBooksCarouselItem1 = document.getElementById("bestBooksCarouselItem1");
const bestBooksCarouselItem2 = document.getElementById("bestBooksCarouselItem2");
const bestBooksCarouselItem3 = document.getElementById("bestBooksCarouselItem3");
const sortedBooksPerRate = books().sort(function (a, b) {
let rateA = a.rating,
rateB = b.rating;
return rateB - rateA;
});
const slicedSortedBooksPerRate1 = sortedBooksPerRate.slice(0, 4);
const slicedSortedBooksPerRate2 = sortedBooksPerRate.slice(4, 8);
const slicedSortedBooksPerRate3 = sortedBooksPerRate.slice(8, 12);
slicedSortedBooksPerRate1.forEach(book => {
bestBooksCarouselItem1.innerHTML += (cartCreator(book));
})
slicedSortedBooksPerRate2.forEach(book => {
bestBooksCarouselItem2.innerHTML += (cartCreator(book));
})
slicedSortedBooksPerRate3.forEach(book => {
bestBooksCarouselItem3.innerHTML += (cartCreator(book));
})
// best deals section
const bestDealsCarouselItem1 = document.getElementById("bestDealsCarouselItem1");
const bestDealsCarouselItem2 = document.getElementById("bestDealsCarouselItem2");
const bestDealsCarouselItem3 = document.getElementById("bestDealsCarouselItem3");
const dealedBooks = books().filter(book => book.deal);
dealedBooks.slice(0,4).forEach(book => {
bestDealsCarouselItem1.innerHTML += (cartCreator(book));
})
dealedBooks.slice(4,8).forEach(book => {
bestDealsCarouselItem2.innerHTML += (cartCreator(book));
})
dealedBooks.slice(8,12).forEach(book => {
bestDealsCarouselItem3.innerHTML += (cartCreator(book));
})
// best of philosophy section
const bestOfPhilosophyCarouselItem1 = document.getElementById("bestOfPhilosophyCarouselItem1");
const bestOfPhilosophyCarouselItem2 = document.getElementById("bestOfPhilosophyCarouselItem2");
const philosophyBooks = books().filter(book => book.categorie.includes("philosophy"));
philosophyBooks.slice(0,4).forEach(book => {
bestOfPhilosophyCarouselItem1.innerHTML += (cartCreator(book));
})
philosophyBooks.slice(4,8).forEach(book => {
bestOfPhilosophyCarouselItem2.innerHTML += (cartCreator(book));
})
// best of self development section
const bestSelfDevCarouselItem1 = document.getElementById("bestSelfDevCarouselItem1");
const bestSelfDevCarouselItem2 = document.getElementById("bestSelfDevCarouselItem2");
const bestSelfDevCarouselItem3 = document.getElementById("bestSelfDevCarouselItem3");
const selfDevBooks = books().filter(book => book.categorie.includes("self-dev"));
selfDevBooks.slice(0,3).forEach(book => {
bestSelfDevCarouselItem1.innerHTML += (cartCreator(book));
})
selfDevBooks.slice(3,6).forEach(book => {
bestSelfDevCarouselItem2.innerHTML += (cartCreator(book));
})
selfDevBooks.slice(6,9).forEach(book => {
bestSelfDevCarouselItem3.innerHTML += (cartCreator(book));
})
// best of novels section
const bestNovelsCarouselItem1 = document.getElementById("bestNovelsCarouselItem1");
const bestNovelsCarouselItem2 = document.getElementById("bestNovelsCarouselItem2");
const bestNovelsCarouselItem3 = document.getElementById("bestNovelsCarouselItem3");
const novels = books().filter(book => book.categorie.includes("novel"));
const sortednovelsPerRate = novels.sort(function (a, b) {
let rateA = a.rating,
rateB = b.rating;
return rateB - rateA;
});
sortednovelsPerRate.slice(0,4).forEach(book => {
bestNovelsCarouselItem1.innerHTML += (cartCreator(book));
})
sortednovelsPerRate.slice(4,8).forEach(book => {
bestNovelsCarouselItem2.innerHTML += (cartCreator(book));
})
sortednovelsPerRate.slice(8,12).forEach(book => {
bestNovelsCarouselItem3.innerHTML += (cartCreator(book));
})
// Get all the button elements by its class
var addToCartButtons = document.querySelectorAll(".add-to-cart-btn");
// Add a click event listener to the button
addToCartButtons.forEach(function(button) {
button.addEventListener("click", function() {
alert("Item added to cart!");
});
});
// Go to top button
let mybutton = document.getElementById("myBtn");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}