Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
HTML
<h1 style="text-align:center; font-family:Vazir, Tahoma; color:#333;font-weight:600;">
  📚 کتابخانه
</h1>

<!-- نوار ابزار / جستجو -->
<div id="book-toolbar" style="max-width:900px; margin:0 auto 10px; padding:0 20px; display:flex; justify-content:flex-start; align-items:center; gap:10px; direction:rtl;">
  <input id="book-search" type="text"
         placeholder="جستجو در عنوان، حیطه، نویسنده یا سال..."
         style="flex:1; padding:8px 12px; border-radius:999px; border:1px solid #ddd; font-family:Vazir, Tahoma; font-size:13px; outline:none;">
</div>

<div id="book-grid" style="display:grid; grid-template-columns:repeat(3, 1fr); gap:20px; padding:10px 40px 60px; direction:rtl;"></div>

<style>

@font-face {
  font-family: "IRANSans";
  src: url("/download//* =========================================
   FONT
========================================= */

@font-face {
  font-family: "IRANSans";
  src: url("/download/attachments/79076976/IRANSansXVF.woff2") format("woff2");
}

@font-face {
  font-family: "Vazir";
  src: url("/download/attachments/79076976/Vazir-Regular.woff2") format("woff2");
}


/* =========================
   تنظیمات کلی
================
   GLOBAL
========================================= */

#book-grid,
#book-toolbar *,
#book-grid * ,
#book-toolbar *grid {
  box-sizing: border-box;
}

#book-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px24px;

  padding: 10px18px 40px 60px70px;

  direction: rtl;

  width: 100%;

  font-family: Vazir, Tahoma, sans-serif;
}


/* =========================================
   نوار جستجوSEARCH
=========================== ============== */

#book-toolbar {
  width: 100%;
  max-width: 940px950px;

  margin: 0 auto 10px18px;

  padding: 0 20px;

  display: flex;
  justify-content: center;
  align-items: center;

  direction: rtl;
}

#book-search {
  width: 100%;
  height: 40px;
  padding: 8px 18px;

  border-radius: 999px;
  border: 1px solid #dedede;

  background: #fff;

  font-family: Vazir, Tahoma, sans-serif;
  font-size: 13px;
  color: #444;

  outline: none;

  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

#book-search::placeholder {
  color: #999;
}

#book-search:focus {
  border-color: #cfcfcf;
  box-shadow: 0 0 0 3px rgba(180, 0, 116, 0.05);
}


/* =========================
   کارت کتاب
========================= */

.card {
  background: #fff;

  border-radius: 18px height: 44px;

  padding: 8px 20px;

  border-radius: 999px;

  border: 1px solid #e2e2e2;

  background: #fff;

  color: #333;

  font-family: Vazir, Tahoma, sans-serif;

  font-size: 13px;

  outline: none;

  box-shadow:
    0 3px 12px rgba(0,0,0,.04);

  transition:
    border-color .25s ease,
    box-shadow .25s ease,
    transform .25s ease;
}

#book-search::placeholder {
  color: #999;
}

#book-search:hover {
  border-color: #cfcfcf;
}

#book-search:focus {
  border-color: #b40074;

  box-shadow:
    0 0 0 4px rgba(180,0,116,.07),
    0 5px 18px rgba(0,0,0,.06);
}


/* =========================================
   BOOK CARD
========================================= */

.card {
  position: relative;

  background: #fff;

  border-radius: 20px;

  padding: 18px;

  min-height: 220px;

  display: flex;

  align-items: flex-start;

  justify-content: space-between;

  flex-direction: row-reverse;

  font-family: Vazir, Tahoma, sans-serif;

  border: 1px solid rgba(0,0,0,.035);

  box-shadow:
    0 5px 15px rgba(0,0,0,.055),
    0 1px 3px rgba(0,0,0,.035);

  overflow: hidden;

  transition:
    transform .3s cubic-bezier(.2,.8,.2,1),
    box-shadow .3s ease,
    border-color .3s ease;
}


/* خط تزئینی بالای کارت */

.card::before {
  content: "";

  position: absolute;

  top: 0;
  right: 0;

  width: 100%;
  height: 3px;

  background: linear-gradient(
    90deg,
    #b40074,
    #d50088,
    #b40074
  );

  opacity: .85;
}


