This commit is contained in:
haoouba 2021-01-24 23:27:05 +08:00
parent 94050964e1
commit 7d49bfe1cb
3 changed files with 54 additions and 88 deletions

View File

@ -1,27 +1,26 @@
window.Joe = function () {
/* 解决移动端Hover问题 */
{
document.addEventListener('touchstart', () => {})
window.Joe = {
BASE_API: '/index.php/joe/api',
IS_MOBILE: /windows phone|iphone|android/gi.test(window.navigator.userAgent),
encryption: str => window.btoa(unescape(encodeURIComponent(str))),
decrypt: str => decodeURIComponent(escape(window.atob(str)))
}
console.time('Global.js执行时长')
document.addEventListener('DOMContentLoaded', () => {
/* 激活全局下拉框功能 */
{
$('.joe_dropdown').each(function (index, item) {
const menu = $(this).find('.joe_dropdown__menu')
/* 弹出方式 */
const trigger = $(item).attr('trigger') || 'click'
/* 弹出高度 */
const placement = $(item).attr('placement') || $(this).height() || 0
/* 设置弹出高度 */
menu.css('top', placement)
/* 如果是hover则绑定hover事件 */
if (trigger === 'hover') {
$(this).hover(
() => $(this).addClass('active'),
() => $(this).removeClass('active')
)
} else {
/* 否则绑定点击事件 */
$(this).on('click', function (e) {
$(this).toggleClass('active')
$(document).one('click', () => $(this).removeClass('active'))
@ -34,13 +33,10 @@ window.Joe = function () {
/* 激活全局返回顶部功能 */
{
const handleScroll = () => {
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop
scrollTop > 300 ? $('.joe_action .joe_action_item.scroll').addClass('active') : $('.joe_action .joe_action_item.scroll').removeClass('active')
}
const handleScroll = () => ((document.documentElement.scrollTop || document.body.scrollTop) > 300 ? $('.joe_action_item.scroll').addClass('active') : $('.joe_action_item.scroll').removeClass('active'))
handleScroll()
$(window).on('scroll', () => handleScroll())
$('.joe_action .joe_action_item.scroll').on('click', () => window.scrollTo({ top: 0, behavior: 'smooth' }))
$('.joe_action_item.scroll').on('click', () => window.scrollTo({ top: 0, behavior: 'smooth' }))
}
/* 激活侧边栏人生倒计时功能 */
@ -97,8 +93,7 @@ window.Joe = function () {
</div>
<div class="progress-percentage">${item.percent}</div>
</div>
</div>
`
</div>`
})
$('.joe_aside__item.timelife .joe_aside__item-contain').html(htmlStr)
}
@ -118,7 +113,7 @@ window.Joe = function () {
{
if ($('.joe_aside__item.ranking').length !== 0) {
$.ajax({
url: Joe.prototype.BASE_API,
url: Joe.BASE_API,
type: 'POST',
data: { routeType: 'aside_ranking' },
success(res) {
@ -146,23 +141,8 @@ window.Joe = function () {
{
$('.joe_aside__item:last-child').css('top', $('.joe_header').height() + 15)
}
/* 懒加载 */
new LazyLoad('.lazyload')
}
/* 加密 */
Joe.prototype.encryption = str => window.btoa(unescape(encodeURIComponent(str)))
/* 解密 */
Joe.prototype.decrypt = str => decodeURIComponent(escape(window.atob(str)))
/* 请求URL */
Joe.prototype.BASE_API = '/index.php/joe/api'
/* 是否是手机 */
Joe.prototype.IS_MOBILE = /windows phone|iphone|android/gi.test(window.navigator.userAgent)
/* 随机值 */
Joe.prototype.getRandomIntInclusive = (min, max) => {
min = Math.ceil(min)
max = Math.floor(max)
return Math.floor(Math.random() * (max - min + 1) + min)
}
document.addEventListener('DOMContentLoaded', () => Joe())
console.timeEnd('Global.js执行时长')
})

View File

@ -1,17 +1,11 @@
console.time("Index.js执行时长")
document.addEventListener('DOMContentLoaded', () => {
/* 激活轮播图功能 */
{
if ($('.joe_index__banner .swiper-container').length !== 0) {
let direction = 'horizontal'
if (!Joe.prototype.IS_MOBILE && $('.joe_index__banner-recommend .item').length === 2) direction = 'vertical'
new Swiper('.swiper-container', {
keyboard: true,
direction,
loop: true,
autoplay: true,
mousewheel: true,
pagination: { el: '.swiper-pagination' }
})
if (!Joe.IS_MOBILE && $('.joe_index__banner-recommend .item').length === 2) direction = 'vertical'
new Swiper('.swiper-container', { keyboard: true, direction, loop: true, autoplay: true, mousewheel: true, pagination: { el: '.swiper-pagination' } })
}
}
@ -31,7 +25,7 @@ document.addEventListener('DOMContentLoaded', () => {
$('.joe_load').html('加载中')
$('.joe_index__list .joe_list__loading').show()
$.ajax({
url: Joe.prototype.BASE_API,
url: Joe.BASE_API,
type: 'POST',
data: { routeType: 'publish_list', page: queryData.page, pageSize: queryData.pageSize, type: queryData.type },
success(res) {
@ -106,15 +100,8 @@ document.addEventListener('DOMContentLoaded', () => {
/* 激活列表特效 */
{
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()
}
console.timeEnd("Index.js执行时长")
})

View File

@ -1,8 +1,10 @@
console.time('Post&Page.js执行时长')
document.addEventListener('DOMContentLoaded', () => {
/* 获取本篇文章百度收录情况 */
{
$.ajax({
url: Joe.prototype.BASE_API,
url: Joe.BASE_API,
type: 'POST',
data: { routeType: 'baidu_record', site: window.location.href },
success(res) {
@ -31,12 +33,7 @@ document.addEventListener('DOMContentLoaded', () => {
/* 设置文章内的链接为新窗口打开 */
{
$('.joe_detail__article a').each(function () {
$(this).attr({
target: '_blank',
rel: 'noopener noreferrer nofollow'
})
})
$('.joe_detail__article a').each(() => $(this).attr({ target: '_blank', rel: 'noopener noreferrer nofollow' }))
}
/* 当前页的CID */
@ -44,19 +41,19 @@ document.addEventListener('DOMContentLoaded', () => {
/* 激活浏览功能 */
{
let viewsArr = localStorage.getItem(Joe.prototype.encryption('views')) ? JSON.parse(Joe.prototype.decrypt(localStorage.getItem(Joe.prototype.encryption('views')))) : []
let viewsArr = localStorage.getItem(Joe.encryption('views')) ? JSON.parse(Joe.decrypt(localStorage.getItem(Joe.encryption('views')))) : []
const flag = viewsArr.includes(cid)
if (!flag) {
$.ajax({
url: Joe.prototype.BASE_API,
url: Joe.BASE_API,
type: 'POST',
data: { routeType: 'handle_views', cid },
success(res) {
if (res.code !== 1) return
$('#Joe_Article_Views').html(`${res.data.views} 阅读`)
viewsArr.push(cid)
const name = Joe.prototype.encryption('views')
const val = Joe.prototype.encryption(JSON.stringify(viewsArr))
const name = Joe.encryption('views')
const val = Joe.encryption(JSON.stringify(viewsArr))
localStorage.setItem(name, val)
}
})
@ -65,17 +62,17 @@ document.addEventListener('DOMContentLoaded', () => {
/* 激活文章点赞功能 */
{
let agreeArr = localStorage.getItem(Joe.prototype.encryption('agree')) ? JSON.parse(Joe.prototype.decrypt(localStorage.getItem(Joe.prototype.encryption('agree')))) : []
let agreeArr = localStorage.getItem(Joe.encryption('agree')) ? JSON.parse(Joe.decrypt(localStorage.getItem(Joe.encryption('agree')))) : []
if (agreeArr.includes(cid)) $('.joe_detail__agree .icon-1').addClass('active')
else $('.joe_detail__agree .icon-2').addClass('active')
let _loading = false
$('.joe_detail__agree .icon').on('click', function () {
if (_loading) return
_loading = true
agreeArr = localStorage.getItem(Joe.prototype.encryption('agree')) ? JSON.parse(Joe.prototype.decrypt(localStorage.getItem(Joe.prototype.encryption('agree')))) : []
agreeArr = localStorage.getItem(Joe.encryption('agree')) ? JSON.parse(Joe.decrypt(localStorage.getItem(Joe.encryption('agree')))) : []
let flag = agreeArr.includes(cid)
$.ajax({
url: Joe.prototype.BASE_API,
url: Joe.BASE_API,
type: 'POST',
data: { routeType: 'handle_agree', cid, type: flag ? 'disagree' : 'agree' },
success(res) {
@ -93,8 +90,8 @@ document.addEventListener('DOMContentLoaded', () => {
$('.joe_detail__agree .icon-1').addClass('active')
$('.joe_detail__agree .icon').addClass('active')
}
const name = Joe.prototype.encryption('agree')
const val = Joe.prototype.encryption(JSON.stringify(agreeArr))
const name = Joe.encryption('agree')
const val = Joe.encryption(JSON.stringify(agreeArr))
localStorage.setItem(name, val)
},
complete() {
@ -103,4 +100,6 @@ document.addEventListener('DOMContentLoaded', () => {
})
})
}
console.timeEnd('Post&Page.js执行时长')
})