Files

131 lines
3.7 KiB
ERB
Executable File

<style>
.universal-table-show {
border: 0;
border-collapse: collapse;
tr{
display: flex;
flex-wrap: wrap;
}
}
.universal-table-show.table td{
padding: 0;
border: 0;
}
.table-title {
border-right: 0;
font-size: 0.8em;
}
</style>
<table class="table table-striped universal-table-show">
<tbody data-level="0" data-list="entry">
<tr>
<td class="col-sm-12 table-title">{{title}}</td>
<td class="col-sm-12 table-txt" data-src="{{img_src}}" data-thumb="{{img_thumb}}" data-mobile="{{img_mobile}}">{{text}}</td>
</tr>
</tbody>
</table>
<div class="col-sm-12 table-title" style="background-color: #f8f8f8;
position: relative;
width: 100%;
color: #676767;
padding-top: 1.5em;">相關詞目</div>
<div data-list="related_entries" data-level="0" class="related_entries">
<tbody data-level="1" data-list="related_entry">
<tr>
<td>{{text}}</td>
</tr>
</tbody>
</div>
<div class="view_count pull-right">
<i class="fa fa-eye">{{view_count_head}}:</i>
<span class="view-count">{{view_count}}</span>
</div>
<script>
$(document).ready(function () {
const $tableShow = $('.universal-table-show');
if ($tableShow.length > 0) {
const firstText = $tableShow.find('tr:first .table-txt:first').text().trim();
if (firstText) {
const $li = $('<li>').text(firstText);
$('.breadcrumb').append($li);
}
}
});
$(document).ready(function () {
$('.related_entries').each(function () {
const $container = $(this);
const children = $container.contents();
let wrapper = null;
children.each(function () {
const $el = $(this);
if ($el.is('a') && !$el.hasClass('tag')) {
// 開始一個新的 wrapper
wrapper = $('<div class="column_entry_files_wrapper"></div>');
$container.append(wrapper); // 先加到底部
wrapper.append($el); // 把主詞條加進 wrapper
} else if ($el.is('ul.column_entry_files')) {
if (wrapper) wrapper.append($el);
} else if (this.nodeType === Node.TEXT_NODE && this.textContent.trim() !== '') {
if (wrapper) wrapper.append(this);
} else if ($el.is('a.tag')) {
if (wrapper) wrapper.append($el);
}
});
// 第二輪:移除每個 .column_entry_files_wrapper 前的 &nbsp; 空白節點
$container.find('.column_entry_files_wrapper').each(function () {
let prev = this.previousSibling;
while (prev && prev.nodeType === Node.TEXT_NODE) {
if (prev.textContent.trim() === '' || prev.textContent.includes('\u00a0')) {
let toRemove = prev;
prev = prev.previousSibling;
toRemove.parentNode.removeChild(toRemove);
} else {
break;
}
}
});
});
});
/**
* 圖片大小控制
* 'src' = 原圖
* 'thumb' = 縮圖 (200x200)
* 'mobile' = 行動版 (768px)
*/
const IMAGE_SIZE = 'src';
document.addEventListener('DOMContentLoaded', function() {
const cells = document.querySelectorAll('td[data-src]');
cells.forEach(cell => {
const imgSrc = cell.dataset[IMAGE_SIZE];
if (imgSrc && imgSrc !== '{{img_src}}' && imgSrc !== '{{img_thumb}}' && imgSrc !== '{{img_mobile}}') {
const oldImg = cell.querySelector('img');
if (oldImg) {
oldImg.remove();
}
const img = document.createElement('img');
img.className = 'image-preview';
img.alt = '圖片';
img.src = imgSrc;
cell.appendChild(img);
} else {
cell.removeAttribute('data-src');
cell.removeAttribute('data-thumb');
cell.removeAttribute('data-mobile'); }
});
});
</script>