/* Hover */

.card:hover {
  transform: translateY(-5px);

  border-color: rgba(180,0,116,.10);

  box-shadow:
    0 14px 30px rgba(0,0,0,.09),
    0 4px 10px rgba(180,0,116,.05);
}


/* =========================================
   CARD CONTENT
========================================= */

.card-content {
  flex: 1;

  min-width: 0;

  text-align: right;

  padding-right: 17px;

  direction: rtl;
}


/* =========================================
   TITLE
========================================= */

.card-content h3 {
  margin: 1px 0 10px;

  font-family: Vazir, Tahoma, sans-serif;

  font-size: 14px;

  line-height: 1.75;

  font-weight: 700;

  color: #242424;

  transition: color .25s ease;
}

.card:hover .card-content h3 {
  color: #b40074;
}


/* =========================================
   INFORMATION
========================================= */

.card-content .dot-line {
  font-family: Vazir, Tahoma, sans-serif;

  font-size: 12.5px;

  line-height: 1.85;

  color: #5b5b5b;

  margin: 1px 0;

  word-break: break-word;
}


/* =========================================
   BOOK IMAGE
========================================= */

.card-icon {
  position: relative;

  flex: 0 0 92px;

  width: 92px;
  height: 104px;

  background:
    linear-gradient(
      145deg,
      #fafafa,
      #f2f2f2
    );

  border-radius: 18px;

  padding: 11px;

  display: flex;

  align-items: center;
  justify-content: center;

  border: 1px solid rgba(0,0,0,.025);

  box-shadow:
    inset 0 3px1px 10px0 rgba(0255, 0255, 0255, 0.089);

  paddingoverflow: 16pxhidden;

  min-height: 216px;

transition:
  display: flex;
  align-items: flex-start;transform .3s ease,
  justify-content: space-between;

  flex-direction: row-reverse;

  font-family: Vazir, Tahoma, sans-serif  box-shadow .3s ease;
}

.card:hover .card-icon {
  transform: scale(1.04);

  transitionbox-shadow:
    transform 0.2s ease,
5px    box-shadow 0.2s ease14px rgba(0,0,0,.07);
}


/* افکت بسیار ملایم هنگام رفتن موس روی کارت */

