Merge pull request #374 from ex-hentai/spoiler

use details summary for spoiler
This commit is contained in:
xiaomlove
2025-09-17 17:08:40 +07:00
committed by GitHub
3 changed files with 9 additions and 20 deletions

View File

@@ -304,13 +304,13 @@ function formatSpoiler($content, $title = '', $defaultCollapsed = true): string
$title = $lang_functions['spoiler_default_title'];
}
// $content = str_replace(['<br>', '<br />'], '', $content);
$contentClass = "spoiler-content";
$contentClass = "";
if ($defaultCollapsed) {
$contentClass .= " collapse";
$contentClass .= " open";
}
$HTML = sprintf(
'<div><div class="spoiler-title-box"><div class="spoiler-title" title="%s">%s</div></div><div class="%s">%s</div></div>',
$lang_functions['spoiler_expand_collapse'], $title, $contentClass, $content
'<details%s><summary>%s</summary>%s</details>',
$contentClass, $title, $content
);
return addTempCode($HTML);
}

9
public/js/nexus.js vendored
View File

@@ -1,13 +1,4 @@
jQuery(document).ready(function () {
jQuery('.spoiler-title').on('click', function () {
let content = jQuery(this).parent().next();
if (content.hasClass('collapse')) {
content.height(content[0].scrollHeight).removeClass('collapse')
} else {
content.height(0).addClass('collapse')
}
})
function getImgPosition(e, imgEle) {
// console.log(e, imgEle)
let imgWidth = imgEle.prop('naturalWidth')

View File

@@ -4,20 +4,18 @@ img.hitandrun {
background: url(icons.gif) no-repeat -100px -171px;
margin-left: 0.5em;
}
.spoiler-title {
details summary {
width: fit-content;
line-height: 28px;
color: #4d6c99;
cursor: pointer;
font-weight: 700;
background-color: rgba(77, 108, 153, 0.1);
display: inline-block;
padding: 0 10px;
transition: margin .15s ease-out;
}
.spoiler-content {
display: inline-block;
height: 0;
overflow: hidden;
transition: height 0.3s ease;
details[open] summary {
margin-bottom: 10px;
}
.layui-layer {
color: black;