mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-12 22:17:06 +08:00
pjax
This commit is contained in:
@@ -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)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user