🏷️ 更新至3.0.0-RC-1 close #189, close #192, close #223, close #224, close #229, close 232, close #240

This commit is contained in:
Jerry
2020-06-16 18:37:22 +08:00
Unverified
parent 0ad2c01fc9
commit aa8c509b96
93 changed files with 2109 additions and 1648 deletions

View File

@@ -1,6 +1,6 @@
$(function () {
const isSnackbar = GLOBAL_CONFIG.Snackbar !== undefined
const $pageHead = $('#page-header')
const $nav = $('#nav')
const $rightside = $('#rightside')
const $body = $('body')
@@ -16,9 +16,9 @@ $(function () {
function isAdjust (n) {
var t
if (n === 1) {
t = blogNameWidth + menusWidth > $pageHead.width() - sidebarWidth - 20
t = blogNameWidth + menusWidth > $nav.width() - sidebarWidth - 20
} else if (n === 2) {
t = blogNameWidth + menusWidth > $pageHead.width() - 20
t = blogNameWidth + menusWidth > $nav.width() - 20
}
if (t) headerAdjust()
@@ -26,15 +26,15 @@ $(function () {
}
function headerAdjust () {
$pageHead.find('.toggle-menu').addClass('is-visible-inline')
$pageHead.find('.menus_items').addClass('is_invisible')
$pageHead.find('#search_button span').addClass('is_invisible')
$nav.find('.toggle-menu').addClass('is-visible-inline')
$nav.find('.menus_items').addClass('is-invisible')
$nav.find('#search_button span').addClass('is-invisible')
}
function headerAdjustBack () {
$pageHead.find('.toggle-menu').removeClass('is-visible-inline')
$pageHead.find('.menus_items').removeClass('is_invisible')
$pageHead.find('#search_button span').removeClass('is_invisible')
$nav.find('.toggle-menu').removeClass('is-visible-inline')
$nav.find('.menus_items').removeClass('is-invisible')
$nav.find('#search_button span').removeClass('is-invisible')
}
// 初始化header
@@ -44,26 +44,16 @@ $(function () {
}
initAjust()
$('#page-header').css({ opacity: '1', animation: 'headerNoOpacity 1s' })
$('#nav').css({ opacity: '1', animation: 'headerNoOpacity 1s' })
$(window).on('resize', function () {
if ($('#sidebar').hasClass('tocOpenPc') && $pageHead.hasClass('fixed')) {
if ($('#sidebar').hasClass('tocOpenPc') && $nav.hasClass('fixed')) {
isAdjust(1)
} else {
initAjust()
}
})
/**
* windows時 設置主頁top_img 為 fixed
*/
if (GLOBAL_CONFIG_SITE.isHome) {
var isSafari = /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent)
if (!isSafari && isDesktop()) {
$('#nav').css('background-attachment', 'fixed')
}
}
/**
* 進入post頁sidebar處理
*/
@@ -117,7 +107,7 @@ $(function () {
opacity: '1'
})
var isAdjustTimeCount = window.setInterval(function () {
if ($pageHead.hasClass('fixed')) isAdjust(1)
if ($nav.hasClass('fixed')) isAdjust(1)
else isAdjust(2)
}, 100)
setTimeout(function () {
@@ -221,7 +211,7 @@ $(function () {
* 首頁top_img底下的箭頭
*/
$('#scroll_down').on('click', function () {
scrollTo('#content-inner')
scrollToDest('#content-inner')
})
/**
@@ -254,50 +244,51 @@ $(function () {
if ($figureHighlight.length) {
const isHighlightCopy = GLOBAL_CONFIG.highlightCopy
const isHighlightLang = GLOBAL_CONFIG.highlightLang
const isHighlightShrink = GLOBAL_CONFIG.highlightShrink
const isHighlightShrink = GLOBAL_CONFIG_SITE.isHighlightShrink
if (isHighlightCopy || isHighlightLang || isHighlightShrink !== 'none') {
$figureHighlight.wrap('<div class="code-area-wrap"></div>').before('<div class="highlight-tools"></div>')
if (isHighlightCopy || isHighlightLang || isHighlightShrink !== undefined) {
$figureHighlight.prepend('<div class="highlight-tools"></div>')
}
/**
* 代碼收縮
*/
const $highlightTools = $('.highlight-tools')
if (isHighlightShrink === 'true') {
$highlightTools.append('<i class="fa fa-angle-down code-expand code-closed" aria-hidden="true"></i>')
} else if (isHighlightShrink === 'false') {
$highlightTools.append('<i class="fa fa-angle-down code-expand" aria-hidden="true"></i>')
if (isHighlightShrink === true) {
$highlightTools.append('<i class="fas fa-angle-down code-expand code-closed"></i>')
} else if (isHighlightShrink === false) {
$highlightTools.append('<i class="fas fa-angle-down code-expand"></i>')
}
$(document).on('click', '.highlight-tools >.code-expand', function () {
var $table = $(this).parent().next()
var $hideItem = $(this).parent().nextAll()
if ($(this).hasClass('code-closed')) {
$table.css('display', 'block')
$hideItem.css('display', 'block')
$(this).removeClass('code-closed')
} else {
$table.css('display', 'none')
$hideItem.css('display', 'none')
$(this).addClass('code-closed')
}
})
/**
* 代碼語言
*/
*/
if (isHighlightLang) {
var langNameIndex, langName
$figureHighlight.each(function () {
langNameIndex = langName = $(this).attr('class').split(' ')[1]
if (langNameIndex === 'plain') langName = 'Code'
$(this).prev().append('<div class="code-lang">' + langName + '</div>')
$(this).find('.highlight-tools').append('<div class="code-lang">' + langName + '</div>')
})
}
/**
* 代碼copy
* copy function
*/
* 代碼copy
* copy function
*/
if (isHighlightCopy) {
$highlightTools.append('<div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i>')
$highlightTools.append('<div class="copy-notice"></div><i class="fas fa-paste copy-button"></i>')
var copy = function (text, ctx) {
if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
try {
@@ -308,13 +299,11 @@ $(function () {
$(ctx).prev('.copy-notice')
.text(GLOBAL_CONFIG.copy.success)
.animate({
opacity: 1,
right: 30
opacity: 1
}, 450, function () {
setTimeout(function () {
$(ctx).prev('.copy-notice').animate({
opacity: 0,
right: 0
opacity: 0
}, 650)
}, 400)
})
@@ -326,13 +315,11 @@ $(function () {
$(ctx).prev('.copy-notice')
.text(GLOBAL_CONFIG.copy.error)
.animate({
opacity: 1,
right: 30
opacity: 1
}, 650, function () {
setTimeout(function () {
$(ctx).prev('.copy-notice').animate({
opacity: 0,
right: 0
opacity: 0
}, 650)
}, 400)
})
@@ -349,15 +336,18 @@ $(function () {
}
// click events
$(document).on('click', '.highlight-tools>.fa-clipboard', function () {
$(document).on('click', '.highlight-tools>.copy-button', function () {
var $buttonParent = $(this).parents('figure.highlight')
$buttonParent.addClass('copy-true')
var selection = window.getSelection()
var range = document.createRange()
range.selectNodeContents($(this).parent().next().find('.code pre')[0])
range.selectNodeContents($buttonParent.find('table .code pre')[0])
selection.removeAllRanges()
selection.addRange(range)
var text = selection.toString()
copy(text, this)
selection.removeAllRanges()
$buttonParent.removeClass('copy-true')
})
}
}
@@ -392,8 +382,8 @@ $(function () {
$(o).wrap('<div></div>')
})
}
$('head').append('<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css">')
loadScript('https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js', function () {
$('head').append(`<link rel="stylesheet" type="text/css" href="${GLOBAL_CONFIG.justifiedGallery.css}">`)
loadScript(`${GLOBAL_CONFIG.justifiedGallery.js}`, function () {
initJustifiedGallery($justifiedGallery)
})
@@ -419,13 +409,7 @@ $(function () {
var images = $('#article-container img:not(.gallery-group-img)').not($('a>img'))
images.each(function (i, o) {
var lazyloadSrc = $(o).attr('data-src') ? $(o).attr('data-src') : $(o).attr('src')
$(o).wrap(
'<a href="' +
lazyloadSrc +
'" data-fancybox="group" data-caption="' +
$(o).attr('alt') +
'" class="fancybox"></a>'
)
$(o).wrap(`<a href="${lazyloadSrc}" data-fancybox="group" data-caption="${$(o).attr('alt')}" class="fancybox"></a>`)
})
$().fancybox({
@@ -445,37 +429,41 @@ $(function () {
})
}
/**
* lazyload
*/
if (GLOBAL_CONFIG.islazyload) {
window.lozad('img').observe()
}
/**
* 滾動處理
*/
var initTop = 0
$(window).scroll(function (event) {
var isChatShow = true
var isChatBtnHide = typeof chatBtnHide === 'function'
var isChatBtnShow = typeof chatBtnShow === 'function'
$(window).scroll(throttle(function (event) {
var currentTop = $(this).scrollTop()
var isUp = scrollDirection(currentTop)
var isDown = scrollDirection(currentTop)
if (currentTop > 56) {
if (isUp) {
if ($pageHead.hasClass('visible')) $pageHead.removeClass('visible')
if (isDown) {
if ($nav.hasClass('visible')) $nav.removeClass('visible')
if (isChatBtnShow && isChatShow === true) {
chatBtnHide()
isChatShow = false
}
} else {
if (!$pageHead.hasClass('visible')) $pageHead.addClass('visible')
if (!$nav.hasClass('visible')) $nav.addClass('visible')
if (isChatBtnHide && isChatShow === false) {
window.chatBtnShow()
isChatShow = true
}
}
$pageHead.addClass('fixed')
$nav.addClass('fixed')
if ($rightside.css('opacity') === '0') {
$rightside.css({ opacity: '1', transform: 'translateX(-38px)' })
}
} else {
if (currentTop === 0) {
$pageHead.removeClass('fixed').removeClass('visible')
$nav.removeClass('fixed').removeClass('visible')
}
$rightside.css({ opacity: '', transform: '' })
}
})
}, 200))
// find the scroll direction
function scrollDirection (currentTop) {
@@ -488,7 +476,7 @@ $(function () {
* 點擊滾回頂部
*/
$('#go-up').on('click', function () {
scrollTo('body')
scrollToDest('body')
})
/**
@@ -512,7 +500,7 @@ $(function () {
closeMobileSidebar('toc')
} else {
e.preventDefault()
scrollTo($(this).attr('href'))
scrollToDest($(this).attr('href'))
}
})
@@ -643,7 +631,7 @@ $(function () {
})
$(window).on('touchmove', function (e) {
var $menusChild = $('#page-header .menus_item_child')
var $menusChild = $('#nav .menus_item_child')
if ($menusChild.is(':visible')) {
$menusChild.css('display', 'none')
}
@@ -689,31 +677,16 @@ $(function () {
/**
* Darkmode
*/
var isFontAwesomeV5 = GLOBAL_CONFIG.isFontAwesomeV5
var $darkModeButtom = $('#darkmode')
if (typeof autoChangeMode !== 'undefined') {
document.documentElement.getAttribute('data-theme') === 'dark' ? changeLightIcon() : changeDarkIcon()
}
function changeLightIcon () {
isFontAwesomeV5 ? $darkModeButtom.removeClass('fa-moon').addClass('fa-sun') : $darkModeButtom.removeClass('fa-moon-o').addClass('fa-sun-o')
}
function changeDarkIcon () {
isFontAwesomeV5 ? $darkModeButtom.removeClass('fa-sun').addClass('fa-moon') : $darkModeButtom.removeClass('fa-sun-o').addClass('fa-moon-o')
}
function switchReadMode () {
var nowMode = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light'
if (nowMode === 'light') {
changeLightIcon()
activateDarkMode()
Cookies.set('theme', 'dark', { expires: 2 })
Cookies.set('theme', 'dark', 2)
if (isSnackbar) snackbarShow(GLOBAL_CONFIG.Snackbar.day_to_night)
} else {
changeDarkIcon()
activateLightMode()
Cookies.set('theme', 'light', { expires: 2 })
Cookies.set('theme', 'light', 2)
if (isSnackbar) snackbarShow(GLOBAL_CONFIG.Snackbar.night_to_day)
}
}
@@ -729,7 +702,7 @@ $(function () {
if (GLOBAL_CONFIG.runtime) {
// get user config
var $runtimeCount = $('#webinfo-runtime-count')
var startDate = $runtimeCount.attr('start_date')
var startDate = $runtimeCount.attr('publish_date')
var showDateTime = function () {
var BirthDay = new Date(startDate)
var today = new Date()
@@ -743,6 +716,15 @@ $(function () {
interval = setInterval(showDateTime, 10000)
}
/**
* table overflow
*/
var $table = $('#article-container table').not($('figure.highlight > table'))
$table.each(function () {
$(this).wrap('<div class="table-wrap"></div>')
})
/**
* 百度推送
*/
@@ -766,7 +748,6 @@ $(function () {
var $hideInline = $('.hide-button')
if ($hideInline.length) {
$hideInline.on('click', function (e) {
e.preventDefault()
var $this = $(this)
var $hideContent = $(this).next('.hide-content')
$this.toggleClass('open')
@@ -778,4 +759,34 @@ $(function () {
}
})
}
var $tab = $('#article-container .tabs')
$tab.find('.tab a').on('click', function (e) {
e.preventDefault()
var $this = $(this)
var $tabItem = $this.parent()
if (!$tabItem.hasClass('active')) {
var $tacbContent = $this.parents('.nav-tabs').next()
$tabItem.siblings('.active').removeClass('active')
$tabItem.addClass('active')
var tabId = $this.attr('href')
$tacbContent.find('> .tab-item-content').removeClass('active')
$tacbContent.find(`> ${tabId}`).addClass('active')
var $isTabJustifiedGallery = $tacbContent.find(tabId).find('.justified-gallery')
if (isJustifiedGallery && $isTabJustifiedGallery.length > 0) {
initJustifiedGallery($isTabJustifiedGallery)
}
}
})
var $cardCategory = $('.card-category-list-item.parent a')
$cardCategory.on('click', function (e) {
if ($(event.target).hasClass('card-category-list-icon')) {
var $this = $(this)
$this.find('.card-category-list-icon').toggleClass('expand')
$this.parent().next().toggle()
return false
}
})
})

View File

@@ -100,7 +100,7 @@ $(function () {
return (
'<hr>' +
stats +
'<span class="algolia-logo pull_right">' +
'<span class="algolia-logo pull-right">' +
' <img src="' + GLOBAL_CONFIG.root + 'img/algolia.svg" alt="Algolia" />' +
'</span>'
)
@@ -115,10 +115,10 @@ $(function () {
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>'
first: '<i class="fas fa-angle-double-left"></i>',
last: '<i class="fas fa-angle-double-right"></i>',
previous: '<i class="fas fa-angle-left"></i>',
next: '<i class="fas fa-angle-right"></i>'
},
cssClasses: {
root: 'pagination',

File diff suppressed because one or more lines are too long

View File

@@ -76,10 +76,10 @@ function isDesktop () {
return !this.isMobile()
}
function scrollTo (name) {
function scrollToDest (name, offset = 0) {
var scrollOffset = $(name).offset()
$('body,html').animate({
scrollTop: scrollOffset.top
scrollTop: scrollOffset.top - offset
})
};
@@ -117,6 +117,33 @@ function snackbarShow (text, showAction, duration) {
})
}
var Cookies = {
get: function (name) {
const value = `; ${document.cookie}`
const parts = value.split(`; ${name}=`)
if (parts.length === 2) return parts.pop().split(';').shift()
},
set: function (name, value, days) {
var expires = ''
if (days) {
var date = new Date()
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))
expires = '; expires=' + date.toUTCString()
}
document.cookie = name + '=' + (value || '') + expires + '; path=/'
}
}
/**
* lazyload
*/
if (GLOBAL_CONFIG.islazyload) {
window.lazyLoadOptions = {
elements_selector: 'img',
threshold: 0
}
}
window.debounce = debounce
window.throttle = throttle