hexo-theme-ayer/source-src/js/share.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-02-06 15:14:35 +00:00
function generate(url, opts) {
var url = url.replace(/<%-sUrl%>/g, encodeURIComponent(opts.sUrl))
2021-03-11 06:12:21 +00:00
.replace(/<%-sTitle%>/g, encodeURIComponent(opts.sTitle))
.replace(/<%-sDesc%>/g, encodeURIComponent(opts.sDesc))
2020-02-06 15:14:35 +00:00
.replace(/<%-sPic%>/g, encodeURIComponent(opts.sPic));
window.open(url);
}
function showWX() {
2020-03-24 04:51:01 +00:00
$('.wx-share-modal').addClass('in ready')
$('#share-mask').show()
2020-02-06 15:14:35 +00:00
}
function hideWX() {
2020-03-24 04:51:01 +00:00
$('.wx-share-modal').removeClass('in ready')
$('#share-mask').hide()
2020-02-06 15:14:35 +00:00
}
function handleClick(type, opts) {
2023-01-20 16:07:42 +00:00
} if (type === 'google') {
2020-02-06 15:14:35 +00:00
generate('https://plus.google.com/share?url=<%-sUrl%>', opts)
}
2020-03-24 04:51:01 +00:00
const share_init = () => {
2020-02-06 15:14:35 +00:00
let $sns = document.querySelectorAll('.share-sns');
if (!$sns || $sns.length === 0) return;
let sUrl = window.location.href;
let sTitle = document.querySelector('title').innerHTML;
let $img = document.querySelectorAll('.article-entry img');
let sPic = $img.length ? document.querySelector('.article-entry img').getAttribute('src') : '';
if ((sPic !== '') && !/^(http:|https:)?\/\//.test(sPic)) {
sPic = window.location.origin + sPic
}
$sns.forEach(($em) => {
$em.onclick = (e) => {
let type = $em.getAttribute('data-type')
handleClick(type, {
sUrl: sUrl,
sPic: sPic,
sTitle: sTitle,
sDesc: sTitle
})
}
})
document.querySelector('#mask').onclick = hideWX
document.querySelector('.modal-close').onclick = hideWX
}
2020-03-24 04:51:01 +00:00
share_init()