代码格式化 & 去除异步

i18n
枋柚 5 years ago
parent b6754389b5
commit 36354ce71c
  1. 2
      layout/_partial/scripts.ejs
  2. 86
      source/js/app.js

@ -23,7 +23,7 @@
<script src="//instant.page/1.2.2" type="module" integrity="sha384-2xV8M5griQmzyiY3CDqh1dn4z3llDVqZDqzjzcY+jCBCk/a5fXJmuZ/40JJAPeoU"></script>
<% if (theme.scrollreveal == true) { %>
<script async src="https://cdn.jsdelivr.net/npm/scrollreveal@4.0.5/dist/scrollreveal.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/scrollreveal@4.0.5/dist/scrollreveal.min.js"></script>
<script type="text/javascript">
$(function() {
const $reveal = $('.reveal');

@ -12,10 +12,12 @@ 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(){
function setScrollAnchor() {
// button
const $postsBtn = $('.menu .active');
const $topBtn = $('.s-top');
@ -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();
@ -163,7 +184,7 @@ var customSearch;
if (event.keyCode == 9) {
return false;
} else {
var isie = (document.all) ? true: false;
var isie = (document.all) ? true : false;
var key;
var ev;
if (isie) { //IE浏览器
@ -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);
Loading…
Cancel
Save