mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 20:30:53 +08:00
💥 支持雙評論系統配置/評論配置整理
✨ 增加mac light 代碼框 ✨ 增加文章過期提醒配置 ✨ 文章copyright 可單獨配置 ✨ card-category 中category名稱和數字限制一行顯示 ✨ 簡繁轉換優化,placeholder文字也會被轉換 🐛 修復配置PWA參數時,如果網站是子目錄時,會出現加載不到文件的bugs 調整當card-category有收縮按鈕時的顯示佈局
This commit is contained in:
@@ -9,12 +9,12 @@ $(function () {
|
||||
* 傳入 1 sidebar打開時
|
||||
* 傳入 2 正常狀態下
|
||||
*/
|
||||
var blogNameWidth = $('#blog_name').width()
|
||||
var menusWidth = $('.menus').width()
|
||||
var sidebarWidth = $('#sidebar').width()
|
||||
const blogNameWidth = $('#blog_name').width()
|
||||
const menusWidth = $('.menus').width()
|
||||
const sidebarWidth = $('#sidebar').width()
|
||||
|
||||
function isAdjust (n) {
|
||||
var t
|
||||
let t
|
||||
if (n === 1) {
|
||||
t = blogNameWidth + menusWidth > $nav.width() - sidebarWidth - 20
|
||||
} else if (n === 2) {
|
||||
@@ -106,7 +106,7 @@ $(function () {
|
||||
color: '#99a9bf',
|
||||
opacity: '1'
|
||||
})
|
||||
var isAdjustTimeCount = window.setInterval(function () {
|
||||
const isAdjustTimeCount = window.setInterval(function () {
|
||||
if ($nav.hasClass('fixed')) isAdjust(1)
|
||||
else isAdjust(2)
|
||||
}, 100)
|
||||
@@ -116,7 +116,7 @@ $(function () {
|
||||
}
|
||||
|
||||
$('#toggle-sidebar').on('click', function () {
|
||||
var isOpen = $(this).hasClass('on')
|
||||
const isOpen = $(this).hasClass('on')
|
||||
isOpen ? $(this).removeClass('on') : $(this).addClass('on')
|
||||
if (isOpen) {
|
||||
closeSidebar()
|
||||
@@ -130,10 +130,10 @@ $(function () {
|
||||
* 顯示menu和toc的sidebar
|
||||
*/
|
||||
|
||||
var $toggleMenu = $('.toggle-menu')
|
||||
var $mobileSidevarMenus = $('#mobile-sidebar-menus')
|
||||
var $mobileTocButton = $('#mobile-toc-button')
|
||||
var $menuMask = $('#menu_mask')
|
||||
const $toggleMenu = $('.toggle-menu')
|
||||
const $mobileSidebarMenus = $('#mobile-sidebar-menus')
|
||||
const $mobileTocButton = $('#mobile-toc-button')
|
||||
const $menuMask = $('#menu_mask')
|
||||
|
||||
function openMobileSidebar (name) {
|
||||
sidebarPaddingR()
|
||||
@@ -142,11 +142,11 @@ $(function () {
|
||||
|
||||
if (name === 'menu') {
|
||||
$toggleMenu.removeClass('close').addClass('open')
|
||||
$mobileSidevarMenus.css('transform', 'translate3d(-100%,0,0)')
|
||||
var $mobileSidevarMenusChild = $mobileSidevarMenus.children()
|
||||
for (let i = 0; i <= $mobileSidevarMenusChild.length; i++) {
|
||||
$mobileSidebarMenus.css('transform', 'translate3d(-100%,0,0)')
|
||||
const $mobileSidebarMenusChild = $mobileSidebarMenus.children()
|
||||
for (let i = 0; i <= $mobileSidebarMenusChild.length; i++) {
|
||||
const duration = i / 5 + 0.2
|
||||
$mobileSidevarMenusChild.eq(i).css('animation', 'sidebarItem ' + duration + 's')
|
||||
$mobileSidebarMenusChild.eq(i).css('animation', 'sidebarItem ' + duration + 's')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ $(function () {
|
||||
|
||||
if (name === 'menu') {
|
||||
$toggleMenu.removeClass('open').addClass('close')
|
||||
$mobileSidevarMenus.css('transform', '')
|
||||
$mobileSidebarMenus.css('transform', '')
|
||||
$('#mobile-sidebar-menus > div,#mobile-sidebar-menus > hr').css('animation', '')
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ $(function () {
|
||||
return true
|
||||
} else { // webkit - safari/chrome
|
||||
if (isSnackbar) {
|
||||
var bookmarkText = GLOBAL_CONFIG.Snackbar.bookmark.message_prev + ' ' + (navigator.userAgent.toLowerCase().indexOf('mac') !== -1 ? 'Command/Cmd' : 'CTRL') + '+ D ' + GLOBAL_CONFIG.Snackbar.bookmark.message_next + '.'
|
||||
const bookmarkText = GLOBAL_CONFIG.Snackbar.bookmark.message_prev + ' ' + (navigator.userAgent.toLowerCase().indexOf('mac') !== -1 ? 'Command/Cmd' : 'CTRL') + '+ D ' + GLOBAL_CONFIG.Snackbar.bookmark.message_next + '.'
|
||||
snackbarShow(bookmarkText)
|
||||
} else {
|
||||
alert(GLOBAL_CONFIG.bookmark.message_prev + ' ' + (navigator.userAgent.toLowerCase().indexOf('mac') !== -1 ? 'Command/Cmd' : 'CTRL') + '+ D ' + GLOBAL_CONFIG.bookmark.message_next + '.')
|
||||
@@ -261,7 +261,7 @@ $(function () {
|
||||
}
|
||||
|
||||
$(document).on('click', '.highlight-tools >.code-expand', function () {
|
||||
var $hideItem = $(this).parent().nextAll()
|
||||
const $hideItem = $(this).parent().nextAll()
|
||||
if ($(this).hasClass('code-closed')) {
|
||||
$hideItem.css('display', 'block')
|
||||
$(this).removeClass('code-closed')
|
||||
@@ -275,7 +275,7 @@ $(function () {
|
||||
* 代碼語言
|
||||
*/
|
||||
if (isHighlightLang) {
|
||||
var langNameIndex, langName
|
||||
let langNameIndex, langName
|
||||
$figureHighlight.each(function () {
|
||||
langNameIndex = langName = $(this).attr('class').split(' ')[1]
|
||||
if (langNameIndex === 'plain' || langNameIndex === undefined) langName = 'Code'
|
||||
@@ -289,7 +289,7 @@ $(function () {
|
||||
*/
|
||||
if (isHighlightCopy) {
|
||||
$highlightTools.append('<div class="copy-notice"></div><i class="fas fa-paste copy-button"></i>')
|
||||
var copy = function (text, ctx) {
|
||||
const copy = function (text, ctx) {
|
||||
if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
|
||||
try {
|
||||
document.execCommand('copy') // Security exception may be thrown by some browsers.
|
||||
@@ -337,14 +337,14 @@ $(function () {
|
||||
|
||||
// click events
|
||||
$(document).on('click', '.highlight-tools>.copy-button', function () {
|
||||
var $buttonParent = $(this).parents('figure.highlight')
|
||||
const $buttonParent = $(this).parents('figure.highlight')
|
||||
$buttonParent.addClass('copy-true')
|
||||
var selection = window.getSelection()
|
||||
var range = document.createRange()
|
||||
const selection = window.getSelection()
|
||||
const range = document.createRange()
|
||||
range.selectNodeContents($buttonParent.find('table .code pre')[0])
|
||||
selection.removeAllRanges()
|
||||
selection.addRange(range)
|
||||
var text = selection.toString()
|
||||
const text = selection.toString()
|
||||
copy(text, this)
|
||||
selection.removeAllRanges()
|
||||
$buttonParent.removeClass('copy-true')
|
||||
@@ -358,9 +358,9 @@ $(function () {
|
||||
function addPhotoFigcaption () {
|
||||
const images = $('#article-container img').not('.justified-gallery img')
|
||||
images.each(function (i, o) {
|
||||
var $this = $(o)
|
||||
const $this = $(o)
|
||||
if ($this.attr('alt')) {
|
||||
var t = $('<div class="img-alt is-center">' + $this.attr('alt') + '</div>')
|
||||
const t = $('<div class="img-alt is-center">' + $this.attr('alt') + '</div>')
|
||||
$this.after(t)
|
||||
}
|
||||
})
|
||||
@@ -370,11 +370,11 @@ $(function () {
|
||||
/**
|
||||
* justified-gallery 圖庫排版
|
||||
*/
|
||||
var $justifiedGallery = $('.justified-gallery')
|
||||
var isJustifiedGallery = false
|
||||
const $justifiedGallery = $('.justified-gallery')
|
||||
let isJustifiedGallery = false
|
||||
if ($justifiedGallery.length) {
|
||||
isJustifiedGallery = true
|
||||
var $imgList = $justifiedGallery.find('img')
|
||||
const $imgList = $justifiedGallery.find('img')
|
||||
$imgList.unwrap()
|
||||
if ($imgList.length) {
|
||||
$imgList.each(function (i, o) {
|
||||
@@ -386,29 +386,18 @@ $(function () {
|
||||
loadScript(`${GLOBAL_CONFIG.justifiedGallery.js}`, function () {
|
||||
initJustifiedGallery($justifiedGallery)
|
||||
})
|
||||
|
||||
var initJustifiedGallery = function (selector) {
|
||||
selector.each(function (i, o) {
|
||||
if ($(this).is(':visible')) {
|
||||
$(this).justifiedGallery({
|
||||
rowHeight: 220,
|
||||
margins: 4
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fancybox和 mediumZoom
|
||||
*/
|
||||
|
||||
var isMediumZoom = GLOBAL_CONFIG.medium_zoom
|
||||
var isFancybox = GLOBAL_CONFIG.fancybox
|
||||
const isMediumZoom = GLOBAL_CONFIG.medium_zoom
|
||||
const isFancybox = GLOBAL_CONFIG.fancybox
|
||||
if (isFancybox) {
|
||||
var images = $('#article-container img:not(.gallery-group-img)').not($('a>img'))
|
||||
const 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')
|
||||
const 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>`)
|
||||
})
|
||||
|
||||
@@ -422,7 +411,7 @@ $(function () {
|
||||
} else if (isMediumZoom) {
|
||||
const zoom = mediumZoom(document.querySelectorAll('#article-container :not(a)>img'))
|
||||
zoom.on('open', function (event) {
|
||||
var photoBg = $(document.documentElement).attr('data-theme') === 'dark' ? '#121212' : '#fff'
|
||||
const photoBg = $(document.documentElement).attr('data-theme') === 'dark' ? '#121212' : '#fff'
|
||||
zoom.update({
|
||||
background: photoBg
|
||||
})
|
||||
@@ -432,13 +421,13 @@ $(function () {
|
||||
/**
|
||||
* 滾動處理
|
||||
*/
|
||||
var initTop = 0
|
||||
var isChatShow = true
|
||||
var isChatBtnHide = typeof chatBtnHide === 'function'
|
||||
var isChatBtnShow = typeof chatBtnShow === 'function'
|
||||
let initTop = 0
|
||||
let isChatShow = true
|
||||
const isChatBtnHide = typeof chatBtnHide === 'function'
|
||||
const isChatBtnShow = typeof chatBtnShow === 'function'
|
||||
$(window).scroll(throttle(function (event) {
|
||||
var currentTop = $(this).scrollTop()
|
||||
var isDown = scrollDirection(currentTop)
|
||||
const currentTop = $(this).scrollTop()
|
||||
const isDown = scrollDirection(currentTop)
|
||||
if (currentTop > 56) {
|
||||
if (isDown) {
|
||||
if ($nav.hasClass('visible')) $nav.removeClass('visible')
|
||||
@@ -467,7 +456,7 @@ $(function () {
|
||||
|
||||
// find the scroll direction
|
||||
function scrollDirection (currentTop) {
|
||||
var result = currentTop > initTop // true is down & false is up
|
||||
const result = currentTop > initTop // true is down & false is up
|
||||
initTop = currentTop
|
||||
return result
|
||||
}
|
||||
@@ -488,7 +477,7 @@ $(function () {
|
||||
|
||||
// main of scroll
|
||||
$(window).scroll(throttle(function (event) {
|
||||
var currentTop = $(this).scrollTop()
|
||||
const currentTop = $(this).scrollTop()
|
||||
scrollPercent(currentTop)
|
||||
findHeadPosition(currentTop)
|
||||
autoScrollToc(currentTop)
|
||||
@@ -505,20 +494,20 @@ $(function () {
|
||||
})
|
||||
|
||||
// expand toc-item
|
||||
var expandToc = function ($item) {
|
||||
const expandToc = function ($item) {
|
||||
if ($item.is(':visible')) {
|
||||
return
|
||||
}
|
||||
$item.fadeIn(400)
|
||||
}
|
||||
|
||||
var scrollPercent = function (currentTop) {
|
||||
var docHeight = $('#article-container').height()
|
||||
var winHeight = $(window).height()
|
||||
var contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : ($(document).height() - winHeight)
|
||||
var scrollPercent = (currentTop) / (contentMath)
|
||||
var scrollPercentRounded = Math.round(scrollPercent * 100)
|
||||
var percentage = (scrollPercentRounded > 100) ? 100
|
||||
const scrollPercent = function (currentTop) {
|
||||
const docHeight = $('#article-container').height()
|
||||
const winHeight = $(window).height()
|
||||
const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : ($(document).height() - winHeight)
|
||||
const scrollPercent = (currentTop) / (contentMath)
|
||||
const scrollPercentRounded = Math.round(scrollPercent * 100)
|
||||
const percentage = (scrollPercentRounded > 100) ? 100
|
||||
: (scrollPercentRounded <= 0) ? 0
|
||||
: scrollPercentRounded
|
||||
$('.progress-num').text(percentage)
|
||||
@@ -528,8 +517,8 @@ $(function () {
|
||||
}
|
||||
|
||||
// anchor
|
||||
var isanchor = GLOBAL_CONFIG.isanchor
|
||||
var updateAnchor = function (anchor) {
|
||||
const isanchor = GLOBAL_CONFIG.isanchor
|
||||
const updateAnchor = function (anchor) {
|
||||
if (window.history.replaceState && anchor !== window.location.hash) {
|
||||
window.history.replaceState(undefined, undefined, anchor)
|
||||
}
|
||||
@@ -539,17 +528,17 @@ $(function () {
|
||||
// DOM Hierarchy:
|
||||
// ol.toc > (li.toc-item, ...)
|
||||
// li.toc-item > (a.toc-link, ol.toc-child > (li.toc-item, ...))
|
||||
var findHeadPosition = function (top) {
|
||||
const findHeadPosition = function (top) {
|
||||
// assume that we are not in the post page if no TOC link be found,
|
||||
// thus no need to update the status
|
||||
if ($('.toc-link').length === 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
var list = $('#article-container').find('h1,h2,h3,h4,h5,h6')
|
||||
var currentId = ''
|
||||
const list = $('#article-container').find('h1,h2,h3,h4,h5,h6')
|
||||
let currentId = ''
|
||||
list.each(function () {
|
||||
var head = $(this)
|
||||
const head = $(this)
|
||||
if (top > head.offset().top - 25) {
|
||||
currentId = '#' + $(this).attr('id')
|
||||
}
|
||||
@@ -560,20 +549,20 @@ $(function () {
|
||||
$('.toc-child').hide()
|
||||
}
|
||||
|
||||
var currentActive = $('.toc-link.active')
|
||||
const currentActive = $('.toc-link.active')
|
||||
if (currentId && currentActive.attr('href') !== currentId) {
|
||||
if (isanchor) updateAnchor(currentId)
|
||||
|
||||
$('.toc-link').removeClass('active')
|
||||
|
||||
var _this = $('.toc-link[href="' + currentId + '"]')
|
||||
const _this = $('.toc-link[href="' + currentId + '"]')
|
||||
_this.addClass('active')
|
||||
|
||||
var parents = _this.parents('.toc-child')
|
||||
const parents = _this.parents('.toc-child')
|
||||
// Returned list is in reverse order of the DOM elements
|
||||
// Thus `parents.last()` is the outermost .toc-child container
|
||||
// i.e. list of subsections
|
||||
var topLink = (parents.length > 0) ? parents.last() : _this
|
||||
const topLink = (parents.length > 0) ? parents.last() : _this
|
||||
expandToc(topLink.closest('.toc-item').find('.toc-child'))
|
||||
topLink
|
||||
// Find all top-level .toc-item containers, i.e. sections
|
||||
@@ -584,10 +573,10 @@ $(function () {
|
||||
}
|
||||
}
|
||||
|
||||
var autoScrollToc = function (currentTop) {
|
||||
const autoScrollToc = function (currentTop) {
|
||||
if ($('.toc-link').hasClass('active')) {
|
||||
var activePosition = $('.active').offset().top
|
||||
var sidebarScrolltop = $('#sidebar .sidebar-toc__content').scrollTop()
|
||||
const activePosition = $('.active').offset().top
|
||||
const sidebarScrolltop = $('#sidebar .sidebar-toc__content').scrollTop()
|
||||
if (activePosition > (currentTop + $(window).height() - 100)) {
|
||||
$('#sidebar .sidebar-toc__content').scrollTop(sidebarScrolltop + 100)
|
||||
}
|
||||
@@ -631,7 +620,7 @@ $(function () {
|
||||
})
|
||||
|
||||
$(window).on('touchmove', function (e) {
|
||||
var $menusChild = $('#nav .menus_item_child')
|
||||
const $menusChild = $('#nav .menus_item_child')
|
||||
if ($menusChild.is(':visible')) {
|
||||
$menusChild.css('display', 'none')
|
||||
}
|
||||
@@ -651,7 +640,7 @@ $(function () {
|
||||
/**
|
||||
* 複製時加上版權信息
|
||||
*/
|
||||
var copyright = GLOBAL_CONFIG.copyright
|
||||
const copyright = GLOBAL_CONFIG.copyright
|
||||
if (copyright !== undefined) {
|
||||
document.body.oncopy = function (event) {
|
||||
event.preventDefault()
|
||||
@@ -677,9 +666,9 @@ $(function () {
|
||||
/**
|
||||
* Darkmode
|
||||
*/
|
||||
var $darkModeButtom = $('#darkmode')
|
||||
const $darkModeButtom = $('#darkmode')
|
||||
function switchReadMode () {
|
||||
var nowMode = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light'
|
||||
const nowMode = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light'
|
||||
if (nowMode === 'light') {
|
||||
activateDarkMode()
|
||||
Cookies.set('theme', 'dark', 2)
|
||||
@@ -701,26 +690,24 @@ $(function () {
|
||||
*/
|
||||
if (GLOBAL_CONFIG.runtime) {
|
||||
// get user config
|
||||
var $runtimeCount = $('#webinfo-runtime-count')
|
||||
var startDate = $runtimeCount.attr('publish_date')
|
||||
var showDateTime = function () {
|
||||
var BirthDay = new Date(startDate)
|
||||
var today = new Date()
|
||||
var timeold = (today.getTime() - BirthDay.getTime())
|
||||
var daysold = Math.floor(timeold / (24 * 60 * 60 * 1000))
|
||||
const $runtimeCount = $('#webinfo-runtime-count')
|
||||
const startDate = $runtimeCount.attr('publish_date')
|
||||
const showDateTime = function () {
|
||||
const BirthDay = new Date(startDate)
|
||||
const today = new Date()
|
||||
const timeold = (today.getTime() - BirthDay.getTime())
|
||||
const daysold = Math.floor(timeold / (24 * 60 * 60 * 1000))
|
||||
$runtimeCount.text(daysold + ' ' + GLOBAL_CONFIG.runtime_unit)
|
||||
}
|
||||
var interval
|
||||
showDateTime()
|
||||
clearInterval(interval)
|
||||
interval = setInterval(showDateTime, 10000)
|
||||
setInterval(showDateTime, 10000)
|
||||
}
|
||||
|
||||
/**
|
||||
* table overflow
|
||||
*/
|
||||
|
||||
var $table = $('#article-container table').not($('figure.highlight > table'))
|
||||
const $table = $('#article-container table').not($('figure.highlight > table'))
|
||||
$table.each(function () {
|
||||
$(this).wrap('<div class="table-wrap"></div>')
|
||||
})
|
||||
@@ -730,14 +717,14 @@ $(function () {
|
||||
*/
|
||||
if (GLOBAL_CONFIG.baiduPush) {
|
||||
(function () {
|
||||
var bp = document.createElement('script')
|
||||
var curProtocol = window.location.protocol.split(':')[0]
|
||||
const bp = document.createElement('script')
|
||||
const curProtocol = window.location.protocol.split(':')[0]
|
||||
if (curProtocol === 'https') {
|
||||
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'
|
||||
} else {
|
||||
bp.src = 'http://push.zhanzhang.baidu.com/push.js'
|
||||
}
|
||||
var s = document.getElementsByTagName('script')[0]
|
||||
const s = document.getElementsByTagName('script')[0]
|
||||
s.parentNode.insertBefore(bp, s)
|
||||
})()
|
||||
}
|
||||
@@ -745,11 +732,11 @@ $(function () {
|
||||
/**
|
||||
* tag-hide
|
||||
*/
|
||||
var $hideInline = $('.hide-button')
|
||||
const $hideInline = $('.hide-button')
|
||||
if ($hideInline.length) {
|
||||
$hideInline.on('click', function (e) {
|
||||
var $this = $(this)
|
||||
var $hideContent = $(this).next('.hide-content')
|
||||
const $this = $(this)
|
||||
const $hideContent = $(this).next('.hide-content')
|
||||
$this.toggleClass('open')
|
||||
$hideContent.toggle()
|
||||
if ($this.hasClass('open')) {
|
||||
@@ -779,13 +766,51 @@ $(function () {
|
||||
}
|
||||
})
|
||||
|
||||
var $cardCategory = $('.card-category-list-item.parent a')
|
||||
const $cardCategory = $('.card-category-list-item.parent a')
|
||||
$cardCategory.on('click', function (e) {
|
||||
if ($(event.target).hasClass('card-category-list-icon')) {
|
||||
var $this = $(this)
|
||||
const $this = $(this)
|
||||
$this.find('.card-category-list-icon').toggleClass('expand')
|
||||
$this.parent().next().toggle()
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
let switchDone = false
|
||||
$('#switch-comments-btn').change(function () {
|
||||
$('#post-comment > .comment-wrap > div').each(function () {
|
||||
if ($(this).is(':visible')) {
|
||||
$(this).hide()
|
||||
} else {
|
||||
$(this).css({
|
||||
display: 'block',
|
||||
animation: 'tabshow .5s'
|
||||
})
|
||||
}
|
||||
})
|
||||
if (!switchDone && typeof loadOtherComment === 'function') {
|
||||
switchDone = true
|
||||
loadOtherComment()
|
||||
}
|
||||
})
|
||||
|
||||
if (GLOBAL_CONFIG_SITE.isPost && GLOBAL_CONFIG.noticeOutdate !== undefined) {
|
||||
const data = GLOBAL_CONFIG.noticeOutdate
|
||||
const diffDate = function (d) {
|
||||
const dateNow = new Date()
|
||||
const datePost = new Date(d.replace(/-/g, '/'))
|
||||
const dateDiff = dateNow.getTime() - datePost.getTime()
|
||||
const dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000))
|
||||
return dayDiff
|
||||
}
|
||||
var diffDay = diffDate(GLOBAL_CONFIG_SITE.postUpdate)
|
||||
if (diffDay >= data.limitDay) {
|
||||
const code = `<div class="post-outdate-notice">${data.messagePrev + ' ' + diffDay + ' ' + data.messageNext}</div>`
|
||||
if (data.position === 'top') {
|
||||
$('#article-container').prepend(code)
|
||||
} else {
|
||||
$('#article-container').append(code)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -13,7 +13,7 @@ $(function () {
|
||||
})
|
||||
})
|
||||
|
||||
var closeSearch = function () {
|
||||
const closeSearch = function () {
|
||||
$('body').css('width', '')
|
||||
$('body').css('overflow', '')
|
||||
$('.search-dialog').css({
|
||||
@@ -33,13 +33,13 @@ $(function () {
|
||||
}
|
||||
$('.search-mask, .search-close-button').on('click touchstart', closeSearch)
|
||||
|
||||
var algolia = GLOBAL_CONFIG.algolia
|
||||
var isAlgoliaValid = algolia.appId && algolia.apiKey && algolia.indexName
|
||||
const algolia = GLOBAL_CONFIG.algolia
|
||||
const isAlgoliaValid = algolia.appId && algolia.apiKey && algolia.indexName
|
||||
if (!isAlgoliaValid) {
|
||||
return console.error('Algolia setting is invalid!')
|
||||
}
|
||||
|
||||
var search = instantsearch({
|
||||
const search = instantsearch({
|
||||
appId: algolia.appId,
|
||||
apiKey: algolia.apiKey,
|
||||
indexName: algolia.indexName,
|
||||
@@ -47,7 +47,7 @@ $(function () {
|
||||
hitsPerPage: algolia.hits.per_page || 10
|
||||
},
|
||||
searchFunction: function (helper) {
|
||||
var searchInput = $('#algolia-search-input').find('input')
|
||||
const searchInput = $('#algolia-search-input').find('input')
|
||||
|
||||
if (searchInput.val()) {
|
||||
helper.search()
|
||||
@@ -68,7 +68,7 @@ $(function () {
|
||||
container: '#algolia-hits',
|
||||
templates: {
|
||||
item: function (data) {
|
||||
var link = data.permalink ? data.permalink : (GLOBAL_CONFIG.root + data.path)
|
||||
const link = data.permalink ? data.permalink : (GLOBAL_CONFIG.root + data.path)
|
||||
return (
|
||||
'<a href="' + link + '" class="algolia-hit-item-link">' +
|
||||
data._highlightResult.title.value +
|
||||
@@ -94,7 +94,7 @@ $(function () {
|
||||
container: '#algolia-stats',
|
||||
templates: {
|
||||
body: function (data) {
|
||||
var stats = GLOBAL_CONFIG.algolia.languages.hits_stats
|
||||
const stats = GLOBAL_CONFIG.algolia.languages.hits_stats
|
||||
.replace(/\$\{hits}/, data.nbHits)
|
||||
.replace(/\$\{time}/, data.processingTimeMS)
|
||||
return (
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
$(function () {
|
||||
var loadFlag = false
|
||||
let loadFlag = false
|
||||
$('a.social-icon.search').on('click', function () {
|
||||
$('body').css({
|
||||
width: '100%',
|
||||
@@ -22,7 +22,7 @@ $(function () {
|
||||
})
|
||||
})
|
||||
|
||||
var closeSearch = function () {
|
||||
const closeSearch = function () {
|
||||
$('body').css('width', '')
|
||||
$('body').css('overflow', '')
|
||||
$('.search-dialog').css({
|
||||
@@ -48,7 +48,7 @@ $(function () {
|
||||
dataType: 'xml',
|
||||
success: function (xmlResponse) {
|
||||
// get the contents from search data
|
||||
var datas = $('entry', xmlResponse).map(function () {
|
||||
const datas = $('entry', xmlResponse).map(function () {
|
||||
return {
|
||||
title: $('title', this).text(),
|
||||
content: $('content', this).text(),
|
||||
@@ -56,29 +56,29 @@ $(function () {
|
||||
}
|
||||
}).get()
|
||||
|
||||
var $input = $('#local-search-input input')[0]
|
||||
var $resultContent = $('#local-hits')[0]
|
||||
const $input = $('#local-search-input input')[0]
|
||||
const $resultContent = $('#local-hits')[0]
|
||||
$input.addEventListener('input', function () {
|
||||
var str = '<div class="search-result-list">'
|
||||
var keywords = this.value.trim().toLowerCase().split(/[\s]+/)
|
||||
let str = '<div class="search-result-list">'
|
||||
const keywords = this.value.trim().toLowerCase().split(/[\s]+/)
|
||||
$resultContent.innerHTML = ''
|
||||
if (this.value.trim().length <= 0) {
|
||||
$('.local-search-stats__hr').hide()
|
||||
return
|
||||
}
|
||||
var count = 0
|
||||
let count = 0
|
||||
// perform local searching
|
||||
datas.forEach(function (data) {
|
||||
var isMatch = true
|
||||
let isMatch = true
|
||||
if (!data.title || data.title.trim() === '') {
|
||||
data.title = 'Untitled'
|
||||
}
|
||||
var dataTitle = data.title.trim().toLowerCase()
|
||||
var dataContent = data.content.trim().replace(/<[^>]+>/g, '').toLowerCase()
|
||||
var dataUrl = data.url
|
||||
var indexTitle = -1
|
||||
var indexContent = -1
|
||||
var firstOccur = -1
|
||||
let dataTitle = data.title.trim().toLowerCase()
|
||||
const dataContent = data.content.trim().replace(/<[^>]+>/g, '').toLowerCase()
|
||||
const dataUrl = 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) {
|
||||
@@ -101,11 +101,11 @@ $(function () {
|
||||
|
||||
// show search results
|
||||
if (isMatch) {
|
||||
var content = data.content.trim().replace(/<[^>]+>/g, '')
|
||||
const content = data.content.trim().replace(/<[^>]+>/g, '')
|
||||
if (firstOccur >= 0) {
|
||||
// cut out 130 characters
|
||||
var start = firstOccur - 30
|
||||
var end = firstOccur + 100
|
||||
let start = firstOccur - 30
|
||||
let end = firstOccur + 100
|
||||
|
||||
if (start < 0) {
|
||||
start = 0
|
||||
@@ -119,11 +119,11 @@ $(function () {
|
||||
end = content.length
|
||||
}
|
||||
|
||||
var matchContent = content.substring(start, end)
|
||||
let matchContent = content.substring(start, end)
|
||||
|
||||
// highlight all keywords
|
||||
keywords.forEach(function (keyword) {
|
||||
var regS = new RegExp(keyword, 'gi')
|
||||
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>')
|
||||
})
|
||||
|
||||
660
source/js/third-party/piao.js
vendored
660
source/js/third-party/piao.js
vendored
@@ -1,334 +1,332 @@
|
||||
|
||||
(function (name, factory) {
|
||||
if (typeof window === "object") {
|
||||
window[name] = factory()
|
||||
}
|
||||
})("Ribbons", function () {
|
||||
var _w = window,
|
||||
_b = document.body,
|
||||
_d = document.documentElement;
|
||||
var random = function () {
|
||||
if (arguments.length === 1) {
|
||||
if (Array.isArray(arguments[0])) {
|
||||
var index = Math.round(random(0, arguments[0].length - 1));
|
||||
return arguments[0][index]
|
||||
}
|
||||
return random(0, arguments[0])
|
||||
} else if (arguments.length === 2) {
|
||||
return Math.random() * (arguments[1] - arguments[0]) + arguments[0]
|
||||
}
|
||||
return 0
|
||||
};
|
||||
var screenInfo = function (e) {
|
||||
var width = Math.max(0, _w.innerWidth || _d.clientWidth || _b.clientWidth || 0),
|
||||
height = Math.max(0, _w.innerHeight || _d.clientHeight || _b.clientHeight || 0),
|
||||
scrollx = Math.max(0, _w.pageXOffset || _d.scrollLeft || _b.scrollLeft || 0) - (_d.clientLeft || 0),
|
||||
scrolly = Math.max(0, _w.pageYOffset || _d.scrollTop || _b.scrollTop || 0) - (_d.clientTop || 0);
|
||||
return {
|
||||
width: width,
|
||||
height: height,
|
||||
ratio: width / height,
|
||||
centerx: width / 2,
|
||||
centery: height / 2,
|
||||
scrollx: scrollx,
|
||||
scrolly: scrolly
|
||||
}
|
||||
};
|
||||
var mouseInfo = function (e) {
|
||||
var screen = screenInfo(e),
|
||||
mousex = e ? Math.max(0, e.pageX || e.clientX || 0) : 0,
|
||||
mousey = e ? Math.max(0, e.pageY || e.clientY || 0) : 0;
|
||||
return {
|
||||
mousex: mousex,
|
||||
mousey: mousey,
|
||||
centerx: mousex - screen.width / 2,
|
||||
centery: mousey - screen.height / 2
|
||||
}
|
||||
};
|
||||
var Point = function (x, y) {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.set(x, y)
|
||||
};
|
||||
Point.prototype = {
|
||||
constructor: Point,
|
||||
set: function (x, y) {
|
||||
this.x = x || 0;
|
||||
this.y = y || 0
|
||||
},
|
||||
copy: function (point) {
|
||||
this.x = point.x || 0;
|
||||
this.y = point.y || 0;
|
||||
return this
|
||||
},
|
||||
multiply: function (x, y) {
|
||||
this.x *= x || 1;
|
||||
this.y *= y || 1;
|
||||
return this
|
||||
},
|
||||
divide: function (x, y) {
|
||||
this.x /= x || 1;
|
||||
this.y /= y || 1;
|
||||
return this
|
||||
},
|
||||
add: function (x, y) {
|
||||
this.x += x || 0;
|
||||
this.y += y || 0;
|
||||
return this
|
||||
},
|
||||
subtract: function (x, y) {
|
||||
this.x -= x || 0;
|
||||
this.y -= y || 0;
|
||||
return this
|
||||
},
|
||||
clampX: function (min, max) {
|
||||
this.x = Math.max(min, Math.min(this.x, max));
|
||||
return this
|
||||
},
|
||||
clampY: function (min, max) {
|
||||
this.y = Math.max(min, Math.min(this.y, max));
|
||||
return this
|
||||
},
|
||||
flipX: function () {
|
||||
this.x *= -1;
|
||||
return this
|
||||
},
|
||||
flipY: function () {
|
||||
this.y *= -1;
|
||||
return this
|
||||
}
|
||||
};
|
||||
var Factory = function (options) {
|
||||
this._canvas = null;
|
||||
this._context = null;
|
||||
this._sto = null;
|
||||
this._width = 0;
|
||||
this._height = 0;
|
||||
this._scroll = 0;
|
||||
this._ribbons = [];
|
||||
this._options = {
|
||||
colorSaturation: "80%",
|
||||
colorBrightness: "60%",
|
||||
colorAlpha: 0.65,
|
||||
colorCycleSpeed: 6,
|
||||
verticalPosition: "center",
|
||||
horizontalSpeed: 150,
|
||||
ribbonCount: 5,
|
||||
strokeSize: 5,
|
||||
parallaxAmount: -0.5,
|
||||
animateSections: true
|
||||
};
|
||||
this._onDraw = this._onDraw.bind(this);
|
||||
this._onResize = this._onResize.bind(this);
|
||||
this._onScroll = this._onScroll.bind(this);
|
||||
this.setOptions(options);
|
||||
this.init()
|
||||
};
|
||||
Factory.prototype = {
|
||||
constructor: Factory,
|
||||
setOptions: function (options) {
|
||||
if (typeof options === "object") {
|
||||
for (var key in options) {
|
||||
if (options.hasOwnProperty(key)) {
|
||||
this._options[key] = options[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
init: function () {
|
||||
try {
|
||||
this._canvas = document.createElement("canvas");
|
||||
this._canvas.style["display"] = "block";
|
||||
this._canvas.style["position"] = "fixed";
|
||||
this._canvas.style["margin"] = "0";
|
||||
this._canvas.style["padding"] = "0";
|
||||
this._canvas.style["border"] = "0";
|
||||
this._canvas.style["outline"] = "0";
|
||||
this._canvas.style["left"] = "0";
|
||||
this._canvas.style["top"] = "0";
|
||||
this._canvas.style["width"] = "100%";
|
||||
this._canvas.style["height"] = "100%";
|
||||
this._canvas.style["z-index"] = "-1";
|
||||
this._onResize();
|
||||
this._context = this._canvas.getContext("2d");
|
||||
this._context.clearRect(0, 0, this._width, this._height);
|
||||
this._context.globalAlpha = this._options.colorAlpha;
|
||||
window.addEventListener("resize", this._onResize);
|
||||
window.addEventListener("scroll", this._onScroll);
|
||||
document.body.appendChild(this._canvas)
|
||||
} catch (e) {
|
||||
console.warn("Canvas Context Error: " + e.toString());
|
||||
return
|
||||
}
|
||||
this._onDraw()
|
||||
},
|
||||
addRibbon: function () {
|
||||
var dir = Math.round(random(1, 9)) > 5 ? "right" : "left",
|
||||
stop = 1000,
|
||||
hide = 200,
|
||||
min = 0 - hide,
|
||||
max = this._width + hide,
|
||||
movex = 0,
|
||||
movey = 0,
|
||||
startx = dir === "right" ? min : max,
|
||||
starty = Math.round(random(0, this._height));
|
||||
if (/^(top|min)$/i.test(this._options.verticalPosition)) {
|
||||
starty = 0 + hide
|
||||
} else if (/^(middle|center)$/i.test(this._options.verticalPosition)) {
|
||||
starty = this._height / 2
|
||||
} else if (/^(bottom|max)$/i.test(this._options.verticalPosition)) {
|
||||
starty = this._height - hide
|
||||
}
|
||||
var ribbon = [],
|
||||
point1 = new Point(startx, starty),
|
||||
point2 = new Point(startx, starty),
|
||||
point3 = null,
|
||||
color = Math.round(random(0, 360)),
|
||||
delay = 0;
|
||||
while (true) {
|
||||
if (stop <= 0) break;
|
||||
stop--;
|
||||
movex = Math.round((Math.random() * 1 - 0.2) * this._options.horizontalSpeed);
|
||||
movey = Math.round((Math.random() * 1 - 0.5) * (this._height * 0.25));
|
||||
point3 = new Point();
|
||||
point3.copy(point2);
|
||||
if (dir === "right") {
|
||||
point3.add(movex, movey);
|
||||
if (point2.x >= max) break
|
||||
} else if (dir === "left") {
|
||||
point3.subtract(movex, movey);
|
||||
if (point2.x <= min) break
|
||||
}
|
||||
ribbon.push({
|
||||
point1: new Point(point1.x, point1.y),
|
||||
point2: new Point(point2.x, point2.y),
|
||||
point3: point3,
|
||||
color: color,
|
||||
delay: delay,
|
||||
dir: dir,
|
||||
alpha: 0,
|
||||
phase: 0
|
||||
});
|
||||
point1.copy(point2);
|
||||
point2.copy(point3);
|
||||
delay += 4;
|
||||
color += this._options.colorCycleSpeed
|
||||
}
|
||||
this._ribbons.push(ribbon)
|
||||
},
|
||||
_drawRibbonSection: function (section) {
|
||||
if (section) {
|
||||
if (section.phase >= 1 && section.alpha <= 0) {
|
||||
return true
|
||||
}
|
||||
if (section.delay <= 0) {
|
||||
section.phase += 0.02;
|
||||
section.alpha = Math.sin(section.phase) * 1;
|
||||
section.alpha = section.alpha <= 0 ? 0 : section.alpha;
|
||||
section.alpha = section.alpha >= 1 ? 1 : section.alpha;
|
||||
if (this._options.animateSections) {
|
||||
var mod = Math.sin(1 + section.phase * Math.PI / 2) * 0.1;
|
||||
if (section.dir === "right") {
|
||||
section.point1.add(mod, 0);
|
||||
section.point2.add(mod, 0);
|
||||
section.point3.add(mod, 0)
|
||||
} else {
|
||||
section.point1.subtract(mod, 0);
|
||||
section.point2.subtract(mod, 0);
|
||||
section.point3.subtract(mod, 0)
|
||||
}
|
||||
section.point1.add(0, mod);
|
||||
section.point2.add(0, mod);
|
||||
section.point3.add(0, mod)
|
||||
}
|
||||
} else {
|
||||
section.delay -= 0.5
|
||||
}
|
||||
var s = this._options.colorSaturation,
|
||||
l = this._options.colorBrightness,
|
||||
c = "hsla(" + section.color + ", " + s + ", " + l + ", " + section.alpha + " )";
|
||||
this._context.save();
|
||||
if (this._options.parallaxAmount !== 0) {
|
||||
this._context.translate(0, this._scroll * this._options.parallaxAmount)
|
||||
}
|
||||
this._context.beginPath();
|
||||
this._context.moveTo(section.point1.x, section.point1.y);
|
||||
this._context.lineTo(section.point2.x, section.point2.y);
|
||||
this._context.lineTo(section.point3.x, section.point3.y);
|
||||
this._context.fillStyle = c;
|
||||
this._context.fill();
|
||||
if (this._options.strokeSize > 0) {
|
||||
this._context.lineWidth = this._options.strokeSize;
|
||||
this._context.strokeStyle = c;
|
||||
this._context.lineCap = "round";
|
||||
this._context.stroke()
|
||||
}
|
||||
this._context.restore()
|
||||
}
|
||||
return false
|
||||
},
|
||||
_onDraw: function () {
|
||||
for (var i = 0, t = this._ribbons.length; i < t; ++i) {
|
||||
if (!this._ribbons[i]) {
|
||||
this._ribbons.splice(i, 1)
|
||||
}
|
||||
}
|
||||
this._context.clearRect(0, 0, this._width, this._height);
|
||||
for (var a = 0; a < this._ribbons.length; ++a) {
|
||||
var ribbon = this._ribbons[a],
|
||||
numSections = ribbon.length,
|
||||
numDone = 0;
|
||||
for (var b = 0; b < numSections; ++b) {
|
||||
if (this._drawRibbonSection(ribbon[b])) {
|
||||
numDone++
|
||||
}
|
||||
}
|
||||
if (numDone >= numSections) {
|
||||
this._ribbons[a] = null
|
||||
}
|
||||
}
|
||||
if (this._ribbons.length < this._options.ribbonCount) {
|
||||
this.addRibbon()
|
||||
}
|
||||
requestAnimationFrame(this._onDraw)
|
||||
},
|
||||
_onResize: function (e) {
|
||||
var screen = screenInfo(e);
|
||||
this._width = screen.width;
|
||||
this._height = screen.height;
|
||||
if (this._canvas) {
|
||||
this._canvas.width = this._width;
|
||||
this._canvas.height = this._height;
|
||||
if (this._context) {
|
||||
this._context.globalAlpha = this._options.colorAlpha
|
||||
}
|
||||
}
|
||||
},
|
||||
_onScroll: function (e) {
|
||||
var screen = screenInfo(e);
|
||||
this._scroll = screen.scrolly
|
||||
}
|
||||
};
|
||||
return Factory
|
||||
});
|
||||
(function (name, factory) {
|
||||
if (typeof window === 'object') {
|
||||
window[name] = factory()
|
||||
}
|
||||
})('Ribbons', function () {
|
||||
var _w = window
|
||||
var _b = document.body
|
||||
var _d = document.documentElement
|
||||
var random = function () {
|
||||
if (arguments.length === 1) {
|
||||
if (Array.isArray(arguments[0])) {
|
||||
var index = Math.round(random(0, arguments[0].length - 1))
|
||||
return arguments[0][index]
|
||||
}
|
||||
return random(0, arguments[0])
|
||||
} else if (arguments.length === 2) {
|
||||
return Math.random() * (arguments[1] - arguments[0]) + arguments[0]
|
||||
}
|
||||
return 0
|
||||
}
|
||||
var screenInfo = function (e) {
|
||||
var width = Math.max(0, _w.innerWidth || _d.clientWidth || _b.clientWidth || 0)
|
||||
var height = Math.max(0, _w.innerHeight || _d.clientHeight || _b.clientHeight || 0)
|
||||
var scrollx = Math.max(0, _w.pageXOffset || _d.scrollLeft || _b.scrollLeft || 0) - (_d.clientLeft || 0)
|
||||
var scrolly = Math.max(0, _w.pageYOffset || _d.scrollTop || _b.scrollTop || 0) - (_d.clientTop || 0)
|
||||
return {
|
||||
width: width,
|
||||
height: height,
|
||||
ratio: width / height,
|
||||
centerx: width / 2,
|
||||
centery: height / 2,
|
||||
scrollx: scrollx,
|
||||
scrolly: scrolly
|
||||
}
|
||||
}
|
||||
var mouseInfo = function (e) {
|
||||
var screen = screenInfo(e)
|
||||
var mousex = e ? Math.max(0, e.pageX || e.clientX || 0) : 0
|
||||
var mousey = e ? Math.max(0, e.pageY || e.clientY || 0) : 0
|
||||
return {
|
||||
mousex: mousex,
|
||||
mousey: mousey,
|
||||
centerx: mousex - screen.width / 2,
|
||||
centery: mousey - screen.height / 2
|
||||
}
|
||||
}
|
||||
var Point = function (x, y) {
|
||||
this.x = 0
|
||||
this.y = 0
|
||||
this.set(x, y)
|
||||
}
|
||||
Point.prototype = {
|
||||
constructor: Point,
|
||||
set: function (x, y) {
|
||||
this.x = x || 0
|
||||
this.y = y || 0
|
||||
},
|
||||
copy: function (point) {
|
||||
this.x = point.x || 0
|
||||
this.y = point.y || 0
|
||||
return this
|
||||
},
|
||||
multiply: function (x, y) {
|
||||
this.x *= x || 1
|
||||
this.y *= y || 1
|
||||
return this
|
||||
},
|
||||
divide: function (x, y) {
|
||||
this.x /= x || 1
|
||||
this.y /= y || 1
|
||||
return this
|
||||
},
|
||||
add: function (x, y) {
|
||||
this.x += x || 0
|
||||
this.y += y || 0
|
||||
return this
|
||||
},
|
||||
subtract: function (x, y) {
|
||||
this.x -= x || 0
|
||||
this.y -= y || 0
|
||||
return this
|
||||
},
|
||||
clampX: function (min, max) {
|
||||
this.x = Math.max(min, Math.min(this.x, max))
|
||||
return this
|
||||
},
|
||||
clampY: function (min, max) {
|
||||
this.y = Math.max(min, Math.min(this.y, max))
|
||||
return this
|
||||
},
|
||||
flipX: function () {
|
||||
this.x *= -1
|
||||
return this
|
||||
},
|
||||
flipY: function () {
|
||||
this.y *= -1
|
||||
return this
|
||||
}
|
||||
}
|
||||
var Factory = function (options) {
|
||||
this._canvas = null
|
||||
this._context = null
|
||||
this._sto = null
|
||||
this._width = 0
|
||||
this._height = 0
|
||||
this._scroll = 0
|
||||
this._ribbons = []
|
||||
this._options = {
|
||||
colorSaturation: '80%',
|
||||
colorBrightness: '60%',
|
||||
colorAlpha: 0.65,
|
||||
colorCycleSpeed: 6,
|
||||
verticalPosition: 'center',
|
||||
horizontalSpeed: 150,
|
||||
ribbonCount: 5,
|
||||
strokeSize: 5,
|
||||
parallaxAmount: -0.5,
|
||||
animateSections: true
|
||||
}
|
||||
this._onDraw = this._onDraw.bind(this)
|
||||
this._onResize = this._onResize.bind(this)
|
||||
this._onScroll = this._onScroll.bind(this)
|
||||
this.setOptions(options)
|
||||
this.init()
|
||||
}
|
||||
Factory.prototype = {
|
||||
constructor: Factory,
|
||||
setOptions: function (options) {
|
||||
if (typeof options === 'object') {
|
||||
for (var key in options) {
|
||||
if (options.hasOwnProperty(key)) {
|
||||
this._options[key] = options[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
init: function () {
|
||||
try {
|
||||
this._canvas = document.createElement('canvas')
|
||||
this._canvas.style.display = 'block'
|
||||
this._canvas.style.position = 'fixed'
|
||||
this._canvas.style.margin = '0'
|
||||
this._canvas.style.padding = '0'
|
||||
this._canvas.style.border = '0'
|
||||
this._canvas.style.outline = '0'
|
||||
this._canvas.style.left = '0'
|
||||
this._canvas.style.top = '0'
|
||||
this._canvas.style.width = '100%'
|
||||
this._canvas.style.height = '100%'
|
||||
this._canvas.style['z-index'] = '-1'
|
||||
this._onResize()
|
||||
this._context = this._canvas.getContext('2d')
|
||||
this._context.clearRect(0, 0, this._width, this._height)
|
||||
this._context.globalAlpha = this._options.colorAlpha
|
||||
window.addEventListener('resize', this._onResize)
|
||||
window.addEventListener('scroll', this._onScroll)
|
||||
document.body.appendChild(this._canvas)
|
||||
} catch (e) {
|
||||
console.warn('Canvas Context Error: ' + e.toString())
|
||||
return
|
||||
}
|
||||
this._onDraw()
|
||||
},
|
||||
addRibbon: function () {
|
||||
var dir = Math.round(random(1, 9)) > 5 ? 'right' : 'left'
|
||||
var stop = 1000
|
||||
var hide = 200
|
||||
var min = 0 - hide
|
||||
var max = this._width + hide
|
||||
var movex = 0
|
||||
var movey = 0
|
||||
var startx = dir === 'right' ? min : max
|
||||
var starty = Math.round(random(0, this._height))
|
||||
if (/^(top|min)$/i.test(this._options.verticalPosition)) {
|
||||
starty = 0 + hide
|
||||
} else if (/^(middle|center)$/i.test(this._options.verticalPosition)) {
|
||||
starty = this._height / 2
|
||||
} else if (/^(bottom|max)$/i.test(this._options.verticalPosition)) {
|
||||
starty = this._height - hide
|
||||
}
|
||||
var ribbon = []
|
||||
var point1 = new Point(startx, starty)
|
||||
var point2 = new Point(startx, starty)
|
||||
var point3 = null
|
||||
var color = Math.round(random(0, 360))
|
||||
var delay = 0
|
||||
while (true) {
|
||||
if (stop <= 0) break
|
||||
stop--
|
||||
movex = Math.round((Math.random() * 1 - 0.2) * this._options.horizontalSpeed)
|
||||
movey = Math.round((Math.random() * 1 - 0.5) * (this._height * 0.25))
|
||||
point3 = new Point()
|
||||
point3.copy(point2)
|
||||
if (dir === 'right') {
|
||||
point3.add(movex, movey)
|
||||
if (point2.x >= max) break
|
||||
} else if (dir === 'left') {
|
||||
point3.subtract(movex, movey)
|
||||
if (point2.x <= min) break
|
||||
}
|
||||
ribbon.push({
|
||||
point1: new Point(point1.x, point1.y),
|
||||
point2: new Point(point2.x, point2.y),
|
||||
point3: point3,
|
||||
color: color,
|
||||
delay: delay,
|
||||
dir: dir,
|
||||
alpha: 0,
|
||||
phase: 0
|
||||
})
|
||||
point1.copy(point2)
|
||||
point2.copy(point3)
|
||||
delay += 4
|
||||
color += this._options.colorCycleSpeed
|
||||
}
|
||||
this._ribbons.push(ribbon)
|
||||
},
|
||||
_drawRibbonSection: function (section) {
|
||||
if (section) {
|
||||
if (section.phase >= 1 && section.alpha <= 0) {
|
||||
return true
|
||||
}
|
||||
if (section.delay <= 0) {
|
||||
section.phase += 0.02
|
||||
section.alpha = Math.sin(section.phase) * 1
|
||||
section.alpha = section.alpha <= 0 ? 0 : section.alpha
|
||||
section.alpha = section.alpha >= 1 ? 1 : section.alpha
|
||||
if (this._options.animateSections) {
|
||||
var mod = Math.sin(1 + section.phase * Math.PI / 2) * 0.1
|
||||
if (section.dir === 'right') {
|
||||
section.point1.add(mod, 0)
|
||||
section.point2.add(mod, 0)
|
||||
section.point3.add(mod, 0)
|
||||
} else {
|
||||
section.point1.subtract(mod, 0)
|
||||
section.point2.subtract(mod, 0)
|
||||
section.point3.subtract(mod, 0)
|
||||
}
|
||||
section.point1.add(0, mod)
|
||||
section.point2.add(0, mod)
|
||||
section.point3.add(0, mod)
|
||||
}
|
||||
} else {
|
||||
section.delay -= 0.5
|
||||
}
|
||||
var s = this._options.colorSaturation
|
||||
var l = this._options.colorBrightness
|
||||
var c = 'hsla(' + section.color + ', ' + s + ', ' + l + ', ' + section.alpha + ' )'
|
||||
this._context.save()
|
||||
if (this._options.parallaxAmount !== 0) {
|
||||
this._context.translate(0, this._scroll * this._options.parallaxAmount)
|
||||
}
|
||||
this._context.beginPath()
|
||||
this._context.moveTo(section.point1.x, section.point1.y)
|
||||
this._context.lineTo(section.point2.x, section.point2.y)
|
||||
this._context.lineTo(section.point3.x, section.point3.y)
|
||||
this._context.fillStyle = c
|
||||
this._context.fill()
|
||||
if (this._options.strokeSize > 0) {
|
||||
this._context.lineWidth = this._options.strokeSize
|
||||
this._context.strokeStyle = c
|
||||
this._context.lineCap = 'round'
|
||||
this._context.stroke()
|
||||
}
|
||||
this._context.restore()
|
||||
}
|
||||
return false
|
||||
},
|
||||
_onDraw: function () {
|
||||
for (var i = 0, t = this._ribbons.length; i < t; ++i) {
|
||||
if (!this._ribbons[i]) {
|
||||
this._ribbons.splice(i, 1)
|
||||
}
|
||||
}
|
||||
this._context.clearRect(0, 0, this._width, this._height)
|
||||
for (var a = 0; a < this._ribbons.length; ++a) {
|
||||
var ribbon = this._ribbons[a]
|
||||
var numSections = ribbon.length
|
||||
var numDone = 0
|
||||
for (var b = 0; b < numSections; ++b) {
|
||||
if (this._drawRibbonSection(ribbon[b])) {
|
||||
numDone++
|
||||
}
|
||||
}
|
||||
if (numDone >= numSections) {
|
||||
this._ribbons[a] = null
|
||||
}
|
||||
}
|
||||
if (this._ribbons.length < this._options.ribbonCount) {
|
||||
this.addRibbon()
|
||||
}
|
||||
requestAnimationFrame(this._onDraw)
|
||||
},
|
||||
_onResize: function (e) {
|
||||
var screen = screenInfo(e)
|
||||
this._width = screen.width
|
||||
this._height = screen.height
|
||||
if (this._canvas) {
|
||||
this._canvas.width = this._width
|
||||
this._canvas.height = this._height
|
||||
if (this._context) {
|
||||
this._context.globalAlpha = this._options.colorAlpha
|
||||
}
|
||||
}
|
||||
},
|
||||
_onScroll: function (e) {
|
||||
var screen = screenInfo(e)
|
||||
this._scroll = screen.scrolly
|
||||
}
|
||||
}
|
||||
return Factory
|
||||
})
|
||||
|
||||
var cn = document.getElementById('ribbon_piao');
|
||||
var mb = cn.getAttribute("mobile");
|
||||
|
||||
if ( mb == 'false' && (/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent))) {
|
||||
var cn = document.getElementById('ribbon_piao')
|
||||
var mb = cn.getAttribute('mobile')
|
||||
|
||||
} else {
|
||||
new Ribbons({
|
||||
colorSaturation: "60%",
|
||||
colorBrightness: "50%",
|
||||
colorAlpha: 0.5,
|
||||
colorCycleSpeed: 5,
|
||||
verticalPosition: "random",
|
||||
horizontalSpeed: 200,
|
||||
ribbonCount: 3,
|
||||
strokeSize: 0,
|
||||
parallaxAmount: -0.2,
|
||||
animateSections: true
|
||||
});
|
||||
}
|
||||
if (mb == 'false' && (/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent))) {
|
||||
|
||||
} else {
|
||||
new Ribbons({
|
||||
colorSaturation: '60%',
|
||||
colorBrightness: '50%',
|
||||
colorAlpha: 0.5,
|
||||
colorCycleSpeed: 5,
|
||||
verticalPosition: 'random',
|
||||
horizontalSpeed: 200,
|
||||
ribbonCount: 3,
|
||||
strokeSize: 0,
|
||||
parallaxAmount: -0.2,
|
||||
animateSections: true
|
||||
})
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,13 +1,15 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
|
||||
function debounce (func, wait, immediate) {
|
||||
var timeout
|
||||
let timeout
|
||||
return function () {
|
||||
var context = this
|
||||
var args = arguments
|
||||
var later = function () {
|
||||
const context = this
|
||||
const args = arguments
|
||||
const later = function () {
|
||||
timeout = null
|
||||
if (!immediate) func.apply(context, args)
|
||||
}
|
||||
var callNow = immediate && !timeout
|
||||
const callNow = immediate && !timeout
|
||||
clearTimeout(timeout)
|
||||
timeout = setTimeout(later, wait)
|
||||
if (callNow) func.apply(context, args)
|
||||
@@ -15,21 +17,21 @@ function debounce (func, wait, immediate) {
|
||||
};
|
||||
|
||||
function throttle (func, wait, options) {
|
||||
var timeout, context, args
|
||||
var previous = 0
|
||||
let timeout, context, args
|
||||
let previous = 0
|
||||
if (!options) options = {}
|
||||
|
||||
var later = function () {
|
||||
const later = function () {
|
||||
previous = options.leading === false ? 0 : new Date().getTime()
|
||||
timeout = null
|
||||
func.apply(context, args)
|
||||
if (!timeout) context = args = null
|
||||
}
|
||||
|
||||
var throttled = function () {
|
||||
var now = new Date().getTime()
|
||||
const throttled = function () {
|
||||
const now = new Date().getTime()
|
||||
if (!previous && options.leading === false) previous = now
|
||||
var remaining = wait - (now - previous)
|
||||
const remaining = wait - (now - previous)
|
||||
context = this
|
||||
args = arguments
|
||||
if (remaining <= 0 || remaining > wait) {
|
||||
@@ -49,9 +51,9 @@ function throttle (func, wait, options) {
|
||||
}
|
||||
|
||||
function sidebarPaddingR () {
|
||||
var innerWidth = window.innerWidth
|
||||
var clientWidth = document.body.clientWidth
|
||||
var paddingRight = innerWidth - clientWidth
|
||||
const innerWidth = window.innerWidth
|
||||
const clientWidth = document.body.clientWidth
|
||||
const paddingRight = innerWidth - clientWidth
|
||||
if (innerWidth !== clientWidth) {
|
||||
$('body').css('padding-right', paddingRight)
|
||||
}
|
||||
@@ -63,8 +65,8 @@ function isIpad () {
|
||||
}
|
||||
|
||||
function isTMobile () {
|
||||
var ua = navigator.userAgent
|
||||
var pa = /iPad|iPhone|iPod|Android|Opera Mini|BlackBerry|webOS|UCWEB|Blazer|PSP|IEMobile|Symbian/g
|
||||
const ua = navigator.userAgent
|
||||
const pa = /iPad|iPhone|iPod|Android|Opera Mini|BlackBerry|webOS|UCWEB|Blazer|PSP|IEMobile|Symbian/g
|
||||
return window.screen.width < 992 && pa.test(ua)
|
||||
}
|
||||
|
||||
@@ -77,14 +79,14 @@ function isDesktop () {
|
||||
}
|
||||
|
||||
function scrollToDest (name, offset = 0) {
|
||||
var scrollOffset = $(name).offset()
|
||||
const scrollOffset = $(name).offset()
|
||||
$('body,html').animate({
|
||||
scrollTop: scrollOffset.top - offset
|
||||
})
|
||||
};
|
||||
|
||||
function loadScript (url, callback) {
|
||||
var script = document.createElement('script')
|
||||
const script = document.createElement('script')
|
||||
script.type = 'text/javascript'
|
||||
if (script.readyState) { // IE
|
||||
script.onreadystatechange = function () {
|
||||
@@ -104,15 +106,15 @@ function loadScript (url, callback) {
|
||||
};
|
||||
|
||||
function snackbarShow (text, showAction, duration) {
|
||||
var a = (typeof showAction !== 'undefined') ? showAction : false
|
||||
var d = (typeof duration !== 'undefined') ? duration : 2000
|
||||
var position = GLOBAL_CONFIG.Snackbar.position
|
||||
var bg = document.documentElement.getAttribute('data-theme') === 'light' ? GLOBAL_CONFIG.Snackbar.bgLight : GLOBAL_CONFIG.Snackbar.bgDark
|
||||
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
|
||||
Snackbar.show({
|
||||
text: text,
|
||||
backgroundColor: bg,
|
||||
showAction: a,
|
||||
duration: d,
|
||||
showAction: sa,
|
||||
duration: dur,
|
||||
pos: position
|
||||
})
|
||||
}
|
||||
@@ -124,9 +126,9 @@ const Cookies = {
|
||||
if (parts.length === 2) return parts.pop().split(';').shift()
|
||||
},
|
||||
set: function (name, value, days) {
|
||||
var expires = ''
|
||||
let expires = ''
|
||||
if (days) {
|
||||
var date = new Date()
|
||||
const date = new Date()
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))
|
||||
expires = '; expires=' + date.toUTCString()
|
||||
}
|
||||
@@ -134,6 +136,17 @@ const Cookies = {
|
||||
}
|
||||
}
|
||||
|
||||
const initJustifiedGallery = function (selector) {
|
||||
selector.each(function (i, o) {
|
||||
if ($(this).is(':visible')) {
|
||||
$(this).justifiedGallery({
|
||||
rowHeight: 220,
|
||||
margins: 4
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* lazyload
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user