mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 20:30:53 +08:00
pjax
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
||||
$(function () {
|
||||
$('a.social-icon.search').on('click', function () {
|
||||
const openSearch = () => {
|
||||
$('body').css({ width: '100%', overflow: 'hidden' })
|
||||
$('.search-dialog').css('display', 'block')
|
||||
$('#algolia-search').css('display', 'block')
|
||||
$('.ais-search-box--input').focus()
|
||||
$('.search-mask').fadeIn()
|
||||
$('#search-mask').fadeIn()
|
||||
// shortcut: ESC
|
||||
document.addEventListener('keydown', function f (event) {
|
||||
if (event.code === 'Escape') {
|
||||
@@ -11,27 +11,35 @@ $(function () {
|
||||
document.removeEventListener('keydown', f)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const closeSearch = function () {
|
||||
$('body').css('width', '')
|
||||
$('body').css('overflow', '')
|
||||
$('.search-dialog').css({
|
||||
const closeSearch = () => {
|
||||
$('body').css({ width: '', overflow: '' })
|
||||
$('#algolia-search').css({
|
||||
animation: 'search_close .5s'
|
||||
})
|
||||
|
||||
$('.search-dialog').animate({}, function () {
|
||||
setTimeout(function () {
|
||||
$('.search-dialog').css({
|
||||
animation: '',
|
||||
display: 'none'
|
||||
})
|
||||
}, 500)
|
||||
})
|
||||
setTimeout(function () {
|
||||
$('#algolia-search').css({
|
||||
animation: '',
|
||||
display: 'none'
|
||||
})
|
||||
}, 500)
|
||||
|
||||
$('.search-mask').fadeOut()
|
||||
$('#search-mask').fadeOut()
|
||||
}
|
||||
$('.search-mask, .search-close-button').on('click touchstart', closeSearch)
|
||||
|
||||
const searchClickFn = () => {
|
||||
$('a.social-icon.search').on('click', openSearch)
|
||||
$('#search-mask, .search-close-button').on('click touchstart', closeSearch)
|
||||
}
|
||||
|
||||
searchClickFn()
|
||||
|
||||
window.addEventListener('pjax:success', function () {
|
||||
closeSearch()
|
||||
searchClickFn()
|
||||
})
|
||||
|
||||
const algolia = GLOBAL_CONFIG.algolia
|
||||
const isAlgoliaValid = algolia.appId && algolia.apiKey && algolia.indexName
|
||||
@@ -130,4 +138,8 @@ $(function () {
|
||||
})
|
||||
)
|
||||
search.start()
|
||||
|
||||
window.pjax && search.on('render', () => {
|
||||
window.pjax.refresh(document.getElementById('algolia-hits'))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
$(function () {
|
||||
let loadFlag = false
|
||||
$('a.social-icon.search').on('click', function () {
|
||||
const openSearch = function () {
|
||||
$('body').css({
|
||||
width: '100%',
|
||||
overflow: 'hidden'
|
||||
})
|
||||
$('.search-dialog').css('display', 'block')
|
||||
$('#local-search').css('display', 'block')
|
||||
$('#local-search-input input').focus()
|
||||
$('.search-mask').fadeIn()
|
||||
$('#search-mask').fadeIn()
|
||||
if (!loadFlag) {
|
||||
search(GLOBAL_CONFIG.localSearch.path)
|
||||
loadFlag = true
|
||||
@@ -20,27 +20,37 @@ $(function () {
|
||||
document.removeEventListener('keydown', f)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const closeSearch = function () {
|
||||
$('body').css('width', '')
|
||||
$('body').css('overflow', '')
|
||||
$('.search-dialog').css({
|
||||
$('body').css({
|
||||
width: '',
|
||||
overflow: ''
|
||||
})
|
||||
$('#local-search').css({
|
||||
animation: 'search_close .5s'
|
||||
})
|
||||
|
||||
$('.search-dialog').animate({}, function () {
|
||||
setTimeout(function () {
|
||||
$('.search-dialog').css({
|
||||
animation: '',
|
||||
display: 'none'
|
||||
})
|
||||
}, 500)
|
||||
})
|
||||
setTimeout(function () {
|
||||
$('#local-search').css({
|
||||
animation: '',
|
||||
display: 'none'
|
||||
})
|
||||
}, 500)
|
||||
|
||||
$('.search-mask').fadeOut()
|
||||
$('#search-mask').fadeOut()
|
||||
}
|
||||
$('.search-mask, .search-close-button').on('click touchstart', closeSearch)
|
||||
|
||||
const searchClickFn = () => {
|
||||
$('a.social-icon.search').on('click', openSearch)
|
||||
$('#search-mask, .search-close-button').on('click', closeSearch)
|
||||
}
|
||||
|
||||
searchClickFn()
|
||||
window.addEventListener('pjax:success', function () {
|
||||
$('#local-search').is(':visible') && closeSearch()
|
||||
searchClickFn()
|
||||
})
|
||||
|
||||
function search (path) {
|
||||
$.ajax({
|
||||
@@ -145,6 +155,7 @@ $(function () {
|
||||
}
|
||||
str += '</div>'
|
||||
$resultContent.innerHTML = str
|
||||
window.pjax && window.pjax.refresh($resultContent)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
const translateDelay = translate.translateDelay // 延遲時間,若不在前, 要設定延遲翻譯時間, 如100表示100ms,默認為0
|
||||
const msgToTraditionalChinese = translate.msgToTraditionalChinese // 此處可以更改為你想要顯示的文字
|
||||
const msgToSimplifiedChinese = translate.msgToSimplifiedChinese // 同上,但兩處均不建議更改
|
||||
const translateButtonId = 'translateLink' // 默認互換id
|
||||
let currentEncoding = defaultEncoding
|
||||
const targetEncodingCookie = 'translate-chn-cht'
|
||||
let targetEncoding =
|
||||
@@ -86,7 +85,7 @@
|
||||
return str
|
||||
}
|
||||
function translateInitilization () {
|
||||
translateButtonObject = document.getElementById(translateButtonId)
|
||||
translateButtonObject = document.getElementById('translateLink')
|
||||
if (translateButtonObject) {
|
||||
if (currentEncoding !== targetEncoding) {
|
||||
setTimeout(function () { translateBody() }, translateDelay)
|
||||
@@ -96,4 +95,5 @@
|
||||
}
|
||||
}
|
||||
translateInitilization()
|
||||
document.addEventListener('pjax:complete', translateInitilization)
|
||||
})()
|
||||
|
||||
@@ -59,25 +59,6 @@ function sidebarPaddingR () {
|
||||
}
|
||||
}
|
||||
|
||||
// iPadOS
|
||||
function isIpad () {
|
||||
return navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1
|
||||
}
|
||||
|
||||
function isTMobile () {
|
||||
const ua = navigator.userAgent
|
||||
const pa = /iPad|iPhone|iPod|Android|Opera Mini|BlackBerry|webOS|UCWEB|Blazer|PSP|IEMobile|Symbian/g
|
||||
return window.screen.width < 992 && pa.test(ua)
|
||||
}
|
||||
|
||||
function isMobile () {
|
||||
return this.isIpad() || this.isTMobile()
|
||||
}
|
||||
|
||||
function isDesktop () {
|
||||
return !this.isMobile()
|
||||
}
|
||||
|
||||
function scrollToDest (name, offset = 0) {
|
||||
const scrollOffset = $(name).offset()
|
||||
$('body,html').animate({
|
||||
@@ -85,26 +66,6 @@ function scrollToDest (name, offset = 0) {
|
||||
})
|
||||
};
|
||||
|
||||
function loadScript (url, callback) {
|
||||
const script = document.createElement('script')
|
||||
script.type = 'text/javascript'
|
||||
if (script.readyState) { // IE
|
||||
script.onreadystatechange = function () {
|
||||
if (script.readyState === 'loaded' ||
|
||||
script.readyState === 'complete') {
|
||||
script.onreadystatechange = null
|
||||
callback()
|
||||
}
|
||||
}
|
||||
} else { // Others
|
||||
script.onload = function () {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
script.src = url
|
||||
document.body.appendChild(script)
|
||||
};
|
||||
|
||||
function snackbarShow (text, showAction, duration) {
|
||||
const sa = (typeof showAction !== 'undefined') ? showAction : false
|
||||
const dur = (typeof duration !== 'undefined') ? duration : 2000
|
||||
@@ -147,12 +108,10 @@ const initJustifiedGallery = function (selector) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* lazyload
|
||||
*/
|
||||
if (GLOBAL_CONFIG.islazyload) {
|
||||
window.lazyLoadOptions = {
|
||||
elements_selector: 'img',
|
||||
threshold: 0
|
||||
}
|
||||
const diffDate = function (d) {
|
||||
const dateNow = new Date()
|
||||
const datePost = new Date(d.replace(/-/g, '/'))
|
||||
const dateDiff = dateNow.getTime() - datePost.getTime()
|
||||
const dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000))
|
||||
return dayDiff
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user