1.2.5原版
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,561 @@
|
||||
main_content = $('.moment_type_main');
|
||||
function remove_image_temp(){
|
||||
if(!$('.image_edit_temp .add_img_box').length > 0){
|
||||
var temp = $('.add_img_box');
|
||||
$('.image_edit_temp').html(temp);
|
||||
}
|
||||
main_content.empty();
|
||||
}
|
||||
|
||||
function back_image_temp(){
|
||||
var temp = $('.add_img_box');
|
||||
main_content.html(temp);
|
||||
$('.image_edit_temp').empty();
|
||||
}
|
||||
|
||||
//发布卡片
|
||||
$('body').on('click', '.moment_card_type a', function () {
|
||||
$('.push_item').attr('type', 'card');
|
||||
main_content = $('.moment_type_main');
|
||||
if ($('.add_card_box').length > 0) {
|
||||
return false;
|
||||
}
|
||||
remove_image_temp();
|
||||
main_content.html('<div class="loading_box"><div uk-spinner></div></div>');
|
||||
$('.moment_type_main .loading_box').remove();
|
||||
main_content.append(
|
||||
`<div class="add_card_box">
|
||||
<div class="edit_card_box">
|
||||
<div class="card_choose" uk-switcher="animation: uk-animation-fade">
|
||||
<li><a class="card_c_btn post" c_type="post">文章</a></li>
|
||||
<li><a class="card_c_btn page" c_type="page">页面</a></li>
|
||||
</div>
|
||||
<div class="tips"># 输入别名或者标题,自动生成链接卡片 <span>支持文章, 页面等网址</span></div>
|
||||
<div class="edit_content">
|
||||
<input type="text" placeholder="别名或者标题" name="moment_card_link" id="moment_card_link" required="required">
|
||||
<a class="push_card">生成</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="show_card"><div class="card_sortble" uk-sortable="handle: .moment_card_item"></div></div>
|
||||
</div>`);
|
||||
});
|
||||
$('body').on('click', '.edit_content .push_card', function () {
|
||||
var card_url = $('.edit_card_box .edit_content input').val();
|
||||
var num = $('.card_sortble .moment_card_item').length;
|
||||
if (num > 2) {
|
||||
cocoMessage.error('最多插入3个卡片');
|
||||
$('.edit_card_box .edit_content input').val('');
|
||||
return false;
|
||||
}
|
||||
var c_type = $('.card_choose .uk-active a').attr('c_type');
|
||||
switch (c_type) {
|
||||
case "post":
|
||||
card_post(card_url);
|
||||
break;
|
||||
case "page":
|
||||
edit_page(card_url);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
function card_post(card_url){
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: `/apis/api.console.halo.run/v1alpha1/posts?keyword=${card_url}&labelSelector=content.halo.run%2Fdeleted%3Dfalse&page=1&size=20`,
|
||||
beforeSend: function () {
|
||||
cocoMessage.info('生成中...');
|
||||
},
|
||||
success: function (data) {
|
||||
$('.edit_card_box .edit_content input').val('');
|
||||
if (data.total > 0) {
|
||||
if(data.total>1){
|
||||
cocoMessage.error('当前搜索的文章有多个无法选择');
|
||||
}else{
|
||||
var item = data.items[0]
|
||||
$('.show_card').show();
|
||||
$('.card_sortble').append(getcard(item.post.metadata.name,item.post.spec.cover,item.post.spec.title,'post'));
|
||||
cocoMessage.success('已生成卡片');
|
||||
}
|
||||
|
||||
} else {
|
||||
cocoMessage.error('文章不存在');
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function edit_page(card_url){
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: `/apis/api.console.halo.run/v1alpha1/singlepages?keyword=${card_url}&labelSelector=content.halo.run%2Fdeleted%3Dfalse&page=1&size=20`,
|
||||
beforeSend: function () {
|
||||
cocoMessage.info('生成中...');
|
||||
},
|
||||
success: function (data) {
|
||||
$('.edit_card_box .edit_content input').val('');
|
||||
if (data.total > 0) {
|
||||
if(data.total>1){
|
||||
cocoMessage.error('当前搜索的页面有多个无法选择');
|
||||
}else{
|
||||
var item = data.items[0]
|
||||
$('.show_card').show();
|
||||
$('.card_sortble').append(getcard(item.page.metadata.name,item.page.spec.cover,item.page.spec.title,'page'));
|
||||
cocoMessage.success('已生成卡片');
|
||||
}
|
||||
|
||||
} else {
|
||||
cocoMessage.error('页面不存在');
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getcard(name,cover,title,type){
|
||||
|
||||
return `<div class="moment_card_item" pid="${name}" type="${type}">
|
||||
<a>
|
||||
<div class="left"><img src="${cover}"></div>
|
||||
<div class="right">
|
||||
<h4>${title}</h4>
|
||||
<div class="content"></div>
|
||||
</div>
|
||||
<span class="de_card"><i class="ri-close-line"></i></span>
|
||||
</a>
|
||||
</div>`
|
||||
}
|
||||
|
||||
$(document).on('click', '.de_card', function() {
|
||||
var msg = "确认删除此卡片?";
|
||||
var num = $('.moment_card_item').length;
|
||||
if (confirm(msg)==true){
|
||||
$(this).parents('.moment_card_item').remove();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(num == 1){
|
||||
$(".show_card").hide();
|
||||
}
|
||||
});
|
||||
|
||||
//图文编辑 返回图文编辑区域
|
||||
$('body').on('click', '.moment_image_type a', function() {
|
||||
back_image_temp();
|
||||
$('.push_item').attr('type','image');
|
||||
});
|
||||
|
||||
//发布音乐--------------------------------------------------------------
|
||||
$('body').on('click', '.moment_audio_type a', function() {
|
||||
$('.push_item').attr('type','audio');
|
||||
main_content = $('.moment_type_main');
|
||||
if($('.add_audio_box').length > 0){
|
||||
return false;
|
||||
}
|
||||
remove_image_temp();
|
||||
main_content.append(
|
||||
`<div class="add_audio_box">
|
||||
<div class="edit_audio_box">
|
||||
<div class="audio_choose" uk-switcher="animation: uk-animation-fade">
|
||||
<li class="local"><a href="#" class="audio_c_btn" au_type="local">本地</a></li>
|
||||
<li class="netease"><a href="#" class="audio_c_btn" au_type="netease">网易云</a></li>
|
||||
<li class="tencent"><a href="#" class="audio_c_btn" au_type="tencent">QQ音乐</a></li>
|
||||
<li class="kugou"><a href="#" class="audio_c_btn" au_type="kugou">酷狗</a></li>
|
||||
<li class="kuwo"><a href="#" class="audio_c_btn" au_type="kuwo">酷我</a></li>
|
||||
</div>
|
||||
<div class="tips"># 请插入歌曲外链 <span></span></div>
|
||||
<div class="edit_content audio_type uk-switcher">
|
||||
<div class="loacl_audio">
|
||||
<input type="text" placeholder="歌曲外链" name="moment_audio_url" id="moment_audio_url" class="required" required="required">
|
||||
</div>
|
||||
<div class="netease_audio type_audio_text"></div>
|
||||
<div class="tencent_audio type_audio_text"></div>
|
||||
<div class="kugou_audio type_audio_text"></div>
|
||||
<div class="kuwo_audio type_audio_text"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`);
|
||||
});
|
||||
|
||||
//音乐和视频上传
|
||||
$(document).on('change','#moment_img_up',function(){
|
||||
if($('#moment_img_up').val() == '')
|
||||
return;
|
||||
var f = this.files[0];
|
||||
var formData = new FormData();
|
||||
formData.append('file',f);
|
||||
const policyName = Theme.moments.policy_name;
|
||||
const groupName = Theme.moments.group_name;
|
||||
policyName && formData.append('policyName',policyName)
|
||||
groupName && formData.append('groupName',groupName)
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: `${Theme.moments.attachments_upload_api}`,
|
||||
dataType: 'json',
|
||||
data: formData,
|
||||
processData : false,
|
||||
contentType : false,
|
||||
beforeSend: function () {
|
||||
cocoMessage.info('上传中...');
|
||||
$('.m_media_left i').remove();
|
||||
$('.m_media_left').append("<div class='up_loading' uk-spinner='ratio: .6'></div>");
|
||||
var imged = $('.m_media_left img');
|
||||
if(imged.length > 0){
|
||||
imged.remove();
|
||||
}
|
||||
},
|
||||
success: function(data){
|
||||
var thum = data.metadata.annotations["storage.halo.run/uri"] || data.metadata.annotations["storage.halo.run/external-link"]
|
||||
$('.m_media_left .up_loading').remove();
|
||||
$('.m_media_left').append('<img src="/themes/theme-pix/assets/img/video.png" data="'+thum+'">');
|
||||
cocoMessage.success('上传成功');
|
||||
$('input#moment_video_url').val(thum)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('body').on('click', '.audio_choose a', function() {
|
||||
var text = '# 请插入封面,歌名以及歌曲外链';
|
||||
var type = $(this).attr('au_type');
|
||||
if(type != 'local'){
|
||||
var text = '# 请输入歌曲ID';
|
||||
}
|
||||
$('.edit_audio_box .tips').text(text);
|
||||
});
|
||||
|
||||
//发布视频--------------------------------------------------------------
|
||||
$('body').on('click', '.moment_video_type a', function() {
|
||||
$('.push_item').attr('type','video');
|
||||
main_content = $('.moment_type_main');
|
||||
if($('.add_video_box').length > 0){
|
||||
return false;
|
||||
}
|
||||
remove_image_temp();
|
||||
main_content.html('<div class="loading_box"><div uk-spinner></div></div>');
|
||||
$('.moment_type_main .loading_box').remove();
|
||||
main_content.append(
|
||||
`<div class="add_video_box">
|
||||
<div class="edit_video_box">
|
||||
<div class="video_choose" uk-switcher="animation: uk-animation-fade">
|
||||
<li><a href="#" class="video_c_btn local" vi_type="local">本地</a></li>
|
||||
<li><a href="#" class="video_c_btn bili" vi_type="bili">B站</a></li>
|
||||
</div>
|
||||
<div class="tips"># 请上传视频或填写视频外链 <span></span></div>
|
||||
<div class="edit_content video_type uk-switcher">
|
||||
<div class="local_video">
|
||||
<div class="video_left m_media_left">
|
||||
<i class="ri-add-line"></i>
|
||||
<input type="file" name="moment_img_up" id="moment_img_up" accept="video/mp4,video/ogg,video/webm,video/3gpp,video/flv,video/avi,video/mov,video/wmv,video/rm,video/rmvb,video/3gp,video/3g2,video/asf,video/mkv,video/mpg,video/mpeg,video/ts" multiple="multiple" title="上传视频">
|
||||
</div>
|
||||
<div class="video_right">
|
||||
<div class="video_meta">
|
||||
<input type="text" placeholder="视频外链" name="moment_video_url" id="moment_video_url" class="required" required="required">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bili_video">
|
||||
<input type="text" placeholder="B站视频bvid" name="moment_video_bili" id="moment_video_bili" class="required" required="required">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`);
|
||||
|
||||
});
|
||||
|
||||
$('body').on('click', '.video_choose a', function() {
|
||||
var text = '# 请上传视频或填写视频外链';
|
||||
var type = $(this).attr('vi_type');
|
||||
if(type == 'bili'){
|
||||
var text = '# 请输入B站视频bvid';
|
||||
}
|
||||
$('.edit_video_box .tips').text(text);
|
||||
});
|
||||
|
||||
//图文类型
|
||||
//$('body').on('click', '.moment_video_type a', function() {
|
||||
|
||||
//});
|
||||
|
||||
//删除片刻文章
|
||||
$('body').on('click', '.control_delete_post', function() {
|
||||
var pid = $(this).parent().attr('pid');
|
||||
|
||||
var msg = "确定删除瞬间?";
|
||||
if (confirm(msg)==true){
|
||||
$.ajax({
|
||||
type: 'DELETE',
|
||||
dataType: 'json',
|
||||
url: `/apis/${Theme.moments.api}/v1alpha1/moments/`+pid,
|
||||
contentType: "application/json",
|
||||
beforeSend: function () {
|
||||
cocoMessage.info('处理中..');
|
||||
},
|
||||
success: function (data) {
|
||||
cocoMessage.success('删除成功');
|
||||
setTimeout(()=>{
|
||||
$(`#post-${pid}`)[0].remove()
|
||||
},1000)
|
||||
},
|
||||
error: function (request) {
|
||||
if(request.status){
|
||||
cocoMessage.error('瞬间不存在或已删除');
|
||||
}else{
|
||||
cocoMessage.error('删除失败');
|
||||
}
|
||||
console.log(request)
|
||||
},
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//置顶片刻
|
||||
$('body').on('click', '.sticky_btn', function() {
|
||||
var pid = $(this).parent().attr('pid');
|
||||
var stick = $(this).hasClass('stick');
|
||||
if(stick){
|
||||
var state = 'stick';
|
||||
} else {
|
||||
var state = 'unstick';
|
||||
}
|
||||
var msg = "确定执行此操作?";
|
||||
if (confirm(msg)==true){
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
url: Theme.ajaxurl,
|
||||
data: {
|
||||
'action':'stick_moment',
|
||||
pid:pid,
|
||||
state:state
|
||||
},
|
||||
beforeSend: function () {
|
||||
cocoMessage.info('处理中..');
|
||||
},
|
||||
success: function (data) {
|
||||
if(data.state == '1'){
|
||||
cocoMessage.success(data.msg);
|
||||
if(data.type == 'stick'){
|
||||
var post_item = $('#post-'+pid+'.moment_item');
|
||||
post_item.remove();
|
||||
$('.moment_list').prepend(post_item.prop('outerHTML'));
|
||||
$('#post-'+pid+'.moment_item').find('.post_footer_meta .right').prepend('<span class="sticky_icon"><i class="ri-fire-line"></i> TOP</span>');
|
||||
$('#post-'+pid+'.moment_item').find('.post_control').remove();
|
||||
} else {
|
||||
$('#post-'+pid+'.moment_item').find('.sticky_icon').remove();
|
||||
}
|
||||
|
||||
} else {
|
||||
cocoMessage.error('操作失败');
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//编辑片刻
|
||||
$('body').on('click', '.control_edit_post', function() {
|
||||
$('.t_media_item').remove();
|
||||
$('#moment_audio_api').remove();
|
||||
var pid = $(this).parent().attr('pid');
|
||||
$('.push_item').html('<i class="ri-edit-box-line"></i>更新');
|
||||
$('.push_item').attr('pid',pid).attr('action','update')
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: `/apis/${Theme.moments.api}/v1alpha1/moments/`+pid,
|
||||
beforeSend: function () {
|
||||
cocoMessage.info('数据拉取中');
|
||||
//$('.t_form').before('<div class="edit_overlay"></div>');
|
||||
},
|
||||
success: function (data) {
|
||||
$('.push_item').attr('version',data.metadata.version)
|
||||
$('.push_item').attr('owner',data.spec.owner)
|
||||
$('.push_item').attr('releaseTime',data.spec.releaseTime)
|
||||
//发布状态
|
||||
if(data.spec.visible == 'PRIVATE'){
|
||||
$(".simi a").html('<i class="ri-lock-line"></i>').attr('visible','PRIVATE');
|
||||
$(".simi a").children().css({"background":"#ddd","color":"#c6c6c6"});
|
||||
} else {
|
||||
$(".simi a").html('<i class="ri-lock-unlock-line"></i>').attr('visible','PUBLIC');
|
||||
$(".simi a").children().css({"background":"#e3efe7","color":"#66c187"});
|
||||
}
|
||||
var medium = data.spec.content.medium;
|
||||
var tags = data.spec.tags
|
||||
if(medium.length > 0){
|
||||
var type = medium[0].type;
|
||||
}
|
||||
let content = data.spec.content.html;
|
||||
if(content == null){
|
||||
content = '';
|
||||
}else{
|
||||
|
||||
// 创建一个新的HTML解析器对象
|
||||
var parser = new DOMParser();
|
||||
// 解析HTML字符串并获取根元素
|
||||
var doc = parser.parseFromString(content, 'text/html');
|
||||
// 获取根元素下的所有子元素
|
||||
var elements = doc.body.childNodes;
|
||||
// 需要删除的链接元素的条件
|
||||
var conditions = doc.querySelectorAll('p > a.tag');
|
||||
// 遍历子元素并删除特定段落元素和链接元素
|
||||
for (var i = 0; i < conditions.length; i++) {
|
||||
for (var j = 0; j < elements.length; j++) {
|
||||
if (elements[j].nodeName === 'P' && elements[j].querySelector('a.tag')) {
|
||||
elements[j].parentNode.removeChild(elements[j]);
|
||||
}
|
||||
}
|
||||
content = doc.body.innerHTML;
|
||||
}
|
||||
}
|
||||
|
||||
$('#topic_content').val(content);
|
||||
if(tags.length > 0){
|
||||
$('.t_cat_toogle span').text(tags[0]);
|
||||
}
|
||||
|
||||
if(data.metadata.annotations?.mylocal!=null && data.metadata.annotations?.mylocal!='') {
|
||||
$('.loca_text').text(data.metadata.annotations?.mylocal);
|
||||
}
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case "PHOTO":
|
||||
//if(data.moment_data.length > 0){ 文字片刻没有数据
|
||||
edit_image(data);
|
||||
//}
|
||||
break;
|
||||
case "POST":
|
||||
edit_card(data);
|
||||
break;
|
||||
case "AUDIO":
|
||||
edit_audio(data);
|
||||
break;
|
||||
case "VIDEO":
|
||||
edit_video(data);
|
||||
break;
|
||||
}
|
||||
cocoMessage.success('拉取完成');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//发布片刻重置
|
||||
$('body').on('click', '.normal_edit,.center .mobile_edit', function() {
|
||||
$('.push_item').attr('action','push').html('<i class="ri-send-plane-2-line"></i>发布');
|
||||
$('.moment_image_type a').click();
|
||||
$(".simi a").html('<i class="ri-lock-unlock-line"></i>').attr('visible','PUBLIC');
|
||||
$(".simi a").children().css({"background":"#e3efe7","color":"#66c187"});
|
||||
$('#topic_content').val('');
|
||||
const mylocalValue = getCookie('mylocal');
|
||||
$(".loca_text").html(mylocalValue).attr("state",'1');
|
||||
$('.t_media_item').remove();
|
||||
});
|
||||
|
||||
//编辑片刻类型------------------------------------------------------------------------------
|
||||
function edit_image(data){
|
||||
var m_data = data.spec.content.medium;
|
||||
$('.t_media_item').remove();
|
||||
$('.moment_image_type a').click();
|
||||
if(m_data.length > 0){
|
||||
var new_data = m_data.reverse();
|
||||
$.each(new_data, function(index, value) {
|
||||
var thum = value.url;
|
||||
var src = value.url;
|
||||
var type = value.originType;
|
||||
var media = `<div class="t_media_item" data-type="${type}" data-src="${src}" data-thum="${thum}">`;
|
||||
media += '<a class="topic-img-de"><i class="ri-subtract-line"></i></a>';
|
||||
media += '<img src="'+thum+'">';//图片预览
|
||||
media += '</div>';
|
||||
$(".img_show").prepend(media);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function edit_video(data){
|
||||
var m_data = data.spec.content.medium[0];
|
||||
var type = m_data.originType;
|
||||
//var url = m_data.url;
|
||||
$('.moment_video_type a').click();
|
||||
|
||||
var add = setInterval(function() {
|
||||
if(type != 'video/bili'){
|
||||
var url = m_data.url;
|
||||
|
||||
$('input#moment_video_url').val(url);
|
||||
if(url !== ''){
|
||||
$('.m_media_left i').remove();
|
||||
$('.m_media_left').append('<img src="/themes/theme-pix/assets/img/video.png" data="'+url+'">');
|
||||
}
|
||||
|
||||
} else if(type == 'video/bili') {
|
||||
if($('.video_choose').length > 0){
|
||||
var bvid = m_data.url;
|
||||
UIkit.switcher('.video_choose').show(1);
|
||||
$('input#moment_video_bili').val(bvid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($('.edit_video_box').length == 1){
|
||||
clearInterval(add);
|
||||
}
|
||||
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function edit_audio(data){
|
||||
var m_data = data.spec.content.medium[0];
|
||||
var type = m_data.originType;
|
||||
$('.moment_audio_type a').click();
|
||||
var add = setInterval(function() {
|
||||
if(type == 'audio/netease' || type == 'audio/tencent' || type == 'audio/kugou' || type == 'audio/kuwo'){
|
||||
var result = type.substring(type.indexOf("audio/") + 6);
|
||||
if($('.audio_choose').length > 0){
|
||||
var n_id = m_data.url;
|
||||
var index = $('.audio_choose li.'+result+'').index();
|
||||
UIkit.switcher('.audio_choose').show(index);
|
||||
$('.edit_audio_box .tips').text('# 请输入歌曲ID');
|
||||
$('.'+result+'_audio').append('<input type="text" placeholder="歌曲ID" name="moment_audio_api" id="moment_audio_api" class="required" required="required">');
|
||||
$('input#moment_audio_api').val(n_id);
|
||||
}
|
||||
} else {
|
||||
var index = $('.audio_choose li.local').index();
|
||||
UIkit.switcher('.audio_choose').show(index);
|
||||
var url = m_data.url;
|
||||
$('.edit_audio_box .tips').text('# 请插入歌曲外链');
|
||||
$('input#moment_audio_url').val(url);
|
||||
}
|
||||
if($('.edit_audio_box').length == 1){
|
||||
clearInterval(add);
|
||||
}
|
||||
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function edit_card(data) {
|
||||
var m_data = data.spec.content.medium;
|
||||
$('.card_sortble .moment_card_item').remove();
|
||||
$('.moment_card_type a').click();
|
||||
var pid = data.metadata.name;
|
||||
var card_list = $("#post-"+pid+"").find('.moment_card_item');
|
||||
var add = setInterval(function() {
|
||||
$('.show_card').show();
|
||||
$.each(m_data, function(index, value) {
|
||||
var srcValue = card_list.eq(index).find('img').attr('src');
|
||||
var h4Text = card_list.eq(index).find('h4').text();
|
||||
$('.card_sortble').append(getcard(value.url,srcValue,h4Text,value.originType));
|
||||
});
|
||||
if($('.edit_card_box').length == 1){
|
||||
clearInterval(add);
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
var pix = {
|
||||
|
||||
|
||||
/**
|
||||
* 页面運行時間
|
||||
*/
|
||||
addRuntime: function () {
|
||||
const $runtimeCount = document.getElementById('runtimeshow');
|
||||
if ($runtimeCount) {
|
||||
var s1 = $runtimeCount.innerText;//建站时间
|
||||
if (s1) {
|
||||
s1 = new Date(s1.replace(/-/g, "/"));
|
||||
s2 = new Date();
|
||||
var days = s2.getTime() - s1.getTime();
|
||||
var number_of_days = parseInt(days / (1000 * 60 * 60 * 24));
|
||||
$runtimeCount.innerText = number_of_days + '天';
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
loadLightbox: function () {
|
||||
/**
|
||||
* fancybox
|
||||
*/
|
||||
const addFancybox = function (ele) {
|
||||
const runFancybox = (ele) => {
|
||||
ele.each(function (i, o) {
|
||||
const $this = $(o)
|
||||
const lazyloadSrc = $this.attr('data-src') || $this.attr('src')
|
||||
const dataCaption = $this.attr('alt') || ''
|
||||
$this.wrap(`<a href="${lazyloadSrc}" data-fancybox="images" class="fancybox" data-srcset="${lazyloadSrc}"></a>`)
|
||||
})
|
||||
}
|
||||
|
||||
runFancybox($(ele))
|
||||
}
|
||||
const $fancyboxEle = document.querySelectorAll('.single-content :not(a) > img,.single-content > img')
|
||||
if ($fancyboxEle.length > 0) {
|
||||
addFancybox($fancyboxEle)
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
initTopBar: function () {
|
||||
let topBar = $('#masthead .top_bar');
|
||||
var placeholder = document.querySelector('#masthead .uk-sticky-placeholder');
|
||||
var width = $('#masthead').width();
|
||||
var height = '71.9979px;'
|
||||
if (window.innerWidth < 960) {
|
||||
if (window.innerWidth <= 540) {
|
||||
height = '63.9957px'
|
||||
}
|
||||
topBar.addClass('uk-sticky-fixed').css({ "width": width, "top": '0px', "position": "fixed" });
|
||||
$('#masthead .uk-sticky-placeholder').css({ "width": width, "height": height, "margin": "0px" });
|
||||
placeholder.hidden = false;
|
||||
} else {
|
||||
topBar.removeAttr("style");
|
||||
$('#masthead .uk-sticky-placeholder').css({ "width": width, "height": '71.9979px;', "margin": "0px" });
|
||||
placeholder.hidden = true;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
getMsg: function () {
|
||||
var com_msg_btn = $('.com_msg_btn')
|
||||
var msg_modal_inner = $('.msg_modal_inner')
|
||||
let username = Theme.username
|
||||
var f_unread_num = 0;
|
||||
if (com_msg_btn.length > 0) {
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: `/apis/api.notification.halo.run/v1alpha1/userspaces/${username}/notifications?fieldSelector=spec.unread=true`,
|
||||
success: function (res) {
|
||||
if (res.total == 0) {
|
||||
$('.f_unread_num').remove();
|
||||
}else {
|
||||
f_unread_num = res.total
|
||||
com_msg_btn.append(`<small class="f_unread_num">${res.total}</small>`);
|
||||
}
|
||||
if (msg_modal_inner.length > 0) {
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: `/apis/api.notification.halo.run/v1alpha1/userspaces/${username}/notifications?page=1&size=10`,
|
||||
success: function (res) {
|
||||
var data = res.items
|
||||
if (data.length > 0) {
|
||||
var unread_box = `
|
||||
<div class="unread_box">
|
||||
<div class="unread_tip"># 您有${f_unread_num}条未读消息 #
|
||||
<a href="/uc/notifications" target="_blank">查看全部</a>
|
||||
</div>
|
||||
`
|
||||
var read_box = `
|
||||
<div class="read_box">
|
||||
`
|
||||
var unreadSum = 0
|
||||
data.forEach((e => {
|
||||
if (e.spec.unread) {
|
||||
unreadSum = unreadSum + 1;
|
||||
unread_box += `
|
||||
<div class="vi_reply_item">
|
||||
<div class="box" msg-name="${e.metadata.name}">
|
||||
<span class="mark_read">标记为已读</span>
|
||||
<div class="avatar_top"><img alt=""
|
||||
src="https://cravatar.cn/avatar/?d=mp"
|
||||
class="avatar avatar-50 photo" height="50" width="50" decoding="async"></div>
|
||||
${e.spec.htmlContent}
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
} else {
|
||||
read_box += `
|
||||
<div class="vi_reply_item">
|
||||
<div class="box">
|
||||
<div class="avatar_top"><img alt=""
|
||||
src="https://cravatar.cn/avatar/?d=mp"
|
||||
class="avatar avatar-50 photo" height="50" width="50" decoding="async"></div>
|
||||
${e.spec.htmlContent}
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
}
|
||||
))
|
||||
unread_box += `</div>`
|
||||
read_box += `</div><p class="msg_limit">只显示最新10条未读和已读信息</p> `
|
||||
msg_modal_inner.html(unread_box + read_box)
|
||||
|
||||
} else {
|
||||
msg_modal_inner.html(`
|
||||
<p class="no_posts"><small># 暂无消息 #</small><img class="s_nodata"
|
||||
src="/themes/theme-pix/assets/img/nodata.png"></p>
|
||||
<p class="msg_limit">只显示最新10条未读和已读信息</p>
|
||||
`)
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
msg_modal_inner.html(`
|
||||
<p class="no_posts"><small># 暂无消息 #</small><img class="s_nodata"
|
||||
src="/themes/theme-pix/assets/img/nodata.png"></p>
|
||||
<p class="msg_limit">只显示最新10条未读和已读信息</p>
|
||||
`)
|
||||
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
initGalleryPhotos: function () {
|
||||
var galleryPhotos = document.querySelectorAll('.gallery-photos .gallery-photo');
|
||||
if (galleryPhotos.length > 0) {
|
||||
// 瀑布流排版
|
||||
imgStatus.watch('.photo-img', () => {
|
||||
waterfall('.gallery-photos');
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
topCategoriesBarScroll: function () {
|
||||
if (document.getElementById("cat_nav_items")) {
|
||||
let xscroll = document.getElementById("cat_nav_items");
|
||||
xscroll.addEventListener("mousewheel", function (e) {
|
||||
//计算鼠标滚轮滚动的距离
|
||||
let v = -e.wheelDelta / 2;
|
||||
xscroll.scrollLeft += v;
|
||||
//阻止浏览器默认方法
|
||||
e.preventDefault();
|
||||
}, false);
|
||||
}
|
||||
},
|
||||
|
||||
topTableBarScroll: function () {
|
||||
var tables = document.querySelectorAll('.single-content table')
|
||||
if (tables.length>0) {
|
||||
tables.forEach(function (xscroll) {
|
||||
xscroll.addEventListener("mousewheel", function (e) {
|
||||
//计算鼠标滚轮滚动的距离
|
||||
let v = -e.wheelDelta / 2;
|
||||
xscroll.scrollLeft += v;
|
||||
//阻止浏览器默认方法
|
||||
e.preventDefault();
|
||||
}, false);
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
//处理瞬间权限
|
||||
roleMoments: async function () {
|
||||
const response = await fetch(`/apis/api.console.halo.run/v1alpha1/users/-`);
|
||||
const data = await response.json();
|
||||
var roles = data.roles;
|
||||
|
||||
if(roles.length>0) {
|
||||
var name = roles[0].metadata.name
|
||||
if(name != 'super-role') {
|
||||
let dependencies = roles[0].metadata.annotations["rbac.authorization.halo.run/dependencies"]
|
||||
if(dependencies != undefined) {
|
||||
var targetRoles = ["role-template-uc-moments-approved","role-template-uc-moments-publish"]
|
||||
const result = targetRoles.some(r => dependencies.includes(r));
|
||||
if(!result) {
|
||||
$('.normal_edit').remove();
|
||||
}
|
||||
}else {
|
||||
$('.normal_edit').remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,662 @@
|
||||
/*
|
||||
* pix主题音乐播放器
|
||||
*/
|
||||
|
||||
var rem=[];
|
||||
rem.audio = $('<audio id="pix_player"></audio>');
|
||||
|
||||
var audiobox = $('<audio id="pix_player"></audio>');
|
||||
var au = $('#pix_player');
|
||||
var volume = 1;
|
||||
var loop = Theme.play.m_loop;
|
||||
var playlist = [];
|
||||
var post_playlist = [];
|
||||
var Paused = true;
|
||||
var playLrc = '';
|
||||
|
||||
var m_cover = $('.player_mod .m_cover img');
|
||||
var m_title = $('.player_mod .m_info h2');
|
||||
var m_artist = $('.player_mod .m_info small');
|
||||
|
||||
|
||||
$(document).on('click','.play_btn',function(){
|
||||
$('.player_box').append(audiobox);
|
||||
$('.pix_player').removeClass('playing');
|
||||
$(this).parents('.pix_player').addClass('playing');
|
||||
var url = $(this).attr('data');
|
||||
var lrc = $(this).attr('lrc');
|
||||
var audio_s = $('#pix_player').attr('src');
|
||||
//var play = new Audio(url);
|
||||
|
||||
var meta = $(this).siblings('.player_meta').find('.title');
|
||||
playLrc = lrc;
|
||||
m_title.text(meta.find('.name').text());
|
||||
m_artist.text(meta.find('.author').text());
|
||||
m_cover.attr('src',$('.pix_player.playing .player_thum img').attr('src'));
|
||||
|
||||
if(audio_s == '' || audio_s !== url){
|
||||
$('#pix_player').attr('src',url);
|
||||
audiobox[0].play();
|
||||
} else {
|
||||
pasued();
|
||||
}
|
||||
|
||||
$(".play_btn").html("<i class='ri-play-line'></i>");
|
||||
|
||||
initAudio();
|
||||
});
|
||||
|
||||
// 初始化函数
|
||||
function initAudio(){
|
||||
|
||||
// 给音乐标签绑定事件之后所触发的函数
|
||||
audiobox[0].addEventListener("play",audioplay);
|
||||
audiobox[0].addEventListener("pause",audiopause);
|
||||
// timeupdate,代表音乐播放过程中只要发生变化就触发updateProcess
|
||||
audiobox[0].addEventListener("timeupdate",updateProcess);
|
||||
if(Theme.bgm_open == true){
|
||||
audiobox[0].addEventListener("ended",endplay);
|
||||
}
|
||||
}
|
||||
|
||||
//音乐结束触发
|
||||
function endplay(){
|
||||
var index = $('.musci_list_box li.active').index() + 1;
|
||||
var max = $('.musci_list_box li').length;
|
||||
var new_mid = 0;
|
||||
if(loop=="one"){
|
||||
new_mid = index-1;
|
||||
}else if(loop=="none") {
|
||||
new_mid = (Math.floor(Math.random() * max) + 1)-1;
|
||||
}else if(loop=="all") {
|
||||
new_mid = index > (max - 1) ? 0 : index;
|
||||
}
|
||||
mulist_play(new_mid);
|
||||
}
|
||||
|
||||
// 当音乐标签加载完成之后所触发的函数
|
||||
audiobox[0].oncanplay=function(){
|
||||
// 音乐的总时间
|
||||
var duration=handleTime(this.duration);
|
||||
// 音乐播放的当前时间
|
||||
var currenttime=handleTime(this.currentTime);
|
||||
$(".timer .total_time").text(duration);
|
||||
$(".timer .current_time").text(currenttime);
|
||||
initAudio();
|
||||
}
|
||||
|
||||
// 音乐播放暂停的函数
|
||||
function pasued(){
|
||||
// paused,保存音乐播放和暂停的状态
|
||||
if(Paused === false){//音乐是一个播放状态
|
||||
audiobox[0].pause();
|
||||
}else{
|
||||
audiobox[0].play();
|
||||
}
|
||||
}
|
||||
|
||||
// 音乐播放之后触发的函数
|
||||
function audioplay(){
|
||||
//var height = $('.footer_menu').height();
|
||||
var mheight = $('.footer_nav_box').height();
|
||||
$('.footer_nav_box').animate({top:-mheight},200,'linear');
|
||||
//music_bar.lock(false);//取消进度条的锁定
|
||||
Paused=false;//更新音乐的播放状态(暂停)
|
||||
$(".pix_player.playing .play_btn").html("<i class='ri-pause-line'></i>");//暂停按钮
|
||||
$('.m_play').html('<i class="ri-pause-circle-fill"></i>');
|
||||
}
|
||||
|
||||
// 音乐暂停之后触发的函数
|
||||
function audiopause(){
|
||||
//music_bar.lock(true);//添加进度条的锁定
|
||||
Paused=true; //播放的状态
|
||||
$(".pix_player.playing .play_btn").html("<i class='ri-play-line'></i>");
|
||||
$('.m_play').html('<i class="ri-play-circle-fill"></i>');
|
||||
}
|
||||
|
||||
// 更新进度条
|
||||
function updateProcess(){
|
||||
// 如果音乐不是暂停状态,则继续执行函数的代码块
|
||||
if(Paused!==false) return true;
|
||||
// 音乐的总时间
|
||||
var duration = handleTime(this.duration);
|
||||
// 音乐播放的当前时间
|
||||
var currenttime = handleTime(this.currentTime);
|
||||
var percent = audiobox[0].currentTime/audiobox[0].duration;
|
||||
$(".player_mod .player_bar .progress").css('width',(percent)*100+"%");
|
||||
$(".timer .total_time").text(duration);
|
||||
$(".timer .current_time").text(currenttime);
|
||||
}
|
||||
|
||||
//循环歌曲 m_loop
|
||||
$(document).on('click','.m_loop',function(){
|
||||
if($(this).hasClass('all')){ // 如果当前是循环
|
||||
$(this).removeClass('all');
|
||||
$(this).addClass('one');
|
||||
$(this).html('<i class="ri-repeat-one-line"></i>');
|
||||
loop = 'one';
|
||||
}else if(($(this).hasClass('one'))){ // 如果当前是单曲循环
|
||||
$(this).removeClass('one');
|
||||
$(this).addClass('none');
|
||||
$(this).html('<i class="ri-shuffle-line"></i>');
|
||||
loop = 'none';
|
||||
}else {
|
||||
$(this).removeClass('none');
|
||||
$(this).addClass('all');
|
||||
$(this).html('<i class="ri-repeat-line"></i>');
|
||||
loop = 'all';
|
||||
}
|
||||
});
|
||||
|
||||
// 时间处理的函数
|
||||
function handleTime(seconedTime){
|
||||
// 定义一个变量保存分钟
|
||||
var minute=parseInt(seconedTime/60,10);
|
||||
if(minute<10){minute="0"+minute};
|
||||
//console.log(minute);
|
||||
// 定义变量存放秒数
|
||||
var second=(seconedTime-minute*60).toFixed(2).split(".")[0];
|
||||
//console.log(second);
|
||||
if(second<10){second="0"+second};
|
||||
var Time=minute+":"+second;
|
||||
// 返回最终的时间数值
|
||||
return Time;
|
||||
}
|
||||
|
||||
//视频播放
|
||||
var video = $('#pix_video_player');
|
||||
$(document).on('click','.video_play_btn',function(){
|
||||
var video = $(this).siblings('#pix_video_player');
|
||||
video.attr('controls','controls'); //显示控制条
|
||||
$(this).remove(); //去除覆盖层
|
||||
video[0].play();
|
||||
});
|
||||
|
||||
function stopOtherMedia(element) {
|
||||
|
||||
$("video").not(element).each(function(index, video) {
|
||||
video.pause();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//背景音乐
|
||||
function autoload_music() {
|
||||
var state = Theme.bgm_open;
|
||||
var api = `${Theme.play.pix_mu_api || 'https://api.i-meto.com/meting/api'}?server=:server&type=:type&id=:id&r=:r`
|
||||
var meta = {
|
||||
server : Theme.play.mu_source,
|
||||
type : Theme.play.mu_type,
|
||||
id : Theme.play.play_id,
|
||||
auth : ''
|
||||
}
|
||||
if(state == true){
|
||||
let url = api.replace(":server", meta.server).replace(":type", meta.type).replace(":id", meta.id).replace(":auth", meta.auth).replace(":r", Math.random());
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url:url,
|
||||
success: function (res) {
|
||||
if(res.length > 0){
|
||||
var new_mid = 0;
|
||||
if(loop=="none") {
|
||||
new_mid = (Math.floor(Math.random() * res.length) + 1)-1;
|
||||
}
|
||||
var f = res[new_mid];
|
||||
var playnum = 1;
|
||||
//$(".m_play").html('<i class="ri-pause-circle-line"></i>');
|
||||
|
||||
//默认播放第一首
|
||||
audiobox.attr('src',f.url);
|
||||
playLrc = f.lrc;
|
||||
$('.player_mod .m_cover img').attr('src',f.pic);
|
||||
$('.player_mod .m_info h2').text(f.title || f.name);
|
||||
$('.player_mod .m_info small').text(f.author || f.artist);
|
||||
$('.player_box').append(audiobox);
|
||||
|
||||
|
||||
//存储一个播放列表
|
||||
playlist.push(res);
|
||||
|
||||
//插入播放列表
|
||||
$.each(res, function(key, data) {
|
||||
$(".musci_list_box").append('<li class="item" id='+ key +'>' + playnum++ + '. ' + (data.title || data.name) + ' - ' + (data.author || data.artist) + '</li>');
|
||||
});
|
||||
|
||||
$(".musci_list_box li").removeClass('active').eq(new_mid).addClass('active');
|
||||
//console.log(playlist);
|
||||
} else {
|
||||
$(".musci_list_box").append('<div class="nodata">背景音乐未设置</div>');
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//播放选中音乐
|
||||
function mulist_play(index){
|
||||
audiobox[0].removeEventListener("play",audioplay);
|
||||
audiobox[0].removeEventListener("pause",audiopause);
|
||||
$(".pix_player.playing .play_btn").html("<i class='ri-play-line'></i>");
|
||||
$(".m_play").html('<i class="ri-pause-circle-fill"></i>');
|
||||
$('.musci_list_box li').eq(index).addClass('active').siblings().removeClass('active');
|
||||
scrollToPosition(index);
|
||||
var data = playlist[0][index];
|
||||
playLrc = data.lrc;
|
||||
audiobox.attr('src',data.url);
|
||||
m_cover.attr('src',data.pic);
|
||||
m_title.text(data.title || data.name);
|
||||
m_artist.text(data.author || data.artist);
|
||||
audiobox[0].play();
|
||||
|
||||
Paused = false;
|
||||
}
|
||||
|
||||
//点击展开播放列表
|
||||
$(document).on('click', '.ri-bar-chart-horizontal-line', function () {
|
||||
var position = $('.musci_list_box li.active').index()
|
||||
// 延迟一段时间后进行滚动
|
||||
setTimeout(function () {
|
||||
if($('.m_list').attr('aria-expanded')){
|
||||
scrollToPosition(position)
|
||||
}
|
||||
}, 200); // 延迟100毫秒后执行滚动操作
|
||||
});
|
||||
|
||||
//点击列表播放
|
||||
$(document).on('click','.musci_list_box li',function(){
|
||||
$('.musci_list_box li').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
var id = $(this).attr('id');
|
||||
mulist_play(id)
|
||||
});
|
||||
|
||||
//上一首
|
||||
$(document).on('click','.m_prev',function(){
|
||||
var index = $('.musci_list_box li.active').index() - 1;
|
||||
var max = $('.musci_list_box li').length;
|
||||
var new_mid = 0;
|
||||
if(loop=="none") {
|
||||
new_mid = (Math.floor(Math.random() * max) + 1)-1;
|
||||
}else {
|
||||
new_mid = index < 0 ? max - 1 : index;
|
||||
}
|
||||
mulist_play(new_mid);
|
||||
});
|
||||
|
||||
//下一首
|
||||
$(document).on('click','.m_next',function(){
|
||||
var index = $('.musci_list_box li.active').index() + 1;
|
||||
var max = $('.musci_list_box li').length;
|
||||
var new_mid = 0;
|
||||
if(loop=="none") {
|
||||
new_mid = (Math.floor(Math.random() * max) + 1)-1;
|
||||
}else{
|
||||
new_mid = index > (max - 1) ? 0 : index;
|
||||
}
|
||||
mulist_play(new_mid);
|
||||
});
|
||||
|
||||
|
||||
//播放和暂停
|
||||
function m_play() {
|
||||
|
||||
if(Paused === false){//音乐是一个播放状态
|
||||
audiobox[0].pause();
|
||||
$('.m_play').html('<i class="ri-play-circle-fill"></i>');
|
||||
Paused = true;
|
||||
}else{
|
||||
audiobox[0].play();
|
||||
$('.m_play').html('<i class="ri-pause-circle-fill"></i>');
|
||||
Paused = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//播放按钮
|
||||
$(document).on('click','.m_play',function(){
|
||||
if(!$("#pix_player").length > 0){
|
||||
cocoMessage.error('没有音乐可播放');
|
||||
return false;
|
||||
} else {
|
||||
m_play();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
document.addEventListener('click', musicPlay);
|
||||
function musicPlay() {
|
||||
audiobox[0].play();
|
||||
document.removeEventListener('click', musicPlay);
|
||||
}
|
||||
*/
|
||||
|
||||
//触发显示播放器
|
||||
var trigger;
|
||||
function mu_box_show(){
|
||||
clearTimeout(trigger);
|
||||
var mheight = $('.footer_nav_box').height();
|
||||
$('.footer_nav_box').animate({top:-mheight},200,'linear');
|
||||
}
|
||||
|
||||
function mu_box_hide(){
|
||||
$('.footer_nav_box').animate({top:"0px"},200,'linear');
|
||||
}
|
||||
|
||||
$(document).on('mouseenter', '.player_hand , .footer_nav_box', function(event) {
|
||||
mu_box_show();
|
||||
|
||||
});
|
||||
|
||||
$(document).on('mouseleave', '.footer_nav_box .right_inner', function(event) {
|
||||
|
||||
trigger = setTimeout(function(){
|
||||
mu_box_hide();
|
||||
},2000);
|
||||
|
||||
});
|
||||
|
||||
//音乐进度条跳转
|
||||
function getMousePosition(e){
|
||||
var e = e || window.event;
|
||||
var x = e.pageX;
|
||||
var y = e.pageY;
|
||||
return {'left':x,'top':y}
|
||||
}
|
||||
|
||||
$(document).on('click','.player_bar',function(){
|
||||
// 获取当前鼠标点击的位置
|
||||
// console.log(getMousePosition().left)
|
||||
// console.log($('.progress').offset())
|
||||
var long = (getMousePosition().left) - ($('.progress').offset().left);
|
||||
// console.log(long)
|
||||
// 将当前点击的长度重新给p标签
|
||||
$('.progress').width(long);
|
||||
// 获得当前点击长度的时间
|
||||
allTime = parseInt(audiobox[0].duration);
|
||||
var nowtime = (long/$('.player_bar').width()) * allTime;
|
||||
audiobox[0].currentTime = nowtime;
|
||||
});
|
||||
|
||||
|
||||
//音量调节 m_volume
|
||||
$(document).on('click','.m_volume',function(){
|
||||
if($(this).hasClass('mute')){ // 如果当前是静音
|
||||
$(this).removeClass('mute');
|
||||
$(this).html('<i class="ri-volume-down-line"></i>');
|
||||
audiobox[0].muted = false;
|
||||
}else{ // 如果当前不是静音
|
||||
$(this).addClass('mute');
|
||||
audiobox[0].muted = true;
|
||||
$(this).html('<i class="ri-volume-mute-line"></i>');
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('click','.vo_bar',function(){
|
||||
var long = (getMousePosition().top) - ($(this).offset().top)
|
||||
|
||||
var meter = long / $(this).height();
|
||||
var finalLong = 1 - meter;
|
||||
|
||||
$('.vo_size').height(finalLong * $(this).height());
|
||||
|
||||
// 将audio音量调整为对应的音量
|
||||
//var finalLong = volume;
|
||||
audiobox[0].volume = finalLong;
|
||||
|
||||
// 改变数字
|
||||
//$('.vol b').html(parseInt(finalLong * 100) + '%')
|
||||
|
||||
// 点击后音量调整键隐藏
|
||||
//$('.vol a').css('display','none')
|
||||
|
||||
});
|
||||
|
||||
//文章歌曲
|
||||
function autoload_posts_music() {
|
||||
post_playlist.splice(0,post_playlist.length);
|
||||
var pid = $('.posts_mu_list').attr('pid');
|
||||
var api = `${Theme.play.pix_mu_api || 'https://api.i-meto.com/meting/api'}?server=:server&type=:type&id=:id&r=:r`
|
||||
var meta = {
|
||||
server : $('.posts_mu_list').attr('mus_source'),
|
||||
type : $('.posts_mu_list').attr('mus_type'),
|
||||
id : $('.posts_mu_list').attr('plays_id'),
|
||||
mu_on: $('.posts_mu_list').attr('mu_on'),
|
||||
auth : ''
|
||||
}
|
||||
if(pid && meta.mu_on=='true'){
|
||||
let url = api.replace(":server", meta.server).replace(":type", meta.type).replace(":id", meta.id).replace(":auth", meta.auth).replace(":r", Math.random());
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url:url,
|
||||
beforeSend: function () {
|
||||
$('.posts_mu_list').html('<div class="loading_box"><div uk-spinner></div></div>');
|
||||
},
|
||||
success: function (res) {
|
||||
|
||||
if(res.length > 0){
|
||||
$('.posts_mu_list .loading_box').remove();
|
||||
|
||||
var playnum = 1;
|
||||
|
||||
if(!$('#pix_player').length > 0){
|
||||
$('.player_box').append(audiobox);
|
||||
}
|
||||
|
||||
|
||||
//存储一个播放列表
|
||||
post_playlist.push(res);
|
||||
|
||||
//插入播放列表
|
||||
$.each(res, function(key, data) {
|
||||
$(".posts_mu_list").append('<li class="item" id='+ key +'><div class="mu_id">' + playnum++ + '</div><a class="s_play_btn"><i class="ri-play-circle-line"></i></a><div class="mus_info">'+ (data.title || data.name) +' <span>- ' + (data.author || data.artist) + '</span></div></li>');
|
||||
|
||||
});
|
||||
|
||||
//$(".musci_list_box li").removeClass('active').eq(0).addClass('active');
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//文章歌曲播放
|
||||
$(document).on('click','.s_play_btn',function(){
|
||||
mu_box_show();
|
||||
$('.posts_mu_list li').removeClass('active');
|
||||
audiobox[0].removeEventListener("play",audioplay);
|
||||
audiobox[0].removeEventListener("pause",audiopause);
|
||||
$(".m_play").html('<i class="ri-pause-circle-fill"></i>');
|
||||
$(this).parent().addClass('active');
|
||||
|
||||
var id = $(this).parents('li').attr('id');
|
||||
var data = post_playlist[0][id];
|
||||
playLrc = data.lrc;
|
||||
audiobox.attr('src',data.url);
|
||||
m_cover.attr('src',data.pic);
|
||||
m_title.text(data.title || data.name);
|
||||
m_artist.text(data.artist || data.artist);
|
||||
audiobox[0].play();
|
||||
|
||||
Paused = false;
|
||||
});
|
||||
|
||||
//播放器按钮
|
||||
$(document).on('click','a.bg_music',function(){
|
||||
mu_box_show();
|
||||
});
|
||||
|
||||
|
||||
|
||||
$(function () {
|
||||
autoload_music();
|
||||
autoload_posts_music();
|
||||
});
|
||||
|
||||
//播放类型切换
|
||||
$(document).on('click','.audio_c_btn',function(){
|
||||
var type = $(this).attr('au_type');
|
||||
var input = $('<input type="text" placeholder="歌曲ID" name="moment_audio_api" id="moment_audio_api" class="required" required="required">');
|
||||
$('.type_audio_text').empty();
|
||||
$('.'+type+'_audio.type_audio_text').append(input);
|
||||
});
|
||||
|
||||
|
||||
$('.bg_lrc').click(function () {
|
||||
if (lyricsContainer.css('display') === 'none') {
|
||||
lyricsContainer.css('display', 'block');
|
||||
$('a.bg_lrc i').css({
|
||||
"color": "",
|
||||
});
|
||||
$('a.bg_lrc').css({
|
||||
"background": "",
|
||||
});
|
||||
} else {
|
||||
lyricsContainer.css('display', 'none');
|
||||
$('a.bg_lrc i').css({
|
||||
"color": "#aeaeae",
|
||||
});
|
||||
$('a.bg_lrc').css({
|
||||
"background": "rgb(196 208 230 / 38%)",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//创建容器
|
||||
if(Theme.play.lrc_open){
|
||||
var lyricsContainer = $('<div class="lyrics-container"></div>');
|
||||
$('.player_box').append(lyricsContainer);
|
||||
var css = $(window).width() > 767 ?
|
||||
{
|
||||
//桌面歌词css(按照下面格式自行修改)
|
||||
position: 'fixed',
|
||||
bottom: '10px',
|
||||
left: '2%',
|
||||
width: '350px',
|
||||
height: '100px',
|
||||
overflow: 'hidden',
|
||||
zIndex: '999',
|
||||
pointerEvents: 'none',
|
||||
} :
|
||||
{
|
||||
//移动端歌词css(按照下面格式自行修改)
|
||||
position: 'fixed',
|
||||
bottom: '88px',
|
||||
left: '0',
|
||||
width: '100%',
|
||||
height: '72px',
|
||||
textAlign: 'center',
|
||||
overflow: 'hidden',
|
||||
zIndex: '999',
|
||||
pointerEvents: 'none',
|
||||
};
|
||||
lyricsContainer.css(css);
|
||||
}
|
||||
|
||||
var lyricsMap = {};
|
||||
|
||||
// 获取歌词
|
||||
async function fetchLyrics(url) {
|
||||
if (!lyricsMap[url]) {
|
||||
var lrcOriginal = await $.get(url);
|
||||
lyricsMap[url] = parseLyrics(lrcOriginal);
|
||||
}
|
||||
return lyricsMap[url];
|
||||
}
|
||||
|
||||
// 解析歌词
|
||||
function parseLyrics(lrcOriginal) {
|
||||
var lyrics = [];
|
||||
var lines = lrcOriginal.split("\n");
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var line = lines[i];
|
||||
if (!line.trim()) {
|
||||
continue;
|
||||
}
|
||||
var timeAndText = line.split("]");
|
||||
var time = timeAndText[0].substr(1);
|
||||
var text = timeAndText[1];
|
||||
// 增加代码:如果歌词为空,跳过此次循环
|
||||
if (!text.trim()) {
|
||||
continue;
|
||||
}
|
||||
// 增加代码:把时间转换成秒
|
||||
var timeInSeconds = 0;
|
||||
var timeParts = time.split(":");
|
||||
timeInSeconds += parseInt(timeParts[0], 10) * 60 - 0.5;
|
||||
timeInSeconds += parseFloat(timeParts[1]);
|
||||
lyrics.push({
|
||||
time: timeInSeconds,
|
||||
text: text
|
||||
});
|
||||
}
|
||||
return lyrics;
|
||||
}
|
||||
|
||||
// 更新歌词
|
||||
function updateLyrics(currentTime, lyrics) {
|
||||
for (var i = 0; i < lyrics.length; i++) {
|
||||
if (currentTime >= lyrics[i].time && (i === lyrics.length - 1 || currentTime < lyrics[i + 1].time)) {
|
||||
// 创建4行歌词
|
||||
// 防止数组i越界
|
||||
var currentLine3 = "";
|
||||
if (i - 1 >= 0 && typeof lyrics[i - 1].text === "string") {
|
||||
currentLine3 = lyrics[i - 1].text;
|
||||
}
|
||||
var currentLine = "";
|
||||
if (typeof lyrics[i].text === "string") {
|
||||
currentLine = lyrics[i].text;
|
||||
}
|
||||
var currentLine1 = "";
|
||||
if (i + 1 < lyrics.length && typeof lyrics[i + 1].text === "string") {
|
||||
currentLine1 = lyrics[i + 1].text;
|
||||
}
|
||||
var currentLine2 = "";
|
||||
if (i + 2 < lyrics.length && typeof lyrics[i + 2].text === "string") {
|
||||
currentLine2 = lyrics[i + 2].text;
|
||||
}
|
||||
//歌词文本css(修改style内的内容即可)
|
||||
lyricsContainer.html(`
|
||||
<div class="current-line" style="font-size: 10px;opacity: .4;">${currentLine3}</div>
|
||||
<div class="current-line active" style="font-size: 14px;">${currentLine}</div>
|
||||
<div class="current-line" style="font-size: 12px;opacity: .4;">${currentLine1}</div>
|
||||
<div class="current-line" style="font-size: 10px;opacity: .1;">${currentLine2}</div>
|
||||
`);
|
||||
// 增加代码:添加从下往上线性滚动的动画
|
||||
$('.current-line').animate({
|
||||
top: '-=30px'
|
||||
}, 2000, function () {
|
||||
$(this).css({
|
||||
top: '30px'
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 监听音频播放进度更新事件,更新歌词
|
||||
Theme.play.lrc_open && audiobox[0].addEventListener("timeupdate", async function () {
|
||||
var lyrics = await fetchLyrics(playLrc)
|
||||
updateLyrics(this.currentTime, lyrics);
|
||||
});
|
||||
|
||||
// 根据选择的位置定位滚动条
|
||||
function scrollToPosition(position) {
|
||||
let container = document.getElementById("musci_list");
|
||||
let items = container.getElementsByClassName("item");
|
||||
|
||||
if (position >= 0 && position < items.length) {
|
||||
items[position].scrollIntoView();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,418 @@
|
||||
// 部分代码来自ZIBILL主题作者
|
||||
// canvas生成海报
|
||||
const poster = (function() {
|
||||
|
||||
const DEBUG = false
|
||||
|
||||
const WIDTH = 700
|
||||
const HEIGHT = 1160
|
||||
|
||||
function init(config) {
|
||||
const $container = document.querySelector(config.selector)
|
||||
$container.style.border = '1px solid #f0f0f0'
|
||||
const $wrapper = createDom('div', 'id', 'wrapper')
|
||||
const $canvas = createDom('canvas', 'id', 'canvas', 'block')
|
||||
const $day = createDom('canvas', 'id', 'day')
|
||||
const $date = createDom('canvas', 'id', 'date')
|
||||
const $title = createDom('canvas', 'id', 'title')
|
||||
const $content = createDom('canvas', 'id', 'content')
|
||||
const $logo = createDom('canvas', 'id', 'logo')
|
||||
const $description = createDom('canvas', 'id', 'description')
|
||||
|
||||
appendChilds($wrapper, $canvas, $day, $date, $title, $content, $logo, $description)
|
||||
$container.appendChild($wrapper)
|
||||
|
||||
const date = new Date()
|
||||
|
||||
// day
|
||||
const dayStyle = {
|
||||
font: 'bold 80px Helvetica',
|
||||
color: 'rgba(255, 255, 255, 1)',
|
||||
position: 'right'
|
||||
}
|
||||
drawOneline($day, dayStyle, date.getDate());
|
||||
|
||||
// date
|
||||
const dateStyle = {
|
||||
font: '23px Helvetica',
|
||||
color: 'rgba(255, 255, 255, 1)',
|
||||
position: 'right'
|
||||
}
|
||||
drawOneline($date, dateStyle, date.getFullYear() + '/' + (date.getMonth() + 1))
|
||||
|
||||
// title canvas
|
||||
const titleStyle = {
|
||||
font: '30px Helvetica',
|
||||
lineHeight: 1.5,
|
||||
color: 'rgba(255, 255, 255, 1)',
|
||||
length: 2,
|
||||
position: 'left'
|
||||
}
|
||||
titleStyle.font = (config.titleStyle && config.titleStyle.font) || titleStyle.font
|
||||
titleStyle.color = (config.titleStyle && config.titleStyle.color) || titleStyle.color
|
||||
titleStyle.position = (config.titleStyle && config.titleStyle.position) || titleStyle.position
|
||||
drawMoreLines($title, titleStyle, config.title)
|
||||
|
||||
// content canvas
|
||||
const contentStyle = {
|
||||
font: '22px Helvetica',
|
||||
lineHeight: 1.5,
|
||||
position: 'left',
|
||||
color: 'rgba(236, 241, 255, 1)'
|
||||
}
|
||||
contentStyle.font = (config.contentStyle && config.contentStyle.font) || contentStyle.font
|
||||
contentStyle.color = (config.contentStyle && config.contentStyle.color) || contentStyle.color
|
||||
contentStyle.lineHeight = (config.contentStyle && config.contentStyle.lineHeight) || contentStyle.lineHeight
|
||||
contentStyle.position = (config.contentStyle && config.contentStyle.position) || contentStyle.position
|
||||
drawMoreLines($content, contentStyle, config.content);
|
||||
|
||||
// description
|
||||
const descriptionStyle = {
|
||||
font: '24px Helvetica',
|
||||
color: 'rgba(180, 180, 180, 1)',
|
||||
lineHeight: 1.2,
|
||||
position: 'left'
|
||||
}
|
||||
drawMoreLines($description, descriptionStyle, config.description)
|
||||
|
||||
|
||||
// background image
|
||||
const image = new Image();
|
||||
image.crossOrigin = "Anonymous";
|
||||
|
||||
//logo
|
||||
const logo = new Image();
|
||||
logo.crossOrigin = "Anonymous";
|
||||
logo.src = config.logo;
|
||||
|
||||
//qrcode
|
||||
const qrcode = new Image();
|
||||
qrcode.src = config.qrcode;
|
||||
|
||||
|
||||
const onload = function() {
|
||||
$canvas.width = WIDTH;
|
||||
$canvas.height = HEIGHT;
|
||||
image.src = config.banner;
|
||||
image.onload = function() {
|
||||
const ctx = $canvas.getContext('2d')
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 1)';
|
||||
ctx.fillRect(0, 0, $canvas.width, $canvas.height);
|
||||
|
||||
// banner
|
||||
imgRect = coverImg($canvas.width - 40, $canvas.height / 1.2 - 40, image.width, image.height);
|
||||
ctx.drawImage(image, imgRect.sx, imgRect.sy, imgRect.sWidth, imgRect.sHeight, 20, 20, $canvas.width - 40, $canvas.height / 1.2 - 40);
|
||||
|
||||
//覆盖层
|
||||
ctx.fillStyle="rgba(0, 0, 0, 0.3)";
|
||||
ctx.fillRect(20,20,$canvas.width - 40,$canvas.height / 1.2 - 40);
|
||||
|
||||
// 时间
|
||||
ctx.drawImage($day, -20, 50)
|
||||
ctx.drawImage($date, -21, 125)
|
||||
|
||||
//logo
|
||||
var logowidth = logo.width;
|
||||
var logoheight = logo.height;
|
||||
var scale = logowidth / logoheight;
|
||||
var logoh = 60;
|
||||
var cwidth = logoh * scale;
|
||||
ctx.drawImage(logo, 60, $canvas.height / 1.2 + 30, cwidth, logoh);
|
||||
|
||||
ctx.drawImage(qrcode, $canvas.width - 160, $canvas.height / 1.2 + 20, 120, 120);
|
||||
|
||||
//标题文字
|
||||
ctx.drawImage($title, 20, $canvas.height / 2 + 20)
|
||||
ctx.drawImage($content, 20, $canvas.height / 2 + 120)
|
||||
ctx.drawImage($description, 20, $canvas.height / 1.2 + 110)
|
||||
ctx.strokeStyle = 'rgba(122, 122, 122, 0.5)';
|
||||
|
||||
const img = new Image();
|
||||
img.crossOrigin = "Anonymous";
|
||||
img.src = $canvas.toDataURL('image/png')
|
||||
const radio = config.radio || 0.7
|
||||
img.width = WIDTH * radio
|
||||
img.height = HEIGHT * radio
|
||||
img.className = 'poster_load';
|
||||
ctx.clearRect(0, 0, $canvas.width, $canvas.height)
|
||||
$canvas.style.display = 'none'
|
||||
|
||||
if ($container.querySelector('.poster_load')) {
|
||||
$container.querySelector('.poster_load').src = img.src;
|
||||
} else {
|
||||
$container.appendChild(img);
|
||||
}
|
||||
|
||||
$container.appendChild(img);
|
||||
$container.removeChild($wrapper)
|
||||
if (config.callback) {
|
||||
config.callback($container)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onload()
|
||||
}
|
||||
|
||||
//裁切
|
||||
function containImg(sx, sy, box_w, box_h, source_w, source_h) {
|
||||
var dx = sx,
|
||||
dy = sy,
|
||||
dWidth = box_w,
|
||||
dHeight = box_h;
|
||||
if (source_w > source_h || (source_w == source_h && box_w < box_h)) {
|
||||
dHeight = source_h * dWidth / source_w;
|
||||
dy = sy + (box_h - dHeight) / 2;
|
||||
|
||||
} else if (source_w < source_h || (source_w == source_h && box_w > box_h)) {
|
||||
dWidth = source_w * dHeight / source_h;
|
||||
dx = sx + (box_w - dWidth) / 2;
|
||||
}
|
||||
return {
|
||||
dx,
|
||||
dy,
|
||||
dWidth,
|
||||
dHeight
|
||||
}
|
||||
}
|
||||
|
||||
function coverImg(box_w, box_h, source_w, source_h) {
|
||||
var sx = 0,
|
||||
sy = 0,
|
||||
sWidth = source_w,
|
||||
sHeight = source_h;
|
||||
if (source_w > source_h || (source_w == source_h && box_w < box_h)) {
|
||||
sWidth = box_w * sHeight / box_h;
|
||||
sx = (source_w - sWidth) / 2;
|
||||
} else if (source_w < source_h || (source_w == source_h && box_w > box_h)) {
|
||||
sHeight = box_h * sWidth / box_w;
|
||||
sy = (source_h - sHeight) / 2;
|
||||
}
|
||||
return {
|
||||
sx,
|
||||
sy,
|
||||
sWidth,
|
||||
sHeight
|
||||
}
|
||||
}
|
||||
|
||||
function createDom(name, key, value, display = 'none') {
|
||||
const $dom = document.createElement(name)
|
||||
$dom.setAttribute(key, value)
|
||||
$dom.style.display = display
|
||||
$dom.width = WIDTH
|
||||
return $dom
|
||||
}
|
||||
|
||||
function appendChilds(parent, ...doms) {
|
||||
doms.forEach(dom => {
|
||||
parent.appendChild(dom)
|
||||
})
|
||||
}
|
||||
|
||||
function drawOneline(canvas, style, content) {
|
||||
const ctx = canvas.getContext('2d')
|
||||
canvas.height = parseInt(style.font.match(/\d+/), 10) + 20
|
||||
ctx.font = style.font
|
||||
ctx.fillStyle = style.color
|
||||
ctx.textBaseline = 'top'
|
||||
|
||||
let lineWidth = 0
|
||||
let idx = 0
|
||||
let truncated = false
|
||||
for (let i = 0; i < content.length; i++) {
|
||||
lineWidth += ctx.measureText(content[i]).width;
|
||||
if (lineWidth > canvas.width - 60) {
|
||||
truncated = true
|
||||
idx = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
let padding = 30
|
||||
|
||||
if (truncated) {
|
||||
content = content.substring(0, idx)
|
||||
padding = canvas.width / 2 - lineWidth / 2
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
ctx.strokeStyle = "#6fda92";
|
||||
ctx.strokeRect(0, 0, canvas.width, canvas.height);
|
||||
}
|
||||
|
||||
if (style.position === 'center') {
|
||||
ctx.textAlign = 'center';
|
||||
ctx.fillText(content, canvas.width / 2, 0)
|
||||
} else if (style.position === 'left') {
|
||||
ctx.fillText(content, padding, 0)
|
||||
} else {
|
||||
ctx.textAlign = 'right'
|
||||
ctx.fillText(content, canvas.width - padding, 0)
|
||||
}
|
||||
}
|
||||
|
||||
function drawMoreLines(canvas, style, content) {
|
||||
const ctx = canvas.getContext('2d')
|
||||
const fontHeight = parseInt(style.font.match(/\d+/), 10)
|
||||
|
||||
if (DEBUG) {
|
||||
ctx.strokeStyle = "#6fda92";
|
||||
ctx.strokeRect(0, 0, canvas.width, canvas.height);
|
||||
}
|
||||
|
||||
ctx.font = style.font
|
||||
ctx.fillStyle = style.color
|
||||
ctx.textBaseline = 'top'
|
||||
ctx.textAlign = 'center'
|
||||
|
||||
let alignX = 0
|
||||
|
||||
if (style.position === 'center') {
|
||||
alignX = canvas.width / 2;
|
||||
} else if (style.position === 'left') {
|
||||
ctx.textAlign = 'left'
|
||||
alignX = 40
|
||||
} else {
|
||||
ctx.textAlign = 'right'
|
||||
alignX = canvas.width - 40
|
||||
}
|
||||
|
||||
let lineWidth = 0
|
||||
let lastSubStrIndex = 0
|
||||
let offsetY = 0
|
||||
for (let i = 0; i < content.length; i++) {
|
||||
lineWidth += ctx.measureText(content[i]).width;
|
||||
if (lineWidth > canvas.width - 120) {
|
||||
ctx.fillText(content.substring(lastSubStrIndex, i), alignX, offsetY);
|
||||
offsetY += fontHeight * style.lineHeight
|
||||
lineWidth = 0
|
||||
lastSubStrIndex = i
|
||||
}
|
||||
if (i === content.length - 1) {
|
||||
ctx.fillText(content.substring(lastSubStrIndex, i + 1), alignX, offsetY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
init
|
||||
}
|
||||
})()
|
||||
|
||||
|
||||
|
||||
|
||||
//ajax生成文章海报
|
||||
$('body').on('click', '.cr_poster', function () {
|
||||
var post_id = $(this).attr('poster-data');
|
||||
var banner = $(this).attr('banner');
|
||||
var single_content = $('.single-content')
|
||||
var t_content = $('#post-'+post_id+' .t_content')
|
||||
var content = single_content.length>0 ? single_content[0].innerText : t_content[0].innerText
|
||||
var content_length = content.length
|
||||
var permalink = t_content.length>0 ? window.location.origin + '/moments/'+post_id : window.location.origin + window.location.pathname;
|
||||
var title = t_content.length>0 ? Theme.site_title+'-瞬间' : document.title;
|
||||
new QRious({ element: document.getElementById("twoCode"), value: permalink, size: 260, });
|
||||
$('.poster_box').remove();
|
||||
$('#share_modal_' + post_id + ' .poster_box_ap').append('<div class="poster_box"></div>');
|
||||
|
||||
if (content_length > 120) {
|
||||
content = content.substring(0, 80) + '...'
|
||||
}
|
||||
|
||||
function Posterdown(e) {
|
||||
if (e == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var modal = '#share_modal_' + post_id;
|
||||
|
||||
var url = $('' + modal + ' .poster_box img').attr('src');
|
||||
$('' + modal + ' .post_share_box').removeClass('hide');
|
||||
$('' + modal + ' .poster_download').attr('href', url).attr('download', 'poster_' + post_id + '.png');
|
||||
}
|
||||
|
||||
$('#share_modal_' + post_id + ' .poster_box').append('<div class="loading_box"><div uk-spinner></div></div>');
|
||||
$('.loading_box').remove();
|
||||
poster.init({
|
||||
banner: banner,
|
||||
selector: '.poster_box',
|
||||
title: title,
|
||||
content: content,
|
||||
logo: Theme.site_logo,
|
||||
qrcode: $('#twoCode').attr('src'),
|
||||
description: Theme.admin_des,
|
||||
callback: Posterdown
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
function convertImgToBase64(url, callback) {
|
||||
var canvas = document.createElement('canvas');
|
||||
var img = new Image();
|
||||
img.crossOrigin = 'Anonymous';
|
||||
img.onload = function () {
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
var ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0);
|
||||
var ext = img.src.substring(img.src.lastIndexOf('.') + 1).toLowerCase();
|
||||
var dataURL = canvas.toDataURL('image/' + ext);
|
||||
callback(dataURL);
|
||||
canvas = null;
|
||||
};
|
||||
img.src = url;
|
||||
}
|
||||
|
||||
|
||||
function handleShare(e, pic, title,pathname) {
|
||||
var permalink = window.location.origin + pathname;
|
||||
switch (e) {
|
||||
case 'wb':
|
||||
var url = `https://service.weibo.com/share/share.php?url=${permalink}&type=button&language=zh_cn&pic=${pic}&title=${title}`
|
||||
window.open(url);
|
||||
break
|
||||
case 'qzone':
|
||||
var url = `https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=${permalink}&title=${title}&pics=${pic}`
|
||||
window.open(url);
|
||||
break
|
||||
case "qq":
|
||||
var url = `http://connect.qq.com/widget/shareqq/index.html?url=${permalink}&title=${title}&pics=${pic}`
|
||||
window.open(url);
|
||||
break;
|
||||
case "copy":
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(permalink).then(function() {
|
||||
cocoMessage.success("链接已复制到剪贴板!");
|
||||
}, function(err) {
|
||||
cocoMessage.error("复制失败,请手动复制链接");
|
||||
});
|
||||
} else {
|
||||
// 兼容旧浏览器
|
||||
var tempInput = document.createElement('input');
|
||||
tempInput.value = permalink;
|
||||
document.body.appendChild(tempInput);
|
||||
tempInput.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
cocoMessage.success("链接已复制到剪贴板!");
|
||||
} catch (err) {
|
||||
cocoMessage.error("复制失败,请手动复制链接");
|
||||
}
|
||||
document.body.removeChild(tempInput);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user