Skip to content
This repository was archived by the owner on Mar 21, 2026. It is now read-only.

Commit ff3f293

Browse files
committed
Breaking script.js into 5 files to make it better for readibility and structured
1 parent cceca5a commit ff3f293

7 files changed

Lines changed: 433 additions & 495 deletions

File tree

assets/js/auction.js

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
$(document).ready(function () {
2+
function countUp() {
3+
$(".counter").each(function () {
4+
const $el = $(this);
5+
const target = parseInt($el.data("target"));
6+
let current = 0;
7+
const increment = target / 30;
8+
const interval = setInterval(() => {
9+
current += increment;
10+
if (current >= target) {
11+
$el.text(target);
12+
clearInterval(interval);
13+
} else {
14+
$el.text(Math.floor(current));
15+
}
16+
}, 30);
17+
});
18+
}
19+
window.countUp = countUp;
20+
21+
function updateTimer() {
22+
$(".auction-timer").each(function () {
23+
const $timer = $(this);
24+
let h = parseInt($timer.data("hours")) || 0;
25+
let m = parseInt($timer.data("minutes")) || 0;
26+
let s = parseInt($timer.data("seconds")) || 0;
27+
if (s > 0) s--;
28+
else if (m > 0) {
29+
m--;
30+
s = 59;
31+
} else if (h > 0) {
32+
h--;
33+
m = 59;
34+
s = 59;
35+
}
36+
$timer.data({ hours: h, minutes: m, seconds: s });
37+
const pad = (num) => String(num).padStart(2, "0");
38+
$timer.text(`${pad(h)}:${pad(m)}:${pad(s)}`);
39+
});
40+
}
41+
setInterval(updateTimer, 1000);
42+
43+
$(".filter-btn").on("click", function () {
44+
const filterValue = $(this).data("filter");
45+
$(".filter-btn")
46+
.removeClass("active btn-primary")
47+
.addClass("btn-outline-light");
48+
$(this).removeClass("btn-outline-light").addClass("active btn-primary");
49+
if (filterValue === "all") {
50+
$(".auction-item").show();
51+
} else {
52+
$(".auction-item").each(function () {
53+
$(this).toggle($(this).data("category") === filterValue);
54+
});
55+
}
56+
});
57+
58+
$(".wishlist-btn").on("click", function (e) {
59+
e.preventDefault();
60+
const $btn = $(this);
61+
$btn.toggleClass("liked");
62+
$btn.find("i").toggleClass("bi-heart bi-heart-fill");
63+
});
64+
65+
$("#itemModal").on("show.bs.modal", function (e) {
66+
const $btn = $(e.relatedTarget);
67+
const title = $btn.data("title");
68+
$("#itemModalLabel, #modalTitle").text(title);
69+
$("#modalImg").attr({ src: $btn.data("img"), alt: title });
70+
$("#modalBid").text($btn.data("bid"));
71+
$("#modalDesc").text($btn.data("desc"));
72+
$(this).data({ "item-title": title, "item-bid": $btn.data("bid") });
73+
});
74+
75+
$(document).on(
76+
"click",
77+
'#itemModal a.btn[data-bs-dismiss="modal"]',
78+
function (e) {
79+
if ($(this).find("i.bi-lightning-fill").length === 0) return;
80+
e.preventDefault();
81+
bootstrap.Modal.getInstance(document.getElementById("itemModal")).hide();
82+
setTimeout(() => {
83+
if ($("#bid").length)
84+
$("html, body").animate(
85+
{ scrollTop: $("#bid").offset().top - 80 },
86+
600,
87+
"swing",
88+
);
89+
}, 400);
90+
},
91+
);
92+
93+
$("#loginModal").on("hidden.bs.modal", function () {
94+
$("#loginBtn, #mobileMenu .nav-link[href='#login']").first().focus();
95+
});
96+
97+
$("#itemModal").on("hidden.bs.modal", function () {});
98+
99+
$("#loginBtn").on("click", () => {
100+
const offcanvasInstance = bootstrap.Offcanvas.getInstance(
101+
document.getElementById("mobileMenu"),
102+
);
103+
if (offcanvasInstance) offcanvasInstance.hide();
104+
});
105+
106+
$("#increaseBtn, #decreaseBtn").on("click", function (e) {
107+
e.preventDefault();
108+
const $input = $("#bidAmount");
109+
let value = parseInt($input.val()) || 100;
110+
const isIncrease = $(this).attr("id") === "increaseBtn";
111+
value = isIncrease
112+
? Math.min(value + 1, 1000000)
113+
: Math.max(value - 1, 100);
114+
$input.val(value);
115+
});
116+
117+
$("#bidAmount").on("change", function () {
118+
let value = parseInt($(this).val()) || 100;
119+
$(this).val(Math.min(Math.max(value, 100), 1000000));
120+
});
121+
122+
$("#bidBtn").on("click", function () {
123+
setTimeout(
124+
() =>
125+
$("html, body").animate(
126+
{ scrollTop: $("#bid").offset().top - 80 },
127+
600,
128+
"swing",
129+
),
130+
100,
131+
);
132+
});
133+
134+
$("#bidForm").on("submit", function (e) {
135+
e.preventDefault();
136+
$("#bidSuccess").addClass("d-none");
137+
if (!this.checkValidity()) {
138+
e.stopPropagation();
139+
$(this).addClass("was-validated");
140+
return false;
141+
}
142+
$("#bidSuccess").removeClass("d-none");
143+
$(this)[0].reset();
144+
$("#bidAmount").val("100");
145+
$(this).removeClass("was-validated");
146+
setTimeout(() => $("#bidSuccess").addClass("d-none"), 5000);
147+
});
148+
});

