share js 分享代码

摘要:
p[url]='+props.url;打破case'googleplus':url='//plus.google.com/share?url='+props.url;打破case'weibo':url='http://service.weibo.com/share/share.php?url=“+props.url+”&title=“+props.title+”+props.description+“&pic=”+props.img+“&searchPic=false”;打破case'tencentweibo':url='http://share.v.t.qq.com/index.php?c=share&a=index&url=“+props.url+”&title=“+props.description+”&pic='+props.img;打破case'qzone':url='http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=“+props.url+”&title='+props.docTitle+'&summary='+props.description+'&pics='+props.img;中断;}returnurl;}functionaddPlatform(url,platform){varqsReg=/(?[^#.]*)/,hashReg=/,(#.*)/;hasHash=hashReg.test(url),hash='',platform=platform?platform:'copy';if(hasHash){url=url.replace(hashReg,function(macthedHash)}hash=macthedHash;returnmacthed哈希=“”;});}if(qsReg.test(url)){url=url.replace(qsReg,‘$1&amp

(function(){
var $doc = $(document);

var shareHandlers = {
'twitter': function(prop,shareUrl){
var D=550,A=450,C=screen.height,B=screen.width,H=Math.round((B/2)-(D/2)),G=0;
if(C>A){G=Math.round((C/2)-(A/2))}
window.open(shareUrl,'','left='+H+',top='+G+',width='+D+',height='+A+',personalbar=0,toolbar=0,scrollbars=1,resizable=1');
},
'facebook': function(prop,shareUrl){
var D=550,A=450,C=screen.height,B=screen.width,H=Math.round((B/2)-(D/2)),G=0;
if(C>A){G=Math.round((C/2)-(A/2))}
window.open(shareUrl,'','left='+H+',top='+G+',width='+D+',height='+A+',personalbar=0,toolbar=0,scrollbars=1,resizable=1');
},
'googleplus': function(prop,shareUrl){
var D=600,A=460,C=screen.height,B=screen.width,H=Math.round((B/2)-(D/2)),G=0;
if(C>A){G=Math.round((C/2)-(A/2))}
window.open(shareUrl, 'Share to Google+','left='+H+',top='+G+',width='+D+',height='+A+',menubar=no,location=no,status=no');
},
'weibo': null,
'tencentweibo': null,
'qzone': null
}

$doc.on('click', '.sns-share-list .share-btn[data-sns]', shareClickHandler);
$doc.on('click', '.djieventsbtn[data-sns]', shareClickHandler);
$doc.on('click', '.newssharebtn[data-sns]', shareClickHandler);

function shareClickHandler(e){
var $target = $(e.currentTarget),
type = $target.data('sns'),
props = {
id: $target.data('id'),
img: $target.data('img'),
title: $target.data('title'),
description: $target.data('description'),
url: $target.data('url'),
docTitle: document.title
};

//线上环境为裸协议,某些SNS平台解析错误,所以针对这种情况统一使用http协议
if(/^///.test(props.img)){
props.img = 'http:' + props.img;
}

//添加平台追踪链接
props.url = addPlatform(props.url,type);

var shareUrl = getShareUrl(type, props);

if(shareHandlers[type]){
shareHandlers[type](props,shareUrl);
}else{
window.open(shareUrl, '', '');
}
}
function getShareUrl(type, origin_props){
var url = '';

var props = {
id: origin_props.id,
img: encodeURIComponent( origin_props.img ),
title: encodeURIComponent( origin_props.title ),
description: encodeURIComponent( origin_props.description ),
url: encodeURIComponent( origin_props.url ),
docTitle: document.title
};

switch(type){
case 'twitter':
url = '//twitter.com/intent/tweet?url='+ props.url +'&text='+ props.description;
break;
case 'facebook':
url = '//www.facebook.com/sharer/sharer.php?p[url]='+ props.url;
break;
case 'googleplus':
url = '//plus.google.com/share?url='+ props.url;
break;
case 'weibo':
url = 'http://service.weibo.com/share/share.php?url='+ props.url +'&title='+ props.title +' '+ props.description +'&pic='+ props.img +'&searchPic=false';
break;
case 'tencentweibo':
url = 'http://share.v.t.qq.com/index.php?c=share&a=index&url='+ props.url +'&title='+ props.description +'&pic='+ props.img;
break;
case 'qzone':
url = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+ props.url +'&title='+ props.docTitle +'&summary='+ props.description +'&pics='+ props.img;
break;
}

return url;
}

function addPlatform(url,platform){
var qsReg = /(?[^#.]*)/,
hashReg = /(#.*)/,
hasHash = hashReg.test(url),
hash = '',
platform = platform ? platform : 'copy';

if(hasHash){
url = url.replace(hashReg, function(macthedHash){
hash = macthedHash;
return macthedHash = '';
});
}
if(qsReg.test(url)){
url = url.replace(qsReg, '$1&p='+ platform);
} else {
url += '?p='+ platform;
}

return url + hash;
}
$("#apply h3").click(function(){

$(this).next("#apply .boxs").slideToggle("slow")
.siblings("#apply .boxs:visible").slideToggle("slow");
$(this).toggleClass("current");
$(this).siblings("#apply h3").removeClass("current");
return false;
});

})();

免责声明:文章转载自《share js 分享代码》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇中国大推力矢量发动机WS15 跨入 世界先进水平!mybatis-plus下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

requirej入门nodeTpl使用(三)

基本语法 HTML部分 在模板中的 HTML 部分,使用定界符“<?”和“?>”作为语法的开始和结束。 在定界符内,可以书写任意JavaScript语句,如: 1 <?for(var i=0; i<10; i++){?> 2 <p>hello, world</p> 3 <?}?> 使用等...

element+vue显示数据库数据

App.vue <template><div class="app"><div id="heard"><h1>部门统计</h1></div><div id="Statistics"><div id="heard3"><h4>统计项</h4>...

Dart: List排序

var list = <Item>[ Item(title: "item 1", isTopping: true), Item(title: "item 2"), Item(title: "item 3", isTopping: true), Item(title: "item 4"), ]; main(List<Str...

【ExtJS】FormPanel 布局(一)

准备工作,布置一个最简单的Form,共5个组件,都为textfield。 1 Ext.onReady(function(){ 2 Ext.create('Ext.form.Panel', { 3 500, 4 title: 'Layout', 5      renderTo : 'form', 6 items:...

微信小程序开发中怎么设置转发(分享)的信息

如果什么都不设置,转发时默认名称是小程序的名称,转发的图片显示的是当前页面的截图,如图一 如何在自定义转发信息呢? 在进行转发的页面中: Page({ onShareAppMessage: function () { return { title: '做任务赢积分', imageUrl: '/images...

Redis 中 byte格式 写入、取出

实体类: package com.nf.redisDemo1.entity; import java.io.Serializable; public class News implements Serializable { private long id; private String title; private Str...