stat2025 commited on
Commit
bc41fa6
·
verified ·
1 Parent(s): d1364e6

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +12 -21
script.js CHANGED
@@ -1,4 +1,4 @@
1
- // عناصر الواجهة
2
  const searchBox = document.getElementById("searchBox");
3
  const clearSearch = document.getElementById("clearSearch");
4
  const pageSizeEl = document.getElementById("pageSize");
@@ -8,28 +8,20 @@ const pagination = document.getElementById("pagination");
8
  const counter = document.getElementById("counter");
9
  const loading = document.getElementById("loading");
10
 
11
- // حالة
12
  let data = [];
13
  let filtered = [];
14
  let currentPage = 1;
15
- const DEFAULT_PAGE_SIZE = 10; // الافتراضي المطلوب
16
  let rowsPerPage = DEFAULT_PAGE_SIZE;
17
 
18
- // لو فيه قائمة حجم موجودة، عيّنيها على 25 فورًا
19
- if (pageSizeEl) pageSizeEl.value = String(DEFAULT_PAGE_SIZE);
20
 
21
- // (اختياري) لو ودك يحفظ اختيار المستخدم بعدين:
22
- // const saved = localStorage.getItem('pageSize');
23
- // if (saved) {
24
- // rowsPerPage = parseInt(saved, 10) || DEFAULT_PAGE_SIZE;
25
- // if (pageSizeEl) pageSizeEl.value = String(rowsPerPage);
26
- // }
27
 
28
 
29
- // ألوان جانبية
30
  const colors = ["#00bcd4","#4caf50","#f44336","#ff9800","#9c27b0","#e91e63","#009688","#3f51b5","#607d8b","#795548"];
31
 