assets/js/forms.js

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
$(document).ready(function () {
2+
function showPremiumAlert(
3+
message,
4+
type = "info",
5+
title = "Notification",
6+
autoHide = true,
7+
) {
8+
const alert = $("#premiumAlert");
9+
const titleEl = $("#alertTitle");
10+
const messageEl = $("#alertMessage");
11+
alert.removeClass("success error info").addClass(type + " show");
12+
titleEl.text(title);
13+
messageEl.text(message);
14+
if (autoHide) {
15+
setTimeout(() => $("#premiumAlert").removeClass("show"), 4000);
16+
}
17+
}
18+
window.hidePremiumAlert = function () {
19+
$("#premiumAlert").removeClass("show");
20+
};
21+
$(".premium-alert-close").on("click", hidePremiumAlert);
22+
23+
$("#registerPassword").on("input", function () {
24+
const pw = $(this).val();
25+
let strength = 0;
26+
if (pw.length >= 7) strength++;
27+
if (/[A-Z]/.test(pw)) strength++;
28+
if (/[a-z]/.test(pw)) strength++;
29+
if (/[0-9]/.test(pw)) strength++;
30+
if (/[@$!%*?&]/.test(pw)) strength++;
31+
$(".progress").toggle(pw.length > 0);
32+
const classes = [
33+
"bg-warning",
34+
"bg-success",
35+
"bg-info",
36+
"bg-orange",
37+
"bg-danger",
38+
];
39+
$("#passwordStrength")
40+
.css("width", (strength / 5) * 100 + "%")
41+
.removeClass()
42+
.addClass("progress-bar " + (classes[strength - 1] || ""));
43+
});
44+
45+
$("#registerForm").on("submit", function (e) {
46+
e.preventDefault();
47+
if ($("#registerPassword").val() !== $("#registerConfirmPassword").val()) {
48+
$("#errorMessage").text("Passwords must match.");
49+
const errorModal = new bootstrap.Modal(
50+
document.getElementById("errorModal"),
51+
);
52+
errorModal.show();
53+
$("#errorModal").on("hidden.bs.modal", function () {
54+
$("#registerPassword").focus();
55+
});
56+
return;
57+
}
58+
showPremiumAlert(
59+
"Your account has been created!",
60+
"success",
61+
"Registration Successful",
62+
);
63+
$(this)[0].reset();
64+
});
65+
66+
$("#loginForm").on("submit", function (e) {
67+
e.preventDefault();
68+
showPremiumAlert(
69+
"Account login successful!",
70+
"success",
71+
"Login Successful",
72+
);
73+
$(this)[0].reset();
74+
});
75+
76+
$("#forgotPasswordForm").on("submit", function (e) {
77+
e.preventDefault();
78+
const email = $("#forgotEmail").val().trim();
79+
if (email) {
80+
showPremiumAlert(
81+
"Password reset link sent to " + email,
82+
"success",
83+
"Success!",
84+
);
85+
$(this)[0].reset();
86+
$("#forgotPasswordModal").modal("hide");
87+
} else {
88+
showPremiumAlert("Please enter a valid email address.", "error", "Error");
89+
}
90+
});
91+
92+
$("#contactForm").on("submit", function (e) {
93+
e.preventDefault();
94+
$("#successMsg, #errorMsg").addClass("d-none");
95+
const $btn = $("#submitBtn");
96+
const originalText = $btn.html();
97+
$btn
98+
.prop("disabled", true)
99+
.html('<i class="bi bi-hourglass-split me-2"></i> Sending...');
100+
$.ajax({
101+
url: $(this).attr("action"),
102+
method: "POST",
103+
data: $(this).serialize(),
104+
headers: { Accept: "application/json" },
105+
success: function () {
106+
$("#contactForm")[0].reset();
107+
$("#successMsg").removeClass("d-none");
108+
},
109+
error: function () {
110+
$("#errorMsg").removeClass("d-none");
111+
},
112+
complete: function () {
113+
$btn.prop("disabled", false).html(originalText);
114+
},
115+
});
116+
});
117+
118+
$("#newsletterForm").on("submit", function (e) {
119+
e.preventDefault();
120+
const email = $("#newsletterEmail").val().trim();
121+
if (email) {
122+
$("#newsletterSuccess").removeClass("d-none");
123+
setTimeout(() => $("#newsletterSuccess").addClass("d-none"), 4000);
124+
$(this)[0].reset();
125+
} else {
126+
$("#newsletterError").removeClass("d-none");
127+
}
128+
});
129+
130+
$(document).on("click", ".toggle-password", function (e) {
131+
e.preventDefault();
132+
const $btn = $(this);
133+
const $icon = $btn.find("i");
134+
const $input = $btn.siblings(".password-input");
135+
if ($input.attr("type") === "password") {
136+
$input.attr("type", "text");
137+
$icon.removeClass("bi-eye").addClass("bi-eye-slash");
138+
} else {
139+
$input.attr("type", "password");
140+
$icon.removeClass("bi-eye-slash").addClass("bi-eye");
141+
}
142+
});
143+
});

