hexo-theme-butterfly/source/js/search/algolia.js
Jerry 336e221de5 V2.0.0
Breaking change
1. 手機端界面卡片化,同時,手機端也可以顯示側邊欄的內容
2. 修復當menu過多時,header界面出現錯亂的bug。當menu過多時,會變為sidebar模式
3. 增加medium-zoom大圖查看模式
4. 增加鼠標點擊特效:文字和愛心 兩個點擊特效
5. 主頁subtitle可以調用第三方api(金山詞霸每日一句、一言網的一句話、一句網、今日詩詞)
6. 添加 snackbar 彈窗
7. 修改nightshift為darkmode,darkmode可隨系統設置而自動切換,可設置隨時間而切換darkmode
8. 修復hexo自帶的標籤外掛(Tag Plugins)顯示bug(Block Quote、Code Block With caption、Gist、Youtube、Vimeo)
9. 主題所需要的css和js可根據需要配置CDN
10. 更改darkmode的加載方式,網站設置dark mode後,現在進入網頁不會在'閃'一下
11. 背景特效和背景圖片在手機界面也會顯示
12. 增加justified-gallery圖片顯示(Tag Plugins)
Feature
1. 文章頁面,字數統計、閲讀時長和閲讀量前面添加icon
2. 更改懶加載js
3. 升級typed.js/instantpage.js到最新版
4. 搜索和右下角按鈕添加退出特效
Fixed
1. 修復在 Hexo 4.0.0下,一些按鈕點擊會跳出一個空白頁的bug
2. 修復在 Hexo 4.0.0下,分頁按鈕出現代碼的bug
3. 修復當沒有設置評論時,右下角依舊出現'直達評論'按鈕的bug
4. 優化sidebar的打開速度
5. 修復文章頁標題左右邊距不平等的bug
6. 修復keywords讀取的bug
7. 修復當post/page 內容為空時,footer位置錯亂的bug
8. 修復在手機safari,toc sidebar底部內容被遮擋的bug
9. 完善Dark mode,一些界面的配色
10. 修復 card-archives 查看更多 跳轉bug
Remove
1. 移除Gitment
2. 移除Gallery
2019-11-03 02:21:01 +08:00

143 lines
3.7 KiB
JavaScript

$(function () {
$('a.social-icon.search').on('click', function () {
$('body').css('width', '100%')
$('body').css('overflow', 'hidden')
$('.search-dialog').animate({}, function () {
$('.search-dialog').css({
'display': 'block'
}),300
})
$('.ais-search-box--input').focus()
$('.search-mask').fadeIn();
// shortcut: ESC
document.addEventListener('keydown', function f(event) {
if (event.code == "Escape") {
closeSearch();
document.removeEventListener('keydown', f);
}
})
})
var closeSearch = function () {
$('body').css('width', '')
$('body').css('overflow', '')
$('.search-dialog').css({
'animation': 'search_close .5s'
})
$('.search-dialog').animate({}, function () {
setTimeout(function () {
$('.search-dialog').css({
'animation': '',
'display': 'none'
})
},500)
})
$('.search-mask').fadeOut();
}
$('.search-mask, .search-close-button').on('click', closeSearch)
var algolia = GLOBAL_CONFIG.algolia
var isAlgoliaValid = algolia.appId && algolia.apiKey && algolia.indexName
if (!isAlgoliaValid) {
return console.error('Algolia setting is invalid!')
}
var search = instantsearch({
appId: algolia.appId,
apiKey: algolia.apiKey,
indexName: algolia.indexName,
searchParameters: {
hitsPerPage: algolia.hits.per_page || 10
},
searchFunction: function (helper) {
var searchInput = $('#algolia-search-input').find('input')
if (searchInput.val()) {
helper.search()
}
}
})
search.addWidget(
instantsearch.widgets.searchBox({
container: '#algolia-search-input',
reset: false,
magnifier: false,
placeholder: GLOBAL_CONFIG.algolia.languages.input_placeholder
})
)
search.addWidget(
instantsearch.widgets.hits({
container: '#algolia-hits',
templates: {
item: function (data) {
var link = data.permalink ? data.permalink : (GLOBAL_CONFIG.root + data.path)
return (
'<a href="' + link + '" class="algolia-hit-item-link">' +
data._highlightResult.title.value +
'</a>'
)
},
empty: function (data) {
return (
'<div id="algolia-hits-empty">' +
GLOBAL_CONFIG.algolia.languages.hits_empty.replace(/\$\{query}/, data.query) +
'</div>'
)
}
},
cssClasses: {
item: 'algolia-hit-item'
}
})
)
search.addWidget(
instantsearch.widgets.stats({
container: '#algolia-stats',
templates: {
body: function (data) {
var stats = GLOBAL_CONFIG.algolia.languages.hits_stats
.replace(/\$\{hits}/, data.nbHits)
.replace(/\$\{time}/, data.processingTimeMS)
return (
'<hr>' +
stats +
'<span class="algolia-logo pull_right">' +
' <img src="' + GLOBAL_CONFIG.root + 'img/algolia.svg" alt="Algolia" />' +
'</span>'
)
}
}
})
)
search.addWidget(
instantsearch.widgets.pagination({
container: '#algolia-pagination',
scrollTo: false,
showFirstLast: false,
labels: {
first: '<i class="fa fa-angle-double-left"></i>',
last: '<i class="fa fa-angle-double-right"></i>',
previous: '<i class="fa fa-angle-left"></i>',
next: '<i class="fa fa-angle-right"></i>'
},
cssClasses: {
root: 'pagination',
item: 'pagination-item',
link: 'page-number',
active: 'current',
disabled: 'disabled-item'
}
})
)
search.start()
})