Update index.html
This commit is contained in:
+40
-7
@@ -1,3 +1,4 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
@@ -96,7 +97,7 @@
|
||||
color: #888;
|
||||
}
|
||||
|
||||
@media(max-width: 600px) {
|
||||
@media (max-width: 600px) {
|
||||
.container {
|
||||
padding: 20px;
|
||||
}
|
||||
@@ -122,6 +123,7 @@
|
||||
type="text"
|
||||
id="searchInput"
|
||||
placeholder="نام سند یا شناسه مانند DOC-S300-015 را وارد کنید..."
|
||||
disabled
|
||||
>
|
||||
|
||||
<div id="status">در حال بارگذاری اسناد...</div>
|
||||
@@ -139,6 +141,21 @@ const results = document.getElementById("results");
|
||||
const status = document.getElementById("status");
|
||||
|
||||
|
||||
// یکسانسازی حروف و اعداد برای جستوجو
|
||||
function normalize(value) {
|
||||
return String(value ?? "")
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/[۰-۹]/g, digit =>
|
||||
"۰۱۲۳۴۵۶۷۸۹".indexOf(digit)
|
||||
)
|
||||
.replace(/[٠-٩]/g, digit =>
|
||||
"٠١٢٣٤٥٦٧٨٩".indexOf(digit)
|
||||
)
|
||||
.replace(/ي/g, "ی")
|
||||
.replace(/ك/g, "ک");
|
||||
}
|
||||
|
||||
|
||||
// خواندن صحیح اطلاعات CSV
|
||||
function parseCSV(text) {
|
||||
@@ -162,8 +179,13 @@ function parseCSV(text) {
|
||||
row.push(field);
|
||||
field = "";
|
||||
}
|
||||
else if ((char === "\n" || char === "\r") && !insideQuotes) {
|
||||
if (char === "\r" && text[i + 1] === "\n") i++;
|
||||
else if (
|
||||
(char === "\n" || char === "\r") &&
|
||||
!insideQuotes
|
||||
) {
|
||||
if (char === "\r" && text[i + 1] === "\n") {
|
||||
i++;
|
||||
}
|
||||
|
||||
row.push(field);
|
||||
|
||||
@@ -188,6 +210,7 @@ function parseCSV(text) {
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
||||
// دریافت فایل CSV
|
||||
async function loadDocuments() {
|
||||
try {
|
||||
@@ -219,6 +242,7 @@ async function loadDocuments() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// جستوجوی اسناد
|
||||
function searchDocuments() {
|
||||
const query = normalize(searchInput.value);
|
||||
@@ -231,10 +255,14 @@ function searchDocuments() {
|
||||
return;
|
||||
}
|
||||
|
||||
const matches = documents.filter(doc =>
|
||||
normalize(doc.title).includes(query) ||
|
||||
normalize(doc.id).includes(query)
|
||||
);
|
||||
const matches = documents.filter(doc => {
|
||||
const titleWords = normalize(doc.title)
|
||||
.split(/[\s\-_]+/);
|
||||
|
||||
const id = normalize(doc.id);
|
||||
|
||||
return titleWords.includes(query) || id === query;
|
||||
});
|
||||
|
||||
status.textContent =
|
||||
`${matches.length} نتیجه پیدا شد.`;
|
||||
@@ -245,6 +273,7 @@ function searchDocuments() {
|
||||
return;
|
||||
}
|
||||
|
||||
// نمایش نتایج
|
||||
matches.forEach(doc => {
|
||||
const item = document.createElement("div");
|
||||
item.className = "result";
|
||||
@@ -275,13 +304,17 @@ function searchDocuments() {
|
||||
idInfo.append(idLabel, idValue);
|
||||
|
||||
item.append(title, rowInfo, idInfo);
|
||||
|
||||
results.appendChild(item);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// جستوجوی لحظهای
|
||||
searchInput.addEventListener("input", searchDocuments);
|
||||
|
||||
|
||||
// شروع بارگذاری
|
||||
loadDocuments();
|
||||
|
||||
</script>
|
||||
|
||||
مرجع در شماره جدید
مسدود کردن کاربر