halo-theme-dream
Version:
梦之城,童话梦境,动漫类型博客主题。
58 lines (57 loc) • 2.04 kB
JavaScript
let journalContextInitial = false
const journalContext = {
/* 初始化事件 */
initEvent() {
if (journalContextInitial) return
let $body = $('body')
// 展开和关闭评论区事件
$body.on('click', '.journal .comment', function () {
$(this).parent().parent().siblings('.journal-comment').stop().slideToggle(200)
})
// 折叠日志区域
$body.on('click', '.journal-content>.expand-done', function () {
Utils.foldBlock($(this).parent())
})
$body.on('click', '.journal-operation-item>.share', function () {
let $journal = $(this).parents('.journal')
let title = '动态: ' + $journal.find('.journal-date>em').text()
let desc = $journal.children('.journal-content').children('.main-content').text()
DShare.sharePoster({
image: DreamConfig.journals_share_image,
title: title,
description: desc.length > 220 ? desc.substring(0, 220) + '...' :desc
})
})
Utils.initLikeEvent('.journal .like', 'journals', ($elem) => $elem.find('em'))
journalContextInitial = true
},
/* 点赞 */
initLike() {
Utils.initLikeButton('.journal .like', 'journals')
},
/* 折叠日志区域 */
foldJournals() {
const $journals = $('.journal .journal-content')
$journals.each(function () {
const $this = $(this)
if (this.scrollHeight >= DreamConfig.journals_fold_height) {
$this.append('<div class="expand-done"><i class="ri-arrow-up-double-line"></i></div>')
} else {
$this.removeClass('fold')
}
})
},
}
window.journalPjax = function (serialNumber) {
if ($('.card.journal').length === 0) return
Object.keys(journalContext).forEach(
(c) => window.pjaxSerialNumber === serialNumber && journalContext[c]()
)
}
!(function () {
!window.pjaxSerialNumber && journalContext.initEvent()
!window.pjaxSerialNumber && journalContext.initLike()
document.addEventListener('DOMContentLoaded', function () {
!window.pjaxSerialNumber && journalContext.foldJournals()
})
})()