|
|
| خط ۳۲: |
خط ۳۲: |
| } | | } |
| | | |
| // نمایش فصل با iframe - فقط محتوای اصلی
| |
| function displayChapterWithIframe() {
| |
| const bookIndex = parseInt(currentBook);
| |
| const bookData = bibleBooks[currentTestament][bookIndex];
| |
| const bookName = bookData.name;
| |
| const bookDisplayName = bookData.displayName;
| |
| const translationName = translations[currentTranslation].name;
| |
|
| |
| chapterTitle.textContent = `${translationName} - ${bookName} - فصل ${currentChapter}`;
| |
|
| |
| // استفاده از الگوی مناسب برای هر ترجمه
| |
| const pageTitle = translations[currentTranslation].getPageTitle(bookDisplayName, currentChapter);
| |
|
| |
| // استفاده از action=render برای نمایش فقط محتوای اصلی
| |
| const contentUrl = `${translations[currentTranslation].baseUrl}${encodeURIComponent(pageTitle)}&action=render`;
| |
|
| |
| versesContainer.innerHTML = `
| |
| <iframe
| |
| id="content-iframe"
| |
| src="${contentUrl}"
| |
| class="content-display"
| |
| frameborder="0"
| |
| loading="lazy"
| |
| allowfullscreen>
| |
| </iframe>
| |
| `;
| |
|
| |
| // اضافه کردن event listener کلیک به iframe
| |
| setTimeout(() => {
| |
| const iframe = document.getElementById('content-iframe');
| |
| if (iframe) {
| |
| iframe.addEventListener('load', function() {
| |
| try {
| |
| // اضافه کردن event listener برای کلیک روی iframe
| |
| iframe.contentWindow.document.addEventListener('click', function(e) {
| |
| if (e.target.tagName === 'A' && e.target.href && e.target.href.includes('pediabible.com')) {
| |
| e.preventDefault();
| |
| window.open(e.target.href, '_blank');
| |
| }
| |
| });
| |
| } catch (error) {
| |
| console.log('امکان دسترسی به iframe وجود ندارد:', error);
| |
| // اگر دسترسی مستقیم ممکن نبود، از postMessage استفاده کنیم
| |
| iframe.contentWindow.postMessage('enableLinkHandling', '*');
| |
| }
| |
| });
| |
| }
| |
| }, 1000);
| |
|
| |
| // لینک صفحه کامل برای باز کردن در تب جدید
| |
| wikiPageLink.href = `${translations[currentTranslation].baseUrl}${encodeURIComponent(pageTitle)}`;
| |
| wikiPageLink.style.display = 'flex';
| |
| updateNavigationButtons();
| |
| }
| |
|
| |
| // اضافه کردن event listener برای پیامهای iframe
| |
| window.addEventListener('message', function(e) {
| |
| if (e.data && e.data.type === 'linkClick' && e.data.url) {
| |
| window.open(e.data.url, '_blank');
| |
| }
| |
| });
| |
| /* مخفی کردن هدرهای اضافی ویکی */ | | /* مخفی کردن هدرهای اضافی ویکی */ |
| body > header:first-child, | | body > header:first-child, |
| خط ۸۳۰: |
خط ۷۶۹: |
| </iframe> | | </iframe> |
| `; | | `; |
| // بعد از اینکه محتوای فصل در صفحه قرار داده شد: | | |
| function enableInternalLinksInNewTab(container) {
| |
| const links = container.querySelectorAll('a[href]');
| |
| links.forEach(link => {
| |
| const href = link.getAttribute('href');
| |
| if (href.startsWith('/wiki/') || href.startsWith('/index.php?title=')) {
| |
| link.setAttribute('target', '_blank');
| |
| }
| |
| });
| |
| }
| |
| | |
| // نمونه: وقتی فصل بارگذاری میشود
| |
| fetch(chapterUrl)
| |
| .then(response => response.text())
| |
| .then(html => {
| |
| const container = document.getElementById('chapter-content'); // یا هر id واقعی بخش فصل تو
| |
| container.innerHTML = html;
| |
| enableInternalLinksInNewTab(container); // این خط را اضافه کن
| |
| });
| |
| | |
| // لینک صفحه کامل برای باز کردن در تب جدید | | // لینک صفحه کامل برای باز کردن در تب جدید |
| wikiPageLink.href = `${translations[currentTranslation].baseUrl}${encodeURIComponent(pageTitle)}`; | | wikiPageLink.href = `${translations[currentTranslation].baseUrl}${encodeURIComponent(pageTitle)}`; |