.card:hover {
  transform: translateY(-2px).card-icon img {
  width: 74px;
  height: 74px;

  object-fit: contain;

  display: block;

  box-shadowtransition:
    transform  0 6px 16px rgba(0, 0, 0, 0.10.3s ease;
}

.card:hover .card-icon img {
  transform: scale(1.06);
}


/* =========================
   بخش متن کارت
========================= */

.card-content {
  flex: 1;

  min-width: 0;

  text-align: right;

  padding-right: 15px;

  direction: rtl;
}


/* عنوان */

.card-content h3 {
  margin: 0 0 8px;

  font-family: Vazir, Tahoma, sans-serif;

  font-size: 14px;

  line-height: 1.65;

  font-weight: 700;

  color: #222;
}


/* خطوط اطلاعات */

.card-content .dot-line {
  font-family: Vazir, Tahoma, sans-serif;

  font-size: 12.5px;

  line-height: 1.8;

  color: #555;

  margin: 1px 0;

  word-break: break-word;
}


/* =========================
   تصویر کتاب
========================= */

.card-icon {
  flex: 0 0 88px;

  width: 88px;
  height: 100px;

  background: #f7f7f7;

  border-radius: 16px;

  padding: 10px;

  display: flex;

  align-items: center;
  justify-content: center;

  margin-top: 0;
}


.card-icon img {
  width: 72px;
  height: 72px;

  object-fit: contain;

  display: block======
   DOWNLOAD BUTTON
========================================= */

.download-btn {
  display: inline-flex;

  align-items: center;
  justify-content: center;

  background: #b40074;

  color: #fff !important;

  border: none;

  border-radius: 999px;

  padding: 6px 17px;

  min-width: 58px;

  text-align: center;

  font-family: Vazir, Tahoma, sans-serif;

  font-size: 11px;

  font-weight: 500;

  line-height: 1.5;

  text-decoration: none !important;

  margin-top: 10px;

  cursor: pointer;

  box-shadow:
    0 4px 10px rgba(180,0,116,.18);

  transition:
    background .25s ease,
    transform .25s ease,
    box-shadow .25s ease;
}

.download-btn:hover {
  background: #d50088;

  transform: translateY(-2px);

  box-shadow:
    0 7px 15px rgba(180,0,116,.25);
}

.download-btn:active {
  transform: translateY(0);
}


/* =========================================
   دکمه دانلود
EMPTY / ERROR BOX
=========================== */

.download-btn {
  display: inline-block;
  background: #b40074;
  color: #fff !important;
  border: none;
  border-radius: 25px;
  padding: 5px 16px;
  min-width: 54px;
  text-align: center;============== */

#book-grid > div[style*="grid-column"] {
  font-family: Vazir, Tahoma, sans-serif;
  font-size: 11px;
  line-height: 1.5; sans-serif !important;

  textborder-decorationradius: none18px !important;

  marginbox-topshadow: 8px;
  cursor: pointer;
 0 transition:4px background14px 0.2s ease, transform 0.2s ease;
}

.download-btn:hover {
  background: #d50088;
  transform: translateY(-1pxrgba(0,0,0,.04);
}


/* =========================================
   پیام‌های خالی / خطاTABLET
========================================= */

#book-grid > div[style*="grid-column"]@media (max-width: 1100px) {

  #book-grid {
   font-family grid-template-columns: Vazirrepeat(2, Tahoma, sans-serif !importantminmax(0, 1fr));

    gap: 20px;

  border  padding-radiusleft: 18px !important;
}


/*  25px;
    padding-right: 25px;
  }

}


/* =========================================
   تبلتMOBILE
========================================= */

@media (max-width: 1100px700px) {

  #book-gridtoolbar {
    grid-template-columnspadding: repeat(2, minmax(0, 1fr))15px;
  }

  #book-grid {
    paddinggrid-template-leftcolumns: 25px1fr;

    padding-rightgap: 25px16px;

    gappadding:
  18px;
  }

}


/* =========================
   موبایل
========================= */

@media (max-width: 700px) {

  #book-toolbar { 12px 15px 45px;
  }

  .card {
    min-height: 205px;

    padding: 0 15px16px;
  }

  #book.card-gridicon {
    gridflex-template-columnsbasis: 1fr82px;

    paddingwidth:
      10px 15px 40px 82px;

    gapheight: 15px94px;
  }

  .card-icon img {
     min-width: 66px;
    height: auto66px;
  }

}

