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,
|
2022-10-11 16:27:04 +08:00
|
|
|
hasToc: false,
|
2022-09-27 17:52:45 +08:00
|
|
|
|
|
|
|
initData() {
|
2022-10-12 11:02:06 +08:00
|
|
|
const { scroll, first_screen } = KEEP.theme_config.style
|
2022-10-27 15:06:16 +08:00
|
|
|
this.isHasScrollProgressBar = scroll.progress_bar === true
|
|
|
|
this.isHasScrollPercent = scroll.percent === true
|
2022-10-12 11:02:06 +08:00
|
|
|
const { enable, header_transparent } = first_screen
|
2022-09-30 11:40:30 +08:00
|
|
|
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
|
2022-10-20 17:26:26 +08:00
|
|
|
this.styleHandleWhenScroll()
|
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() {
|
2022-11-02 22:50:34 +08:00
|
|
|
const sideToolsListDom = document.querySelector('.side-tools-list')
|
|
|
|
const toggleShowToolsDom = document.querySelector('.tool-toggle-show')
|
|
|
|
toggleShowToolsDom.addEventListener('click', (e) => {
|
|
|
|
sideToolsListDom.classList.toggle('show')
|
|
|
|
e.stopPropagation()
|
|
|
|
})
|
|
|
|
sideToolsListDom.querySelectorAll('.tools-item').forEach((item) => {
|
|
|
|
item.addEventListener('click', (e) => {
|
|
|
|
e.stopPropagation()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
document.addEventListener('click', () => {
|
|
|
|
sideToolsListDom.classList.contains('show') && sideToolsListDom.classList.remove('show')
|
2022-09-30 11:40:30 +08:00
|
|
|
})
|
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
|
|
|
// 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
|
|
|
},
|
|
|
|
|
2022-10-11 16:27:04 +08:00
|
|
|
// init has TOC
|
|
|
|
initHasToc() {
|
|
|
|
const tocNavDoms = document.querySelectorAll('.post-toc-wrap .post-toc li')
|
|
|
|
if (tocNavDoms.length > 0) {
|
|
|
|
this.hasToc = true
|
|
|
|
document.body.classList.add('has-toc')
|
|
|
|
} else {
|
|
|
|
this.hasToc = false
|
|
|
|
document.body.classList.remove('has-toc')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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() {
|
2022-10-09 17:17:28 +08:00
|
|
|
let SIDE_GAP = 40
|
2022-10-08 20:56:08 +08:00
|
|
|
let isZoomIn = false
|
2022-10-12 10:37:43 +08:00
|
|
|
let curWinScrollY = 0
|
2022-10-08 20:56:08 +08:00
|
|
|
let selectedImgDom = null
|
2022-10-16 00:44:40 +08:00
|
|
|
const imgDomList = document.querySelectorAll('.keep-markdown-body img')
|
2022-10-08 20:56:08 +08:00
|
|
|
const zoomInImgMask = document.querySelector('.zoom-in-image-mask')
|
|
|
|
const zoomInImg = zoomInImgMask.querySelector('.zoom-in-image')
|
|
|
|
|
|
|
|
const zoomOut = () => {
|
|
|
|
if (isZoomIn) {
|
|
|
|
isZoomIn = false
|
2022-10-12 10:37:43 +08:00
|
|
|
curWinScrollY = 0
|
2022-10-08 20:56:08 +08:00
|
|
|
zoomInImg && (zoomInImg.style.transform = `scale(1)`)
|
|
|
|
zoomInImgMask && zoomInImgMask.classList.remove('show')
|
2022-10-12 10:37:43 +08:00
|
|
|
setTimeout(() => {
|
2022-10-08 20:56:08 +08:00
|
|
|
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 &&
|
2022-10-12 11:02:06 +08:00
|
|
|
zoomInImgMask.addEventListener('click', () => {
|
|
|
|
zoomOut()
|
|
|
|
})
|
2020-11-13 14:43:22 +08:00
|
|
|
|
2022-10-08 20:56:08 +08:00
|
|
|
document.addEventListener('scroll', () => {
|
2022-10-12 10:37:43 +08:00
|
|
|
if (isZoomIn && Math.abs(curWinScrollY - window.scrollY) >= 50) {
|
|
|
|
zoomOut()
|
|
|
|
}
|
2022-10-08 20:56:08 +08:00
|
|
|
})
|
|
|
|
}
|
2020-11-16 19:04:24 +08:00
|
|
|
|
2022-10-09 17:17:28 +08:00
|
|
|
const setSideGap = () => {
|
|
|
|
const w = document.body.offsetWidth
|
|
|
|
if (w <= 500) {
|
|
|
|
SIDE_GAP = 10
|
2022-10-12 15:55:47 +08:00
|
|
|
} else if (w <= 800) {
|
2022-10-09 17:17:28 +08:00
|
|
|
SIDE_GAP = 20
|
|
|
|
} else {
|
|
|
|
SIDE_GAP = 40
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-12 10:37:43 +08:00
|
|
|
curWinScrollY = window.scrollY
|
2022-10-08 20:56:08 +08:00
|
|
|
isZoomIn = !isZoomIn
|
2022-10-09 17:17:28 +08:00
|
|
|
setSideGap()
|
2022-10-08 20:56:08 +08:00
|
|
|
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 &&
|
2022-10-12 11:02:06 +08:00
|
|
|
post.forEach((v) => {
|
|
|
|
const nowDate = Date.now()
|
2023-06-17 21:23:37 +08:00
|
|
|
const postDate = new Date(v.dataset.date.split(' GMT')[0]).getTime()
|
2022-10-12 11:02:06 +08:00
|
|
|
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) => {
|
2022-10-12 11:02:06 +08:00
|
|
|
const { content, offsetX, offsetY } = element.dataset
|
2022-10-11 17:42:27 +08:00
|
|
|
|
|
|
|
let style = ''
|
|
|
|
let sTop = ''
|
|
|
|
let sLeft = ''
|
|
|
|
if (offsetX) {
|
|
|
|
sTop = `left: ${offsetX};`
|
|
|
|
}
|
|
|
|
if (offsetY) {
|
|
|
|
sLeft = `top: ${offsetY};`
|
|
|
|
}
|
|
|
|
if (offsetX || offsetY) {
|
|
|
|
style = ` style="${sLeft}${sTop}"`
|
|
|
|
}
|
|
|
|
|
2022-09-29 16:42:09 +08:00
|
|
|
if (content) {
|
|
|
|
element.insertAdjacentHTML(
|
|
|
|
'afterbegin',
|
2022-10-11 17:42:27 +08:00
|
|
|
`<span class="tooltip-content"${style}>${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()
|
2022-10-12 11:02:06 +08:00
|
|
|
const { src } = img.dataset
|
2022-10-02 00:17:32 +08:00
|
|
|
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) => {
|
2022-10-12 11:02:06 +08:00
|
|
|
const { imgUrl, name } = dom.dataset
|
2022-10-02 00:17:32 +08:00
|
|
|
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
|
|
|
|
|
|
|
// init page height handle
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.initPageHeightHandle()
|
2020-12-30 18:11:46 +08:00
|
|
|
|
2022-10-11 16:27:04 +08:00
|
|
|
// check whether TOC exists
|
|
|
|
KEEP.utils.initHasToc()
|
|
|
|
|
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
|
|
|
}
|