doc: update butterfly theme
This commit is contained in:
1 parent
b71987abfb
commit
20c5eb31dd
118 files changed
+2158
-2564
No files matched your search
@@ -1,190 +0,0 @@
|
||||
/**
|
||||
* @preserve jQuery flipcountdown plugin v3.0.4
|
||||
* @homepage http://xdsoft.net/jqplugins/flipcountdown/
|
||||
* (c) 2013, Chupurnov Valeriy.
|
||||
*/
|
||||
(function($){
|
||||
jQuery.fn.flipCountDown = jQuery.fn.flipcountdown = function( _options ){
|
||||
var default_options = {
|
||||
showHour :true,
|
||||
showMinute :true,
|
||||
showSecond :true,
|
||||
am :false,
|
||||
tzoneOffset :0,
|
||||
speedFlip :60,
|
||||
period :1000,
|
||||
tick :function(){
|
||||
return new Date();
|
||||
},
|
||||
autoUpdate :true,
|
||||
size :'md'
|
||||
},
|
||||
|
||||
sizes = {
|
||||
lg:77,
|
||||
md:52,
|
||||
sm:35,
|
||||
xs:24
|
||||
},
|
||||
|
||||
createFlipCountDown = function( $box ){
|
||||
let $flipcountdown = $('<div class="xdsoft_flipcountdown"></div>'),
|
||||
$clearex = $('<div class="xdsoft_clearex"></div>'),
|
||||
|
||||
options = $.extend({},default_options),
|
||||
|
||||
timer = 0,
|
||||
|
||||
_animateRange = function( box,a,b ){
|
||||
_animateOne( box,a,(a>b&&!(a==9&&b==0))?-1:1,!(a==9&&b==0)?Math.abs(a-b):1 );
|
||||
},
|
||||
|
||||
_animateOne = function( box,a,arrow,range ){
|
||||
if( range<1 )
|
||||
return;
|
||||
|
||||
_setMargin(box,-(a*6*sizes[options.size]+1),1,arrow,function(){
|
||||
_animateOne(box,a+arrow,arrow,range-1);
|
||||
},range);
|
||||
},
|
||||
|
||||
_setMargin = function( box, marginTop, rec, arrow,callback,range){
|
||||
if( marginTop<=-sizes[options.size]*60 )
|
||||
marginTop = -1;
|
||||
box.css('background-position','0px '+marginTop+'px' );
|
||||
if( rec<=6 ){
|
||||
setTimeout(function(){
|
||||
_setMargin(box, marginTop-arrow*sizes[options.size], ++rec, arrow, callback,range);
|
||||
},parseInt(options.speedFlip/range));
|
||||
}else
|
||||
callback();
|
||||
},
|
||||
|
||||
blocks = [],
|
||||
|
||||
_typeCompare = function ( a,b ){
|
||||
return a&&b&&(
|
||||
(a==b)||
|
||||
(/^[0-9]+$/.test(a+''+b))||
|
||||
(/^[:.\s]+$/.test(a+''+b))
|
||||
);
|
||||
},
|
||||
|
||||
_generate = function( chars ){
|
||||
if( !(chars instanceof Array) || !chars.length )
|
||||
return false;
|
||||
for( var i = 0, n = chars.length;i<n;i++ ){
|
||||
if( !blocks[i] ){
|
||||
blocks[i] = $('<div class="xdsoft_digit"></div>');
|
||||
$clearex.before(blocks[i]);
|
||||
}
|
||||
if( blocks[i].data('value')!=chars[i] ){
|
||||
if( !_typeCompare(blocks[i].data('value'),chars[i]) ){
|
||||
blocks[i]
|
||||
.removeClass('xdsoft_separator')
|
||||
.removeClass('xdsoft_dot');
|
||||
switch( chars[i] ){
|
||||
case ':':blocks[i].addClass('xdsoft_separator');break;
|
||||
case '.':blocks[i].addClass('xdsoft_dot');break;
|
||||
case ' ':blocks[i].addClass('xdsoft_space');break;
|
||||
}
|
||||
}
|
||||
if( !isNaN(chars[i]) ){
|
||||
var old = parseInt(blocks[i].data('value')),
|
||||
ii = parseInt(blocks[i].data('i')),
|
||||
crnt = parseInt(chars[i]);
|
||||
if( isNaN(old)||i!=ii ){
|
||||
old = (crnt-1)<0?9:crnt-1;
|
||||
}
|
||||
_animateRange(blocks[i],old,crnt);
|
||||
}
|
||||
blocks[i].data('value',chars[i]);
|
||||
blocks[i].data('i',i);
|
||||
}
|
||||
}
|
||||
if( blocks.length>chars.length ){
|
||||
for(;i<blocks.length;i++ ){
|
||||
blocks[i][0].parentNode.removeChild(blocks[i][0]);
|
||||
delete blocks[i];
|
||||
}
|
||||
blocks.splice(chars.length);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
counter = 0,
|
||||
|
||||
_calcMoment = function(){
|
||||
var value = '1',chars = [];
|
||||
if(options.tick)
|
||||
value = (options.tick instanceof Function)?options.tick.call($box,counter):options.tick;
|
||||
|
||||
if( typeof value!=='undefined' ){
|
||||
switch( value.constructor ){
|
||||
case Date:
|
||||
var h = (value.getHours()+options.tzoneOffset)%(options.am?12:24);
|
||||
|
||||
if( options.showHour ){
|
||||
chars.push(parseInt(h/10));
|
||||
chars.push(h%10);
|
||||
}
|
||||
|
||||
if( options.showHour && (options.showMinute || options.showSecond) )
|
||||
chars.push(':');
|
||||
|
||||
if( options.showMinute ){
|
||||
chars.push(parseInt(value.getMinutes()/10));
|
||||
chars.push(value.getMinutes() % 10);
|
||||
}
|
||||
|
||||
if( options.showMinute && options.showSecond )
|
||||
chars.push(':');
|
||||
|
||||
if( options.showSecond ){
|
||||
chars.push(parseInt(value.getSeconds()/10));
|
||||
chars.push(value.getSeconds() % 10);
|
||||
}
|
||||
break;
|
||||
case String:
|
||||
chars = value.replace(/[^0-9\:\.\s]/g,'').split('');
|
||||
break;
|
||||
case Number:
|
||||
chars = value.toString().split('');
|
||||
break;
|
||||
}
|
||||
_generate(chars);
|
||||
}
|
||||
};
|
||||
|
||||
$flipcountdown
|
||||
.append($clearex)
|
||||
.on('xdinit.xdsoft',function(){
|
||||
clearInterval(timer);
|
||||
if( options.autoUpdate )
|
||||
timer = setInterval( _calcMoment,options.period );
|
||||
_calcMoment();
|
||||
});
|
||||
|
||||
$box.data('setOptions',function( _options ){
|
||||
options = $.extend({},options,_options);
|
||||
if( !sizes[options.size] )
|
||||
options.size = 'lg';
|
||||
$flipcountdown
|
||||
.addClass('xdsoft_size_'+options.size)
|
||||
.trigger('xdinit.xdsoft');
|
||||
});
|
||||
$box.append($flipcountdown);
|
||||
};
|
||||
return this.each(function(){
|
||||
var $box = $(this);
|
||||
if( !$box.data('setOptions') ){
|
||||
$box.addClass('xdsoft')
|
||||
createFlipCountDown($box);
|
||||
}
|
||||
$box.data('setOptions')&&
|
||||
$.isFunction($box.data('setOptions'))&&
|
||||
$box.data('setOptions')(_options);
|
||||
});
|
||||
}
|
||||
})(jQuery);
|
||||
|
||||
+207
-293
@@ -1,23 +1,23 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const $blogName = document.getElementById('site-name')
|
||||
let blogNameWidth = $blogName && $blogName.offsetWidth
|
||||
const $menusEle = document.querySelector('#menus .menus_items')
|
||||
let menusWidth = $menusEle && $menusEle.offsetWidth
|
||||
const $searchEle = document.querySelector('#search-button')
|
||||
let searchWidth = $searchEle && $searchEle.offsetWidth
|
||||
let blogNameWidth, menusWidth, searchWidth, $nav
|
||||
let mobileSidebarOpen = false
|
||||
|
||||
const adjustMenu = (change = false) => {
|
||||
if (change) {
|
||||
blogNameWidth = $blogName && $blogName.offsetWidth
|
||||
menusWidth = $menusEle && $menusEle.offsetWidth
|
||||
searchWidth = $searchEle && $searchEle.offsetWidth
|
||||
const adjustMenu = (init) => {
|
||||
if (init) {
|
||||
blogNameWidth = document.getElementById('site-name').offsetWidth
|
||||
const $menusEle = document.querySelectorAll('#menus .menus_item')
|
||||
menusWidth = 0
|
||||
$menusEle.length && $menusEle.forEach(i => { menusWidth += i.offsetWidth })
|
||||
const $searchEle = document.querySelector('#search-button')
|
||||
searchWidth = $searchEle ? $searchEle.offsetWidth : 0
|
||||
$nav = document.getElementById('nav')
|
||||
}
|
||||
const $nav = document.getElementById('nav')
|
||||
let t
|
||||
if (window.innerWidth < 768) t = true
|
||||
else t = blogNameWidth + menusWidth + searchWidth > $nav.offsetWidth - 120
|
||||
|
||||
if (t) {
|
||||
let hideMenuIndex = ''
|
||||
if (window.innerWidth < 768) hideMenuIndex = true
|
||||
else hideMenuIndex = blogNameWidth + menusWidth + searchWidth > $nav.offsetWidth - 120
|
||||
|
||||
if (hideMenuIndex) {
|
||||
$nav.classList.add('hide-menu')
|
||||
} else {
|
||||
$nav.classList.remove('hide-menu')
|
||||
@@ -26,49 +26,32 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
// 初始化header
|
||||
const initAdjust = () => {
|
||||
adjustMenu()
|
||||
document.getElementById('nav').classList.add('show')
|
||||
adjustMenu(true)
|
||||
$nav.classList.add('show')
|
||||
}
|
||||
|
||||
// sidebar menus
|
||||
const sidebarFn = () => {
|
||||
const $toggleMenu = document.getElementById('toggle-menu')
|
||||
const $mobileSidebarMenus = document.getElementById('sidebar-menus')
|
||||
const $menuMask = document.getElementById('menu-mask')
|
||||
const $body = document.body
|
||||
|
||||
function openMobileSidebar () {
|
||||
const sidebarFn = {
|
||||
open: () => {
|
||||
btf.sidebarPaddingR()
|
||||
$body.style.overflow = 'hidden'
|
||||
btf.fadeIn($menuMask, 0.5)
|
||||
$mobileSidebarMenus.classList.add('open')
|
||||
}
|
||||
|
||||
function closeMobileSidebar () {
|
||||
document.body.style.overflow = 'hidden'
|
||||
btf.animateIn(document.getElementById('menu-mask'), 'to_show 0.5s')
|
||||
document.getElementById('sidebar-menus').classList.add('open')
|
||||
mobileSidebarOpen = true
|
||||
},
|
||||
close: () => {
|
||||
const $body = document.body
|
||||
$body.style.overflow = ''
|
||||
$body.style.paddingRight = ''
|
||||
btf.fadeOut($menuMask, 0.5)
|
||||
$mobileSidebarMenus.classList.remove('open')
|
||||
btf.animateOut(document.getElementById('menu-mask'), 'to_hide 0.5s')
|
||||
document.getElementById('sidebar-menus').classList.remove('open')
|
||||
mobileSidebarOpen = false
|
||||
}
|
||||
|
||||
$toggleMenu.addEventListener('click', openMobileSidebar)
|
||||
|
||||
$menuMask.addEventListener('click', e => {
|
||||
if ($mobileSidebarMenus.classList.contains('open')) {
|
||||
closeMobileSidebar()
|
||||
}
|
||||
})
|
||||
|
||||
window.addEventListener('resize', e => {
|
||||
if (btf.isHidden($toggleMenu)) {
|
||||
if ($mobileSidebarMenus.classList.contains('open')) closeMobileSidebar()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 首頁top_img底下的箭頭
|
||||
*/
|
||||
* 首頁top_img底下的箭頭
|
||||
*/
|
||||
const scrollDownInIndex = () => {
|
||||
const $scrollDownEle = document.getElementById('scroll-down')
|
||||
$scrollDownEle && $scrollDownEle.addEventListener('click', function () {
|
||||
@@ -77,9 +60,9 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
|
||||
/**
|
||||
* 代碼
|
||||
* 只適用於Hexo默認的代碼渲染
|
||||
*/
|
||||
* 代碼
|
||||
* 只適用於Hexo默認的代碼渲染
|
||||
*/
|
||||
const addHighlightTool = function () {
|
||||
const highLight = GLOBAL_CONFIG.highlight
|
||||
if (!highLight) return
|
||||
@@ -220,115 +203,64 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
|
||||
/**
|
||||
* PhotoFigcaption
|
||||
*/
|
||||
* PhotoFigcaption
|
||||
*/
|
||||
function addPhotoFigcaption () {
|
||||
document.querySelectorAll('#article-container img').forEach(function (item) {
|
||||
const parentEle = item.parentNode
|
||||
if (!parentEle.parentNode.classList.contains('justified-gallery')) {
|
||||
const altValue = item.title || item.alt
|
||||
if (altValue && !parentEle.parentNode.classList.contains('justified-gallery')) {
|
||||
const ele = document.createElement('div')
|
||||
ele.className = 'img-alt is-center'
|
||||
ele.textContent = item.getAttribute('alt')
|
||||
ele.textContent = altValue
|
||||
parentEle.insertBefore(ele, item.nextSibling)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* justified-gallery 圖庫排版
|
||||
* 需要 jQuery
|
||||
*/
|
||||
|
||||
let detectJgJsLoad = false
|
||||
const runJustifiedGallery = function (ele) {
|
||||
const $justifiedGallery = $(ele)
|
||||
const $imgList = $justifiedGallery.find('img')
|
||||
$imgList.unwrap()
|
||||
if ($imgList.length) {
|
||||
$imgList.each(function (i, o) {
|
||||
if ($(o).attr('data-lazy-src')) $(o).attr('src', $(o).attr('data-lazy-src'))
|
||||
$(o).wrap('<div></div>')
|
||||
})
|
||||
}
|
||||
|
||||
if (detectJgJsLoad) btf.initJustifiedGallery($justifiedGallery)
|
||||
else {
|
||||
$('head').append(`<link rel="stylesheet" type="text/css" href="${GLOBAL_CONFIG.source.justifiedGallery.css}">`)
|
||||
$.getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`, function () {
|
||||
btf.initJustifiedGallery($justifiedGallery)
|
||||
})
|
||||
detectJgJsLoad = true
|
||||
}
|
||||
* Lightbox
|
||||
*/
|
||||
const runLightbox = () => {
|
||||
btf.loadLightbox(document.querySelectorAll('#article-container img:not(.no-lightbox)'))
|
||||
}
|
||||
|
||||
/**
|
||||
* fancybox和 mediumZoom
|
||||
*/
|
||||
const addFancybox = function (ele) {
|
||||
const runFancybox = (ele) => {
|
||||
ele.each(function (i, o) {
|
||||
const $this = $(o)
|
||||
const lazyloadSrc = $this.attr('data-lazy-src') || $this.attr('src')
|
||||
const dataCaption = $this.attr('alt') || ''
|
||||
$this.wrap(`<a href="${lazyloadSrc}" data-fancybox="group" data-caption="${dataCaption}" class="fancybox"></a>`)
|
||||
})
|
||||
* justified-gallery 圖庫排版
|
||||
*/
|
||||
const runJustifiedGallery = function (ele) {
|
||||
ele.forEach(item => {
|
||||
const $imgList = item.querySelectorAll('img')
|
||||
|
||||
$().fancybox({
|
||||
selector: '[data-fancybox]',
|
||||
loop: true,
|
||||
transitionEffect: 'slide',
|
||||
protect: true,
|
||||
buttons: ['slideShow', 'fullScreen', 'thumbs', 'close'],
|
||||
hash: false
|
||||
})
|
||||
}
|
||||
|
||||
if (typeof $.fancybox === 'undefined') {
|
||||
$('head').append(`<link rel="stylesheet" type="text/css" href="${GLOBAL_CONFIG.source.fancybox.css}">`)
|
||||
$.getScript(`${GLOBAL_CONFIG.source.fancybox.js}`, function () {
|
||||
runFancybox($(ele))
|
||||
})
|
||||
} else {
|
||||
runFancybox($(ele))
|
||||
}
|
||||
}
|
||||
|
||||
const addMediumZoom = () => {
|
||||
const zoom = mediumZoom(document.querySelectorAll('#article-container :not(a):not(.flink-item-icon) > img'))
|
||||
zoom.on('open', e => {
|
||||
const photoBg = document.documentElement.getAttribute('data-theme') === 'dark' ? '#121212' : '#fff'
|
||||
zoom.update({
|
||||
background: photoBg
|
||||
$imgList.forEach(i => {
|
||||
const dataLazySrc = i.getAttribute('data-lazy-src')
|
||||
if (dataLazySrc) i.src = dataLazySrc
|
||||
btf.wrap(i, 'div', { class: 'fj-gallery-item' })
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const jqLoadAndRun = () => {
|
||||
const $fancyboxEle = GLOBAL_CONFIG.lightbox === 'fancybox'
|
||||
? document.querySelectorAll('#article-container :not(a):not(.gallery-group):not(.flink-item-icon) > img, #article-container > img')
|
||||
: []
|
||||
const fbLengthNoZero = $fancyboxEle.length > 0
|
||||
const $jgEle = document.querySelectorAll('#article-container .justified-gallery')
|
||||
const jgLengthNoZero = $jgEle.length > 0
|
||||
|
||||
if (jgLengthNoZero || fbLengthNoZero) {
|
||||
btf.isJqueryLoad(() => {
|
||||
jgLengthNoZero && runJustifiedGallery($jgEle)
|
||||
fbLengthNoZero && addFancybox($fancyboxEle)
|
||||
})
|
||||
if (window.fjGallery) {
|
||||
setTimeout(() => { btf.initJustifiedGallery(ele) }, 100)
|
||||
return
|
||||
}
|
||||
|
||||
const newEle = document.createElement('link')
|
||||
newEle.rel = 'stylesheet'
|
||||
newEle.href = GLOBAL_CONFIG.source.justifiedGallery.css
|
||||
document.body.appendChild(newEle)
|
||||
getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(() => { btf.initJustifiedGallery(ele) })
|
||||
}
|
||||
|
||||
/**
|
||||
* 滾動處理
|
||||
*/
|
||||
* 滾動處理
|
||||
*/
|
||||
const scrollFn = function () {
|
||||
const $rightside = document.getElementById('rightside')
|
||||
const innerHeight = window.innerHeight + 56
|
||||
|
||||
// 當滾動條小于 56 的時候
|
||||
if (document.body.scrollHeight <= innerHeight) {
|
||||
$rightside.style.cssText = 'opacity: 1; transform: translateX(-38px)'
|
||||
$rightside.style.cssText = 'opacity: 1; transform: translateX(-58px)'
|
||||
return
|
||||
}
|
||||
|
||||
@@ -365,7 +297,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
$header.classList.add('nav-fixed')
|
||||
if (window.getComputedStyle($rightside).getPropertyValue('opacity') === '0') {
|
||||
$rightside.style.cssText = 'opacity: 1; transform: translateX(-38px)'
|
||||
$rightside.style.cssText = 'opacity: 0.8; transform: translateX(-58px)'
|
||||
}
|
||||
} else {
|
||||
if (currentTop === 0) {
|
||||
@@ -375,7 +307,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
|
||||
if (document.body.scrollHeight <= innerHeight) {
|
||||
$rightside.style.cssText = 'opacity: 1; transform: translateX(-38px)'
|
||||
$rightside.style.cssText = 'opacity: 0.8; transform: translateX(-58px)'
|
||||
}
|
||||
}, 200)()
|
||||
}
|
||||
@@ -384,86 +316,69 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
|
||||
/**
|
||||
* toc
|
||||
*/
|
||||
const tocFn = function () {
|
||||
const $cardTocLayout = document.getElementById('card-toc')
|
||||
const $cardToc = $cardTocLayout.getElementsByClassName('toc-content')[0]
|
||||
const $tocLink = $cardToc.querySelectorAll('.toc-link')
|
||||
* toc,anchor
|
||||
*/
|
||||
const scrollFnToDo = function () {
|
||||
const isToc = GLOBAL_CONFIG_SITE.isToc
|
||||
const isAnchor = GLOBAL_CONFIG.isAnchor
|
||||
const $article = document.getElementById('article-container')
|
||||
|
||||
// main of scroll
|
||||
window.tocScrollFn = function () {
|
||||
return btf.throttle(function () {
|
||||
const currentTop = window.scrollY || document.documentElement.scrollTop
|
||||
scrollPercent(currentTop)
|
||||
findHeadPosition(currentTop)
|
||||
}, 100)()
|
||||
}
|
||||
window.addEventListener('scroll', tocScrollFn)
|
||||
if (!($article && (isToc || isAnchor))) return
|
||||
|
||||
const scrollPercent = function (currentTop) {
|
||||
const docHeight = $article.clientHeight
|
||||
const winHeight = document.documentElement.clientHeight
|
||||
const headerHeight = $article.offsetTop
|
||||
const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : (document.documentElement.scrollHeight - winHeight)
|
||||
const scrollPercent = (currentTop - headerHeight) / (contentMath)
|
||||
const scrollPercentRounded = Math.round(scrollPercent * 100)
|
||||
const percentage = (scrollPercentRounded > 100) ? 100 : (scrollPercentRounded <= 0) ? 0 : scrollPercentRounded
|
||||
$cardToc.setAttribute('progress-percentage', percentage)
|
||||
}
|
||||
let $tocLink, $cardToc, scrollPercent, autoScrollToc, isExpand
|
||||
|
||||
// anchor
|
||||
const isAnchor = GLOBAL_CONFIG.isanchor
|
||||
const updateAnchor = function (anchor) {
|
||||
if (window.history.replaceState && anchor !== window.location.hash) {
|
||||
if (!anchor) anchor = location.pathname
|
||||
const title = GLOBAL_CONFIG_SITE.title
|
||||
window.history.replaceState({
|
||||
url: location.href,
|
||||
title: title
|
||||
}, title, anchor)
|
||||
if (isToc) {
|
||||
const $cardTocLayout = document.getElementById('card-toc')
|
||||
$cardToc = $cardTocLayout.getElementsByClassName('toc-content')[0]
|
||||
$tocLink = $cardToc.querySelectorAll('.toc-link')
|
||||
const $tocPercentage = $cardTocLayout.querySelector('.toc-percentage')
|
||||
isExpand = $cardToc.classList.contains('is-expand')
|
||||
|
||||
scrollPercent = currentTop => {
|
||||
const docHeight = $article.clientHeight
|
||||
const winHeight = document.documentElement.clientHeight
|
||||
const headerHeight = $article.offsetTop
|
||||
const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : (document.documentElement.scrollHeight - winHeight)
|
||||
const scrollPercent = (currentTop - headerHeight) / (contentMath)
|
||||
const scrollPercentRounded = Math.round(scrollPercent * 100)
|
||||
const percentage = (scrollPercentRounded > 100) ? 100 : (scrollPercentRounded <= 0) ? 0 : scrollPercentRounded
|
||||
$tocPercentage.textContent = percentage
|
||||
}
|
||||
}
|
||||
|
||||
const mobileToc = {
|
||||
open: () => {
|
||||
$cardTocLayout.style.cssText = 'animation: toc-open .3s; opacity: 1; right: 45px'
|
||||
},
|
||||
window.mobileToc = {
|
||||
open: () => {
|
||||
$cardTocLayout.style.cssText = 'animation: toc-open .3s; opacity: 1; right: 55px'
|
||||
},
|
||||
|
||||
close: () => {
|
||||
$cardTocLayout.style.animation = 'toc-close .2s'
|
||||
setTimeout(() => {
|
||||
$cardTocLayout.style.cssText = "opacity:''; animation: ''; right: ''"
|
||||
}, 100)
|
||||
close: () => {
|
||||
$cardTocLayout.style.animation = 'toc-close .2s'
|
||||
setTimeout(() => {
|
||||
$cardTocLayout.style.cssText = "opacity:''; animation: ''; right: ''"
|
||||
}, 100)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('mobile-toc-button').addEventListener('click', () => {
|
||||
if (window.getComputedStyle($cardTocLayout).getPropertyValue('opacity') === '0') mobileToc.open()
|
||||
else mobileToc.close()
|
||||
})
|
||||
// toc元素點擊
|
||||
$cardToc.addEventListener('click', e => {
|
||||
e.preventDefault()
|
||||
const $target = e.target.classList.contains('toc-link')
|
||||
? e.target
|
||||
: e.target.parentElement
|
||||
btf.scrollToDest(btf.getEleTop(document.getElementById(decodeURI($target.getAttribute('href')).replace('#', ''))), 300)
|
||||
if (window.innerWidth < 900) {
|
||||
window.mobileToc.close()
|
||||
}
|
||||
})
|
||||
|
||||
// toc元素點擊
|
||||
$cardToc.addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
const $target = e.target.classList.contains('toc-link')
|
||||
? e.target
|
||||
: e.target.parentElement
|
||||
btf.scrollToDest(btf.getEleTop(document.getElementById(decodeURI($target.getAttribute('href')).replace('#', ''))), 300)
|
||||
if (window.innerWidth < 900) {
|
||||
mobileToc.close()
|
||||
}
|
||||
})
|
||||
|
||||
const autoScrollToc = function (item) {
|
||||
const activePosition = item.getBoundingClientRect().top
|
||||
const sidebarScrollTop = $cardToc.scrollTop
|
||||
if (activePosition > (document.documentElement.clientHeight - 100)) {
|
||||
$cardToc.scrollTop = sidebarScrollTop + 150
|
||||
}
|
||||
if (activePosition < 100) {
|
||||
$cardToc.scrollTop = sidebarScrollTop - 150
|
||||
autoScrollToc = item => {
|
||||
const activePosition = item.getBoundingClientRect().top
|
||||
const sidebarScrollTop = $cardToc.scrollTop
|
||||
if (activePosition > (document.documentElement.clientHeight - 100)) {
|
||||
$cardToc.scrollTop = sidebarScrollTop + 150
|
||||
}
|
||||
if (activePosition < 100) {
|
||||
$cardToc.scrollTop = sidebarScrollTop - 150
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,7 +386,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
const list = $article.querySelectorAll('h1,h2,h3,h4,h5,h6')
|
||||
let detectItem = ''
|
||||
const findHeadPosition = function (top) {
|
||||
if ($tocLink.length === 0 || top === 0) {
|
||||
if (top === 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -480,42 +395,55 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
list.forEach(function (ele, index) {
|
||||
if (top > btf.getEleTop(ele) - 80) {
|
||||
currentId = '#' + encodeURI(ele.getAttribute('id'))
|
||||
const id = ele.id
|
||||
currentId = id ? '#' + encodeURI(id) : ''
|
||||
currentIndex = index
|
||||
}
|
||||
})
|
||||
|
||||
if (detectItem === currentIndex) return
|
||||
|
||||
if (isAnchor) updateAnchor(currentId)
|
||||
|
||||
if (currentId === '') {
|
||||
$cardToc.querySelectorAll('.active').forEach(i => { i.classList.remove('active') })
|
||||
detectItem = currentIndex
|
||||
return
|
||||
}
|
||||
if (isAnchor) btf.updateAnchor(currentId)
|
||||
|
||||
detectItem = currentIndex
|
||||
|
||||
$cardToc.querySelectorAll('.active').forEach(item => { item.classList.remove('active') })
|
||||
const currentActive = $tocLink[currentIndex]
|
||||
currentActive.classList.add('active')
|
||||
if (isToc) {
|
||||
$cardToc.querySelectorAll('.active').forEach(i => { i.classList.remove('active') })
|
||||
|
||||
setTimeout(() => {
|
||||
autoScrollToc(currentActive)
|
||||
}, 0)
|
||||
if (currentId === '') {
|
||||
return
|
||||
}
|
||||
|
||||
let parent = currentActive.parentNode
|
||||
const currentActive = $tocLink[currentIndex]
|
||||
currentActive.classList.add('active')
|
||||
|
||||
for (; !parent.matches('.toc'); parent = parent.parentNode) {
|
||||
if (parent.matches('li')) parent.classList.add('active')
|
||||
setTimeout(() => {
|
||||
autoScrollToc(currentActive)
|
||||
}, 0)
|
||||
|
||||
if (isExpand) return
|
||||
let parent = currentActive.parentNode
|
||||
|
||||
for (; !parent.matches('.toc'); parent = parent.parentNode) {
|
||||
if (parent.matches('li')) parent.classList.add('active')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// main of scroll
|
||||
window.tocScrollFn = function () {
|
||||
return btf.throttle(function () {
|
||||
const currentTop = window.scrollY || document.documentElement.scrollTop
|
||||
isToc && scrollPercent(currentTop)
|
||||
findHeadPosition(currentTop)
|
||||
}, 100)()
|
||||
}
|
||||
window.addEventListener('scroll', tocScrollFn)
|
||||
}
|
||||
|
||||
/**
|
||||
* Rightside
|
||||
*/
|
||||
* Rightside
|
||||
*/
|
||||
const rightSideFn = {
|
||||
switchReadMode: () => { // read-mode
|
||||
const $body = document.body
|
||||
@@ -546,11 +474,21 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
// handle some cases
|
||||
typeof utterancesTheme === 'function' && utterancesTheme()
|
||||
typeof changeGiscusTheme === 'function' && changeGiscusTheme()
|
||||
typeof FB === 'object' && window.loadFBComment()
|
||||
window.DISQUS && document.getElementById('disqus_thread').children.length && setTimeout(() => window.disqusReset(), 200)
|
||||
typeof runMermaid === 'function' && window.runMermaid()
|
||||
},
|
||||
showOrHideBtn: () => { // rightside 點擊設置 按鈕 展開
|
||||
document.getElementById('rightside-config-hide').classList.toggle('show')
|
||||
showOrHideBtn: (e) => { // rightside 點擊設置 按鈕 展開
|
||||
const rightsideHideClassList = document.getElementById('rightside-config-hide').classList
|
||||
rightsideHideClassList.toggle('show')
|
||||
if (e.classList.contains('show')) {
|
||||
rightsideHideClassList.add('status')
|
||||
setTimeout(() => {
|
||||
rightsideHideClassList.remove('status')
|
||||
}, 300)
|
||||
}
|
||||
e.classList.toggle('show')
|
||||
},
|
||||
scrollToTop: () => { // Back to top
|
||||
btf.scrollToDest(0, 500)
|
||||
@@ -563,34 +501,23 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
$htmlDom.toggle('hide-aside')
|
||||
},
|
||||
|
||||
adjustFontSize: (plus) => {
|
||||
const fontSizeVal = parseInt(window.getComputedStyle(document.documentElement).getPropertyValue('--global-font-size'))
|
||||
let newValue = ''
|
||||
if (plus) {
|
||||
if (fontSizeVal >= 20) return
|
||||
newValue = fontSizeVal + 1
|
||||
document.documentElement.style.setProperty('--global-font-size', newValue + 'px')
|
||||
!document.getElementById('nav').classList.contains('hide-menu') && adjustMenu(true)
|
||||
} else {
|
||||
if (fontSizeVal <= 10) return
|
||||
newValue = fontSizeVal - 1
|
||||
document.documentElement.style.setProperty('--global-font-size', newValue + 'px')
|
||||
document.getElementById('nav').classList.contains('hide-menu') && adjustMenu(true)
|
||||
}
|
||||
|
||||
saveToLocal.set('global-font-size', newValue, 2)
|
||||
// document.getElementById('font-text').innerText = newValue
|
||||
runMobileToc: () => {
|
||||
if (window.getComputedStyle(document.getElementById('card-toc')).getPropertyValue('opacity') === '0') window.mobileToc.open()
|
||||
else window.mobileToc.close()
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('rightside').addEventListener('click', function (e) {
|
||||
const $target = e.target.id || e.target.parentNode.id
|
||||
switch ($target) {
|
||||
const $target = e.target.id ? e.target : e.target.parentNode
|
||||
switch ($target.id) {
|
||||
case 'go-up':
|
||||
rightSideFn.scrollToTop()
|
||||
break
|
||||
case 'rightside_config':
|
||||
rightSideFn.showOrHideBtn()
|
||||
rightSideFn.showOrHideBtn($target)
|
||||
break
|
||||
case 'mobile-toc-button':
|
||||
rightSideFn.runMobileToc()
|
||||
break
|
||||
case 'readmode':
|
||||
rightSideFn.switchReadMode()
|
||||
@@ -601,46 +528,26 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
case 'hide-aside-btn':
|
||||
rightSideFn.hideAsideBtn()
|
||||
break
|
||||
case 'font-plus':
|
||||
rightSideFn.adjustFontSize(true)
|
||||
break
|
||||
case 'font-minus':
|
||||
rightSideFn.adjustFontSize()
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* menu
|
||||
* 側邊欄sub-menu 展開/收縮
|
||||
* 解決menus在觸摸屏下,滑動屏幕menus_item_child不消失的問題(手機hover的bug)
|
||||
*/
|
||||
const clickFnOfSubMenu = function () {
|
||||
document.querySelectorAll('#sidebar-menus .expand').forEach(function (e) {
|
||||
e.addEventListener('click', function () {
|
||||
* menu
|
||||
* 側邊欄sub-menu 展開/收縮
|
||||
*/
|
||||
const clickFnOfSubMenu = () => {
|
||||
document.querySelectorAll('#sidebar-menus .site-page.group').forEach(function (item) {
|
||||
item.addEventListener('click', function () {
|
||||
this.classList.toggle('hide')
|
||||
const $dom = this.parentNode.nextElementSibling
|
||||
if (btf.isHidden($dom)) {
|
||||
$dom.style.display = 'block'
|
||||
} else {
|
||||
$dom.style.display = 'none'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
window.addEventListener('touchmove', function (e) {
|
||||
const $menusChild = document.querySelectorAll('#nav .menus_item_child')
|
||||
$menusChild.forEach(item => {
|
||||
if (!btf.isHidden(item)) item.style.display = 'none'
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 複製時加上版權信息
|
||||
*/
|
||||
* 複製時加上版權信息
|
||||
*/
|
||||
const addCopyright = () => {
|
||||
const copyright = GLOBAL_CONFIG.copyright
|
||||
document.body.oncopy = (e) => {
|
||||
@@ -664,8 +571,8 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
|
||||
/**
|
||||
* 網頁運行時間
|
||||
*/
|
||||
* 網頁運行時間
|
||||
*/
|
||||
const addRuntime = () => {
|
||||
const $runtimeCount = document.getElementById('runtimeshow')
|
||||
if ($runtimeCount) {
|
||||
@@ -675,8 +582,8 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
|
||||
/**
|
||||
* 最後一次更新時間
|
||||
*/
|
||||
* 最後一次更新時間
|
||||
*/
|
||||
const addLastPushDate = () => {
|
||||
const $lastPushDateItem = document.getElementById('last-push-date')
|
||||
if ($lastPushDateItem) {
|
||||
@@ -686,9 +593,9 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
|
||||
/**
|
||||
* table overflow
|
||||
*/
|
||||
const addTableWrap = function () {
|
||||
* table overflow
|
||||
*/
|
||||
const addTableWrap = () => {
|
||||
const $table = document.querySelectorAll('#article-container :not(.highlight) > table, #article-container > table')
|
||||
if ($table.length) {
|
||||
$table.forEach(item => {
|
||||
@@ -698,8 +605,8 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
|
||||
/**
|
||||
* tag-hide
|
||||
*/
|
||||
* tag-hide
|
||||
*/
|
||||
const clickFnOfTagHide = function () {
|
||||
const $hideInline = document.querySelectorAll('#article-container .hide-button')
|
||||
if ($hideInline.length) {
|
||||
@@ -709,8 +616,8 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
const $hideContent = $this.nextElementSibling
|
||||
$this.classList.toggle('open')
|
||||
if ($this.classList.contains('open')) {
|
||||
if ($hideContent.querySelectorAll('.justified-gallery').length > 0) {
|
||||
btf.initJustifiedGallery($hideContent.querySelectorAll('.justified-gallery'))
|
||||
if ($hideContent.querySelectorAll('.fj-gallery').length > 0) {
|
||||
btf.initJustifiedGallery($hideContent.querySelectorAll('.fj-gallery'))
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -736,7 +643,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
if (item.id === tabId) item.classList.add('active')
|
||||
else item.classList.remove('active')
|
||||
})
|
||||
const $isTabJustifiedGallery = $tabContent.querySelectorAll(`#${tabId} .justified-gallery`)
|
||||
const $isTabJustifiedGallery = $tabContent.querySelectorAll(`#${tabId} .fj-gallery`)
|
||||
if ($isTabJustifiedGallery.length > 0) {
|
||||
btf.initJustifiedGallery($isTabJustifiedGallery)
|
||||
}
|
||||
@@ -826,8 +733,12 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
|
||||
const unRefreshFn = function () {
|
||||
window.addEventListener('resize', adjustMenu)
|
||||
window.addEventListener('orientationchange', () => { setTimeout(adjustMenu(true), 100) })
|
||||
window.addEventListener('resize', () => {
|
||||
adjustMenu(false)
|
||||
btf.isHidden(document.getElementById('toggle-menu')) && mobileSidebarOpen && sidebarFn.close()
|
||||
})
|
||||
|
||||
document.getElementById('menu-mask').addEventListener('click', e => { sidebarFn.close() })
|
||||
|
||||
clickFnOfSubMenu()
|
||||
GLOBAL_CONFIG.islazyload && lazyloadImg()
|
||||
@@ -838,7 +749,6 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
initAdjust()
|
||||
|
||||
if (GLOBAL_CONFIG_SITE.isPost) {
|
||||
GLOBAL_CONFIG_SITE.isToc && tocFn()
|
||||
GLOBAL_CONFIG.noticeOutdate !== undefined && addPostOutdateNotice()
|
||||
GLOBAL_CONFIG.relativeDate.post && relativeDate(document.querySelectorAll('#post-meta time'))
|
||||
} else {
|
||||
@@ -848,18 +758,22 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
toggleCardCategory()
|
||||
}
|
||||
|
||||
sidebarFn()
|
||||
scrollFnToDo()
|
||||
GLOBAL_CONFIG_SITE.isHome && scrollDownInIndex()
|
||||
addHighlightTool()
|
||||
GLOBAL_CONFIG.isPhotoFigcaption && addPhotoFigcaption()
|
||||
jqLoadAndRun()
|
||||
GLOBAL_CONFIG.lightbox === 'mediumZoom' && addMediumZoom()
|
||||
scrollFn()
|
||||
|
||||
const $jgEle = document.querySelectorAll('#article-container .fj-gallery')
|
||||
$jgEle.length && runJustifiedGallery($jgEle)
|
||||
|
||||
runLightbox()
|
||||
addTableWrap()
|
||||
clickFnOfTagHide()
|
||||
tabsFn.clickFnOfTabs()
|
||||
tabsFn.backToTop()
|
||||
switchComments()
|
||||
document.getElementById('toggle-menu').addEventListener('click', () => { sidebarFn.open() })
|
||||
}
|
||||
|
||||
refreshFn()
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
setInterval(() => {
|
||||
let create_time = Math.round(new Date('2021-07-02 00:00:00').getTime() / 1000); //在此行修改建站时间
|
||||
let timestamp = Math.round((new Date().getTime()) / 1000);
|
||||
let second = timestamp - create_time;
|
||||
let time = new Array(0, 0, 0, 0, 0);
|
||||
//格式规范化,个位数前面加0
|
||||
var nol = function(h){
|
||||
return h>9?h:'0'+h;
|
||||
}
|
||||
if (second >= 365 * 24 * 3600) {
|
||||
time[0] = parseInt(second / (365 * 24 * 3600));
|
||||
second %= 365 * 24 * 3600;
|
||||
}//年
|
||||
if (second >= 24 * 3600) {
|
||||
time[1] = parseInt(second / (24 * 3600));
|
||||
second %= 24 * 3600;
|
||||
}//天
|
||||
if (second >= 3600) {
|
||||
time[2] = nol(parseInt(second / 3600));
|
||||
second %= 3600;
|
||||
}//时
|
||||
if (second >= 60) {
|
||||
time[3] = nol(parseInt(second / 60));
|
||||
second %= 60;
|
||||
}//分
|
||||
if (second > 0) {
|
||||
time[4] = nol(second);
|
||||
}//秒
|
||||
//早上7点到晚上10点营业
|
||||
if ((Number(time[2])<22) && (Number(time[2])>7)){
|
||||
currentTimeHtml ="<img class='boardsign' src='https://img.shields.io/badge/Leon的技术阁-营业中-6adea8?style=social&logo=cakephp' title='距离百年老店也就差不到一百年~'><div id='runtime'>" + time[0] + ' YEAR ' + time[1] + ' DAYS ' + time[2] + ' : ' + time[3] + ' : ' + time[4] + '</div>';
|
||||
} //徽标内容参考站内教程
|
||||
//其余时间打烊
|
||||
else{
|
||||
currentTimeHtml ="<img class='boardsign' src='https://img.shields.io/badge/Leon的技术阁-打烊了-6adea8?style=social&logo=coffeescript' title='这个点了应该去睡觉啦,熬夜对身体不好哦'><div id='runtime'>" + time[0] + ' YEAR ' + time[1] + ' DAYS ' + time[2] + ' : ' + time[3] + ' : ' + time[4] + '</div>'; //徽标内容参考站内教程
|
||||
}
|
||||
//覆写挂载标签的内容
|
||||
document.getElementById("workboard").innerHTML = currentTimeHtml;
|
||||
}, 1000);
|
||||
@@ -1,9 +1,12 @@
|
||||
window.addEventListener('load', () => {
|
||||
const openSearch = () => {
|
||||
document.body.style.cssText = 'width: 100%;overflow: hidden'
|
||||
document.querySelector('#algolia-search .search-dialog').style.display = 'block'
|
||||
document.querySelector('#algolia-search .ais-search-box--input').focus()
|
||||
btf.fadeIn(document.getElementById('search-mask'), 0.5)
|
||||
const bodyStyle = document.body.style
|
||||
bodyStyle.width = '100%'
|
||||
bodyStyle.overflow = 'hidden'
|
||||
btf.animateIn(document.getElementById('search-mask'), 'to_show 0.5s')
|
||||
btf.animateIn(document.querySelector('#algolia-search .search-dialog'), 'titleScale 0.5s')
|
||||
setTimeout(() => { document.querySelector('#algolia-search .ais-SearchBox-input').focus() }, 100)
|
||||
|
||||
// shortcut: ESC
|
||||
document.addEventListener('keydown', function f (event) {
|
||||
if (event.code === 'Escape') {
|
||||
@@ -14,11 +17,11 @@ window.addEventListener('load', () => {
|
||||
}
|
||||
|
||||
const closeSearch = () => {
|
||||
document.body.style.cssText = "width: '';overflow: ''"
|
||||
const $searchDialog = document.querySelector('#algolia-search .search-dialog')
|
||||
$searchDialog.style.animation = 'search_close .5s'
|
||||
setTimeout(() => { $searchDialog.style.cssText = "display: none; animation: ''" }, 500)
|
||||
btf.fadeOut(document.getElementById('search-mask'), 0.5)
|
||||
const bodyStyle = document.body.style
|
||||
bodyStyle.width = ''
|
||||
bodyStyle.overflow = ''
|
||||
btf.animateOut(document.querySelector('#algolia-search .search-dialog'), 'search_close .5s')
|
||||
btf.animateOut(document.getElementById('search-mask'), 'to_hide 0.5s')
|
||||
}
|
||||
|
||||
const searchClickFn = () => {
|
||||
@@ -40,41 +43,38 @@ window.addEventListener('load', () => {
|
||||
return console.error('Algolia setting is invalid!')
|
||||
}
|
||||
|
||||
const searchClient = window.algoliasearch(algolia.appId, algolia.apiKey)
|
||||
const search = instantsearch({
|
||||
appId: algolia.appId,
|
||||
apiKey: algolia.apiKey,
|
||||
indexName: algolia.indexName,
|
||||
searchParameters: {
|
||||
hitsPerPage: algolia.hits.per_page || 10
|
||||
},
|
||||
searchFunction: function (helper) {
|
||||
const searchInput = document.querySelector('#algolia-search-input input')
|
||||
|
||||
if (searchInput.value) {
|
||||
helper.search()
|
||||
}
|
||||
}
|
||||
searchClient
|
||||
})
|
||||
|
||||
search.addWidget(
|
||||
search.addWidgets([
|
||||
instantsearch.widgets.configure({
|
||||
hitsPerPage: 5
|
||||
})
|
||||
])
|
||||
|
||||
search.addWidgets([
|
||||
instantsearch.widgets.searchBox({
|
||||
container: '#algolia-search-input',
|
||||
reset: false,
|
||||
magnifier: false,
|
||||
placeholder: GLOBAL_CONFIG.algolia.languages.input_placeholder
|
||||
showReset: false,
|
||||
showSubmit: false,
|
||||
placeholder: GLOBAL_CONFIG.algolia.languages.input_placeholder,
|
||||
showLoadingIndicator: true
|
||||
})
|
||||
)
|
||||
search.addWidget(
|
||||
])
|
||||
|
||||
search.addWidgets([
|
||||
instantsearch.widgets.hits({
|
||||
container: '#algolia-hits',
|
||||
templates: {
|
||||
item: function (data) {
|
||||
const link = data.permalink ? data.permalink : (GLOBAL_CONFIG.root + data.path)
|
||||
return (
|
||||
'<a href="' + link + '" class="algolia-hit-item-link">' +
|
||||
data._highlightResult.title.value +
|
||||
'</a>'
|
||||
)
|
||||
return `
|
||||
<a href="${link}" class="algolia-hit-item-link">
|
||||
${data._highlightResult.title.value || 'no-title'}
|
||||
</a>`
|
||||
},
|
||||
empty: function (data) {
|
||||
return (
|
||||
@@ -83,53 +83,39 @@ window.addEventListener('load', () => {
|
||||
'</div>'
|
||||
)
|
||||
}
|
||||
},
|
||||
cssClasses: {
|
||||
item: 'algolia-hit-item'
|
||||
}
|
||||
})
|
||||
)
|
||||
])
|
||||
|
||||
search.addWidget(
|
||||
search.addWidgets([
|
||||
instantsearch.widgets.stats({
|
||||
container: '#algolia-stats',
|
||||
templates: {
|
||||
body: function (data) {
|
||||
text: function (data) {
|
||||
const icon = '<svg viewBox="0 0 1366 362" xmlns="http://www.w3.org/2000/svg"><linearGradient id="a" x1="428.26" x2="434.14" y1="404.15" y2="409.85" gradientTransform="matrix(94.045 0 0 -94.072 -40382 38480)" gradientUnits="userSpaceOnUse"><stop stop-color="#00aeff" offset="0"/><stop stop-color="#3369e7" offset="1"/></linearGradient><path d="M61.8 15.4h242.8c23.9 0 43.4 19.4 43.4 43.4v242.9c0 23.9-19.4 43.4-43.4 43.4H61.8c-23.9 0-43.4-19.4-43.4-43.4v-243c0-23.9 19.4-43.3 43.4-43.3z" fill="url(#a)"/><path d="M187 98.7c-51.4 0-93.1 41.7-93.1 93.2S135.6 285 187 285s93.1-41.7 93.1-93.2-41.6-93.1-93.1-93.1zm0 158.8c-36.2 0-65.6-29.4-65.6-65.6s29.4-65.6 65.6-65.6 65.6 29.4 65.6 65.6-29.3 65.6-65.6 65.6zm0-117.8v48.9c0 1.4 1.5 2.4 2.8 1.7l43.4-22.5c1-.5 1.3-1.7.8-2.7-9-15.8-25.7-26.6-45-27.3-1 0-2 .8-2 1.9zm-60.8-35.9l-5.7-5.7c-5.6-5.6-14.6-5.6-20.2 0l-6.8 6.8c-5.6 5.6-5.6 14.6 0 20.2l5.6 5.6c.9.9 2.2.7 3-.2 3.3-4.5 6.9-8.8 10.9-12.8 4.1-4.1 8.3-7.7 12.9-11 1-.6 1.1-2 .3-2.9zM217.5 89V77.7c0-7.9-6.4-14.3-14.3-14.3h-33.3c-7.9 0-14.3 6.4-14.3 14.3v11.6c0 1.3 1.2 2.2 2.5 1.9 9.3-2.7 19.1-4.1 29-4.1 9.5 0 18.9 1.3 28 3.8 1.2.3 2.4-.6 2.4-1.9z" fill="#FFF"/><path d="m842.5 267.6c0 26.7-6.8 46.2-20.5 58.6s-34.6 18.6-62.8 18.6c-10.3 0-31.7-2-48.8-5.8l6.3-31c14.3 3 33.2 3.8 43.1 3.8 15.7 0 26.9-3.2 33.6-9.6s10-15.9 10-28.5v-6.4c-3.9 1.9-9 3.8-15.3 5.8-6.3 1.9-13.6 2.9-21.8 2.9-10.8 0-20.6-1.7-29.5-5.1s-16.6-8.4-22.9-15-11.3-14.9-14.8-24.8-5.3-27.6-5.3-40.6c0-12.2 1.9-27.5 5.6-37.7 3.8-10.2 9.2-19 16.5-26.3 7.2-7.3 16-12.9 26.3-17s22.4-6.7 35.5-6.7c12.7 0 24.4 1.6 35.8 3.5s21.1 3.9 29 6.1v155.2zm-108.7-77.2c0 16.4 3.6 34.6 10.8 42.2s16.5 11.4 27.9 11.4c6.2 0 12.1-0.9 17.6-2.6s9.9-3.7 13.4-6.1v-97.1c-2.8-0.6-14.5-3-25.8-3.3-14.2-0.4-25 5.4-32.6 14.7-7.5 9.3-11.3 25.6-11.3 40.8zm294.3 0c0 13.2-1.9 23.2-5.8 34.1s-9.4 20.2-16.5 27.9-15.6 13.7-25.6 17.9-25.4 6.6-33.1 6.6c-7.7-0.1-23-2.3-32.9-6.6s-18.4-10.2-25.5-17.9-12.6-17-16.6-27.9-6-20.9-6-34.1 1.8-25.9 5.8-36.7 9.6-20 16.8-27.7 15.8-13.6 25.6-17.8c9.9-4.2 20.8-6.2 32.6-6.2s22.7 2.1 32.7 6.2c10 4.2 18.6 10.1 25.6 17.8 7.1 7.7 12.6 16.9 16.6 27.7 4.2 10.8 6.3 23.5 6.3 36.7zm-40 0.1c0-16.9-3.7-31-10.9-40.8-7.2-9.9-17.3-14.8-30.2-14.8s-23 4.9-30.2 14.8-10.7 23.9-10.7 40.8c0 17.1 3.6 28.6 10.8 38.5 7.2 10 17.3 14.9 30.2 14.9s23-5 30.2-14.9c7.2-10 10.8-21.4 10.8-38.5zm127.1 86.4c-64.1 0.3-64.1-51.8-64.1-60.1l-0.1-184.8 39.1-6.2v183.6c0 4.7 0 34.5 25.1 34.6v32.9zm68.9 0h-39.3v-168.8l39.3-6.2v175zm-19.7-193.5c13.1 0 23.8-10.6 23.8-23.7s-10.6-23.7-23.8-23.7-23.8 10.6-23.8 23.7 10.7 23.7 23.8 23.7zm117.4 18.6c12.9 0 23.8 1.6 32.6 4.8s15.9 7.7 21.1 13.4 8.9 13.5 11.1 21.7c2.3 8.2 3.4 17.2 3.4 27.1v100.6c-6 1.3-15.1 2.8-27.3 4.6s-25.9 2.7-41.1 2.7c-10.1 0-19.4-1-27.7-2.9-8.4-1.9-15.5-5-21.5-9.3-5.9-4.3-10.5-9.8-13.9-16.6-3.3-6.8-5-16.4-5-26.4 0-9.6 1.9-15.7 5.6-22.3 3.8-6.6 8.9-12 15.3-16.2 6.5-4.2 13.9-7.2 22.4-9s17.4-2.7 26.6-2.7c4.3 0 8.8 0.3 13.6 0.8s9.8 1.4 15.2 2.7v-6.4c0-4.5-0.5-8.8-1.6-12.8-1.1-4.1-3-7.6-5.6-10.7-2.7-3.1-6.2-5.5-10.6-7.2s-10-3-16.7-3c-9 0-17.2 1.1-24.7 2.4s-13.7 2.8-18.4 4.5l-4.7-32.1c4.9-1.7 12.2-3.4 21.6-5.1s19.5-2.6 30.3-2.6zm3.3 141.9c12 0 20.9-0.7 27.1-1.9v-39.8c-2.2-0.6-5.3-1.3-9.4-1.9s-8.6-1-13.6-1c-4.3 0-8.7 0.3-13.1 1-4.4 0.6-8.4 1.8-11.9 3.5s-6.4 4.1-8.5 7.2c-2.2 3.1-3.2 4.9-3.2 9.6 0 9.2 3.2 14.5 9 18 5.9 3.6 13.7 5.3 23.6 5.3zm-772.2-140.9c12.9 0 23.8 1.6 32.6 4.8s15.9 7.7 21.1 13.4c5.3 5.8 8.9 13.5 11.1 21.7 2.3 8.2 3.4 17.2 3.4 27.1v100.6c-6 1.3-15.1 2.8-27.3 4.6s-25.9 2.7-41.1 2.7c-10.1 0-19.4-1-27.7-2.9-8.4-1.9-15.5-5-21.5-9.3-5.9-4.3-10.5-9.8-13.9-16.6-3.3-6.8-5-16.4-5-26.4 0-9.6 1.9-15.7 5.6-22.3 3.8-6.6 8.9-12 15.3-16.2 6.5-4.2 13.9-7.2 22.4-9s17.4-2.7 26.6-2.7c4.3 0 8.8 0.3 13.6 0.8 4.7 0.5 9.8 1.4 15.2 2.7v-6.4c0-4.5-0.5-8.8-1.6-12.8-1.1-4.1-3-7.6-5.6-10.7-2.7-3.1-6.2-5.5-10.6-7.2s-10-3-16.7-3c-9 0-17.2 1.1-24.7 2.4s-13.7 2.8-18.4 4.5l-4.7-32.1c4.9-1.7 12.2-3.4 21.6-5.1 9.4-1.8 19.5-2.6 30.3-2.6zm3.4 142c12 0 20.9-0.7 27.1-1.9v-39.8c-2.2-0.6-5.3-1.3-9.4-1.9s-8.6-1-13.6-1c-4.3 0-8.7 0.3-13.1 1-4.4 0.6-8.4 1.8-11.9 3.5s-6.4 4.1-8.5 7.2c-2.2 3.1-3.2 4.9-3.2 9.6 0 9.2 3.2 14.5 9 18s13.7 5.3 23.6 5.3zm158.5 31.9c-64.1 0.3-64.1-51.8-64.1-60.1l-0.1-184.8 39.1-6.2v183.6c0 4.7 0 34.5 25.1 34.6v32.9z" fill="#182359"/></svg>'
|
||||
const 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>'
|
||||
`<hr>${stats}<span class="algolia-logo pull-right">${icon}</span>`
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
])
|
||||
|
||||
search.addWidget(
|
||||
search.addWidgets([
|
||||
instantsearch.widgets.pagination({
|
||||
container: '#algolia-pagination',
|
||||
scrollTo: false,
|
||||
showFirstLast: false,
|
||||
labels: {
|
||||
totalPages: 5,
|
||||
templates: {
|
||||
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',
|
||||
item: 'pagination-item',
|
||||
link: 'page-number',
|
||||
active: 'current',
|
||||
disabled: 'disabled-item'
|
||||
}
|
||||
})
|
||||
)
|
||||
])
|
||||
search.start()
|
||||
|
||||
window.pjax && search.on('render', () => {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
window.addEventListener('load', () => {
|
||||
let loadFlag = false
|
||||
const openSearch = function () {
|
||||
document.body.style.cssText = 'width: 100%;overflow: hidden'
|
||||
document.querySelector('#local-search .search-dialog').style.display = 'block'
|
||||
document.querySelector('#local-search-input input').focus()
|
||||
btf.fadeIn(document.getElementById('search-mask'), 0.5)
|
||||
const openSearch = () => {
|
||||
const bodyStyle = document.body.style
|
||||
bodyStyle.width = '100%'
|
||||
bodyStyle.overflow = 'hidden'
|
||||
btf.animateIn(document.getElementById('search-mask'), 'to_show 0.5s')
|
||||
btf.animateIn(document.querySelector('#local-search .search-dialog'), 'titleScale 0.5s')
|
||||
setTimeout(() => { document.querySelector('#local-search-input input').focus() }, 100)
|
||||
if (!loadFlag) {
|
||||
search(GLOBAL_CONFIG.localSearch.path)
|
||||
loadFlag = true
|
||||
@@ -18,12 +20,12 @@ window.addEventListener('load', () => {
|
||||
})
|
||||
}
|
||||
|
||||
const closeSearch = function () {
|
||||
document.body.style.cssText = "width: '';overflow: ''"
|
||||
const $searchDialog = document.querySelector('#local-search .search-dialog')
|
||||
$searchDialog.style.animation = 'search_close .5s'
|
||||
setTimeout(() => { $searchDialog.style.cssText = "display: none; animation: ''" }, 500)
|
||||
btf.fadeOut(document.getElementById('search-mask'), 0.5)
|
||||
const closeSearch = () => {
|
||||
const bodyStyle = document.body.style
|
||||
bodyStyle.width = ''
|
||||
bodyStyle.overflow = ''
|
||||
btf.animateOut(document.querySelector('#local-search .search-dialog'), 'search_close .5s')
|
||||
btf.animateOut(document.getElementById('search-mask'), 'to_hide 0.5s')
|
||||
}
|
||||
|
||||
// click function
|
||||
@@ -41,106 +43,122 @@ window.addEventListener('load', () => {
|
||||
searchClickFn()
|
||||
})
|
||||
|
||||
function search (path) {
|
||||
fetch(GLOBAL_CONFIG.root + path)
|
||||
.then(response => response.text())
|
||||
.then(str => new window.DOMParser().parseFromString(str, 'text/xml'))
|
||||
.then(data => {
|
||||
const datas = [...data.querySelectorAll('entry')].map(function (item) {
|
||||
return {
|
||||
title: item.querySelector('title').textContent,
|
||||
content: item.querySelector('content').textContent,
|
||||
url: item.querySelector('url').textContent
|
||||
}
|
||||
})
|
||||
async function search (path) {
|
||||
let datas = []
|
||||
const typeF = path.split('.')[1]
|
||||
const response = await fetch(GLOBAL_CONFIG.root + path)
|
||||
if (typeF === 'json') {
|
||||
datas = await response.json()
|
||||
} else if (typeF === 'xml') {
|
||||
const res = await response.text()
|
||||
const t = await new window.DOMParser().parseFromString(res, 'text/xml')
|
||||
const a = await t
|
||||
datas = [...a.querySelectorAll('entry')].map(function (item) {
|
||||
return {
|
||||
title: item.querySelector('title').textContent,
|
||||
content: item.querySelector('content').textContent,
|
||||
url: item.querySelector('url').textContent
|
||||
}
|
||||
})
|
||||
}
|
||||
if (response.ok) {
|
||||
const $loadDataItem = document.getElementById('loading-database')
|
||||
$loadDataItem.nextElementSibling.style.display = 'block'
|
||||
$loadDataItem.remove()
|
||||
}
|
||||
|
||||
const $input = document.querySelector('#local-search-input input')
|
||||
const $resultContent = document.getElementById('local-search-results')
|
||||
$input.addEventListener('input', function () {
|
||||
let str = '<div class="search-result-list">'
|
||||
const keywords = this.value.trim().toLowerCase().split(/[\s]+/)
|
||||
$resultContent.innerHTML = ''
|
||||
if (this.value.trim().length <= 0) return
|
||||
let count = 0
|
||||
// perform local searching
|
||||
datas.forEach(function (data) {
|
||||
let isMatch = true
|
||||
if (!data.title || data.title.trim() === '') {
|
||||
data.title = 'Untitled'
|
||||
}
|
||||
let dataTitle = data.title.trim().toLowerCase()
|
||||
const dataContent = data.content.trim().replace(/<[^>]+>/g, '').toLowerCase()
|
||||
const dataUrl = data.url.startsWith('/') ? data.url : GLOBAL_CONFIG.root + data.url
|
||||
let indexTitle = -1
|
||||
let indexContent = -1
|
||||
let firstOccur = -1
|
||||
// only match artiles with not empty titles and contents
|
||||
if (dataTitle !== '' || dataContent !== '') {
|
||||
keywords.forEach(function (keyword, i) {
|
||||
indexTitle = dataTitle.indexOf(keyword)
|
||||
indexContent = dataContent.indexOf(keyword)
|
||||
if (indexTitle < 0 && indexContent < 0) {
|
||||
isMatch = false
|
||||
} else {
|
||||
if (indexContent < 0) {
|
||||
indexContent = 0
|
||||
}
|
||||
if (i === 0) {
|
||||
firstOccur = indexContent
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
const $input = document.querySelector('#local-search-input input')
|
||||
const $resultContent = document.getElementById('local-search-results')
|
||||
const $loadingStatus = document.getElementById('loading-status')
|
||||
$input.addEventListener('input', function () {
|
||||
const keywords = this.value.trim().toLowerCase().split(/[\s]+/)
|
||||
if (keywords[0] !== '') $loadingStatus.innerHTML = '<i class="fas fa-spinner fa-pulse"></i>'
|
||||
|
||||
$resultContent.innerHTML = ''
|
||||
let str = '<div class="search-result-list">'
|
||||
if (this.value.trim().length <= 0) return
|
||||
let count = 0
|
||||
// perform local searching
|
||||
datas.forEach(function (data) {
|
||||
let isMatch = true
|
||||
if (!data.title || data.title.trim() === '') {
|
||||
data.title = ''
|
||||
}
|
||||
let dataTitle = data.title.trim().toLowerCase()
|
||||
const dataContent = data.content ? data.content.trim().replace(/<[^>]+>/g, '').toLowerCase() : ''
|
||||
const dataUrl = data.url.startsWith('/') ? data.url : GLOBAL_CONFIG.root + data.url
|
||||
let indexTitle = -1
|
||||
let indexContent = -1
|
||||
let firstOccur = -1
|
||||
// only match artiles with not empty titles and contents
|
||||
if (dataTitle !== '' || dataContent !== '') {
|
||||
keywords.forEach(function (keyword, i) {
|
||||
indexTitle = dataTitle.indexOf(keyword)
|
||||
indexContent = dataContent.indexOf(keyword)
|
||||
if (indexTitle < 0 && indexContent < 0) {
|
||||
isMatch = false
|
||||
}
|
||||
|
||||
// show search results
|
||||
if (isMatch) {
|
||||
const content = data.content.trim().replace(/<[^>]+>/g, '')
|
||||
if (firstOccur >= 0) {
|
||||
// cut out 130 characters
|
||||
let start = firstOccur - 30
|
||||
let end = firstOccur + 100
|
||||
|
||||
if (start < 0) {
|
||||
start = 0
|
||||
}
|
||||
|
||||
if (start === 0) {
|
||||
end = 100
|
||||
}
|
||||
|
||||
if (end > content.length) {
|
||||
end = content.length
|
||||
}
|
||||
|
||||
let matchContent = content.substring(start, end)
|
||||
|
||||
// highlight all keywords
|
||||
keywords.forEach(function (keyword) {
|
||||
const regS = new RegExp(keyword, 'gi')
|
||||
matchContent = matchContent.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
||||
dataTitle = dataTitle.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
||||
})
|
||||
|
||||
str += '<div class="local-search__hit-item"><a href="' + dataUrl + '" class="search-result-title">' + dataTitle + '</a>'
|
||||
count += 1
|
||||
|
||||
if (dataContent !== '') {
|
||||
str += '<p class="search-result">' + matchContent + '...</p>'
|
||||
}
|
||||
} else {
|
||||
if (indexContent < 0) {
|
||||
indexContent = 0
|
||||
}
|
||||
if (i === 0) {
|
||||
firstOccur = indexContent
|
||||
}
|
||||
str += '</div>'
|
||||
}
|
||||
})
|
||||
if (count === 0) {
|
||||
str += '<div id="local-search__hits-empty">' + GLOBAL_CONFIG.localSearch.languages.hits_empty.replace(/\$\{query}/, this.value.trim()) +
|
||||
'</div>'
|
||||
} else {
|
||||
isMatch = false
|
||||
}
|
||||
|
||||
// show search results
|
||||
if (isMatch) {
|
||||
const content = data.content.trim().replace(/<[^>]+>/g, '')
|
||||
if (firstOccur >= 0) {
|
||||
// cut out 130 characters
|
||||
// let start = firstOccur - 30 < 0 ? 0 : firstOccur - 30
|
||||
// let end = firstOccur + 50 > content.length ? content.length : firstOccur + 50
|
||||
let start = firstOccur - 30
|
||||
let end = firstOccur + 100
|
||||
|
||||
if (start < 0) {
|
||||
start = 0
|
||||
}
|
||||
|
||||
if (start === 0) {
|
||||
end = 100
|
||||
}
|
||||
|
||||
if (end > content.length) {
|
||||
end = content.length
|
||||
}
|
||||
|
||||
let matchContent = content.substring(start, end)
|
||||
|
||||
// highlight all keywords
|
||||
keywords.forEach(function (keyword) {
|
||||
const regS = new RegExp(keyword, 'gi')
|
||||
matchContent = matchContent.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
||||
dataTitle = dataTitle.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
||||
})
|
||||
|
||||
str += '<div class="local-search__hit-item"><a href="' + dataUrl + '" class="search-result-title">' + dataTitle + '</a>'
|
||||
count += 1
|
||||
|
||||
if (dataContent !== '') {
|
||||
str += '<p class="search-result">' + matchContent + '...</p>'
|
||||
}
|
||||
}
|
||||
str += '</div>'
|
||||
$resultContent.innerHTML = str
|
||||
window.pjax && window.pjax.refresh($resultContent)
|
||||
})
|
||||
}
|
||||
})
|
||||
if (count === 0) {
|
||||
str += '<div id="local-search__hits-empty">' + GLOBAL_CONFIG.localSearch.languages.hits_empty.replace(/\$\{query}/, this.value.trim()) +
|
||||
'</div>'
|
||||
}
|
||||
str += '</div>'
|
||||
$resultContent.innerHTML = str
|
||||
if (keywords[0] !== '') $loadingStatus.innerHTML = ''
|
||||
window.pjax && window.pjax.refresh($resultContent)
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -58,34 +58,18 @@ const btf = {
|
||||
}
|
||||
},
|
||||
|
||||
snackbarShow: (text, showAction, duration) => {
|
||||
const sa = (typeof showAction !== 'undefined') ? showAction : false
|
||||
const dur = (typeof duration !== 'undefined') ? duration : 2000
|
||||
const position = GLOBAL_CONFIG.Snackbar.position
|
||||
const bg = document.documentElement.getAttribute('data-theme') === 'light' ? GLOBAL_CONFIG.Snackbar.bgLight : GLOBAL_CONFIG.Snackbar.bgDark
|
||||
snackbarShow: (text, showAction = false, duration = 2000) => {
|
||||
const { position, bgLight, bgDark } = GLOBAL_CONFIG.Snackbar
|
||||
const bg = document.documentElement.getAttribute('data-theme') === 'light' ? bgLight : bgDark
|
||||
Snackbar.show({
|
||||
text: text,
|
||||
backgroundColor: bg,
|
||||
showAction: sa,
|
||||
duration: dur,
|
||||
showAction: showAction,
|
||||
duration: duration,
|
||||
pos: position
|
||||
})
|
||||
},
|
||||
|
||||
initJustifiedGallery: function (selector) {
|
||||
if (!(selector instanceof jQuery)) {
|
||||
selector = $(selector)
|
||||
}
|
||||
selector.each(function (i, o) {
|
||||
if ($(this).is(':visible')) {
|
||||
$(this).justifiedGallery({
|
||||
rowHeight: 220,
|
||||
margins: 4
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
diffDate: (d, more = false) => {
|
||||
const dateNow = new Date()
|
||||
const datePost = new Date(d)
|
||||
@@ -135,15 +119,11 @@ const btf = {
|
||||
}
|
||||
},
|
||||
|
||||
scrollToDest: (pos, time) => {
|
||||
if (pos < 0 || time < 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const currentPos = window.scrollY || window.screenTop
|
||||
scrollToDest: (pos, time = 500) => {
|
||||
const currentPos = window.pageYOffset
|
||||
if (currentPos > pos) pos = pos - 70
|
||||
|
||||
if ('CSS' in window && CSS.supports('scroll-behavior', 'smooth')) {
|
||||
if ('scrollBehavior' in document.documentElement.style) {
|
||||
window.scrollTo({
|
||||
top: pos,
|
||||
behavior: 'smooth'
|
||||
@@ -152,39 +132,35 @@ const btf = {
|
||||
}
|
||||
|
||||
let start = null
|
||||
time = time || 500
|
||||
pos = +pos
|
||||
window.requestAnimationFrame(function step (currentTime) {
|
||||
start = !start ? currentTime : start
|
||||
const progress = currentTime - start
|
||||
if (currentPos < pos) {
|
||||
const progress = currentTime - start
|
||||
window.scrollTo(0, ((pos - currentPos) * progress / time) + currentPos)
|
||||
if (progress < time) {
|
||||
window.requestAnimationFrame(step)
|
||||
} else {
|
||||
window.scrollTo(0, pos)
|
||||
}
|
||||
} else {
|
||||
const progress = currentTime - start
|
||||
window.scrollTo(0, currentPos - ((currentPos - pos) * progress / time))
|
||||
if (progress < time) {
|
||||
window.requestAnimationFrame(step)
|
||||
} else {
|
||||
window.scrollTo(0, pos)
|
||||
}
|
||||
}
|
||||
if (progress < time) {
|
||||
window.requestAnimationFrame(step)
|
||||
} else {
|
||||
window.scrollTo(0, pos)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
fadeIn: (ele, time) => {
|
||||
ele.style.cssText = `display:block;animation: to_show ${time}s`
|
||||
animateIn: (ele, text) => {
|
||||
ele.style.display = 'block'
|
||||
ele.style.animation = text
|
||||
},
|
||||
|
||||
fadeOut: (ele, time) => {
|
||||
animateOut: (ele, text) => {
|
||||
ele.addEventListener('animationend', function f () {
|
||||
ele.style.cssText = "display: none; animation: '' "
|
||||
ele.style.display = ''
|
||||
ele.style.animation = ''
|
||||
ele.removeEventListener('animationend', f)
|
||||
})
|
||||
ele.style.animation = `to_hide ${time}s`
|
||||
ele.style.animation = text
|
||||
},
|
||||
|
||||
getParents: (elem, selector) => {
|
||||
@@ -204,7 +180,6 @@ const btf = {
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} selector
|
||||
* @param {*} eleType the type of create element
|
||||
* @param {*} options object key: value
|
||||
@@ -226,14 +201,6 @@ const btf = {
|
||||
}
|
||||
},
|
||||
|
||||
isJqueryLoad: fn => {
|
||||
if (typeof jQuery === 'undefined') {
|
||||
getScript(GLOBAL_CONFIG.source.jQuery).then(fn)
|
||||
} else {
|
||||
fn()
|
||||
}
|
||||
},
|
||||
|
||||
isHidden: ele => ele.offsetHeight === 0 && ele.offsetWidth === 0,
|
||||
|
||||
getEleTop: ele => {
|
||||
@@ -246,6 +213,65 @@ const btf = {
|
||||
}
|
||||
|
||||
return actualTop
|
||||
}
|
||||
},
|
||||
|
||||
loadLightbox: ele => {
|
||||
const service = GLOBAL_CONFIG.lightbox
|
||||
|
||||
if (service === 'mediumZoom') {
|
||||
const zoom = mediumZoom(ele)
|
||||
zoom.on('open', e => {
|
||||
const photoBg = document.documentElement.getAttribute('data-theme') === 'dark' ? '#121212' : '#fff'
|
||||
zoom.update({
|
||||
background: photoBg
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (service === 'fancybox') {
|
||||
ele.forEach(i => {
|
||||
if (i.parentNode.tagName !== 'A') {
|
||||
const dataSrc = i.dataset.lazySrc || i.src
|
||||
const dataCaption = i.title || i.alt || ''
|
||||
btf.wrap(i, 'a', { href: dataSrc, 'data-fancybox': 'gallery', 'data-caption': dataCaption, 'data-thumb': dataSrc })
|
||||
}
|
||||
})
|
||||
|
||||
if (!window.fancyboxRun) {
|
||||
Fancybox.bind('[data-fancybox]', {
|
||||
Hash: false,
|
||||
Thumbs: {
|
||||
autoStart: false
|
||||
}
|
||||
})
|
||||
window.fancyboxRun = true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
initJustifiedGallery: function (selector) {
|
||||
selector.forEach(function (i) {
|
||||
if (!btf.isHidden(i)) {
|
||||
fjGallery(i, {
|
||||
itemSelector: '.fj-gallery-item',
|
||||
rowHeight: 220,
|
||||
gutter: 4,
|
||||
onJustify: function () {
|
||||
this.$container.style.opacity = '1'
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
updateAnchor: (anchor) => {
|
||||
if (anchor !== window.location.hash) {
|
||||
if (!anchor) anchor = location.pathname
|
||||
const title = GLOBAL_CONFIG_SITE.title
|
||||
window.history.replaceState({
|
||||
url: location.href,
|
||||
title: title
|
||||
}, title, anchor)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user