mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2025-09-15 12:58:48 +08:00
2. Feature: 可設置夜間模式作爲默認樣式 3. Feature: 可設置是否顯示code language名稱 4. Feature: 可設置是否展開或關閉代碼框 5. Feature: 可設置背景圖片/顔色 6. Feature: 可設置是否顯示footer背景 7. Feature: 增加 canvas-nest.js 8. Feature: 頭像可設置效果(轉圈圈) 9. Feature: menu可設置分組 9. Fix: 優化打賞和搜索打開特效 10. Fix: 優化sidebar的打開特效,避免與文章頁特效不同步 11. Fix: 適配**hexo-blog-encrypt**,現在可以顯示toc 12. Fix: 修復設置不顯示評論時,直達評論按鈕沒有消失的bug 13. Fix: 修復post頁底欄,當沒有顯示評論,不顯示TOC,評論和toc都不顯示 這三種狀態下按鈕的bug 14. Fix: 修復代碼框左右滑動時,代碼名字跟著滑動的bug 15. Fix: 其他page頁標題的字體顯示 16. Fix: 修復當設置開啓canvas_ribbons,進入網站會先顯示canvas_ribbons的bug 17. Fix: 完善夜間模式下,字體顯示問題 18. Fix: 修復代碼框 複製 和 代碼名 z-index bug #25 19. Fix: 完善阅读模式
136 lines
3.5 KiB
JavaScript
136 lines
3.5 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',
|
|
'animation': 'titlescale 0.5s'
|
|
}),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('overflow', 'auto')
|
|
|
|
$('.search-dialog').animate({}, function () {
|
|
$('.search-dialog').css({
|
|
'display': 'none'
|
|
})
|
|
})
|
|
|
|
$('.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()
|
|
}) |