assets/js/navigation.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
$(document).ready(function () {
2+
const $window = $(window);
3+
const $htmlBody = $("html, body");
4+
5+
$(document).on("click", ".nav-link.mobile-link", function (e) {
6+
var target = $(this).attr("href");
7+
if (target && target.startsWith("#") && $(target).length) {
8+
e.preventDefault();
9+
var offcanvasInstance = bootstrap.Offcanvas.getInstance(
10+
document.getElementById("mobileMenu"),
11+
);
12+
if (offcanvasInstance) offcanvasInstance.hide();
13+
setTimeout(() => {
14+
$htmlBody.animate(
15+
{ scrollTop: $(target).offset().top - 80 },
16+
600,
17+
"swing",
18+
);
19+
}, 350);
20+
}
21+
});
22+
23+
$("#scrollTopBtn").on("click", function () {
24+
$htmlBody.animate({ scrollTop: 0 }, 600, "swing");
25+
});
26+
27+
$window.on("scroll", function () {
28+
const scrollPos = $(this).scrollTop();
29+
$("#scrollTopBtn").toggleClass("visible", scrollPos > 400);
30+
if (scrollPos < $window.height()) {
31+
$(".hero-overlay .container").css("opacity", 1 - scrollPos * 0.001);
32+
}
33+
$("section[id]").each(function () {
34+
const $sec = $(this);
35+
const top = $sec.offset().top;
36+
const bottom = top + $sec.outerHeight();
37+
const id = $sec.attr("id");
38+
if (scrollPos + 120 >= top && scrollPos + 120 < bottom) {
39+
$(".nav-link").removeClass("active");
40+
$('.nav-link[href="#' + id + '"]').addClass("active");
41+
}
42+
});
43+
});
44+
});

assets/js/preloader.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
$(document).ready(function () {
2+
const $window = $(window);
3+
const $body = $("body");
4+
$body.css("overflow", "hidden");
5+
6+
function handlePreloader() {
7+
$("#preloader").fadeOut(500, function () {
8+
$body.css("overflow", "auto");
9+
window.countUp && window.countUp();
10+
});
11+
}
12+
13+
$window.on("load", handlePreloader);
14+
setTimeout(handlePreloader, 2000);
15+
});

0 commit comments

Comments
 (0)