-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-script.js
174 lines (163 loc) · 4.8 KB
/
index-script.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
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
/*------------------------------------*\
#DATA
\*------------------------------------*/
const demos = [
{
id: 0, // an id that is unique in the array
name: "EventLand", // Name of your page
createdBy: {
name: "Ahmad Mohammadirad", // Your name
github: "https://github.com/ahmadmohammadirad2006", // link of your github profile
},
url: "event-land/index.html", // URL of your page based on root dir
mainImage: "event-land-main.png", // Name of your main page image in shared/images/
entirePageImage: "event-land-entire.png", // Name of your entire page image in shared/images/
},
{
id: 1,
name: "SolarLand",
createdBy: {
name: "AbdolMajed ShahBakhsh",
github: "https://github.com/abdolmajed3",
},
url: "solar-land/index.html",
mainImage: "solar-land-main.jpeg",
entirePageImage: "solar-land-entire.jpeg",
},
{
id: 2,
name: "AppLand",
createdBy: {
name: "Max Richard",
github: "https://github.com/MaxRichard2007",
},
url: "app-land/index.html",
mainImage: "app-land-main.jpeg",
entirePageImage: "app-land-entire.jpeg",
},
{
id: 3,
name: "Basket",
createdBy: {
name: "Ahmad Mohammadirad",
github: "https://github.com/ahmadmohammadirad2006",
},
url: "basket/index.html",
mainImage: "basket-entire-main.png",
entirePageImage: "basket-entire-main.png",
},
{
id: 4,
name: "ShowLand",
createdBy: {
name: "Sadi Karimi",
github: "https://github.com/sadiGFG",
},
url: "show-land/index.html",
mainImage: "show-land-main.png",
entirePageImage: "show-land-entire.png",
},
{
id: 5,
name: "ProductDetails",
createdBy: {
name: "Ahmad Mohammadirad",
github: "https://github.com/ahmadmohammadirad2006",
},
url: "product-details/index.html",
mainImage: "product-details-main.png",
entirePageImage: "product-details-entire.png",
},
{
id: 6,
name: "Blog",
createdBy: {
name: "Max Richard",
github: "https://github.com/MaxRichard2007",
},
url: "blog/index.html",
mainImage: "blog-main.png",
entirePageImage: "blog-entire.png",
},
];
/*------------------------------------*\
#SELECTING ELEMENTS
\*------------------------------------*/
const homePagesContainerEl = document.querySelector(".home-pages-container-js");
/*------------------------------------*\
#FUNCTIONS
\*------------------------------------*/
const displayDemoModal = function (demoId) {
const demo = demos.find((demo) => demo.id === demoId);
document.body.classList.add("modal-open");
document.body.insertAdjacentHTML(
"beforeend",
`
<div class="demo-modal fade-in demo-modal-js">
<div class="demo-modal__box">
<div class="demo-modal__info">
<div>
<h3 class="demo-modal__name">${demo.name}</h3>
<span class="demo-modal__by"
>By
<a
href="${demo.createdBy.github}"
class="demo-modal__by-link"
target="_blank"
>${demo.createdBy.name}</a
></span
>
</div>
<a href="apps/original/${demo.url}" target="_blank" class="btn btn-button">Live Demo</a>
</div>
<img class="demo-modal__image" src="shared/assets/images/${demo.entirePageImage}" alt="${demo.name} Entire Page">
</div>
</div>
`
);
};
const removeDemoModal = function () {
const demoModalEl = document.querySelector(".demo-modal-js");
if (!demoModalEl) return;
document.body.classList.remove("modal-open");
demoModalEl.classList.remove("fade-in");
demoModalEl.classList.add("fade-out");
setTimeout(function () {
demoModalEl.remove();
}, 300);
};
/*------------------------------------*\
#EVENT HANDLERS
\*------------------------------------*/
homePagesContainerEl.addEventListener("click", (e) => {
const homePageEl = e.target.closest(".home-page-js");
if (!homePageEl) return;
displayDemoModal(+homePageEl.dataset.id);
const demoModalEl = document.querySelector(".demo-modal-js");
demoModalEl.addEventListener("click", (e) => {
if (e.target.closest(".demo-modal__box")) return;
removeDemoModal();
});
});
document.addEventListener("keydown", (e) => {
if (e.code === "Escape") {
removeDemoModal();
}
});
/*------------------------------------*\
#RENDER DMOES
\*------------------------------------*/
for (const demo of demos) {
homePagesContainerEl.insertAdjacentHTML(
"beforeend",
`
<div class="home-page__img_boxs home-page-js" data-id="${demo.id}">
<img
src="shared/assets/images/${demo.mainImage}"
alt="${demo.name} main page"
/>
<p class="home-page__number">${demo.name}</p>
</div>
`
);
}