This commit is contained in:
杜恒 2021-02-20 09:18:12 +08:00
parent 1776d21763
commit 9aca51ef5a
2 changed files with 102 additions and 99 deletions

View File

@ -2,8 +2,8 @@ document.addEventListener('DOMContentLoaded', () => {
/* 激活轮播图功能 */ /* 激活轮播图功能 */
{ {
if ($('.joe_index__banner .swiper-container').length !== 0) { if ($('.joe_index__banner .swiper-container').length !== 0) {
let direction = 'horizontal' let direction = 'horizontal';
if (!Joe.IS_MOBILE && $('.joe_index__banner-recommend .item').length === 2) direction = 'vertical' if (!Joe.IS_MOBILE && $('.joe_index__banner-recommend .item').length === 2) direction = 'vertical';
new Swiper('.swiper-container', { new Swiper('.swiper-container', {
keyboard: true, keyboard: true,
direction, direction,
@ -15,7 +15,7 @@ document.addEventListener('DOMContentLoaded', () => {
nextEl: '.swiper-button-next', nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev' prevEl: '.swiper-button-prev'
} }
}) });
} }
} }
@ -55,7 +55,7 @@ document.addEventListener('DOMContentLoaded', () => {
</div> </div>
</div> </div>
</li> </li>
` `;
} else if (_.mode === 'single') { } else if (_.mode === 'single') {
return ` return `
<li class="joe_list__item wow single"> <li class="joe_list__item wow single">
@ -91,7 +91,7 @@ document.addEventListener('DOMContentLoaded', () => {
<a class="abstract" href="${_.permalink}" title="文章摘要">${_.abstract}</a> <a class="abstract" href="${_.permalink}" title="文章摘要">${_.abstract}</a>
</div> </div>
</li> </li>
` `;
} else if (_.mode === 'multiple') { } else if (_.mode === 'multiple') {
return ` return `
<li class="joe_list__item wow multiple"> <li class="joe_list__item wow multiple">
@ -106,7 +106,7 @@ document.addEventListener('DOMContentLoaded', () => {
${_.image ${_.image
.map((item, index) => { .map((item, index) => {
if (index < 3) { if (index < 3) {
return `<img class="lazyload" src="${_.lazyload}" data-src="${item}" onerror="javascript: this.src='${_.lazyload}';" alt="${_.title}" />` return `<img class="lazyload" src="${_.lazyload}" data-src="${item}" onerror="javascript: this.src='${_.lazyload}';" alt="${_.title}" />`;
} }
}) })
.join('')} .join('')}
@ -126,7 +126,7 @@ document.addEventListener('DOMContentLoaded', () => {
</div> </div>
</div> </div>
</li> </li>
` `;
} else { } else {
return ` return `
<li class="joe_list__item wow none"> <li class="joe_list__item wow none">
@ -152,65 +152,68 @@ document.addEventListener('DOMContentLoaded', () => {
</div> </div>
</div> </div>
</li> </li>
` `;
} }
} };
let queryData = { page: 1, pageSize: 12, type: 'created' } let queryData = { page: 1, pageSize: 12, type: 'created' };
const initDom = () => { const initDom = () => {
$('.joe_index__list .joe_list').html('') $('.joe_index__list .joe_list').html('');
let activeItem = $('.joe_index__title-title .item[data-type="' + queryData.type + '"]') $('.joe_load').show();
let activeLine = $('.joe_index__title-title .line') let activeItem = $('.joe_index__title-title .item[data-type="' + queryData.type + '"]');
activeItem.addClass('active').siblings().removeClass('active') let activeLine = $('.joe_index__title-title .line');
activeLine.css({ left: activeItem.position().left, width: activeItem.width() }) activeItem.addClass('active').siblings().removeClass('active');
} activeLine.css({ left: activeItem.position().left, width: activeItem.width() });
};
const pushDom = () => { const pushDom = () => {
return new Promise((reslove, reject) => { return new Promise((reslove, reject) => {
$('.joe_load').attr('loading', true) $('.joe_load').attr('loading', true);
$('.joe_load').html('加载中') $('.joe_load').html('loading...');
$('.joe_index__list .joe_list__loading').show() $('.joe_index__list .joe_list__loading').show();
$.ajax({ $.ajax({
url: Joe.BASE_API, url: Joe.BASE_API,
type: 'POST', type: 'POST',
data: { routeType: 'publish_list', page: queryData.page, pageSize: queryData.pageSize, type: queryData.type }, data: { routeType: 'publish_list', page: queryData.page, pageSize: queryData.pageSize, type: queryData.type },
success(res) { success(res) {
if (res.data.length === 0) { if (res.data.length === 0) {
$('.joe_load').remove() $('.joe_load').removeAttr('loading');
$('.joe_index__list .joe_list__loading').hide() $('.joe_load').html('查看更多');
return $('.joe_load').hide();
$('.joe_index__list .joe_list__loading').hide();
return Qmsg.warning('没有更多内容了');
} }
res.data.forEach(_ => $('.joe_index__list .joe_list').append(getListMode(_))) res.data.forEach(_ => $('.joe_index__list .joe_list').append(getListMode(_)));
$('.joe_load').removeAttr('loading') $('.joe_load').removeAttr('loading');
$('.joe_load').html('查看更多') $('.joe_load').html('查看更多');
$('.joe_index__list .joe_list__loading').hide() $('.joe_index__list .joe_list__loading').hide();
reslove(res.data.length > 0 ? res.data.length - 1 : 0) reslove(res.data.length > 0 ? res.data.length - 1 : 0);
} }
}) });
}) });
} };
initDom() initDom();
pushDom() pushDom();
$('.joe_index__title-title .item').on('click', async function () { $('.joe_index__title-title .item').on('click', async function () {
if ($(this).attr('data-type') === queryData.type) return if ($(this).attr('data-type') === queryData.type) return;
queryData = { page: 1, pageSize: 12, type: $(this).attr('data-type') } queryData = { page: 1, pageSize: 12, type: $(this).attr('data-type') };
initDom() initDom();
pushDom() pushDom();
}) });
$('.joe_load').on('click', async function () { $('.joe_load').on('click', async function () {
if ($(this).attr('loading')) return if ($(this).attr('loading')) return;
queryData.page++ queryData.page++;
let length = await pushDom() let length = await pushDom();
length = $('.joe_index__list .joe_list .joe_list__item').length - length length = $('.joe_index__list .joe_list .joe_list__item').length - length;
const queryElement = `.joe_index__list .joe_list .joe_list__item:nth-child(${length})` const queryElement = `.joe_index__list .joe_list .joe_list__item:nth-child(${length})`;
const offset = $(queryElement).offset().top - $('.joe_header').height() const offset = $(queryElement).offset().top - $('.joe_header').height();
window.scrollTo({ top: offset - 15, behavior: 'smooth' }) window.scrollTo({ top: offset - 15, behavior: 'smooth' });
}) });
} }
/* 激活列表特效 */ /* 激活列表特效 */
{ {
const wow = $('.joe_index__list').attr('data-wow') const wow = $('.joe_index__list').attr('data-wow');
if (wow !== 'off' && wow) new WOW({ boxClass: 'wow', animateClass: `animated ${wow}`, offset: 0, mobile: true, live: true, scrollContainer: null }).init() if (wow !== 'off' && wow) new WOW({ boxClass: 'wow', animateClass: `animated ${wow}`, offset: 0, mobile: true, live: true, scrollContainer: null }).init();
} }
}) });

View File

@ -3,7 +3,7 @@
/* 获取主题当前版本号 */ /* 获取主题当前版本号 */
function _getVersion() function _getVersion()
{ {
return "5.2.3"; return "5.2.4";
}; };
/* 判断是否是手机 */ /* 判断是否是手机 */