Skip to content

Commit 58cb706

Browse files
committed
Add surah search bar
1 parent 2370f97 commit 58cb706

3 files changed

Lines changed: 126 additions & 4 deletions

File tree

assets/subpages/holy-quran.html

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="ar" dir="rtl">
33
<head>
44
<!-- Required meta tags -->
@@ -29,10 +29,12 @@
2929
<body class="d-flex flex-column min-h-dvh">
3030
<!-- Page loader -->
3131
<div id="pre-loader"></div>
32+
3233
<!-- Back to TOP -->
3334
<div id="progress">
3435
<span id="progress-value"><i class="fa-solid fa-up-long"></i></span>
3536
</div>
37+
3638
<!-- NavBar -->
3739
<nav class="navbar navbar-expand-lg shadow sticky-top">
3840
<div
@@ -41,6 +43,7 @@
4143
<a href="../../index.html" class="ms-auto" id="back" title="عودة للخلف">
4244
<i class="fa-solid fa-left-long fa-flip-horizontal"></i>
4345
</a>
46+
4447
<a
4548
href="../../index.html"
4649
class="navbar-brand position-absolute start-50 translate-middle-x"
@@ -51,20 +54,35 @@
5154
height="60px"
5255
/>
5356
</a>
57+
5458
<button id="theme-switch">
5559
<i class="fa-solid fa-moon"></i>
5660
<i class="fa-solid fa-sun"></i>
5761
</button>
5862
</div>
5963
</nav>
60-
<!-- Main -->
64+
6165
<main class="container text-center my-4" id="main">
6266
<section class="container my-4">
6367
<h1 class="text-center fs-1 fs-md-2 fs-lg-3" id="section-header">
6468
فهرس السور
6569
</h1>
66-
<br />
67-
<div class="row row-cols-2 row-cols-md-3 row-cols-lg-3 g-4">
70+
<div class="row justify-content-center my-3">
71+
<div class="col-12 col-md-6">
72+
<input
73+
type="text"
74+
id="surahSearch"
75+
class="form-control text-center"
76+
placeholder="ابحث عن اسم السورة..."
77+
autocomplete="off"
78+
/>
79+
<small id="searchError" class="text-warning d-none mt-2"></small>
80+
</div>
81+
</div>
82+
<div
83+
id="surahGrid"
84+
class="row row-cols-2 row-cols-md-3 row-cols-lg-3 g-4"
85+
>
6886
<article class="col">
6987
<a href="quran-pages/surah-1.html" class="text-decoration-none">
7088
<div
@@ -1092,7 +1110,9 @@ <h5 class="card-title">سورة الناس</h5>
10921110
</a>
10931111
</article>
10941112
</div>
1113+
10951114
<div></div>
1115+
10961116
<a
10971117
href="https://www.youtube.com/playlist?list=PLWzzF688g_njHA-QzbZUcxNGneHOYpVbQ"
10981118
download
@@ -1103,19 +1123,22 @@ <h5 class="card-title">سورة الناس</h5>
11031123
المصحف المرتل &nbsp<i class="fa-brands fa-youtube fa-lg"></i>
11041124
</button>
11051125
</a>
1126+
11061127
<a href="../resources/holy-quran.pdf" download id="more-link-3">
11071128
<button class="mt-4" id="more">
11081129
رابط التحميل &nbsp<i class="fa-solid fa-file-pdf fa-lg"></i>
11091130
</button>
11101131
</a>
11111132
</section>
11121133
</main>
1134+
11131135
<!-- Footer -->
11141136
<footer class="mt-auto">
11151137
<div class="text-center">
11161138
<p>جميع الحقوق محفوظة &copy; 2025</p>
11171139
</div>
11181140
</footer>
1141+
11191142
<!-- Required scripts -->
11201143
<script src="../../js/script.js"></script>
11211144
<script src="../../js/bootstrap.js"></script>

css/style.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,3 +734,51 @@ label {
734734
border-radius: 15px;
735735
}
736736
}
737+
738+
/* -------------------- Search Bar Style ---------------------- */
739+
740+
#surahSearch {
741+
width: 100%;
742+
max-width: 600px;
743+
margin: 0 auto !important;
744+
padding: 14px 18px !important;
745+
746+
background-color: var(--nav-cards-bg) !important;
747+
color: var(--text-color) !important;
748+
749+
border: 2px solid var(--accent-color) !important;
750+
border-radius: 15px !important;
751+
752+
box-shadow: none !important;
753+
transition: none !important;
754+
}
755+
756+
#surahSearch::placeholder {
757+
color: var(--text-color) !important;
758+
opacity: 0.6;
759+
}
760+
761+
#surahSearch:focus {
762+
outline: none !important;
763+
box-shadow: none !important;
764+
border-color: var(--accent-color) !important;
765+
}
766+
767+
#searchError {
768+
display: inline-block;
769+
font-size: 2rem;
770+
font-weight: 500;
771+
opacity: 0.85;
772+
color: var(--accent-color);
773+
}
774+
775+
@media (max-width: 576px) {
776+
#surahSearch {
777+
padding: 12px 16px !important;
778+
font-size: 1rem !important;
779+
}
780+
781+
#searchError {
782+
font-size: 0.95rem;
783+
}
784+
}

js/script.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,54 @@ function shareContent() {
117117
alert("المشاركة غير مدعومة على متصفحك.");
118118
}
119119
}
120+
121+
// -------------------------- Search Bar Logic ----------------------------
122+
123+
document.addEventListener("DOMContentLoaded", () => {
124+
const searchInput = document.getElementById("surahSearch");
125+
const errorMsg = document.getElementById("searchError");
126+
const surahCards = document.querySelectorAll("#surahGrid article.col");
127+
128+
if (!searchInput || !errorMsg || !surahCards.length) return;
129+
130+
function normalizeArabic(text) {
131+
return text
132+
.replace(/[أإآ]/g, "ا")
133+
.replace(/ى/g, "ي")
134+
.replace(/ؤ/g, "و")
135+
.replace(/ئ/g, "ي")
136+
.replace(/ة/g, "ه")
137+
.replace(/[\u064B-\u065F]/g, "")
138+
.replace(/\s+/g, " ")
139+
.replace("سورة", "")
140+
.trim()
141+
.toLowerCase();
142+
}
143+
144+
searchInput.addEventListener("input", function () {
145+
const query = normalizeArabic(this.value);
146+
let found = false;
147+
148+
if (query === "") {
149+
surahCards.forEach((card) => (card.style.display = ""));
150+
errorMsg.classList.add("d-none");
151+
return;
152+
}
153+
154+
surahCards.forEach((card) => {
155+
const titleEl = card.querySelector(".card-title");
156+
const title = titleEl ? titleEl.innerText : "";
157+
const normalizedTitle = normalizeArabic(title);
158+
159+
if (normalizedTitle.includes(query)) {
160+
card.style.display = "";
161+
found = true;
162+
} else {
163+
card.style.display = "none";
164+
}
165+
});
166+
167+
if (!found) errorMsg.classList.remove("d-none");
168+
else errorMsg.classList.add("d-none");
169+
});
170+
});

0 commit comments

Comments
 (0)