</style>
<script>
(() => {
  /* ===== تنظیمات ===== */
  const LIB_ID             = "nikan-aqhdasiyeh_library";     // با صفحه ثبت یکی باشد
  const FORCED_DATA_PAGE_ID = 79076976;          // صفحه‌ی فرم ثبت / ریشه دیتا
  const JSON_FILE_NAME     = `library-${LIB_ID}.json`;
  /* =================== */

  // تشخیص BASE (context path)
  function detectBase(){
    try{ if (window.AJS && typeof AJS.contextPath==="function") return AJS.contextPath(); }catch(e){}
    const meta = document.querySelector('meta[name="ajs-context-path"]')?.content;
    if (meta) return meta;
    const m = location.pathname.match(/^(.*)\/(pages|display|download)\//);
    if (m) return m[1];
    return '';
  }

  const BASE        = detectBase();
  const DATA_PAGE_ID = FORCED_DATA_PAGE_ID;   // چون می‌دانیم دیتا روی صفحه‌ی فرم ثبت است
  const ENDPOINT_ATTACH_LIST =
    `${BASE}/rest/api/content/${DATA_PAGE_ID}/child/attachment`;

  const grid        = document.getElementById("book-grid");
  const searchInput = document.getElementById("book-search");

  let allBooks = [];

  function createBookCard(book){
    const authorsBlock = (book.authors && book.authors.length)
      ? book.authors.map(a=>`<div class="dot-line">• ${a}</div>`).join("")
      : `<div class="dot-line">• بدون نویسنده</div>`;

    const card = document.createElement("div");
    card.className = "card";
    card.innerHTML = `
      <div class="card-content">
        <h3>${book.title || "-"}</h3>
        <div class="dot-line">• حیطه: ${book.category || "-"}</div>
        ${authorsBlock}
        <div class="dot-line">• تاریخ انتشار: ${book.year || "-"}</div>
        ${book.fileUrl ? `<a href="${book.fileUrl}" target="_blank" class="download-btn">دانلود</a>` : ""}
      </div>
      <div class="card-icon">
        <img src="https://kb.h-soft.ir/download/thumbnails/79076976/12%20-%20Copy.png?api=v2&nonce=1787742747363" alt="کتاب">
      </div>
    `;
    return card;
  }

  function renderBooks(list){
    grid.innerHTML = "";
    if (!list.length){
      grid.innerHTML = `
        <div style="grid-column:1/-1; text-align:center; font-family:Vazir, Tahoma; color:#777;
                    background:#fafafa; border:1px dashed #e4e4e4; padding:14px; border-radius:18px;">
          کتابی با این فیلتر پیدا نشد.
        </div>`;
      return;
    }
    list.forEach(b => grid.appendChild(createBookCard(b)));
  }

  async function getExistingAttachmentMeta() {
    const url = `${ENDPOINT_ATTACH_LIST}?filename=${encodeURIComponent(JSON_FILE_NAME)}&expand=results`;
    const res = await fetch(url, { credentials: "include" });
    if (!res.ok) return null;
    const data = await res.json();
    if (!data.results || !data.results.length) return null;
    return data.results[0];
  }

  async function loadJsonFromAttachment() {
    const meta = await getExistingAttachmentMeta();
    if (!meta) return { libId: LIB_ID, books: [] };

    const downloadLink = meta._links && meta._links.download;
    if (!downloadLink) return { libId: LIB_ID, books: [] };

    const res = await fetch(BASE + downloadLink, { credentials: "include" });
    if (!res.ok) throw new Error("خطا در دانلود JSON: " + res.status);
    const text = await res.text();
    if (!text.trim()) return { libId: LIB_ID, books: [] };

    try {
      const parsed = JSON.parse(text.replace(/^\uFEFF/, '').trim());
      if (!parsed.books) parsed.books = [];
      if (!parsed.libId) parsed.libId = LIB_ID;
      return parsed;
    } catch(e) {
      console.error("JSON parse error:", e);
      return { libId: LIB_ID, books: [] };
    }
  }

  async function loadBooks() {
    try {
      const data = await loadJsonFromAttachment();
      allBooks = data.books || [];
      if (!allBooks.length) {
        grid.innerHTML = `
          <div style="grid-column:1/-1; text-align:center; font-family:Vazir, Tahoma; color:#777;
                      background:#fafafa; border:1px dashed #e4e4e4; padding:14px; border-radius:18px;">
            هنوز کتابی ثبت نشده است.
          </div>`;
        return;
      }
      renderBooks(allBooks);
    } catch (e) {
      console.error(e);
      grid.innerHTML = `
        <div style="grid-column:1/-1; text-align:center; font-family:Vazir, Tahoma; color:#c00;
                    background:#fff5f5; border:1px dashed #f5b5b5; padding:14px; border-radius:18px;">
          خطا در خواندن کتاب‌ها: ${e.message}
        </div>`;
    }
  }

  // سرچ روی آرایه‌ی allBooks
  function handleSearch(){
    const q = (searchInput.value || "").trim().toLowerCase();
    if (!q){
      renderBooks(allBooks);
      return;
    }

    const filtered = allBooks.filter(b => {
      const title    = (b.title    || "").toLowerCase();
      const category = (b.category || "").toLowerCase();
      const year     = (b.year     || "").toLowerCase();
      const authors  = Array.isArray(b.authors) ? b.authors.join(" ") : (b.authors || "");
      const authorsL = authors.toLowerCase();

      const haystack = `${title} ${category} ${year} ${authorsL}`;
      return haystack.includes(q);
    });

    renderBooks(filtered);
  }

  searchInput.addEventListener("input", handleSearch);

  loadBooks();
})();
</script>