提交 1ab2fb6f 编写于 作者: EvanOne(文一)'s avatar EvanOne(文一)

style: Format code with prettier & lint with standard rules

上级 67787f23
$(document).ready(function() {
$('.header-nav-search').click(function() {
$(document).ready(function () {
$('.header-nav-search').click(function () {
$('body').css('overflow', 'hidden');
$('.algolia-popup').velocity('stop')
$('.algolia-popup')
.velocity('stop')
.velocity('transition.expandIn', {
duration: 300,
complete: function () {
$('.algolia-popup input').focus()
$('.algolia-popup input').focus();
}
})
$('.algolia-mask').velocity('stop')
});
$('.algolia-mask')
.velocity('stop')
.velocity('transition.fadeIn', {
duration: 300
})
});
});
$('.algolia-mask, .algolia-close').on('click', function () {
closeSearch();
});
$('.algolia-mask, .algolia-close')
.on('click', function () {
closeSearch();
});
$(document).on('keydown', function (e) {
var e = e || window.event;
var ev = e || window.event;
// Escape <=> 27
if (e.keyCode === codeToKeyCode('Escape')) {
if (ev.keyCode === codeToKeyCode('Escape')) {
closeSearch();
}
});
var algolia = CONFIG.algolia;
if (!(algolia.appId && algolia.apiKey && algolia.indexName)) {
return console.error('Algolia setting is invalid.');
}
......@@ -65,19 +66,21 @@ $(document).ready(function() {
container: '#algolia-hits',
templates: {
item: function (data) {
var link = data.permalink ? data.permalink : (CONFIG.root + data.path)
var link = data.permalink ? data.permalink : CONFIG.root + data.path;
return (
'<a href="' + link + '" class="algolia-hit-item-link">' +
'<a href="' +
link +
'" class="algolia-hit-item-link">' +
data._highlightResult.title.value +
'</a>'
)
);
},
empty: function (data) {
return (
'<div id="algolia-hits-empty">' +
algolia.languages.hits_empty.replace(/\$\{query}/, data.query) +
'</div>'
)
);
}
},
cssClasses: {
......@@ -85,9 +88,9 @@ $(document).ready(function() {
}
})
);
// The stats of search results.
if (!!$('#algolia-stats')[0]) {
if ($('#algolia-stats')[0]) {
search.addWidget(
instantsearch.widgets.stats({
container: '#algolia-stats',
......@@ -95,11 +98,13 @@ $(document).ready(function() {
body: function (data) {
var stats = algolia.languages.hits_stats
.replace(/\$\{hits}/, data.nbHits)
.replace(/\$\{time}/, data.processingTimeMS)
.replace(/\$\{time}/, data.processingTimeMS);
return (
stats +
'<span class="algolia-logo pull-right">' +
' <img src="' + CONFIG.root + 'images/algolia.svg" alt="Algolia" />' +
' <img src="' +
CONFIG.root +
'images/algolia.svg" alt="Algolia" />' +
'</span>'
);
}
......@@ -132,15 +137,17 @@ $(document).ready(function() {
search.start();
function closeSearch() {
function closeSearch () {
$('body').css('overflow', 'auto');
$('.algolia-popup').velocity('stop')
$('.algolia-popup')
.velocity('stop')
.velocity('transition.expandOut', {
duration: 300
})
$('.algolia-mask').velocity('stop')
});
$('.algolia-mask')
.velocity('stop')
.velocity('transition.fadeOut', {
duration: 300
})
});
}
});
$(document).ready(function() {
$(document).ready(function test () {
var CODEBLOCK_CLASS_NAME = 'highlight';
var $codeBlocks = $('figure.highlight');
$codeBlocks.each(function(index, item) {
$codeBlocks.each(function test (index, item) {
if (!$(item).find('figcaption')[0]) {
var lang = item.getAttribute('class')
.split(/\s/).filter(e => e !== CODEBLOCK_CLASS_NAME);
var lang = item
.getAttribute('class')
.split(/\s/)
.filter(e => e !== CODEBLOCK_CLASS_NAME);
var codeHeader = $(`
<figcaption class="custom">
<span>${lang}</span>
</figcaption>`)[0];
item.insertBefore(codeHeader, $(item).find('table')[0]);
}
});
......@@ -19,12 +21,14 @@ $(document).ready(function() {
<div class="copy-button">
<i class="fa fa-clipboard"></i>
</div>`);
$('figure.highlight figcaption').append($copyIcon);
$('.copy-button').on('click', function() {
var codeContainer = $(this).parent('figcaption')
.siblings('table').find('td.code')[0];
$('.copy-button').on('click', function () {
var codeContainer = $(this)
.parent('figcaption')
.siblings('table')
.find('td.code')[0];
if (copy(codeContainer)) {
popAlert('success', '复制成功', 4);
} else {
......@@ -36,16 +40,16 @@ $(document).ready(function() {
* Copy code
* @param {HTMLElement} container Container of code.
*/
function copy(container) {
function copy (container) {
try {
var selection = window.getSelection();
var range = document.createRange();
// Select text by the content of node.
range.selectNodeContents(container);
selection.removeAllRanges();
selection.addRange(range);
var text = selection.toString();
var input = document.createElement('input');
......
$(document).ready(function() {
$(document).ready(function () {
var $menu = $('.header-nav-menu');
$(document).click(function() {
$(document).click(function () {
$menu.removeClass('show');
});
[1, 2, 3].forEach(item => item);
$('.header-nav-menu a').click(function(e) {
var e = e || window.event;
e.stopPropagation();
$('.header-nav-menu a').click(function (e) {
var ev = e || window.event;
ev.stopPropagation();
});
$('.header-nav-menu-icon').click(function() {
$('.header-nav-menu-icon').click(function () {
$menu.toggleClass('show');
return false;
......
$(document).ready(function() {
$('img').each(function(index, img) {
$(document).ready(function () {
$('img').each(function (index, img) {
if (img.src.includes('?size=')) {
var size = img.src.split('?size=')[1] &&
img.src.split('?size=')[1].toLowerCase();
var size =
img.src.split('?size=')[1] && img.src.split('?size=')[1].toLowerCase();
var w = size.split('x')[0];
var h = size.split('x')[1];
......@@ -11,26 +11,31 @@ $(document).ready(function() {
}
});
$('.reward-button').click(function() {
$('.reward-button').click(function () {
if ($('.reward-qr-wrapper').css('display') === 'block') {
$('.reward-qr-wrapper').css('display', 'none');
} else {
$('.reward-qr-wrapper').velocity('stop')
$('.reward-qr-wrapper')
.velocity('stop')
.velocity('transition.slideDownBigIn', {
duration: 300
});
}
});
$(document).on('keydown', function(e) {
var e = e || window.event;
$(document).on('keydown', function (e) {
var ev = e || window.event;
// ArrowLeft <=> 37
if (e.keyCode === codeToKeyCode('ArrowLeft')) {
$('.article-prev').find('a')[0].click();
} // ArrowRight <=> 39
else if (e.keyCode === codeToKeyCode('ArrowRight')) {
$('.article-next').find('a')[0].click();
if (ev.keyCode === codeToKeyCode('ArrowLeft')) {
// ArrowLeft <=> 37
$('.article-prev')
.find('a')[0]
.click();
} else if (ev.keyCode === codeToKeyCode('ArrowRight')) {
// ArrowRight <=> 39
$('.article-next')
.find('a')[0]
.click();
}
});
});
$(document).ready(function() {
$(document).ready(function () {
// The previous distance from the page to the top.
var prevScrollTop = 0;
// Initial run.
headerNavScroll();
backToTop();
$(window).scroll(throttle(function () {
headerNavScroll();
backToTop();
}, 20, 100));
$(window).scroll(
throttle(
function () {
headerNavScroll();
backToTop();
},
20,
100
)
);
// Click the heading.
$('.main-content')
.find('h1,h2,h3,h4,h5,h6')
.on('click', function () {
scrollHeadingToTop('#' + $(this).attr('id'))
scrollHeadingToTop('#' + $(this).attr('id'));
});
// Click the post toc.
$('.toc-link').on('click', function (e) {
e.preventDefault();
var ev = e || window.event;
ev.preventDefault();
scrollHeadingToTop($(this).attr('href'));
});
$('#back-top').click(function () {
$('body').velocity('stop')
$('body')
.velocity('stop')
.velocity('scroll', {
duration: 500,
easing: 'easeOutQuart'
});
if (CONFIG.back2top_animation) {
$('#back-top').velocity({
translateY: '-100vh',
}, {
duration: 500
}).velocity('reverse', {
duration: 10
});
$('#back-top')
.velocity(
{
translateY: '-100vh'
},
{
duration: 500
}
)
.velocity('reverse', {
duration: 10
});
}
});
function headerNavScroll() {
function headerNavScroll () {
var scrollTop = $(window).scrollTop();
var delta = scrollTop - prevScrollTop;
......@@ -70,15 +83,16 @@ $(document).ready(function() {
prevScrollTop = scrollTop;
}
function scrollHeadingToTop(anchor) {
$(anchor).velocity('stop')
function scrollHeadingToTop (anchor) {
$(anchor)
.velocity('stop')
.velocity('scroll', {
duration: 500,
easing: 'easeOutSine'
});
}
function backToTop() {
function backToTop () {
var scrollTop = $(window).scrollTop();
if (scrollTop !== 0) {
......
$(document).ready(function() {
$(document).ready(function () {
var $toc = $('.sidebar-toc');
var $view = $('.sidebar-overview');
// The heading that reached the top currently.
var currHeading = null;
// The heading that reached the top last time.
......@@ -11,14 +11,13 @@ $(document).ready(function() {
var isTocScroll = false;
// Distance from sidebar to top.
var SIDEBAR_STICKY_TOP =
parseInt(CONFIG.sidebar_offsetTop);
var SIDEBAR_STICKY_TOP = parseInt(CONFIG.sidebar_offsetTop);
// Is toc in anime.
var isAnime = false;
// Is toc in max heihgt.
var isMaxH = true;
// Initial run
autoSpreadToc();
scrollTocToMiddle();
......@@ -33,14 +32,14 @@ $(document).ready(function() {
sidebarSticky();
sidebarAdjustHeight();
});
$('.sidebar-nav-toc').click(function () {
$('.sidebar-nav-toc').toggleClass('current');
$('.sidebar-nav-overview').toggleClass('current');
$toc.css('display', 'block');
$toc.velocity('fadeIn');
$view.css('display', 'none');
$view.velocity('fadeOut');
});
......@@ -56,34 +55,36 @@ $(document).ready(function() {
$view.velocity('fadeIn');
});
if ($('.main-content, .main-content-layout').height() <
$('#sidebar').height()) {
if (
$('.main-content, .main-content-layout').height() < $('#sidebar').height()
) {
$('#main').css('min-height', $('#main').height());
}
// Automatically expand items in the article directory
// based on the scrolling of heading in the article.
function autoSpreadToc() {
function autoSpreadToc () {
var $postBody = $('.post-body');
var $firsetChild = $postBody.find('h1,h2,h3,h4,h5,h6').first();
// All heading are not to the top.
if ($postBody[0] && (!!$firsetChild[0] &&
$firsetChild.offset().top - $(window).scrollTop() > 0)) {
if (
$postBody[0] &&
(!!$firsetChild[0] &&
$firsetChild.offset().top - $(window).scrollTop() > 0)
) {
$('.sidebar-toc li').removeClass('active current');
return;
}
$postBody.find('h1,h2,h3,h4,h5,h6')
.each(function (index, item) {
if (item && (item.getBoundingClientRect().top < 0)) {
currHeading = $(item).attr('id');
}
});
$postBody.find('h1,h2,h3,h4,h5,h6').each(function (index, item) {
if (item && item.getBoundingClientRect().top < 0) {
currHeading = $(item).attr('id');
}
});
if (currHeading === lastHeading) {
return;
} else {
var targetLink = $(`.sidebar-toc a[href="#${currHeading}"]`);
......@@ -100,32 +101,30 @@ $(document).ready(function() {
}
// Scroll the post toc to the middle.
function scrollTocToMiddle() {
function scrollTocToMiddle () {
var $toc = $('.sidebar-toc');
var $currLink = $('.sidebar-toc .current a');
if ($currLink[0] && $toc[0]) {
var tocTop = $currLink.offset().top - $toc.offset().top;
isTocScroll = (tocTop > $toc.height() ||
tocTop < 0) ? true : false;
isTocScroll = !!(tocTop > $toc.height() || tocTop < 0);
}
if (isTocScroll) {
$currLink.velocity('stop')
.velocity('scroll', {
container: $toc,
offset: -($toc.height() / 2),
duration: 500,
easing: 'easeOutQuart'
});
$currLink.velocity('stop').velocity('scroll', {
container: $toc,
offset: -($toc.height() / 2),
duration: 500,
easing: 'easeOutQuart'
});
}
}
// Sticky the sidebar when it arrived the top.
function sidebarSticky() {
function sidebarSticky () {
var mainInner = $('.main-inner')[0];
if (mainInner) {
var targetY = mainInner.getBoundingClientRect().top;
......@@ -138,50 +137,58 @@ $(document).ready(function() {
}
// Auto adjust the height of sidebar when it arrive footer.
function sidebarAdjustHeight() {
var footerTop = $('#footer').offset().top
function sidebarAdjustHeight () {
var footerTop = $('#footer').offset().top;
var footerH = $('#footer')[0].getBoundingClientRect().height;
var sidebarTop = $('.sidebar-inner').offset().top
var sidebarTop = $('.sidebar-inner').offset().top;
var sidebarH = $('.sidebar-inner')[0].getBoundingClientRect().height;
if (!isAnime && sidebarTop + sidebarH > footerTop) {
var targetTocH =
parseInt($('.sidebar-toc').css('max-height')) - footerH;
var targetTocH = parseInt($('.sidebar-toc').css('max-height')) - footerH;
isAnime = true;
$('.sidebar-toc').velocity({
maxHeight: targetTocH
}, {
duration: 300,
complete: function () {
isAnime = false;
isMaxH = false;
$('.sidebar-toc').velocity(
{
maxHeight: targetTocH
},
{
duration: 300,
complete: function () {
isAnime = false;
isMaxH = false;
}
}
});
} else if (!isMaxH && !isAnime && $(window).height() <
$('#footer')[0].getBoundingClientRect().top) {
);
} else if (
!isMaxH &&
!isAnime &&
$(window).height() < $('#footer')[0].getBoundingClientRect().top
) {
isAnime = true;
$('.sidebar-toc').velocity({
maxHeight: '70vh'
}, {
duration: 240,
complete: function () {
isAnime = false;
isMaxH = true;
$('.sidebar-toc').velocity(
{
maxHeight: '70vh'
},
{
duration: 240,
complete: function () {
isAnime = false;
isMaxH = true;
}
}
});
);
}
}
// Update the reading progress lines of post.
function readProgress() {
function readProgress () {
var $post = $('.main-content');
var scrollH = ($post[0] &&
$post[0].getBoundingClientRect().top * -1) || 0;
var percent = parseInt((scrollH / Math.abs(($post.height() -
$(window).height()))) * 100);
var scrollH = ($post[0] && $post[0].getBoundingClientRect().top * -1) || 0;
var percent = parseInt(
(scrollH / Math.abs($post.height() - $(window).height())) * 100
);
percent = percent > 100 ? 100 : percent < 0 ? 0 : percent;
percent += '%';
......
......@@ -51,8 +51,14 @@ function throttle(func, wait, mustRun) {
function isMobile() {
var check = false;
(function(a) {
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) ||
/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
if (
/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(
a
) ||
/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(
a.substr(0, 4)
)
)
check = true;
})(navigator.userAgent || navigator.vendor || window.opera);
return check;
......@@ -64,9 +70,9 @@ function isMobile() {
*/
function codeToKeyCode(code) {
var codes = {
'ArrowLeft': 37,
'ArrowRight': 39,
'Escape': 27
ArrowLeft: 37,
ArrowRight: 39,
Escape: 27
};
return codes[code];
......@@ -80,12 +86,12 @@ function codeToKeyCode(code) {
*/
function popAlert(status, text, delay) {
var icon = {
'success': 'check-circle',
'info': 'exclamation-circle',
'warning': 'exclamation-circle',
'error': 'times-circle'
success: 'check-circle',
info: 'exclamation-circle',
warning: 'exclamation-circle',
error: 'times-circle'
};
if (!$('.stun-alert')[0]) {
var $alert = $(`
<div class="stun-message">
......@@ -95,21 +101,23 @@ function popAlert(status, text, delay) {
</div>
</div>
`);
$('body').append($alert);
}
$(document).ready(function() {
$('.stun-alert').velocity('stop')
$('.stun-alert')
.velocity('stop')
.velocity('transition.slideDownBigIn', {
duration: 300
}).velocity('reverse', {
})
.velocity('reverse', {
delay: delay * 1000 || 5000,
duration: 260,
complete: function() {
$('.stun-alert').css('display', 'none');
}
})
});
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册