|
|
|
@ -12,8 +12,10 @@ var customSearch; |
|
|
|
|
function scrolltoElement(elem, correction) { |
|
|
|
|
correction = correction || scrollCorrection; |
|
|
|
|
const $elem = elem.href ? $(elem.getAttribute('href')) : $(elem); |
|
|
|
|
$('html, body').animate({ 'scrollTop': $elem.offset().top - correction }, 400); |
|
|
|
|
}; |
|
|
|
|
$('html, body').animate({ |
|
|
|
|
'scrollTop': $elem.offset().top - correction |
|
|
|
|
}, 400); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function setScrollAnchor() { |
|
|
|
|
// button
|
|
|
|
@ -24,13 +26,25 @@ var customSearch; |
|
|
|
|
const $bodyAnchor = $('.l_body'); |
|
|
|
|
// action
|
|
|
|
|
if ($postsBtn.length && $bodyAnchor) { |
|
|
|
|
$postsBtn.click(e => { e.preventDefault(); e.stopPropagation(); scrolltoElement($bodyAnchor); }); |
|
|
|
|
$postsBtn.click(e => { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
scrolltoElement($bodyAnchor); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
if ($titleBtn.length && $bodyAnchor) { |
|
|
|
|
$titleBtn.click(e => { e.preventDefault(); e.stopPropagation(); scrolltoElement($bodyAnchor); }); |
|
|
|
|
$titleBtn.click(e => { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
scrolltoElement($bodyAnchor); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
if ($topBtn.length && $bodyAnchor) { |
|
|
|
|
$topBtn.click(e => { e.preventDefault(); e.stopPropagation(); scrolltoElement($bodyAnchor); }); |
|
|
|
|
$topBtn.click(e => { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
scrolltoElement($bodyAnchor); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const $coverAnchor = $('.cover-wrapper'); |
|
|
|
@ -84,12 +98,19 @@ var customSearch; |
|
|
|
|
// bind events to every btn
|
|
|
|
|
const $commentTarget = $('#comments'); |
|
|
|
|
if ($commentTarget.length) { |
|
|
|
|
$comment.click(e => { e.preventDefault(); e.stopPropagation(); scrolltoElement($commentTarget); }); |
|
|
|
|
$comment.click(e => { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
scrolltoElement($commentTarget); |
|
|
|
|
}); |
|
|
|
|
} else $comment.remove(); |
|
|
|
|
|
|
|
|
|
const $tocTarget = $('.toc-wrapper'); |
|
|
|
|
if ($tocTarget.length && $tocTarget.children().length) { |
|
|
|
|
$toc.click((e) => { e.stopPropagation(); $tocTarget.toggleClass('active'); }); |
|
|
|
|
$toc.click((e) => { |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
$tocTarget.toggleClass('active'); |
|
|
|
|
}); |
|
|
|
|
} else $toc.remove(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -216,7 +237,9 @@ var customSearch; |
|
|
|
|
const scrollTop = $('html').scrollTop() || $('body').scrollTop(); |
|
|
|
|
if (!anchor) return; |
|
|
|
|
//binary search.
|
|
|
|
|
let l = 0, r = anchor.length - 1, mid; |
|
|
|
|
let l = 0, |
|
|
|
|
r = anchor.length - 1, |
|
|
|
|
mid; |
|
|
|
|
while (l < r) { |
|
|
|
|
mid = (l + r + 1) >> 1; |
|
|
|
|
if (anchor[mid] === scrollTop) l = r = mid; |
|
|
|
@ -236,57 +259,52 @@ var customSearch; |
|
|
|
|
scrollListener(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(function () { |
|
|
|
|
//set header
|
|
|
|
|
setHeader(); |
|
|
|
|
setHeaderMenuSelection(); |
|
|
|
|
setHeaderMenuPhone(); |
|
|
|
|
setHeaderSearch(); |
|
|
|
|
|
|
|
|
|
setTocToggle(); |
|
|
|
|
setScrollAnchor(); |
|
|
|
|
// $(".article .video-container").fitVids();
|
|
|
|
|
|
|
|
|
|
setTimeout(function () { |
|
|
|
|
$('#loading-bar-wrapper').fadeOut(500); |
|
|
|
|
}, 300); |
|
|
|
|
|
|
|
|
|
function setSearchService() { |
|
|
|
|
if (SEARCH_SERVICE === 'google') { |
|
|
|
|
customSearch = new GoogleCustomSearch({ |
|
|
|
|
apiKey: GOOGLE_CUSTOM_SEARCH_API_KEY, |
|
|
|
|
engineId: GOOGLE_CUSTOM_SEARCH_ENGINE_ID, |
|
|
|
|
imagePath: "/img/" |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else if (SEARCH_SERVICE === 'algolia') { |
|
|
|
|
} else if (SEARCH_SERVICE === 'algolia') { |
|
|
|
|
customSearch = new AlgoliaSearch({ |
|
|
|
|
apiKey: ALGOLIA_API_KEY, |
|
|
|
|
appId: ALGOLIA_APP_ID, |
|
|
|
|
indexName: ALGOLIA_INDEX_NAME, |
|
|
|
|
imagePath: "/img/" |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else if (SEARCH_SERVICE === 'hexo') { |
|
|
|
|
} else if (SEARCH_SERVICE === 'hexo') { |
|
|
|
|
customSearch = new HexoSearch({ |
|
|
|
|
imagePath: "/img/" |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else if (SEARCH_SERVICE === 'azure') { |
|
|
|
|
} else if (SEARCH_SERVICE === 'azure') { |
|
|
|
|
customSearch = new AzureSearch({ |
|
|
|
|
serviceName: AZURE_SERVICE_NAME, |
|
|
|
|
indexName: AZURE_INDEX_NAME, |
|
|
|
|
queryKey: AZURE_QUERY_KEY, |
|
|
|
|
imagePath: "/img/" |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else if (SEARCH_SERVICE === 'baidu') { |
|
|
|
|
} else if (SEARCH_SERVICE === 'baidu') { |
|
|
|
|
customSearch = new BaiduSearch({ |
|
|
|
|
apiId: BAIDU_API_ID, |
|
|
|
|
imagePath: "/img/" |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$(function () { |
|
|
|
|
setHeader(); |
|
|
|
|
setHeaderMenuSelection(); |
|
|
|
|
setHeaderMenuPhone(); |
|
|
|
|
setHeaderSearch(); |
|
|
|
|
setTocToggle(); |
|
|
|
|
setScrollAnchor(); |
|
|
|
|
setSearchService(); |
|
|
|
|
// $(".article .video-container").fitVids();
|
|
|
|
|
|
|
|
|
|
setTimeout(function () { |
|
|
|
|
$('#loading-bar-wrapper').fadeOut(500); |
|
|
|
|
}, 300); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
})(jQuery); |