This commit is contained in:
Jerry
2020-07-16 19:30:54 +08:00
Unverified
parent 5b6e008b84
commit 898cc31c58
93 changed files with 2128 additions and 2151 deletions

View File

@@ -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'))
})
})

View File

@@ -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)
})
}
})