@ -247,121 +247,128 @@ $(function () {
/ * *
* 代碼
* 只適用於Hexo默認的代碼渲染
* /
const isHighlightCopy = GLOBAL _CONFIG . highlightCopy
const isHighlightLang = GLOBAL _CONFIG . highlightLang
const isHighlightShrink = GLOBAL _CONFIG . highlightShrink
const $figureHighlight = $ ( 'figure.highlight' )
if ( isHighlightCopy || isHighlightLang || isHighlightShrink !== 'none' ) {
$figureHighlight . wrap ( '<div class="code-area-wrap"></div>' ) . before ( '<div class="highlight-tools"></div>' )
}
/ * *
if ( $figureHighlight . length ) {
const isHighlightCopy = GLOBAL _CONFIG . highlightCopy
const isHighlightLang = GLOBAL _CONFIG . highlightLang
const isHighlightShrink = GLOBAL _CONFIG . highlightShrink
if ( isHighlightCopy || isHighlightLang || isHighlightShrink !== 'none' ) {
$figureHighlight . wrap ( '<div class="code-area-wrap"></div>' ) . before ( '<div class="highlight-tools"></div>' )
}
/ * *
* 代碼收縮
* /
const $highlightTools = $ ( '.highlight-tools' )
if ( isHighlightShrink === 'true' ) {
$highlightTools . append ( '<i class="fa fa-angle-down code-expand code-closed" aria-hidden="true"></i>' )
} else if ( isHighlightShrink === 'false' ) {
$highlightTools . append ( '<i class="fa fa-angle-down code-expand" aria-hidden="true"></i>' )
}
$ ( document ) . on ( 'click' , '.highlight-tools >.code-expand' , function ( ) {
var $table = $ ( this ) . parent ( ) . next ( )
if ( $ ( this ) . hasClass ( 'code-closed' ) ) {
$table . css ( 'display' , 'block' )
$ ( this ) . removeClass ( 'code-closed' )
} else {
$table . css ( 'display' , 'none' )
$ ( this ) . addClass ( 'code-closed' )
const $highlightTools = $ ( '.highlight-tools' )
if ( isHighlightShrink === 'true' ) {
$highlightTools . append ( '<i class="fa fa-angle-down code-expand code-closed" aria-hidden="true"></i>' )
} else if ( isHighlightShrink === 'false' ) {
$highlightTools . append ( '<i class="fa fa-angle-down code-expand" aria-hidden="true"></i>' )
}
} )
/ * *
$ ( document ) . on ( 'click' , '.highlight-tools >.code-expand' , function ( ) {
var $table = $ ( this ) . parent ( ) . next ( )
if ( $ ( this ) . hasClass ( 'code-closed' ) ) {
$table . css ( 'display' , 'block' )
$ ( this ) . removeClass ( 'code-closed' )
} else {
$table . css ( 'display' , 'none' )
$ ( this ) . addClass ( 'code-closed' )
}
} )
/ * *
* 代碼語言
* /
if ( isHighlightLang ) {
var langNameIndex , langName
$figureHighlight . each ( function ( ) {
langNameIndex = langName = $ ( this ) . attr ( 'class' ) . split ( ' ' ) [ 1 ]
if ( langNameIndex === 'plain' ) langName = 'Code'
$ ( this ) . prev ( ) . append ( '<div class="code-lang">' + langName + '</div>' )
} )
}
/ * *
if ( isHighlightLang ) {
var langNameIndex , langName
$figureHighlight . each ( function ( ) {
langNameIndex = langName = $ ( this ) . attr ( 'class' ) . split ( ' ' ) [ 1 ]
if ( langNameIndex === 'plain' ) langName = 'Code'
$ ( this ) . prev ( ) . append ( '<div class="code-lang">' + langName + '</div>' )
} )
}
/ * *
* 代碼copy
* copy function
* /
if ( isHighlightCopy ) {
$highlightTools . append ( '<div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i>' )
var copy = function ( text , ctx ) {
if ( document . queryCommandSupported && document . queryCommandSupported ( 'copy' ) ) {
try {
document . execCommand ( 'copy' ) // Security exception may be thrown by some browsers.
if ( isSnackbar ) {
snackbarShow ( GLOBAL _CONFIG . copy . success )
} else {
$ ( ctx ) . prev ( '.copy-notice' )
. text ( GLOBAL _CONFIG . copy . success )
. animate ( {
opacity : 1 ,
right : 30
} , 450 , function ( ) {
setTimeout ( function ( ) {
$ ( ctx ) . prev ( '.copy-notice' ) . animate ( {
opacity : 0 ,
right : 0
} , 650 )
} , 400 )
} )
if ( isHighlightCopy ) {
$highlightTools . append ( '<div class="copy-notice"></div><i class="fa fa-clipboard" aria-hidden="true"></i>' )
var copy = function ( text , ctx ) {
if ( document . queryCommandSupported && document . queryCommandSupported ( 'copy' ) ) {
try {
document . execCommand ( 'copy' ) // Security exception may be thrown by some browsers.
if ( isSnackbar ) {
snackbarShow ( GLOBAL _CONFIG . copy . success )
} else {
$ ( ctx ) . prev ( '.copy-notice' )
. text ( GLOBAL _CONFIG . copy . success )
. animate ( {
opacity : 1 ,
right : 30
} , 450 , function ( ) {
setTimeout ( function ( ) {
$ ( ctx ) . prev ( '.copy-notice' ) . animate ( {
opacity : 0 ,
right : 0
} , 650 )
} , 400 )
} )
}
} catch ( ex ) {
if ( isSnackbar ) {
snackbarShow ( GLOBAL _CONFIG . copy . success )
} else {
$ ( ctx ) . prev ( '.copy-notice' )
. text ( GLOBAL _CONFIG . copy . error )
. animate ( {
opacity : 1 ,
right : 30
} , 650 , function ( ) {
setTimeout ( function ( ) {
$ ( ctx ) . prev ( '.copy-notice' ) . animate ( {
opacity : 0 ,
right : 0
} , 650 )
} , 400 )
} )
return false
}
}
} catch ( ex ) {
} else {
if ( isSnackbar ) {
snackbarShow ( GLOBAL _CONFIG . copy . success )
snackbarShow ( GLOBAL _CONFIG . copy . noSupport )
} else {
$ ( ctx ) . prev ( '.copy-notice' )
. text ( GLOBAL _CONFIG . copy . error )
. animate ( {
opacity : 1 ,
right : 30
} , 650 , function ( ) {
setTimeout ( function ( ) {
$ ( ctx ) . prev ( '.copy-notice' ) . animate ( {
opacity : 0 ,
right : 0
} , 650 )
} , 400 )
} )
return false
$ ( ctx ) . prev ( '.copy-notice' ) . text ( GLOBAL _CONFIG . copy . noSupport )
}
}
} else {
if ( isSnackbar ) {
snackbarShow ( GLOBAL _CONFIG . copy . noSupport )
} else {
$ ( ctx ) . prev ( '.copy-notice' ) . text ( GLOBAL _CONFIG . copy . noSupport )
}
}
}
// click events
$ ( document ) . on ( 'click' , '.highlight-tools>.fa-clipboard' , function ( ) {
var selection = window . getSelection ( )
var range = document . createRange ( )
range . selectNodeContents ( $ ( this ) . parent ( ) . next ( ) . find ( '.code pre' ) [ 0 ] )
selection . removeAllRanges ( )
selection . addRange ( range )
var text = selection . toString ( )
copy ( text , this )
selection . removeAllRanges ( )
} )
// click events
$ ( document ) . on ( 'click' , '.highlight-tools>.fa-clipboard' , function ( ) {
var selection = window . getSelection ( )
var range = document . createRange ( )
range . selectNodeContents ( $ ( this ) . parent ( ) . next ( ) . find ( '.code pre' ) [ 0 ] )
selection . removeAllRanges ( )
selection . addRange ( range )
var text = selection . toString ( )
copy ( text , this )
selection . removeAllRanges ( )
} )
}
}
/ * *
* justified - gallery 圖庫排版
* /
var $justifiedGallery = $ ( '.justified-gallery' )
var isJustifiedGallery = false
if ( $justifiedGallery . length ) {
isJustifiedGallery = true
var $imgList = $justifiedGallery . find ( 'img' )
$imgList . unwrap ( )
if ( $imgList . length ) {
@ -372,11 +379,19 @@ $(function () {
}
$ ( 'head' ) . append ( '<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css">' )
loadScript ( 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js' , function ( ) {
$justifiedGallery . not ( $ ( '.hide-content .justified-gallery' ) ) . justifiedGallery ( {
rowHeight : 220 ,
margins : 4
} )
initJustifiedGallery ( $justifiedGallery )
} )
var initJustifiedGallery = function ( selector ) {
selector . each ( function ( i , o ) {
if ( $ ( this ) . is ( ':visible' ) ) {
$ ( this ) . justifiedGallery ( {
rowHeight : 220 ,
margins : 4
} )
}
} )
}
}
/ * *
@ -708,6 +723,9 @@ $(function () {
interval = setInterval ( showDateTime , 10000 )
}
/ * *
* 百度推送
* /
if ( GLOBAL _CONFIG . baiduPush ) {
( function ( ) {
var bp = document . createElement ( 'script' )
@ -726,17 +744,24 @@ $(function () {
* tag - hide
* /
var $hideInline = $ ( '.hide-button' )
$hideInline . on ( 'click' , function ( e ) {
e . preventDefault ( )
$ ( this ) . hide ( )
var $hideContent = $ ( this ) . next ( '.hide-content' )
$hideContent . show ( )
$hideContent . find ( '.justified-gallery' ) . justifiedGallery ( {
rowHeight : 220 ,
margins : 4
if ( $hideInline . length ) {
$hideInline . on ( 'click' , function ( e ) {
e . preventDefault ( )
var $this = $ ( this )
var $hideContent = $ ( this ) . next ( '.hide-content' )
$this . toggleClass ( 'open' )
$hideContent . toggle ( )
if ( $this . hasClass ( 'open' ) ) {
if ( isJustifiedGallery && $hideContent . find ( '.justified-gallery' ) . length > 0 ) {
initJustifiedGallery ( $hideContent . find ( '.justified-gallery' ) )
}
}
} )
} )
}
/ * *
* PhotoFigcaption
* /
function addPhotoFigcaption ( ) {
var images = $ ( '#article-container img' )
images . each ( function ( i , o ) {