2021-01-23 01:02:56 +08:00
|
|
|
/* global KEEP */
|
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
KEEP.initUtils = () => {
|
|
|
|
KEEP.utils = {
|
|
|
|
html_root_dom: document.querySelector('html'),
|
|
|
|
pageContainer_dom: document.querySelector('.page-container'),
|
|
|
|
pageTop_dom: document.querySelector('.page-main-content-top'),
|
|
|
|
firstScreen_dom: document.querySelector('.first-screen-container'),
|
2021-01-06 18:36:28 +08:00
|
|
|
scrollProgressBar_dom: document.querySelector('.scroll-progress-bar'),
|
2021-01-08 16:07:54 +08:00
|
|
|
pjaxProgressBar_dom: document.querySelector('.pjax-progress-bar'),
|
|
|
|
pjaxProgressIcon_dom: document.querySelector('.pjax-progress-icon'),
|
2021-01-10 23:49:25 +08:00
|
|
|
back2TopButton_dom: document.querySelector('.tool-scroll-to-top'),
|
2022-09-27 17:52:45 +08:00
|
|
|
headerWrapper_dom: document.querySelector('.header-wrapper'),
|
2020-12-30 18:11:46 +08:00
|
|
|
|
|
|
|
innerHeight: window.innerHeight,
|
2021-01-10 23:49:25 +08:00
|
|
|
pjaxProgressBarTimer: null,
|
2020-12-30 18:11:46 +08:00
|
|
|
prevScrollValue: 0,
|
2021-01-23 01:02:56 +08:00
|
|
|
fontSizeLevel: 0,
|
2022-09-27 17:52:45 +08:00
|
|
|
isHasScrollProgressBar: false,
|
|
|
|
isHasScrollPercent: false,
|
|
|
|
isHeaderTransparent: false,
|
|
|
|
|
|
|
|
initData() {
|
2022-09-30 11:40:30 +08:00
|
|
|
const { scroll, first_screen } = KEEP.theme_config.style
|
|
|
|
this.isHasScrollProgressBar = scroll.progress_bar.enable === true
|
|
|
|
this.isHasScrollPercent = scroll.percent.enable === true
|
|
|
|
const { enable, header_transparent } = first_screen
|
|
|
|
this.isHeaderTransparent = enable === true && header_transparent === true
|
2022-09-27 17:52:45 +08:00
|
|
|
},
|
2021-01-10 23:49:25 +08:00
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
// Scroll Style Handle
|
|
|
|
styleHandleWhenScroll() {
|
2022-09-30 11:40:30 +08:00
|
|
|
const scrollTop = document.body.scrollTop || document.documentElement.scrollTop
|
|
|
|
const scrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight
|
|
|
|
const clientHeight = window.innerHeight || document.documentElement.clientHeight
|
2021-01-25 11:12:01 +08:00
|
|
|
|
2022-09-30 11:40:30 +08:00
|
|
|
const percent = Math.round((scrollTop / (scrollHeight - clientHeight)) * 100)
|
2020-12-30 18:11:46 +08:00
|
|
|
|
2021-01-10 23:49:25 +08:00
|
|
|
if (this.isHasScrollProgressBar) {
|
2022-09-30 11:40:30 +08:00
|
|
|
const ProgressPercent = ((scrollTop / (scrollHeight - clientHeight)) * 100).toFixed(3)
|
|
|
|
this.scrollProgressBar_dom.style.visibility = percent === 0 ? 'hidden' : 'visible'
|
|
|
|
this.scrollProgressBar_dom.style.width = `${ProgressPercent}%`
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
2020-10-21 19:36:38 +08:00
|
|
|
|
2021-01-10 23:49:25 +08:00
|
|
|
if (this.isHasScrollPercent) {
|
2022-09-30 11:40:30 +08:00
|
|
|
const percent_dom = this.back2TopButton_dom.querySelector('.percent')
|
2021-01-25 11:12:01 +08:00
|
|
|
if (percent === 0 || percent === undefined) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.back2TopButton_dom.classList.remove('show')
|
2021-01-10 23:49:25 +08:00
|
|
|
} else {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.back2TopButton_dom.classList.add('show')
|
|
|
|
percent_dom.innerHTML = percent.toFixed(0)
|
2021-01-10 23:49:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
// hide header handle
|
|
|
|
if (scrollTop > this.prevScrollValue && scrollTop > this.innerHeight) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.pageTop_dom.classList.add('hide')
|
2022-09-27 17:52:45 +08:00
|
|
|
if (this.isHeaderTransparent) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.headerWrapper_dom.classList.remove('transparent-1', 'transparent-2')
|
2022-09-27 17:52:45 +08:00
|
|
|
}
|
2020-12-30 18:11:46 +08:00
|
|
|
} else {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.pageTop_dom.classList.remove('hide')
|
2022-09-27 17:52:45 +08:00
|
|
|
if (this.isHeaderTransparent) {
|
|
|
|
if (scrollTop <= this.headerWrapper_dom.getBoundingClientRect().height) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.headerWrapper_dom.classList.remove('transparent-2')
|
|
|
|
this.headerWrapper_dom.classList.add('transparent-1')
|
2022-09-27 17:52:45 +08:00
|
|
|
} else if (scrollTop < this.innerHeight) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.headerWrapper_dom.classList.add('transparent-2')
|
2022-09-27 17:52:45 +08:00
|
|
|
}
|
|
|
|
}
|
2020-10-21 19:36:38 +08:00
|
|
|
}
|
2022-09-30 11:40:30 +08:00
|
|
|
this.prevScrollValue = scrollTop
|
2020-12-30 18:11:46 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// register window scroll event
|
|
|
|
registerWindowScroll() {
|
|
|
|
window.addEventListener('scroll', () => {
|
|
|
|
// style handle when scroll
|
2021-01-10 23:49:25 +08:00
|
|
|
if (this.isHasScrollPercent || this.isHasScrollProgressBar) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.styleHandleWhenScroll()
|
2021-01-10 23:49:25 +08:00
|
|
|
}
|
2020-12-30 18:11:46 +08:00
|
|
|
|
|
|
|
// TOC scroll handle
|
|
|
|
if (KEEP.theme_config.toc.enable && KEEP.utils.hasOwnProperty('findActiveIndexByTOC')) {
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.findActiveIndexByTOC()
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// header shrink
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.headerShrink.headerShrink()
|
|
|
|
})
|
2020-12-30 18:11:46 +08:00
|
|
|
},
|
2020-10-21 19:36:38 +08:00
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
// toggle show tools list
|
|
|
|
toggleShowToolsList() {
|
|
|
|
document.querySelector('.tool-toggle-show').addEventListener('click', () => {
|
2022-09-30 11:40:30 +08:00
|
|
|
document.querySelector('.side-tools-list').classList.toggle('show')
|
|
|
|
})
|
2020-12-30 18:11:46 +08:00
|
|
|
},
|
2020-10-25 10:48:07 +08:00
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
// global font adjust
|
|
|
|
globalFontAdjust() {
|
2022-09-30 11:40:30 +08:00
|
|
|
const fontSize = document.defaultView.getComputedStyle(document.body).fontSize
|
|
|
|
const fs = parseFloat(fontSize)
|
2021-01-23 01:02:56 +08:00
|
|
|
|
|
|
|
const initFontSize = () => {
|
2022-09-30 11:40:30 +08:00
|
|
|
const styleStatus = KEEP.getStyleStatus()
|
2021-01-23 01:02:56 +08:00
|
|
|
if (styleStatus) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.fontSizeLevel = styleStatus.fontSizeLevel
|
|
|
|
setFontSize(this.fontSizeLevel)
|
2021-01-23 01:02:56 +08:00
|
|
|
}
|
|
|
|
}
|
2020-10-25 10:48:07 +08:00
|
|
|
|
2021-01-23 01:02:56 +08:00
|
|
|
const setFontSize = (fontSizeLevel) => {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.html_root_dom.style.fontSize = `${fs * (1 + fontSizeLevel * 0.05)}px`
|
|
|
|
KEEP.styleStatus.fontSizeLevel = fontSizeLevel
|
|
|
|
KEEP.setStyleStatus()
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
2020-10-25 10:48:07 +08:00
|
|
|
|
2022-09-30 11:40:30 +08:00
|
|
|
initFontSize()
|
2021-01-23 01:02:56 +08:00
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
document.querySelector('.tool-font-adjust-plus').addEventListener('click', () => {
|
2022-09-30 11:40:30 +08:00
|
|
|
if (this.fontSizeLevel === 5) return
|
|
|
|
this.fontSizeLevel++
|
|
|
|
setFontSize(this.fontSizeLevel)
|
|
|
|
})
|
2020-11-25 16:54:44 +08:00
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
document.querySelector('.tool-font-adjust-minus').addEventListener('click', () => {
|
2022-09-30 11:40:30 +08:00
|
|
|
if (this.fontSizeLevel <= 0) return
|
|
|
|
this.fontSizeLevel--
|
|
|
|
setFontSize(this.fontSizeLevel)
|
|
|
|
})
|
2020-12-30 18:11:46 +08:00
|
|
|
},
|
2020-11-25 23:39:24 +08:00
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
// toggle content area width
|
|
|
|
contentAreaWidthAdjust() {
|
2022-09-30 11:40:30 +08:00
|
|
|
const toolExpandDom = document.querySelector('.tool-expand-width')
|
|
|
|
const headerContentDom = document.querySelector('.header-content')
|
|
|
|
const mainContentDom = document.querySelector('.main-content')
|
|
|
|
const iconDom = toolExpandDom.querySelector('i')
|
|
|
|
|
|
|
|
const defaultMaxWidth = KEEP.theme_config.style.content_max_width || '1000px'
|
|
|
|
const expandMaxWidth = '90%'
|
|
|
|
let headerMaxWidth = defaultMaxWidth
|
|
|
|
|
|
|
|
let isExpand = false
|
|
|
|
|
|
|
|
if (
|
|
|
|
KEEP.theme_config.style.first_screen.enable === true &&
|
|
|
|
window.location.pathname === '/'
|
|
|
|
) {
|
|
|
|
headerMaxWidth = parseInt(defaultMaxWidth) * 1.2 + 'px'
|
2020-11-25 23:39:24 +08:00
|
|
|
}
|
|
|
|
|
2021-01-23 01:02:56 +08:00
|
|
|
const setPageWidth = (isExpand) => {
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.styleStatus.isExpandPageWidth = isExpand
|
|
|
|
KEEP.setStyleStatus()
|
2020-12-30 18:11:46 +08:00
|
|
|
if (isExpand) {
|
2022-09-30 11:40:30 +08:00
|
|
|
iconDom.classList.remove('fa-up-right-and-down-left-from-center')
|
|
|
|
iconDom.classList.add('fa-down-left-and-up-right-to-center')
|
|
|
|
headerContentDom.style.maxWidth = expandMaxWidth
|
|
|
|
mainContentDom.style.maxWidth = expandMaxWidth
|
2020-12-30 18:11:46 +08:00
|
|
|
} else {
|
2022-09-30 11:40:30 +08:00
|
|
|
iconDom.classList.remove('fa-down-left-and-up-right-to-center')
|
|
|
|
iconDom.classList.add('fa-up-right-and-down-left-from-center')
|
|
|
|
headerContentDom.style.maxWidth = headerMaxWidth
|
|
|
|
mainContentDom.style.maxWidth = defaultMaxWidth
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
2021-01-23 01:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const initPageWidth = () => {
|
2022-09-30 11:40:30 +08:00
|
|
|
const styleStatus = KEEP.getStyleStatus()
|
2021-01-23 01:02:56 +08:00
|
|
|
if (styleStatus) {
|
2022-09-30 11:40:30 +08:00
|
|
|
isExpand = styleStatus.isExpandPageWidth
|
|
|
|
setPageWidth(isExpand)
|
2021-01-23 01:02:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-30 11:40:30 +08:00
|
|
|
initPageWidth()
|
2020-11-25 23:39:24 +08:00
|
|
|
|
2021-01-23 01:02:56 +08:00
|
|
|
toolExpandDom.addEventListener('click', () => {
|
2022-09-30 11:40:30 +08:00
|
|
|
isExpand = !isExpand
|
2021-01-23 01:02:56 +08:00
|
|
|
setPageWidth(isExpand)
|
2022-09-30 11:40:30 +08:00
|
|
|
})
|
2020-12-30 18:11:46 +08:00
|
|
|
},
|
|
|
|
|
2021-01-06 18:36:28 +08:00
|
|
|
// go comment anchor
|
2020-12-30 18:11:46 +08:00
|
|
|
goComment() {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.goComment_dom = document.querySelector('.go-comment')
|
2020-12-30 18:11:46 +08:00
|
|
|
if (this.goComment_dom) {
|
|
|
|
this.goComment_dom.addEventListener('click', () => {
|
2022-09-30 11:40:30 +08:00
|
|
|
document.querySelector('#comment-anchor').scrollIntoView()
|
|
|
|
})
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// get dom element height
|
|
|
|
getElementHeight(selectors) {
|
2022-09-30 11:40:30 +08:00
|
|
|
const dom = document.querySelector(selectors)
|
|
|
|
return dom ? dom.getBoundingClientRect().height : 0
|
2020-12-30 18:11:46 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// init first screen height
|
|
|
|
initFirstScreenHeight() {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.firstScreen_dom && (this.firstScreen_dom.style.height = this.innerHeight + 'px')
|
2020-12-30 18:11:46 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// init page height handle
|
|
|
|
initPageHeightHandle() {
|
2022-09-30 11:40:30 +08:00
|
|
|
if (this.firstScreen_dom) return
|
|
|
|
const temp_h1 = this.getElementHeight('.page-main-content-top')
|
|
|
|
const temp_h2 = this.getElementHeight('.page-main-content-middle')
|
|
|
|
const temp_h3 = this.getElementHeight('.page-main-content-bottom')
|
|
|
|
const allDomHeight = temp_h1 + temp_h2 + temp_h3
|
|
|
|
const innerHeight = window.innerHeight
|
|
|
|
const pb_dom = document.querySelector('.page-main-content-bottom')
|
2020-12-30 18:11:46 +08:00
|
|
|
if (allDomHeight < innerHeight) {
|
2022-09-30 11:40:30 +08:00
|
|
|
const marginTopValue = Math.floor(innerHeight - allDomHeight)
|
2021-12-04 17:43:31 +08:00
|
|
|
if (marginTopValue > 0) {
|
2022-09-30 11:40:30 +08:00
|
|
|
pb_dom.style.marginTop = `${marginTopValue - 2}px`
|
2021-12-04 17:43:31 +08:00
|
|
|
}
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
|
|
|
},
|
2020-10-25 10:48:07 +08:00
|
|
|
|
2022-10-08 20:56:08 +08:00
|
|
|
// zoom in image
|
|
|
|
zoomInImage() {
|
|
|
|
const SIDE_GAP = 30
|
|
|
|
let isZoomIn = false
|
|
|
|
let selectedImgDom = null
|
|
|
|
const imgDomList = document.querySelectorAll('.markdown-body img')
|
|
|
|
const zoomInImgMask = document.querySelector('.zoom-in-image-mask')
|
|
|
|
const zoomInImg = zoomInImgMask.querySelector('.zoom-in-image')
|
|
|
|
|
|
|
|
const zoomOut = () => {
|
|
|
|
if (isZoomIn) {
|
|
|
|
isZoomIn = false
|
|
|
|
zoomInImg && (zoomInImg.style.transform = `scale(1)`)
|
|
|
|
zoomInImgMask && zoomInImgMask.classList.remove('show')
|
|
|
|
const timer = setTimeout(() => {
|
|
|
|
clearTimeout(timer)
|
|
|
|
selectedImgDom && selectedImgDom.classList.remove('hide')
|
|
|
|
}, 300)
|
2020-12-31 16:28:39 +08:00
|
|
|
}
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
2020-11-20 14:41:03 +08:00
|
|
|
|
2022-10-08 20:56:08 +08:00
|
|
|
const zoomOutHandle = () => {
|
|
|
|
zoomInImgMask &&
|
|
|
|
zoomInImgMask.addEventListener('click', () => {
|
|
|
|
zoomOut()
|
|
|
|
})
|
2020-11-13 14:43:22 +08:00
|
|
|
|
2022-10-08 20:56:08 +08:00
|
|
|
document.addEventListener('scroll', () => {
|
|
|
|
zoomOut()
|
|
|
|
})
|
|
|
|
}
|
2020-11-16 19:04:24 +08:00
|
|
|
|
2022-10-08 20:56:08 +08:00
|
|
|
if (imgDomList.length) {
|
|
|
|
zoomOutHandle()
|
|
|
|
imgDomList.forEach((img) => {
|
2020-12-30 18:11:46 +08:00
|
|
|
img.addEventListener('click', () => {
|
2022-10-08 20:56:08 +08:00
|
|
|
isZoomIn = !isZoomIn
|
|
|
|
zoomInImg.setAttribute('src', img.getAttribute('src'))
|
|
|
|
selectedImgDom = img
|
|
|
|
if (isZoomIn) {
|
|
|
|
const imgRect = selectedImgDom.getBoundingClientRect()
|
|
|
|
const imgW = imgRect.width
|
|
|
|
const imgH = imgRect.height
|
|
|
|
const imgL = imgRect.left
|
|
|
|
const imgT = imgRect.top
|
|
|
|
const winW = document.body.offsetWidth - SIDE_GAP * 2
|
|
|
|
const winH = document.body.offsetHeight - SIDE_GAP * 2
|
|
|
|
const scaleX = winW / imgW
|
|
|
|
const scaleY = winH / imgH
|
|
|
|
const scale = (scaleX < scaleY ? scaleX : scaleY) || 1
|
|
|
|
const translateX = winW / 2 - (imgRect.x + imgW / 2) + SIDE_GAP
|
|
|
|
const translateY = winH / 2 - (imgRect.y + imgH / 2) + SIDE_GAP
|
|
|
|
|
|
|
|
selectedImgDom.classList.add('hide')
|
|
|
|
zoomInImgMask.classList.add('show')
|
|
|
|
zoomInImg.style.top = imgT + 'px'
|
|
|
|
zoomInImg.style.left = imgL + 'px'
|
|
|
|
zoomInImg.style.width = imgW + 'px'
|
|
|
|
zoomInImg.style.height = imgH + 'px'
|
|
|
|
zoomInImg.style.transform = `translateX(${translateX}px) translateY(${translateY}px) scale(${scale}) `
|
|
|
|
}
|
2022-09-30 11:40:30 +08:00
|
|
|
})
|
|
|
|
})
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
|
|
|
},
|
2020-11-16 19:04:24 +08:00
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
// set how long ago language
|
|
|
|
setHowLongAgoLanguage(p1, p2) {
|
|
|
|
return p2.replace(/%s/g, p1)
|
|
|
|
},
|
2020-11-16 19:04:24 +08:00
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
getHowLongAgo(timestamp) {
|
2022-09-30 11:40:30 +08:00
|
|
|
const lang = KEEP.language_ago
|
|
|
|
const __Y = Math.floor(timestamp / (60 * 60 * 24 * 30) / 12)
|
|
|
|
const __M = Math.floor(timestamp / (60 * 60 * 24 * 30))
|
|
|
|
const __W = Math.floor(timestamp / (60 * 60 * 24) / 7)
|
|
|
|
const __d = Math.floor(timestamp / (60 * 60 * 24))
|
|
|
|
const __h = Math.floor((timestamp / (60 * 60)) % 24)
|
|
|
|
const __m = Math.floor((timestamp / 60) % 60)
|
|
|
|
const __s = Math.floor(timestamp % 60)
|
2020-11-24 20:06:08 +08:00
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
if (__Y > 0) {
|
2022-09-30 11:40:30 +08:00
|
|
|
return this.setHowLongAgoLanguage(__Y, lang.year)
|
2020-12-30 18:11:46 +08:00
|
|
|
} else if (__M > 0) {
|
2022-09-30 11:40:30 +08:00
|
|
|
return this.setHowLongAgoLanguage(__M, lang.month)
|
2020-12-30 18:11:46 +08:00
|
|
|
} else if (__W > 0) {
|
2022-09-30 11:40:30 +08:00
|
|
|
return this.setHowLongAgoLanguage(__W, lang.week)
|
2020-12-30 18:11:46 +08:00
|
|
|
} else if (__d > 0) {
|
2022-09-30 11:40:30 +08:00
|
|
|
return this.setHowLongAgoLanguage(__d, lang.day)
|
2020-12-30 18:11:46 +08:00
|
|
|
} else if (__h > 0) {
|
2022-09-30 11:40:30 +08:00
|
|
|
return this.setHowLongAgoLanguage(__h, lang.hour)
|
2020-12-30 18:11:46 +08:00
|
|
|
} else if (__m > 0) {
|
2022-09-30 11:40:30 +08:00
|
|
|
return this.setHowLongAgoLanguage(__m, lang.minute)
|
2020-12-30 18:11:46 +08:00
|
|
|
} else if (__s > 0) {
|
2022-09-30 11:40:30 +08:00
|
|
|
return this.setHowLongAgoLanguage(__s, lang.second)
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
|
|
|
},
|
2020-11-24 20:06:08 +08:00
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
setHowLongAgoInHome() {
|
2022-09-30 11:40:30 +08:00
|
|
|
const post = document.querySelectorAll('.home-article-meta-info .home-article-date')
|
|
|
|
post &&
|
|
|
|
post.forEach((v) => {
|
|
|
|
const nowDate = Date.now()
|
|
|
|
const postDate = new Date(v.dataset.date.split(' GMT')[0]).getTime()
|
|
|
|
v.innerHTML = this.getHowLongAgo(Math.floor((nowDate - postDate) / 1000))
|
|
|
|
})
|
2021-01-06 18:36:28 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// loading progress bar start
|
2021-01-10 23:49:25 +08:00
|
|
|
pjaxProgressBarStart() {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.pjaxProgressBarTimer && clearInterval(this.pjaxProgressBarTimer)
|
2021-01-10 23:49:25 +08:00
|
|
|
if (this.isHasScrollProgressBar) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.scrollProgressBar_dom.classList.add('hide')
|
2021-01-10 23:49:25 +08:00
|
|
|
}
|
|
|
|
|
2022-09-30 11:40:30 +08:00
|
|
|
this.pjaxProgressBar_dom.style.width = '0'
|
|
|
|
this.pjaxProgressIcon_dom.classList.add('show')
|
2021-01-06 18:36:28 +08:00
|
|
|
|
2022-09-30 11:40:30 +08:00
|
|
|
let width = 1
|
|
|
|
const maxWidth = 99
|
2021-01-06 18:36:28 +08:00
|
|
|
|
2022-09-30 11:40:30 +08:00
|
|
|
this.pjaxProgressBar_dom.classList.add('show')
|
|
|
|
this.pjaxProgressBar_dom.style.width = width + '%'
|
2021-01-06 18:36:28 +08:00
|
|
|
|
2021-01-10 23:49:25 +08:00
|
|
|
this.pjaxProgressBarTimer = setInterval(() => {
|
2022-09-30 11:40:30 +08:00
|
|
|
width += 5
|
|
|
|
if (width > maxWidth) width = maxWidth
|
|
|
|
this.pjaxProgressBar_dom.style.width = width + '%'
|
|
|
|
}, 100)
|
2021-01-06 18:36:28 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// loading progress bar end
|
2021-01-10 23:49:25 +08:00
|
|
|
pjaxProgressBarEnd() {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.pjaxProgressBarTimer && clearInterval(this.pjaxProgressBarTimer)
|
|
|
|
this.pjaxProgressBar_dom.style.width = '100%'
|
2021-01-06 18:36:28 +08:00
|
|
|
|
2021-01-14 15:19:38 +08:00
|
|
|
const temp_1 = setTimeout(() => {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.pjaxProgressBar_dom.classList.remove('show')
|
|
|
|
this.pjaxProgressIcon_dom.classList.remove('show')
|
2021-01-10 23:49:25 +08:00
|
|
|
|
|
|
|
if (this.isHasScrollProgressBar) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.scrollProgressBar_dom.classList.remove('hide')
|
2021-01-10 23:49:25 +08:00
|
|
|
}
|
2021-01-14 15:19:38 +08:00
|
|
|
|
|
|
|
const temp_2 = setTimeout(() => {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.pjaxProgressBar_dom.style.width = '0'
|
|
|
|
clearTimeout(temp_1), clearTimeout(temp_2)
|
|
|
|
}, 200)
|
|
|
|
}, 200)
|
2022-04-17 23:38:45 +08:00
|
|
|
},
|
2022-09-29 16:42:09 +08:00
|
|
|
|
|
|
|
// insert tooltip content dom
|
|
|
|
insertTooltipContent() {
|
|
|
|
const init = () => {
|
2022-10-02 00:17:32 +08:00
|
|
|
// tooltip
|
2022-09-30 11:40:30 +08:00
|
|
|
document.querySelectorAll('.tooltip').forEach((element) => {
|
|
|
|
const { content } = element.dataset
|
2022-09-29 16:42:09 +08:00
|
|
|
if (content) {
|
|
|
|
element.insertAdjacentHTML(
|
|
|
|
'afterbegin',
|
|
|
|
`<span class="tooltip-content">${content}</span>`
|
2022-09-30 11:40:30 +08:00
|
|
|
)
|
2022-09-29 16:42:09 +08:00
|
|
|
}
|
2022-09-30 11:40:30 +08:00
|
|
|
})
|
2022-10-02 00:17:32 +08:00
|
|
|
|
|
|
|
// tooltip-img
|
|
|
|
|
|
|
|
const imgsSet = {}
|
|
|
|
|
|
|
|
const toggleShowImg = (dom, nameIdx) => {
|
|
|
|
document.addEventListener('click', () => {
|
|
|
|
if (imgsSet[nameIdx].isShowImg) {
|
|
|
|
dom.classList.remove('show-img')
|
|
|
|
imgsSet[nameIdx].isShowImg = false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const loadImg = (img, imgLoaded) => {
|
|
|
|
const temp = new Image()
|
|
|
|
const { src } = img.dataset
|
|
|
|
temp.src = src
|
|
|
|
temp.onload = () => {
|
|
|
|
img.src = src
|
2022-10-04 23:52:46 +08:00
|
|
|
img.removeAttribute('lazyload')
|
|
|
|
imgLoaded = true
|
2022-10-02 00:17:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.querySelectorAll('.tooltip-img').forEach((dom, idx) => {
|
|
|
|
const { imgUrl, name } = dom.dataset
|
|
|
|
if (imgUrl) {
|
|
|
|
const imgDomClass = `tooltip-img-${name}`
|
|
|
|
const nameIdx = `${name}_${idx}`
|
2022-10-04 23:52:46 +08:00
|
|
|
const imgDom = `<img class="${imgDomClass}" lazyload data-src="${imgUrl}" alt="${name}">`
|
2022-10-02 00:17:32 +08:00
|
|
|
const imgTooltipBox = `<div class="tooltip-img-box">${imgDom}</div>`
|
|
|
|
|
|
|
|
imgsSet[nameIdx] = {
|
|
|
|
imgLoaded: false,
|
2022-10-02 14:00:54 +08:00
|
|
|
isShowImg: false
|
2022-10-02 00:17:32 +08:00
|
|
|
}
|
|
|
|
|
2022-10-02 14:00:54 +08:00
|
|
|
dom.insertAdjacentHTML('afterbegin', imgTooltipBox)
|
2022-10-02 00:17:32 +08:00
|
|
|
dom.addEventListener('click', (e) => {
|
|
|
|
if (!imgsSet[nameIdx].imgLoaded) {
|
2022-10-02 14:00:54 +08:00
|
|
|
loadImg(
|
|
|
|
document.querySelector(`.tooltip-img-box img.${imgDomClass}`),
|
|
|
|
imgsSet[nameIdx].imgLoaded
|
|
|
|
)
|
2022-10-02 00:17:32 +08:00
|
|
|
}
|
|
|
|
imgsSet[nameIdx].isShowImg = !imgsSet[nameIdx].isShowImg
|
|
|
|
dom.classList.toggle('show-img')
|
|
|
|
e.stopPropagation()
|
|
|
|
})
|
|
|
|
|
|
|
|
toggleShowImg(dom, nameIdx)
|
|
|
|
}
|
|
|
|
})
|
2022-09-29 16:42:09 +08:00
|
|
|
}
|
|
|
|
setTimeout(() => {
|
2022-09-30 11:40:30 +08:00
|
|
|
init()
|
|
|
|
}, 1000)
|
2022-09-29 16:42:09 +08:00
|
|
|
}
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|
2020-11-24 20:06:08 +08:00
|
|
|
|
2022-09-27 17:52:45 +08:00
|
|
|
// init data
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.initData()
|
2022-09-27 17:52:45 +08:00
|
|
|
|
2020-12-30 18:11:46 +08:00
|
|
|
// init scroll
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.registerWindowScroll()
|
2020-12-30 18:11:46 +08:00
|
|
|
|
|
|
|
// toggle show tools list
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.toggleShowToolsList()
|
2020-12-30 18:11:46 +08:00
|
|
|
|
|
|
|
// global font adjust
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.globalFontAdjust()
|
2020-12-30 18:11:46 +08:00
|
|
|
|
|
|
|
// adjust content area width
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.contentAreaWidthAdjust()
|
2020-12-30 18:11:46 +08:00
|
|
|
|
|
|
|
// go comment
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.goComment()
|
2020-12-30 18:11:46 +08:00
|
|
|
|
|
|
|
// init page height handle
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.initPageHeightHandle()
|
2020-12-30 18:11:46 +08:00
|
|
|
|
|
|
|
// init first screen height
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.initFirstScreenHeight()
|
2020-12-30 18:11:46 +08:00
|
|
|
|
|
|
|
// big image viewer handle
|
2022-10-08 20:56:08 +08:00
|
|
|
KEEP.utils.zoomInImage()
|
2020-12-30 18:11:46 +08:00
|
|
|
|
|
|
|
// set how long age in home article block
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.setHowLongAgoInHome()
|
2020-11-24 20:06:08 +08:00
|
|
|
|
2022-09-29 16:42:09 +08:00
|
|
|
// insert tooltip content dom
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.insertTooltipContent()
|
2020-10-21 19:36:38 +08:00
|
|
|
}
|