add table of contents field to book entity
This commit is contained in:
parent
48484966ba
commit
09d7a7b142
4 changed files with 29 additions and 17 deletions
|
@ -40,6 +40,7 @@ class BookForm(forms.ModelForm):
|
|||
'pages',
|
||||
'cover',
|
||||
'brief',
|
||||
'contents',
|
||||
'other_info',
|
||||
]
|
||||
labels = {
|
||||
|
@ -58,6 +59,7 @@ class BookForm(forms.ModelForm):
|
|||
'pages': _("页数"),
|
||||
'cover': _("封面"),
|
||||
'brief': _("简介"),
|
||||
'contents': _("目录"),
|
||||
'other_info': _("其他信息"),
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ class Book(Resource):
|
|||
isbn = models.CharField(_("ISBN"), blank=True, null=True, max_length=20, unique=True, db_index=True)
|
||||
# to store previously scrapped data
|
||||
cover = models.ImageField(_("cover picture"), upload_to=book_cover_path, default=DEFAULT_BOOK_IMAGE, blank=True)
|
||||
contents = models.TextField(blank=True, default="")
|
||||
|
||||
class Meta:
|
||||
# more info: https://docs.djangoproject.com/en/2.2/ref/models/options/
|
||||
|
|
|
@ -105,22 +105,31 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="dividing-line"></div>
|
||||
<div class="entity-desc">
|
||||
<div class="entity-desc" id="description">
|
||||
<h5 class="entity-desc__title">{% trans '简介' %}</h5>
|
||||
{% if book.brief %}
|
||||
|
||||
|
||||
<p class="entity-desc__content">{{ book.brief | linebreaksbr }}</p>
|
||||
<div class="entity-desc__unfold-button entity-desc__unfold-button--hidden">
|
||||
<a href="javascript:void(0);">展开全部</a>
|
||||
</div>
|
||||
|
||||
|
||||
{% else %}
|
||||
<div>{% trans '暂无简介' %}</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
{% if book.contents %}
|
||||
<div class="entity-desc" id="contents">
|
||||
<h5 class="entity-desc__title">{% trans '目录' %}</h5>
|
||||
<p class="entity-desc__content">{{ book.contents | linebreaksbr }}</p>
|
||||
<div class="entity-desc__unfold-button entity-desc__unfold-button--hidden">
|
||||
<a href="javascript:void(0);">展开全部</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="entity-marks">
|
||||
<h5 class="entity-marks__title">{% trans '这本书的标记' %}</h5>
|
||||
{% if mark_list_more %}
|
||||
|
|
|
@ -103,22 +103,22 @@ $(document).ready( function() {
|
|||
|
||||
|
||||
// hide long text
|
||||
let copy = $(".entity-desc__content").clone()
|
||||
.addClass('entity-desc__content--folded')
|
||||
.css("visibility", "hidden");
|
||||
|
||||
$(".entity-desc__content").after(copy);
|
||||
if ($(".entity-desc__content").height() > copy.height()) {
|
||||
$(".entity-desc__content").addClass('entity-desc__content--folded');
|
||||
$(".entity-desc__unfold-button").removeClass("entity-desc__unfold-button--hidden");
|
||||
console.log($(".entity-desc__content").height())
|
||||
console.log(copy.height())
|
||||
}
|
||||
copy.remove();
|
||||
$(".entity-desc__content").each(function() {
|
||||
let copy = $(this).clone()
|
||||
.addClass('entity-desc__content--folded')
|
||||
.css("visibility", "hidden");
|
||||
$(this).after(copy);
|
||||
if ($(this).height() > copy.height()) {
|
||||
$(this).addClass('entity-desc__content--folded');
|
||||
$(this).siblings(".entity-desc__unfold-button").removeClass("entity-desc__unfold-button--hidden");
|
||||
}
|
||||
copy.remove();
|
||||
});
|
||||
|
||||
// expand hidden long text
|
||||
$(".entity-desc__unfold-button a").click(function() {
|
||||
$(".entity-desc__content").removeClass('entity-desc__content--folded');
|
||||
$(".entity-desc__unfold-button").remove();
|
||||
$(this).parent().siblings(".entity-desc__content").removeClass('entity-desc__content--folded');
|
||||
$(this).parent(".entity-desc__unfold-button").remove();
|
||||
});
|
||||
|
||||
});
|
Loading…
Add table
Reference in a new issue