-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
193 lines (161 loc) · 6.16 KB
/
scripts.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
let currentIndex = 0;
let useCoupon = "";
const coupons = {
tzc: { name: "Crook", discountPercentage: 50 },
save50: { name: "SAVE20", discountPercentage: 20 },
free10: { name: "Free", discountPercentage: 100 },
};
const images = [
{
src: `.\\assets\\Farm1Screenshot_5ar-1-Echo-jue-50.jpg`,
title: "(1) تفريم أيكو C4",
},
{
src: `.\\assets\\Farm1Screenshot_6ar-2-Echo-jue-50.jpg`,
title: "(2) تفريم أيكو C4",
},
{
src: `.\\assets\\Farm1Screenshot_7ar-3-Echo-jue-50.jpg`,
title: "(3) تفريم أيكو C4",
},
{
src: `.\\assets\\Data-bank1Screenshot_4en-ar.jpg`,
title: "(1) داتا بانك ماكس",
},
{
src: `.\\assets\\Exp-1Screenshot_3ar.jpg`,
title: "(1) أستكشاف",
},
];
document.addEventListener("DOMContentLoaded", function () {
const navToggle = document.getElementById("nav-toggle");
const navMenu = document.getElementById("nav-menu");
navToggle.addEventListener("click", function () {
navMenu.classList.toggle("show");
});
});
function showContactPopup() {
document.getElementById("contact-popup").style.display = "flex";
document.getElementById("overlay").style.display = "block";
}
function hideContactPopup() {
document.getElementById("contact-popup").style.display = "none";
document.getElementById("overlay").style.display = "none";
}
function showOrderPopup(button) {
const card = button.closest(".card-container");
const title = card.querySelector(".card__title").textContent;
const originalPrice = card.querySelector(".original-price");
const discountedPrice = card.querySelector(".discounted-price");
const orderNameInput = document.getElementById("unique-order-name");
const priceInput = document.getElementById("unique-price");
orderNameInput.value = title;
priceInput.value = originalPrice
? originalPrice.textContent
: discountedPrice.textContent;
document.getElementById("order-receipt-popup").style.display = "block";
}
function hideOrderPopup() {
document.getElementById("order-receipt-popup").style.display = "none";
}
function printReceipt() {
const orderForm = document.getElementById("unique-order-form");
html2canvas(orderForm).then((canvas) => {
const link = document.createElement("a");
link.href = canvas.toDataURL("image/png");
link.download = "receipt.png";
link.click();
});
}
const galleryImage = document.querySelector(".gallery-image");
const imageTitle = document.querySelector(".image-title");
const modal = document.getElementById("imageModal");
const modalImg = document.getElementById("modalImage");
const captionText = document.getElementById("caption");
function prevImage() {
currentIndex = currentIndex === 0 ? images.length - 1 : currentIndex - 1;
updateImage();
}
function nextImage() {
currentIndex = currentIndex === images.length - 1 ? 0 : currentIndex + 1;
updateImage();
}
function updateImage() {
galleryImage.style.transform = "translateX(-100%)";
setTimeout(() => {
galleryImage.src = images[currentIndex].src;
imageTitle.textContent = images[currentIndex].title;
galleryImage.style.transform = "translateX(0)";
}, 500);
}
updateImage();
function openModal() {
modal.style.display = "block";
modalImg.src = images[currentIndex].src;
captionText.innerHTML = images[currentIndex].title;
}
function closeModal() {
modal.style.display = "none";
}
function applyCoupon() {
let couponCode = document.getElementById("coupon-code").value.trim();
couponCode = couponCode.toLowerCase();
if (coupons[couponCode]) {
const { name, discountPercentage } = coupons[couponCode];
const nonDiscountedOffers = document.querySelectorAll(
".nondiscounted-offer"
);
nonDiscountedOffers.forEach((offer) => {
const cardContainer = offer.closest(".card-container");
const cardHeadContent = offer.querySelector(".card__head-content");
const originalPriceElement = cardHeadContent.querySelector(
".upper-cent-price__body"
);
const originalPriceText = originalPriceElement.innerText;
const [priceEGP, priceUSD] = originalPriceText
.split("/")
.map((price) => price.trim());
const newPriceEGP = parseFloat(priceEGP) * (1 - discountPercentage / 100);
const newPriceUSD =
parseFloat(priceUSD.replace("$", "")) * (1 - discountPercentage / 100);
// Create discount wrapper
const discountWrapper = document.createElement("div");
discountWrapper.classList.add("discount-wrapper");
// Create discount badge
const discountBadge = document.createElement("div");
discountBadge.classList.add("discount-badge");
discountBadge.innerText = `${discountPercentage}%`;
// Update offer class and data attribute
offer.classList.remove("nondiscounted-offer");
offer.classList.add("discounted-offer");
offer.setAttribute("data-discount", discountPercentage);
// Update prices
const upperCentPriceBody = cardHeadContent.querySelector(
".upper-cent-price__body"
);
upperCentPriceBody.innerHTML = `
<span class="old-price">${priceEGP}</span>
<span class="discounted-price">${newPriceEGP.toFixed(
2
)} جنية / ${newPriceUSD.toFixed(2)}$</span>
`;
// Wrap card container with discount wrapper
cardContainer.parentNode.insertBefore(discountWrapper, cardContainer);
discountWrapper.appendChild(discountBadge);
discountWrapper.appendChild(cardContainer);
});
// Set the coupon code in the unique-coupon input field
document.getElementById("unique-coupon").value = couponCode;
hideCouponPopup();
} else {
alert("Invalid coupon code.");
}
}
function showCouponPopup() {
document.getElementById("coupon-popup").style.display = "flex";
document.getElementById("overlay").style.display = "block";
}
function hideCouponPopup() {
document.getElementById("coupon-popup").style.display = "none";
document.getElementById("overlay").style.display = "none";
}