32
- /* ========= أدوات بحث عربية ========= */
33
  function normalizeArabic(str=""){
34
  return str
35
  .replace(/[\u064B-\u0652]/g, "")
@@ -47,7 +39,7 @@ function highlight(text, q){
47
  return String(text ?? "").replace(new RegExp(esc, 'gi'), m => `<mark class="hl">${m}</mark>`);
48
  }
49
 
50
- /* ========= ترقيم الصفحات ========= */
51
  function renderPagination(){
52
  const pages = Math.ceil(filtered.length / rowsPerPage);
53
  pagination.innerHTML = "";
@@ -89,7 +81,7 @@ function renderPagination(){
89
  pagination.appendChild(makeBtn("›", Math.min(total, currentPage+1), {ghost:true, disabled: currentPage===total}));
90
  }
91
 
92
- /* ========= عرض الجدول ========= */
93
  function renderTable(){
94
  const q = searchBox.value.trim();
95
  tableBody.innerHTML = "";
@@ -129,12 +121,11 @@ function renderTable(){
129
  });
130
  }
131
 
132
- /* ========= تحديث العرض ========= */
133
  function updateView(){
134
  const q = searchBox.value.trim();
135
  filtered = data.filter(it => matches(it.code, q) || matches(it.activity ?? it.name, q));
136
 
137
- // عدّاد مباشر بالرموز
138
  if (!q) {
139
  counter.textContent = `📊 إجمالي الأنشطة: ${data.length.toLocaleString()}`;
140
  } else {
@@ -148,17 +139,17 @@ function updateView(){
148
  renderPagination();
149
  }
150
 
151
- /* ========= أحداث ========= */
152
  function debounce(fn, delay=200){ let t; return (...a)=>{ clearTimeout(t); t=setTimeout(()=>fn(...a), delay); }; }
153
 
154
  searchBox.addEventListener("input", debounce(()=>{ currentPage=1; updateView(); }, 180));
155
  clearSearch.addEventListener("click", ()=>{ searchBox.value=""; searchBox.focus(); currentPage=1; updateView(); });
156
  pageSizeEl.addEventListener("change", ()=>{ rowsPerPage = parseInt(pageSizeEl.value, 10); currentPage=1; updateView(); });
157
 
158
- // اختصار للانتقال للبحث
159
  document.addEventListener("keydown", (e)=>{ if(e.key==="/"){ e.preventDefault(); searchBox.focus(); } });
160
 
161
- /* ========= وضع ليلي ========= */
162
  (function initTheme(){
163
  const saved = localStorage.getItem("theme") || "light";
164
  document.documentElement.classList.toggle("dark", saved === "dark");
@@ -170,7 +161,7 @@ document.addEventListener("keydown", (e)=>{ if(e.key==="/"){ e.preventDefault();
170
  });
171
  })();
172
 
173
- /* ========= تحميل البيانات ========= */
174
  fetch("data.json", { cache: "no-cache" })
175
  .then(r=> r.json())
176
  .then(json=>{
 
1
+
2
  const searchBox = document.getElementById("searchBox");
3
  const clearSearch = document.getElementById("clearSearch");
4
  const pageSizeEl = document.getElementById("pageSize");
 
8
  const counter = document.getElementById("counter");
9
  const loading = document.getElementById("loading");
10
 
11
+
12
  let data = [];
13
  let filtered = [];
14
  let currentPage = 1;
15
+ const DEFAULT_PAGE_SIZE = 10;
16
  let rowsPerPage = DEFAULT_PAGE_SIZE;
17
 
 
 
18
 
19
+ if (pageSizeEl) pageSizeEl.value = String(DEFAULT_PAGE_SIZE);
 
 
 
 
 
20
 
21
 
 
22
  const colors = ["#00bcd4","#4caf50","#f44336","#ff9800","#9c27b0","#e91e63","#009688","#3f51b5","#607d8b","#795548"];
23
 
24
+
25
  function normalizeArabic(str=""){
26
  return str
27
  .replace(/[\u064B-\u0652]/g, "")
 
39
  return String(text ?? "").replace(new RegExp(esc, 'gi'), m => `<mark class="hl">${m}</mark>`);
40
  }
41
 
42
+
43
  function renderPagination(){
44
  const pages = Math.ceil(filtered.length / rowsPerPage);
45
  pagination.innerHTML = "";
 
81
  pagination.appendChild(makeBtn("›", Math.min(total, currentPage+1), {ghost:true, disabled: currentPage===total}));
82
  }
83
 
84
+
85
  function renderTable(){
86
  const q = searchBox.value.trim();
87
  tableBody.innerHTML = "";
 
121
  });
122
  }
123
 
 
124
  function updateView(){
125
  const q = searchBox.value.trim();
126
  filtered = data.filter(it => matches(it.code, q) || matches(it.activity ?? it.name, q));
127
 
128
+
129
  if (!q) {
130
  counter.textContent = `📊 إجمالي الأنشطة: ${data.length.toLocaleString()}`;
131
  } else {
 
139
  renderPagination();
140
  }
141
 
142
+
143
  function debounce(fn, delay=200){ let t; return (...a)=>{ clearTimeout(t); t=setTimeout(()=>fn(...a), delay); }; }
144
 
145
  searchBox.addEventListener("input", debounce(()=>{ currentPage=1; updateView(); }, 180));
146
  clearSearch.addEventListener("click", ()=>{ searchBox.value=""; searchBox.focus(); currentPage=1; updateView(); });
147
  pageSizeEl.addEventListener("change", ()=>{ rowsPerPage = parseInt(pageSizeEl.value, 10); currentPage=1; updateView(); });
148
 
149
+
150
  document.addEventListener("keydown", (e)=>{ if(e.key==="/"){ e.preventDefault(); searchBox.focus(); } });
151
 
152
+
153
  (function initTheme(){
154
  const saved = localStorage.getItem("theme") || "light";
155
  document.documentElement.classList.toggle("dark", saved === "dark");
 
161
  });
162
  })();
163
 
164
+
165
  fetch("data.json", { cache: "no-cache" })
166
  .then(r=> r.json())
167
  .then(json=>{